banshee r3704 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Library src/Core/Banshee.ThickClient/Banshee.Gui src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage src/Dap/Banshee.Dap/Banshee.Dap



Author: gburt
Date: Mon Apr  7 20:52:48 2008
New Revision: 3704
URL: http://svn.gnome.org/viewvc/banshee?rev=3704&view=rev

Log:
2008-04-07  Gabriel Burt  <gabriel burt gmail com>

	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs:
	Add force_copy protected bool that we pass to CopyToLibraryIfAppropriate.
	Used when importing DAPs to force copy to library.

	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs:
	Rename CopyToLibrary method, and add bool arg that forces it to copy the
	track, even if the user's preference is not to do so.

	* src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs:

	* src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs: Fix up
	ImportSourceAction so it's now functional.

	* src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs:
	Avoid spawning unnecessary thread.  Fix bug with accessing the
	BaseDirectory; cache the Hal.Device's mount point property.  Implement
	IImportSource, so can now import MassStorageSources from the Media ->
	Import menu and via its context menu (dnd to come).

	* src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs: Implement most of
	IImportSource.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
   trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs	Mon Apr  7 20:52:48 2008
@@ -90,11 +90,11 @@
         public delegate PrimarySource TrackPrimarySourceChooser (DatabaseTrackInfo track);
 
         private TrackPrimarySourceChooser trackPrimarySourceChooser;
-        protected bool can_copy_to_library = false;
         private Dictionary<int, int> counts;
         private ErrorSource error_source;
         protected int [] primary_source_ids;
         protected string base_directory;
+        protected bool force_copy;
     
         public DatabaseImportManager (PrimarySource psource) :
             this (psource.ErrorSource, delegate { return psource; }, new int [] {psource.DbId}, psource.BaseDirectory)
@@ -133,7 +133,7 @@
                 return;
             }
 
