Пример #1
0
        public HeaderWidget CreateHeaderWidget()
        {
            var header_widget = new HeaderWidget(shuffler, populate_shuffle_mode, populate_from_name);

            header_widget.ModeChanged += delegate(object sender, EventArgs <RandomBy> e) {
                populate_shuffle_mode = e.Value.Id;
                PopulateModeSchema.Set(populate_shuffle_mode);
                UpdatePlayQueue();
                OnUpdated();
            };

            populate_shuffle_mode = header_widget.ShuffleModeId;

            header_widget.SourceChanged += delegate(object sender, EventArgs <DatabaseSource> e) {
                populate_from = e.Value;
                if (populate_from == null)
                {
                    populate_from_name = String.Empty;
                    PopulateFromSchema.Set(String.Empty);
                    return;
                }

                populate_from_name = e.Value.Name;
                PopulateFromSchema.Set(e.Value.Name);
                source_set_at = DateTime.Now;
                populate_from.Reload();
                Refresh();
            };

            return(header_widget);
        }
Пример #2
0
        /// <summary>
        /// Clear filters of a certain source.
        /// </summary>
        /// <param name="s">
        /// Source whose filters sould be cleared.
        /// </param>
        public static void ClearSourceFilters(DatabaseSource s)
        {
            foreach (IFilterListModel f in s.CurrentFilters)
            {
                f.Selection.Clear();
            }

            if (s.FilterQuery != null && s.FilterQuery.Trim().Length != 0)
            {
                s.FilterQuery = "";
            }

            s.Reload();
        }
Пример #3
0
        public PlayQueueSource() : base(Catalog.GetString("Play Queue"), null)
        {
            BindToDatabase();
            TypeUniqueId = DbId.ToString();
            Initialize();
            AfterInitialized();

            Order = 20;
            Properties.SetString("Icon.Name", "source-playlist");
            Properties.SetString("RemoveTracksActionLabel", Catalog.GetString("Remove From Play Queue"));

            DatabaseTrackModel.ForcedSortQuery = "CorePlaylistEntries.ViewOrder ASC, CorePlaylistEntries.EntryID ASC";
            DatabaseTrackModel.CanReorder      = true;

            ServiceManager.PlayerEngine.ConnectEvent(OnPlayerEvent);
            ServiceManager.PlaybackController.TrackStarted += OnTrackStarted;

            // TODO change this Gtk.Action code so that the actions can be removed.  And so this
            // class doesn't depend on Gtk/ThickClient.
            actions = new PlayQueueActions(this);

            Properties.SetString("ActiveSourceUIResource", "ActiveSourceUI.xml");
            Properties.SetString("GtkActionPath", "/PlayQueueContextMenu");

            // TODO listen to all primary sources, and handle transient primary sources
            ServiceManager.SourceManager.MusicLibrary.TracksChanged += HandleTracksChanged;
            ServiceManager.SourceManager.MusicLibrary.TracksDeleted += HandleTracksDeleted;
            ServiceManager.SourceManager.VideoLibrary.TracksChanged += HandleTracksChanged;
            ServiceManager.SourceManager.VideoLibrary.TracksDeleted += HandleTracksDeleted;

            populate_from = ServiceManager.SourceManager.Sources.FirstOrDefault(
                source => source.Name == populate_from_name) as DatabaseSource;
            if (populate_from != null)
            {
                populate_from.Reload();
            }

            TrackModel.Reloaded += HandleReloaded;

            int saved_offset = DatabaseConfigurationClient.Client.Get(CurrentOffsetSchema, CurrentOffsetSchema.Get());

            Offset = Math.Min(
                saved_offset,
                ServiceManager.DbConnection.Query <long> (@"
                    SELECT MAX(ViewOrder) + 1
                    FROM CorePlaylistEntries
                    WHERE PlaylistID = ?", DbId));

            ServiceManager.SourceManager.AddSource(this);
        }
Пример #4
0
        public static int AddArtistOrAlbumToPlayList(int playlistId, int id, bool allowTwice, bool isAlbum)
        {
            if (playlistId != 1 && playlistId != 2)
            {
                return(0);
            }

            int count = 0;
            MusicLibrarySource lib       = MusicLibrary;
            DatabaseSource     dest      = playlistId == 1 ? RemotePlaylist : PlayQueuePlaylist;
            TrackListModel     model     = lib.TrackModel;
            Selection          selection = new Selection();

            if (allowTwice)
            {
                for (int i = 0; i < model.Count; i++)
                {
                    object t = model.GetItem(i);

                    if (t is DatabaseTrackInfo && (isAlbum && ((DatabaseTrackInfo)t).AlbumId == id ||
                                                   !isAlbum && ((DatabaseTrackInfo)t).ArtistId == id))
                    {
                        selection.Select(i);
                        count++;
                    }
                }
            }
            else
            {
                List <SortEntry> ids       = new List <SortEntry>();
                List <int>       doubleIds = new List <int>();

                for (int i = 0; i < model.Count; i++)
                {
                    object t = model.GetItem(i);

                    if (t is DatabaseTrackInfo && (isAlbum && ((DatabaseTrackInfo)t).AlbumId == id ||
                                                   !isAlbum && ((DatabaseTrackInfo)t).ArtistId == id))
                    {
                        SortEntry e = new SortEntry();
                        e.pos      = i;
                        e.selected = true;
                        e.id       = (t as DatabaseTrackInfo).TrackId;
                        ids.Add(e);
                    }
                }

                ids.Sort();
                dest.Reload();
                model = dest.TrackModel;

                for (int i = 0; i < model.Count; i++)
                {
                    object t = model.GetItem(i);

                    if (t is DatabaseTrackInfo && (isAlbum && ((DatabaseTrackInfo)t).AlbumId == id ||
                                                   !isAlbum && ((DatabaseTrackInfo)t).ArtistId == id))
                    {
                        doubleIds.Add((t as DatabaseTrackInfo).TrackId);
                    }
                }

                doubleIds.Sort();

                int si = 0, di = 0;

                while (si < ids.Count && di < doubleIds.Count)
                {
                    if (ids[si].id == doubleIds[di])
                    {
                        ids[si].selected = false;
                        si++;
                    }
                    else if (ids[si].id < doubleIds[di])
                    {
                        si++;
                    }
                    else
                    {
                        di++;
                    }
                }

                for (int i = 0; i < ids.Count; i++)
                {
                    if (ids[i].selected)
                    {
                        selection.Select(ids[i].pos);
                        count++;
                    }
                }
            }

            if (count != 0)
            {
                if (dest != PlayQueuePlaylist)
                {
                    dest.AddSelectedTracks(lib, selection);
                }
                else
                {
                    foreach (int s in selection)
                    {
                        ((PlayQueueSource)dest).EnqueueTrack(lib.TrackModel.GetItem(s) as TrackInfo, false);
                    }
                }
            }

            return(count);
        }