示例#1
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("RemoveSelectedTracksActionLabel", Catalog.GetString("Remove From Play Queue"));
            Properties.SetString("RemovePlayingTrackActionLabel", Catalog.GetString("Remove From Library"));

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

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

            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);
        }