示例#1
0
 // Have our parent handle deleting tracks
 public override void DeleteTracks(DatabaseTrackListModel model, Selection selection)
 {
     if (Parent is PrimarySource)
     {
         (Parent as PrimarySource).DeleteTracks(model, selection);
     }
 }
示例#2
0
        public virtual void RateSelectedTracks(DatabaseTrackListModel model, int rating)
        {
            Selection selection = model.Selection;

            if (selection.Count == 0)
            {
                return;
            }

            lock (model) {
                foreach (RangeCollection.Range range in selection.Ranges)
                {
                    RateTrackRange(model, range, rating);
                }
            }
            OnTracksChanged(BansheeQuery.RatingField);

            // In case we updated the currently playing track
            DatabaseTrackInfo track = ServiceManager.PlayerEngine.CurrentTrack as DatabaseTrackInfo;

            if (track != null)
            {
                track.Refresh();
                ServiceManager.PlayerEngine.TrackInfoUpdated();
            }
        }
示例#3
0
 protected override void RemoveTrackRange(DatabaseTrackListModel model, RangeCollection.Range range)
 {
     ServiceManager.DbConnection.Execute(
         String.Format(remove_range_sql, model.TrackIdsSql),
         DateTime.Now,
         model.CacheId, range.Start, range.End - range.Start + 1,
         model.CacheId, range.Start, range.End - range.Start + 1
         );
 }
示例#4
0
        public FilterListModel(DatabaseTrackListModel trackModel) : base()
        {
            browsing_model = trackModel;

            var selection = new SelectAllSelection();

            selection.SelectAll();
            Selection = selection;
        }
示例#5
0
        public FilterListModel(DatabaseTrackListModel trackModel) : base()
        {
            browsing_model = trackModel;

            selection = new SelectAllSelection();
            selection.SelectAll();

            Selection.Changed += HandleSelectionChanged;
        }
示例#6
0
        public AudiobookModel(AudiobookLibrarySource source, DatabaseTrackListModel trackModel, BansheeDbConnection connection, string uuid) : base(source, trackModel, connection, uuid)
        {
            Selection        = new Hyena.Collections.Selection();
            HasSelectAllItem = false;

            ReloadFragmentFormat = String.Format(@"
                FROM CoreAlbums WHERE CoreAlbums.AlbumID IN (SELECT AlbumID FROM CoreTracks WHERE PrimarySourceID = {0})
                ORDER BY CoreAlbums.TitleSortKey, CoreAlbums.ArtistNameSortKey",
                                                 source.DbId);
        }
示例#7
0
        protected virtual void DeleteSelectedTracks(DatabaseTrackListModel model)
        {
            if (model == null)
            {
                return;
            }

            WithTrackSelection(model, DeleteTrackRange);
            OnTracksDeleted();
        }
示例#8
0
        public virtual void DeleteTracks(DatabaseTrackListModel model, Selection selection)
        {
            if (model == null)
            {
                return;
            }

            FindFirstNotRemovedTrack(model, selection);
            WithTrackSelection(model, selection, DeleteTrackRange);
            OnTracksDeleted();
        }
 public PodcastFeedModel(Banshee.Sources.DatabaseSource source, DatabaseTrackListModel trackModel, BansheeDbConnection connection, string uuid)
     : base("podcast", Catalog.GetString("Podcast"), source, trackModel, connection, Feed.Provider, new Feed(null, FeedAutoDownload.None), uuid)
 {
     ReloadFragmentFormat = @"
         FROM PodcastSyndications WHERE FeedID IN
             (SELECT DISTINCT PodcastSyndications.FeedID FROM PodcastItems, CoreTracks, PodcastEnclosures, PodcastSyndications, CoreCache{0}
                 WHERE PodcastSyndications.FeedID = PodcastItems.FeedID AND
                   PodcastItems.ItemID = CoreTracks.ExternalID AND PodcastEnclosures.ItemID = PodcastItems.ItemID AND
                   CoreCache.ModelID = {1} AND CoreCache.ItemId = {2} {3})
             ORDER BY lower(Title)";
 }
示例#10
0
        protected override void DeleteSelectedTracks(DatabaseTrackListModel model)
        {
            if (model == null || model.Count < 1)
            {
                return;
            }

            ThreadAssist.SpawnFromMain(delegate {
                CachedList <DatabaseTrackInfo> list = CachedList <DatabaseTrackInfo> .CreateFromModelSelection(model);
                DeleteTrackList(list);
            });
        }