-            try {            
+            try {
                 DatabaseTrackInfo track = ImportTrack (path);
                 if (track != null && track.TrackId > 0) {
                     IncrementProcessedCount (String.Format ("{0} - {1}", 
@@ -167,19 +167,15 @@
                 track = new DatabaseTrackInfo ();
                 StreamTagger.TrackInfoMerge (track, file);
                 
-                if (can_copy_to_library) {
-                    SafeUri newpath = track.CopyToLibrary ();
-                    if (newpath != null) {
-                        track.Uri = newpath;
-                    }
-                }
-
                 track.DateAdded = DateTime.Now;
-
                 track.PrimarySource = trackPrimarySourceChooser (track);
-                counts[track.PrimarySourceId] = counts.ContainsKey (track.PrimarySourceId) ? counts[track.PrimarySourceId] + 1 : 1;
+
+                if (track.PrimarySource is Banshee.Library.LibrarySource) {
+                    track.CopyToLibraryIfAppropriate (force_copy);
+                }
 
                 track.Save (false);
+                counts[track.PrimarySourceId] = counts.ContainsKey (track.PrimarySourceId) ? counts[track.PrimarySourceId] + 1 : 1;
 
                 ServiceManager.DbConnection.CommitTransaction ();
 

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	Mon Apr  7 20:52:48 2008
@@ -67,7 +67,6 @@
 
         private bool? artist_changed = null, album_changed = null;
         private bool uri_fields_dirty = false;
-        private bool updating_uri = false;
         
         public DatabaseTrackInfo () : base ()
         {
@@ -225,7 +224,7 @@
             get {
                 if (uri_fields_dirty) {
                     PrimarySource.UriToFields (Uri, out uri_type, out uri_field);
-                    uri_fields_dirty = !updating_uri;
+                    uri_fields_dirty = false;
                 }
                 return uri_field;
             }
@@ -400,47 +399,36 @@
         private void UpdateUri ()
         {
             if (Uri == null && uri_type_set && UriField != null && PrimarySource != null) {
-                updating_uri = true;
                 Uri = PrimarySource.UriAndTypeToSafeUri (UriType, UriField);
-                updating_uri = false;
             }
         }
         
-        public SafeUri CopyToLibrary ()
+        public void CopyToLibraryIfAppropriate (bool force_copy)
         {
             SafeUri old_uri = this.Uri;
             if (old_uri == null) {
                 // Get out quick, no URI set yet.
-                return null;
+                return;
             }
             
-            SafeUri library_check = new SafeUri (Paths.LibraryLocation + Path.DirectorySeparatorChar);
-        
-            bool in_library = old_uri.ToString ().StartsWith (library_check.ToString ());
+            bool in_library = old_uri.AbsolutePath.StartsWith (Paths.CachedLibraryLocation);
             //Console.WriteLine ("{0} is{1}in library.", old_uri.ToString (), in_library ? " " : " not ");
 
-            if (!in_library && LibrarySchema.CopyOnImport.Get ()) {
-                string new_filename = FileNamePattern.BuildFull (this,
-                    Path.GetExtension (old_uri.ToString ()).Substring (1));
+            if (!in_library && (LibrarySchema.CopyOnImport.Get () || force_copy)) {
+                string new_filename = FileNamePattern.BuildFull (this, Path.GetExtension (old_uri.ToString ()).Substring (1));
                 SafeUri new_uri = new SafeUri (new_filename);
 
                 try {
                     if (Banshee.IO.File.Exists (new_uri)) {
-                        return null;
+                        return;
                     }
                     
-                    // TODO: Once GnomeVfs and Unix have proper Copy providers, use IOProxy.File.Copy instead.
-                    System.IO.File.Copy (old_uri.LocalPath, new_uri.LocalPath);
-                    
-                    // Return new SafeUri after copy
-                    return new_uri;
+                    Banshee.IO.File.Copy (old_uri, new_uri, false);
+                    Uri = new_uri;
                 } catch (Exception e) {
                     Log.Error (String.Format("Exception copying into library: {0}", e), false);
-                    return null;
                 }
             }
-            
-            return null;
         }
 
         private static HyenaSqliteCommand check_command = new HyenaSqliteCommand (

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs	Mon Apr  7 20:52:48 2008
@@ -47,9 +47,13 @@
 {
     public class LibraryImportManager : DatabaseImportManager, IService
     {
-        public LibraryImportManager () : base (DefaultTrackPrimarySourceChooser)
+        public LibraryImportManager () : this (false)
         {
-            can_copy_to_library = true;
+        }
+
+        public LibraryImportManager (bool force_copy) : base (DefaultTrackPrimarySourceChooser)
+        {
+            this.force_copy = force_copy;
         }
 
         protected override ErrorSource ErrorSource {
@@ -68,7 +72,7 @@
         }
 
         protected override string BaseDirectory {
-            get { return ServiceManager.SourceManager.VideoLibrary.BaseDirectory; }
+            get { return ServiceManager.SourceManager.MusicLibrary.BaseDirectory; }
         }
 
         protected static PrimarySource DefaultTrackPrimarySourceChooser (DatabaseTrackInfo track)

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs	Mon Apr  7 20:52:48 2008
@@ -87,7 +87,7 @@
                     String.Empty, null, null, OnSourceContextMenu),
 
                 new ActionEntry ("ImportSourceAction", null,
-                    Catalog.GetString ("Import Source"), null,
+                    Catalog.GetString ("Import to Library"), null,
                     Catalog.GetString ("Import source to library"), OnImportSource),
 
                 new ActionEntry ("RenameSourceAction", "gtk-edit", 
@@ -236,6 +236,7 @@
             
         private void OnImportSource (object o, EventArgs args)
         {
+            (ActionSource as IImportSource).Import ();
         }
 
         private void OnRenameSource (object o, EventArgs args)
@@ -317,10 +318,11 @@
 
             if (source != last_source && source != null) {
                 IUnmapableSource unmapable = source as IUnmapableSource;
+                IImportSource import_source = source as IImportSource;
                 SmartPlaylistSource smart_playlist = source as SmartPlaylistSource;
                 UpdateAction ("UnmapSourceAction", unmapable != null, unmapable != null && unmapable.CanUnmap, source);
                 UpdateAction ("RenameSourceAction", source.CanRename, true, null);
-                UpdateAction ("ImportSourceAction", source is IImportable, true, source);
+                UpdateAction ("ImportSourceAction", import_source != null, import_source != null && import_source.CanImport, source);
                 UpdateAction ("ExportPlaylistAction", source is AbstractPlaylistSource, true, source);
                 UpdateAction ("SourcePropertiesAction", source.HasProperties, true, source);
                 UpdateAction ("RefreshSmartPlaylistAction", smart_playlist != null && smart_playlist.CanRefresh, true, source);

Modified: trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs	Mon Apr  7 20:52:48 2008
@@ -36,6 +36,7 @@
 
 using Banshee.Base;
 using Banshee.ServiceStack;
+using Banshee.Library;
 using Banshee.Sources;
 using Banshee.Collection;
 using Banshee.Collection.Database;
@@ -46,20 +47,11 @@
     public class MassStorageSource : DapSource
     {
         protected IVolume volume;
-        public IVolume Volume {
-            get { return volume; }
-        }
 
         public MassStorageSource () : base ()
         {
         }
 
-        // Override PrimarySource's Initialize method
-        protected override void Initialize ()
-        {
-            base.Initialize ();
-        }
-
         public override bool Initialize (IDevice device)
         {
             this.volume = device as IVolume;
@@ -76,6 +68,7 @@
             Initialize ();
 
             Properties.SetStringList ("Icon.Name", "harddrive");
+            mount_point = volume.MountPoint;
 
             // TODO differentiate between Audio Players and normal Disks, and include the size, eg "2GB Audio Player"?
             //GenericName = Catalog.GetString ("Audio Player");
@@ -83,28 +76,27 @@
             // TODO construct device-specific icon name as preferred icon
             //Properties.SetStringList ("Icon.Name", "media-player");
 
-            ThreadPool.QueueUserWorkItem (delegate {
-                DatabaseImportManager importer = new DatabaseImportManager (this);
-                importer.KeepUserJobHidden = true;
-                SetStatus (String.Format (Catalog.GetString ("Loading {0}"), Name), false);
-                importer.ImportFinished += delegate  { HideStatus (); };
-                importer.QueueSource (new string [] { volume.MountPoint });
-            });
+            SetStatus (String.Format (Catalog.GetString ("Loading {0}"), Name), false);
+            DatabaseImportManager importer = new DatabaseImportManager (this);
+            importer.KeepUserJobHidden = true;
+            importer.ImportFinished += delegate  { HideStatus (); };
+            importer.QueueSource (BaseDirectory);
 
             return true;
         }
 
-        protected override void DeleteTrack (DatabaseTrackInfo track)
+        public override void Import ()
         {
-            try {
-                Banshee.IO.Utilities.DeleteFileTrimmingParentDirectories (track.Uri);
-            } catch (System.IO.FileNotFoundException) {
-            } catch (System.IO.DirectoryNotFoundException) {
-            }
+            new LibraryImportManager (true).QueueSource (BaseDirectory);
         }
 
+        public IVolume Volume {
+            get { return volume; }
+        }
+
+        private string mount_point;
         public override string BaseDirectory {
-            get { return volume.MountPoint; }
+            get { return mount_point; }
         }
 
         protected string IsAudioPlayerPath {
@@ -123,6 +115,15 @@
             get { return volume.IsReadOnly; }
         }
 
+        protected override void DeleteTrack (DatabaseTrackInfo track)
+        {
+            try {
+                Banshee.IO.Utilities.DeleteFileTrimmingParentDirectories (track.Uri);
+            } catch (System.IO.FileNotFoundException) {
+            } catch (System.IO.DirectoryNotFoundException) {
+            }
+        }
+
         protected override void Eject ()
         {
             if (volume.CanUnmount)

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/RemovableSource.cs	Mon Apr  7 20:52:48 2008
@@ -41,7 +41,7 @@
 
 namespace Banshee.Dap
 {
-    public abstract class RemovableSource : PrimarySource, IUnmapableSource, IDisposable
+    public abstract class RemovableSource : PrimarySource, IUnmapableSource, IDisposable, Banshee.Library.IImportSource
     {
         protected RemovableSource () : base ()
         {
@@ -80,6 +80,10 @@
             get { return !IsReadOnly; }
         }
 
+        public virtual bool CanImport {
+            get { return true; }
+        }
+
         public double StorageUsageFraction {
             get { return (double) BytesUsed / (double) BytesCapacity; }
         }
@@ -170,6 +174,12 @@
         public abstract long BytesUsed { get; }
         public abstract long BytesCapacity { get; }
 
+        public abstract void Import ();
+
+        public virtual string [] IconNames {
+            get { return Properties.GetStringList ("Icon.Name"); }
+        }
+
 #endregion
 
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]