/* * private void OnSourceAdded (SourceAddedArgs args) * { * var library = args.Source as LibrarySource; * if (library != null) { * AddLibrary (library); * } * } * * private void OnSourceRemoved (SourceEventArgs args) * { * var library = args.Source as LibrarySource; * if (library != null) { * RemoveLibrary (library); * } * } */ private void AddLibrary(LibrarySource library) { if (!Banshee.IO.Directory.Exists(library.BaseDirectoryWithSeparator)) { Hyena.Log.DebugFormat("Will not watch library {0} because its folder doesn't exist: {1}", library.Name, library.BaseDirectoryWithSeparator); return; } lock (watchers) { if (!watchers.ContainsKey(library)) { try { var dir = library.BaseDirectoryWithSeparator; if (!Banshee.IO.Directory.Exists(dir)) { Hyena.Log.DebugFormat("Skipped LibraryWatcher for {0} ({1})", library.Name, dir); } else { watchers[library] = new SourceWatcher(library); Hyena.Log.DebugFormat("Started LibraryWatcher for {0} ({1})", library.Name, dir); } } catch (Exception e) { Log.Error(e); } } } }
public bool CopyToLibraryIfAppropriate(bool force_copy) { bool copy_success = true; LibrarySource library_source = PrimarySource as LibrarySource; if (library_source == null) { // Get out, not a local Library return(false); } SafeUri old_uri = this.Uri; if (old_uri == null) { // Get out quick, no URI set yet. return(copy_success); } bool in_library = old_uri.IsLocalPath ? old_uri.AbsolutePath.StartsWith(PrimarySource.BaseDirectoryWithSeparator) : false; if (!in_library && ((library_source.HasCopyOnImport && library_source.CopyOnImport) || force_copy)) { string new_filename = PathPattern != null?PathPattern.BuildFull(PrimarySource.BaseDirectory, this, Path.GetExtension(old_uri.ToString())) : Path.Combine(PrimarySource.BaseDirectory, Path.GetFileName(SafeUri.UriToFilename(old_uri))); SafeUri new_uri = new SafeUri(new_filename); try { if (Banshee.IO.File.Exists(new_uri)) { if (Banshee.IO.File.GetSize(old_uri) == Banshee.IO.File.GetSize(new_uri)) { Hyena.Log.DebugFormat("Not copying {0} to library because there is already a file of same size at {1}", old_uri, new_uri); copy_success = false; return(copy_success); } else { string extension = Path.GetExtension(new_filename); string filename_no_ext = new_filename.Remove(new_filename.Length - extension.Length); int duplicate_index = 1; while (Banshee.IO.File.Exists(new_uri)) { new_filename = String.Format("{0} ({1}){2}", filename_no_ext, duplicate_index, extension); new_uri = new SafeUri(new_filename); duplicate_index++; } } } Banshee.IO.File.Copy(old_uri, new_uri, false); Uri = new_uri; } catch (Exception e) { Log.ErrorFormat("Exception copying into library: {0}", e); } } return(copy_success); }
public LibraryLocationButton(LibrarySource source) { this.source = source; preference = source.PreferencesPage["library-location"]["library-location"] as SchemaPreference <string>; preference.ShowLabel = false; preference.DisplayWidget = this; string dir = preference.Value ?? source.DefaultBaseDirectory; Spacing = 5; // FileChooserButton wigs out if the directory does not exist, // so create it if it doesn't and store the fact that we did // in case it ends up not being used, we can remove it try { if (!Banshee.IO.Directory.Exists(dir)) { Banshee.IO.Directory.Create(dir); created_directory = dir; Log.DebugFormat("Created library directory: {0}", created_directory); } } catch { } chooser = new FileChooserButton(Catalog.GetString("Select library location"), FileChooserAction.SelectFolder); // Only set the LocalOnly property if false; setting it when true // causes the "Other..." entry to be hidden in older Gtk+ if (!Banshee.IO.Provider.LocalOnly) { chooser.LocalOnly = Banshee.IO.Provider.LocalOnly; } chooser.SetCurrentFolder(dir); chooser.SelectionChanged += OnChooserChanged; HBox box = new HBox(); box.Spacing = 2; box.PackStart(new Image(Stock.Undo, IconSize.Button), false, false, 0); box.PackStart(new Label(Catalog.GetString("Reset")), false, false, 0); reset = new Button() { Sensitive = dir != source.DefaultBaseDirectory, TooltipText = String.Format(Catalog.GetString("Reset location to default ({0})"), source.DefaultBaseDirectory) }; reset.Clicked += OnReset; reset.Add(box); //Button open = new Button (); //open.PackStart (new Image (Stock.Open, IconSize.Button), false, false, 0); //open.Clicked += OnOpen; PackStart(chooser, true, true, 0); PackStart(reset, false, false, 0); //PackStart (open, false, false, 0); chooser.Show(); reset.ShowAll(); }
internal DapLibrarySync(DapSync sync, LibrarySource library) { this.sync = sync; this.library = library; BuildPreferences(); BuildSyncLists(); }
public RescanPipeline(LibrarySource psource) : base() { this.psource = psource; scan_started = DateTime.Now; AddElement(new Banshee.IO.DirectoryScannerPipelineElement()); AddElement(track_sync = new TrackSyncPipelineElement(psource, scan_started)); Finished += OnFinished; BuildJob(); Enqueue(psource.BaseDirectory); }
private void UnmonitorLibrary(LibrarySource library) { if (library == null || !libraries.Contains(library)) { return; } library.TracksAdded -= OnLibraryChanged; library.TracksDeleted -= OnLibraryChanged; library.TracksChanged -= OnLibraryChanged; libraries.Remove(library); }
private void MonitorLibrary(LibrarySource library) { if (library == null || !library.Indexable || libraries.Contains(library)) { return; } libraries.Add(library); library.TracksAdded += OnLibraryChanged; library.TracksDeleted += OnLibraryChanged; library.TracksChanged += OnLibraryChanged; }
public SourceWatcher(LibrarySource library) { this.library = library; handle = new ManualResetEvent(false); string path = library.BaseDirectoryWithSeparator; if (String.IsNullOrEmpty(path)) { throw new Exception("Will not create LibraryWatcher for the blank directory"); } string home = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar; if (path == home) { throw new Exception("Will not create LibraryWatcher for the entire home directory"); } string root = Path.GetPathRoot(Environment.CurrentDirectory); if (path == root || path == root + Path.DirectorySeparatorChar) { throw new Exception("Will not create LibraryWatcher for the entire root directory"); } if (!Banshee.IO.Directory.Exists(path)) { throw new Exception("Will not create LibraryWatcher for non-existent directory"); } import_manager = ServiceManager.Get <LibraryImportManager> (); watcher = new FileSystemWatcher(path); watcher.IncludeSubdirectories = true; watcher.Changed += OnChanged; watcher.Created += OnChanged; watcher.Deleted += OnChanged; watcher.Renamed += OnChanged; active = true; watch_thread = new Thread(new ThreadStart(Watch)); watch_thread.Name = String.Format("LibraryWatcher for {0}", library.Name); watch_thread.IsBackground = true; watch_thread.Start(); }
public void Index() { lock (this) { DisposeModels(); foreach (Source source in ServiceManager.SourceManager.Sources) { LibrarySource library = source as LibrarySource; if (library != null && library.Indexable) { model_caches.Add(CachedList <DatabaseTrackInfo> .CreateFromSourceModel( (DatabaseTrackListModel)library.TrackModel)); } } } OnIndexingFinished(); }
private void OnRemoveTracksFromLibrary(object o, EventArgs args) { ITrackModelSource source = ActiveSource as ITrackModelSource; if (source != null) { LibrarySource library = source.Parent as LibrarySource; if (library != null) { if (!ConfirmRemove(library, false, Selection.Count)) { return; } ThreadAssist.SpawnFromMain(delegate { library.RemoveTracks(source.TrackModel as DatabaseTrackListModel, Selection); }); } } }