示例#11
0
        protected override void RemoveTrackRange(DatabaseTrackListModel model, RangeCollection.Range range)
        {
            base.RemoveTrackRange(model, range);

            model.Selection.UnselectRange(range.Start, range.End);

            int index = TrackModel.IndexOf(current_track);

            if (range.Start <= index && index <= range.End)
            {
                SetCurrentTrack(range.End + 1 < Count ? TrackModel[range.End + 1] as DatabaseTrackInfo : null);
            }
        }
示例#12
0
        public override void DeleteTracks(DatabaseTrackListModel model, Selection selection)
        {
            if (model == null || model.Count < 1)
            {
                return;
            }

            var list = CachedList <DatabaseTrackInfo> .CreateFromModelAndSelection(model, selection);

            ThreadAssist.SpawnFromMain(delegate {
                DeleteTrackList(list);
            });
        }
示例#13
0
        public bool AddSelectedTracks(Source source, Selection selection, QueueMode mode)
        {
            if ((Parent == null || source == Parent || source.Parent == Parent) && AcceptsInputFromSource(source))
            {
                DatabaseTrackListModel model = (source as ITrackModelSource).TrackModel as DatabaseTrackListModel;
                if (model == null)
                {
                    return(false);
                }

                selection = selection ?? model.Selection;

                long view_order         = CalculateViewOrder(mode);
                long max_view_order     = MaxViewOrder;
                long current_view_order = CurrentTrackViewOrder;

                // If the current_track is not playing, insert before it.
                int index = -1;
                if (current_track != null && !ServiceManager.PlayerEngine.IsPlaying(current_track))
                {
                    current_view_order--;
                    index = TrackModel.IndexOf(current_track);
                }

                WithTrackSelection(model, selection, shuffler.RecordInsertions);

                // Add the tracks to the end of the queue.
                WithTrackSelection(model, selection, AddTrackRange);

                if (mode != QueueMode.Normal)
                {
                    ShiftForAddedAfter(view_order, max_view_order);
                }

                ShiftGeneratedTracks(view_order);

                OnTracksAdded();
                OnUserNotifyUpdated();

                // If the current_track was not playing, and there were no non-generated tracks,
                // mark the first added track as current.
                if (index != -1 && view_order == current_view_order)
                {
                    SetCurrentTrack(TrackModel[index] as DatabaseTrackInfo);
                    SetAsPlaybackSourceUnlessPlaying();
                }
                return(true);
            }
            return(false);
        }
示例#14
0
        protected void WithTrackSelection(DatabaseTrackListModel model, Selection selection, TrackRangeHandler handler)
        {
            if (selection.Count == 0)
            {
                return;
            }

            lock (model) {
                foreach (RangeCollection.Range range in selection.Ranges)
                {
                    handler(model, range);
                }
            }
        }
示例#15
0
        protected override void AddTrackRange(DatabaseTrackListModel from, RangeCollection.Range range)
        {
            last_add_range_command = (!from.CachesJoinTableEntries)
                ? add_track_range_command
                : from == last_add_range_from_model
                    ? last_add_range_command
                    : new HyenaSqliteCommand(String.Format(add_track_range_from_joined_model_sql, from.JoinTable, from.JoinPrimaryKey));

            long first_order_id = ServiceManager.DbConnection.Query <long> ("SELECT OrderID FROM CoreCache WHERE ModelID = ? LIMIT 1 OFFSET ?", from.CacheId, range.Start);

            ServiceManager.DbConnection.Execute(last_add_range_command, DbId, MaxViewOrder - first_order_id, from.CacheId, range.Start, range.Count);

            last_add_range_from_model = from;
        }
示例#16
0
        public virtual bool AddAllTracks(Source source)
        {
            if (!AcceptsInputFromSource(source) || source.Count == 0)
            {
                return(false);
            }

            DatabaseTrackListModel model = (source as ITrackModelSource).TrackModel as DatabaseTrackListModel;

            lock (model) {
                AddTrackRange(model, new RangeCollection.Range(0, source.Count));
            }
            OnTracksAdded();
            OnUserNotifyUpdated();
            return(true);
        }
示例#17
0
        protected void LoadTrackModel(TrackListModel model)
        {
            DatabaseTrackListModel db_model = model as DatabaseTrackListModel;

            if (db_model != null)
            {
                db_selection = CachedList <DatabaseTrackInfo> .CreateFromModelSelection(db_model);
            }
            else
            {
                memory_selection = new List <TrackInfo> ();
                foreach (TrackInfo track in model.SelectedItems)
                {
                    memory_selection.Add(track);
                }
            }
        }
