private void InstallPreferences() { music_lib = ServiceManager.SourceManager.MusicLibrary; disable_album_grid = music_lib.PreferencesPage["misc"].FindOrAdd(DisableAlbumGridPref); ServiceManager.SourceManager.SourceAdded -= InstallPreferences; }
/// <summary> /// Add track to playlist. /// </summary> /// <param name="playlistId"> /// ID of playlist (1 and 2 supported only). /// </param> /// <param name="trackId"> /// Track ID of track to add. /// </param> /// <param name="allowTwice"> /// True if track should be added although it's already in available in the playlist. /// </param> /// <returns> /// True if track successfully added to playlist. /// </returns> public static bool AddTrackToPlayList(int playlistId, int trackId, bool allowTwice) { if (!allowTwice) { TrackListModel m = (playlistId == 1 ? RemotePlaylist : PlayQueuePlaylist).TrackModel; for (int i = 0; i < m.Count; i++) { object t = m.GetItem(i); if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == trackId) { return(false); } } } switch (playlistId) { case 1: { Selection selection = null; MusicLibrarySource source = MusicLibrary; for (int i = 0; i < source.TrackModel.Count; i++) { object t = source.TrackModel.GetItem(i); if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == trackId) { selection = new Hyena.Collections.Selection(); selection.Select(i); break; } } if (selection != null) { RemotePlaylist.AddSelectedTracks(source, selection); return(true); } break; } case 2: { DatabaseTrackInfo track = new DatabaseTrackModelProvider <DatabaseTrackInfo>( ServiceManager.DbConnection).FetchSingle(trackId); if (track != null) { PlayQueuePlaylist.EnqueueTrack(track, false); return(true); } break; } } return(false); }
private void RemoveClutterFlow() { Clutter.Threads.Enter(); music_library.Properties.Remove("Nereid.SourceContents"); Clutter.Threads.Leave(); clutter_flow_contents.Dispose(); clutter_flow_contents = null; source_manager.ActiveSourceChanged -= HandleActiveSourceChanged; BrowserAction.Activated -= OnToggleBrowser; BrowserAction.Active = ClutterFlowSchemas.OldShowBrowser.Get(); CfBrowsAction.Activated -= OnToggleClutterFlow; CfBrowsAction.Visible = false; action_service.RemoveActionGroup("ClutterFlowView"); action_service.UIManager.RemoveUi(ui_manager_id); clutterflow_actions = null; cfbrows_action = null; preference_service = null; source_manager = null; music_library = null; action_service = null; browser_action = null; cfbrows_action = null; }
public void Dispose() { lock (this) { try { AddinManager.RemoveExtensionNodeHandler("/Banshee/SourceManager/Source", OnExtensionChanged); } catch {} active_source = null; default_source = null; music_library = null; video_library = null; // Do dispose extension sources foreach (Source source in extension_sources.Values) { RemoveSource(source, true); } // But do not dispose non-extension sources while (sources.Count > 0) { RemoveSource(sources[0], false); } sources.Clear(); extension_sources.Clear(); } }
public void AddSource(Source source, bool isDefault) { Banshee.Base.ThreadAssist.AssertInMainThread(); if (source == null || ContainsSource(source)) { return; } int position = FindSourceInsertPosition(source); sources.Insert(position, source); if (isDefault) { default_source = source; } source.Updated += OnSourceUpdated; source.ChildSourceAdded += OnChildSourceAdded; source.ChildSourceRemoved += OnChildSourceRemoved; SourceAddedHandler handler = SourceAdded; if (handler != null) { SourceAddedArgs args = new SourceAddedArgs(); args.Position = position; args.Source = source; handler(args); } if (source is MusicLibrarySource) { music_library = source as MusicLibrarySource; } else if (source is VideoLibrarySource) { video_library = source as VideoLibrarySource; } IDBusExportable exportable = source as IDBusExportable; if (exportable != null) { ServiceManager.DBusServiceManager.RegisterObject(exportable); } List <Source> children = new List <Source> (source.Children); foreach (Source child_source in children) { AddSource(child_source, false); } if (isDefault && ActiveSource == null) { SetActiveSource(source); } }
private void OnSourceAdded(SourceAddedArgs args) { if (args.Source is MusicLibrarySource) { music_library = args.Source as MusicLibrarySource; } SetupSourceContents(); }
public void ResetSource() { if (source != null) { source.TracksAdded -= HandleTracksAdded; source.TracksDeleted -= HandleTracksDeleted; source = null; } TrackView.SetModel(null); FilterView.SetModel(null); }
private void UninstallPreferences(Sources.SourceEventArgs args) { if (!args.Source.Equals(music_lib)) { return; } music_lib.PreferencesPage["misc"].Remove(disable_album_grid); music_lib = null; ServiceManager.SourceManager.SourceRemoved -= UninstallPreferences; }
void IExtensionService.Initialize() { ClutterHelper.Init(); preference_service = ServiceManager.Get <PreferenceService> (); action_service = ServiceManager.Get <InterfaceActionService> (); source_manager = ServiceManager.SourceManager; music_library = source_manager.MusicLibrary; if (!SetupPreferences() || !SetupInterfaceActions()) { ServiceManager.ServiceStarted += OnServiceStarted; } else if (!SetupSourceContents()) { source_manager.SourceAdded += OnSourceAdded; } //--> TODO Banshee.ServiceStack.Application. register Exit event to close threads etc. }
void OnExecuteCommand(bool Delete) { if (ConfirmRemove(Delete)) { MusicLibrarySource Library = ServiceManager.SourceManager.MusicLibrary; if (Library.CanRemoveTracks && Library.CanDeleteTracks) { Gtk.TreeIter Iter = new Gtk.TreeIter(); if (MusicListStore.GetIterFirst(out Iter)) { do { if (Delete && (bool)MusicListStore.GetValue(Iter, 0)) { //delete string Uri = (string)MusicListStore.GetValue(Iter, 5); Uri = Uri.Replace("file://", ""); RemoveTrack((int)MusicListStore.GetValue(Iter, 7)); DeleteTrack(Uri); } else if ((bool)MusicListStore.GetValue(Iter, 0)) { RemoveTrack((int)MusicListStore.GetValue(Iter, 7)); } } while (MusicListStore.IterNext(ref Iter)); Library.Reload(); } else { Log.Warning("Please Don't Click Execute with nothing selected"); } } else { Log.Warning("Can not remove or delete any tracks"); } ReloadWindow(); } }
public bool SetSource(ISource source) { if ((source as MusicLibrarySource) == null) { return(false); } if ((source as MusicLibrarySource) == this.source) { SelectAllTracks(); return(true); } else { ResetSource(); } this.source = (source as MusicLibrarySource); this.source.TrackModel.Selection.Clear(false); this.source.TracksAdded += HandleTracksAdded; this.source.TracksDeleted += HandleTracksDeleted; foreach (IFilterListModel list_model in this.source.CurrentFilters) { list_model.Clear(); //clear selections, we need all albums!! if (list_model is FilterListModel <AlbumInfo> ) { external_filter = list_model as FilterListModel <AlbumInfo>; break; } } main_view.SetModel(TrackModel); FilterView.SetModel(external_filter); return(true); }
public void ResetSource() { source = null; }
public bool SetSource(ISource source) { this.source = source as MusicLibrarySource; return(this.source != null); }
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); }
public void AddSource(Source source, bool isDefault) { ThreadAssist.AssertInMainThread(); if (source == null || ContainsSource(source)) { return; } GroupSource group_source = source as GroupSource; if (group_source != null && !group_sources.Contains(group_source)) { group_sources.Add(group_source); return; } AddSource(FindAssociatedGroupSource(source.Order)); int position = FindSourceInsertPosition(source); sources.Insert(position, source); if (isDefault) { default_source = source; } source.Updated += OnSourceUpdated; source.ChildSourceAdded += OnChildSourceAdded; source.ChildSourceRemoved += OnChildSourceRemoved; if (source is MusicLibrarySource) { music_library = source as MusicLibrarySource; } SourceAdded.SafeInvoke(new SourceAddedArgs() { Position = position, Source = source }); IDBusExportable exportable = source as IDBusExportable; if (exportable != null) { ServiceManager.DBusServiceManager.RegisterObject(exportable); } List <Source> children = new List <Source> (source.Children); foreach (Source child_source in children) { AddSource(child_source, false); } if (isDefault && ActiveSource == null) { SetActiveSource(source); } }