示例#18
0
        public virtual bool AddSelectedTracks(Source source)
        {
            if (!AcceptsInputFromSource(source))
            {
                return(false);
            }

            DatabaseTrackListModel model = (source as ITrackModelSource).TrackModel as DatabaseTrackListModel;

            if (model == null)
            {
                return(false);
            }
            WithTrackSelection(model, AddTrackRange);
            OnTracksAdded();
            OnUserNotifyUpdated();
            return(true);
        }
示例#19
0
        public override bool AddAllTracks(Source source)
        {
            if (!AcceptsInputFromSource(source) || source.Count == 0)
            {
                return(false);
            }

            DatabaseTrackListModel         model       = (source as ITrackModelSource).TrackModel as DatabaseTrackListModel;
            CachedList <DatabaseTrackInfo> cached_list = CachedList <DatabaseTrackInfo> .CreateFromModel(model);

            if (ThreadAssist.InMainThread)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(AddTrackList, cached_list);
            }
            else
            {
                AddTrackList(cached_list);
            }
            return(true);
        }
示例#20
0
        protected void FindFirstNotRemovedTrack(DatabaseTrackListModel model, Selection selection)
        {
            first_nonremoved_track = null;

            var playback_src = ServiceManager.PlaybackController.Source as DatabaseSource;

            if (playback_src != this && playback_src.Parent != this)
            {
                return;
            }

            int i = model.IndexOf(ServiceManager.PlayerEngine.CurrentTrack);

            if (!selection.Contains(i))
            {
                return;
            }

            var range = selection.Ranges.First(r => r.Start <= i && i <= r.End);

            first_nonremoved_track = model[range.Start - 1];
        }
示例#21
0
        public override bool AddSelectedTracks(Source source, Selection selection)
        {
            if (!AcceptsInputFromSource(source))
            {
                return(false);
            }

            DatabaseTrackListModel model = (source as ITrackModelSource).TrackModel as DatabaseTrackListModel;

            // Store a snapshot of the current selection
            CachedList <DatabaseTrackInfo> cached_list = CachedList <DatabaseTrackInfo> .CreateFromModelAndSelection(model, selection);

            if (ThreadAssist.InMainThread)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(AddTrackList, cached_list);
            }
            else
            {
                AddTrackList(cached_list);
            }
            return(true);
        }
        public override void GetChunks(int chunk_size)
        {
            CachedList <DatabaseTrackInfo> list;
            DatabaseTrackListModel         track_model = null;

            // mark as critical region to prevent consecutive calls from mucking things up
            lock (payload_lock) {
                long timestamp;

                lock (timestamp_lock) {
                    if (UseBuffer)
                    {
                        buffer = new Dictionary <int, IDictionary <string, object> []> ();
                    }
                    timestamp        = DateTime.Now.Ticks;
                    CurrentTimestamp = timestamp;
                }

                switch ((LibraryType)Id)
                {
                case LibraryType.Music:
                    track_model = (DatabaseTrackListModel)ServiceManager.SourceManager.MusicLibrary.TrackModel;
                    break;

                case LibraryType.Video:
                    track_model = (DatabaseTrackListModel)ServiceManager.SourceManager.VideoLibrary.TrackModel;
                    break;
                }

                if (track_model == null)
                {
                    IDictionary <string, object> [] empty = {};     // d-bus no like nulls
                    OnChunkReady(ObjectPath, empty, timestamp, 1, 0);
                    return;
                }

                chunk_size = chunk_size < 1 ? 100 : chunk_size;         // default chunk_size

                list = CachedList <DatabaseTrackInfo> .CreateFromSourceModel(track_model);

                int total = track_model.UnfilteredCount;

                // deliver data asynchronously via signal in chunks of chunk_size
                // this should make things look like they are happening quickly over our tube
                int sequence_num = 1;

                for (int i = 0; i < total; i += chunk_size)
                {
                    int dict_size = (total - i) < chunk_size ? (total - i) : chunk_size;
                    IDictionary <string, object> [] dict = new Dictionary <string, object> [dict_size];

                    for (int j = 0; j < dict.Length; j++)
                    {
                        int index = j + i;
                        dict[j] = list[index].GenerateExportable();
                        dict[j].Add("TrackId", list[index].TrackId);
                    }

                    if (UseBuffer)
                    {
                        buffer.Add(sequence_num, dict);
                    }

                    //System.Threading.Thread.Sleep (2500); // FIXME simulate slowness
                    OnChunkReady(ObjectPath, dict, timestamp, sequence_num++, total);
                }

                list.Dispose();
            }
        }
示例#23
0
 public virtual void RemoveSelectedTracks(DatabaseTrackListModel model)
 {
     WithTrackSelection(model, RemoveTrackRange);
     OnTracksRemoved();
 }
示例#24
0
        public override bool AddSelectedTracks(Source source)
        {
            if ((Parent == null || source == Parent || source.Parent == Parent) && AcceptsInputFromSource(source))
            {
                DatabaseTrackListModel model = (source as ITrackModelSource).TrackModel as DatabaseTrackListModel;
                if (model == null)
                {
                    return(false);
                }

                // Get the ViewOrder of the current_track
                long current_view_order = current_track == null?
                                          ServiceManager.DbConnection.Query <long> (@"
                        SELECT MAX(ViewOrder) + 1
                        FROM CorePlaylistEntries
                        WHERE PlaylistID = ?",
                                                                                    DbId
                                                                                    ) :
                                              ServiceManager.DbConnection.Query <long> (@"
                        SELECT ViewOrder
                        FROM CorePlaylistEntries
                        WHERE PlaylistID = ? AND EntryID = ?",
                                                                                        DbId, Convert.ToInt64(current_track.CacheEntryId)
                                                                                        );

                // If the current_track is not playing, insert before it.
                int index = -1;
                if (current_track != null && !ServiceManager.PlayerEngine.IsPlaying(current_track))
                {
                    current_view_order--;
                    index = TrackModel.IndexOf(current_track);
                }

                // view_order will point to the last pending non-generated track in the queue
                // or to the current_track if all tracks are generated. We want to insert tracks after it.
                long view_order = Math.Max(current_view_order, ServiceManager.DbConnection.Query <long> (@"
                    SELECT MAX(ViewOrder)
                    FROM CorePlaylistEntries
                    WHERE PlaylistID = ? AND ViewOrder > ? AND Generated = 0",
                                                                                                         DbId, current_view_order
                                                                                                         ));

                // Add the tracks to the end of the queue.
                WithTrackSelection(model, AddTrackRange);

                // Shift generated tracks to the end of the queue.
                ServiceManager.DbConnection.Execute(@"
                    UPDATE CorePlaylistEntries
                    SET ViewOrder = ViewOrder - ? + ?
                    WHERE PlaylistID = ? AND ViewOrder > ? AND Generated = 1",
                                                    view_order, MaxViewOrder, DbId, view_order
                                                    );

                OnTracksAdded();
                OnUserNotifyUpdated();

                // If the current_track was not playing, and there were no non-generated tracks,
                // mark the first added track as current.
                if (index != -1 && view_order == current_view_order)
                {
                    SetCurrentTrack(TrackModel[index] as DatabaseTrackInfo);
                    SetAsPlaybackSourceUnlessPlaying();
                }
                return(true);
            }
            return(false);
        }
 public DownloadStatusFilterModel(DatabaseTrackListModel trackModel) : base(trackModel)
 {
     // By default, select All items
     Selection.Clear(false);
     Selection.QuietSelect(0);
 }
示例#26
0
 protected override void RemoveTrackRange(DatabaseTrackListModel from, RangeCollection.Range range)
 {
     ServiceManager.DbConnection.Execute(remove_track_range_command,
                                         DbId, from.CacheId, range.Start, range.Count);
 }
示例#27
0
 protected void WithTrackSelection(DatabaseTrackListModel model, TrackRangeHandler handler)
 {
     WithTrackSelection(model, model.Selection, handler);
 }
示例#28
0
 protected virtual void RateTrackRange(DatabaseTrackListModel model, RangeCollection.Range range, int rating)
 {
     ServiceManager.DbConnection.Execute(RateTrackRangeCommand,
                                         rating, DateTime.Now, range.Start, range.End - range.Start + 1);
 }
示例#29
0
 protected virtual void AddTrackRange(DatabaseTrackListModel model, RangeCollection.Range range)
 {
     Log.ErrorFormat("AddTrackRange not implemented by {0}", this);
 }
示例#30
0
 public void RemoveTracks(DatabaseTrackListModel model, Selection selection)
 {
     FindFirstNotRemovedTrack(model, selection);
     WithTrackSelection(model, selection, RemoveTrackRange);
     OnTracksRemoved();
 }