banshee r3698 - in trunk/banshee: . src/Backends/Banshee.Unix/Banshee.IO.Unix src/Core/Banshee.Core/Banshee.Base src/Core/Banshee.Core/Banshee.IO src/Core/Banshee.Core/Banshee.IO.SystemIO src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Library src/Core/Banshee.Services/Banshee.Sources src/Core/Banshee.ThickClient/Banshee.Gui src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage tests tests/Banshee.Core tests/Hyena



Author: gburt
Date: Mon Apr  7 01:41:19 2008
New Revision: 3698
URL: http://svn.gnome.org/viewvc/banshee?rev=3698&view=rev

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

	This patch extends the relative-Uri goodness we use for Library tracks to
	any PrimarySource's tracks, meaning if your DAP has one mount point one
	time, and another the next, we'll detect the songs that are already in the
	database since we now check against the relative Uri.  Also, delete from
	MassStorage sources is working.

	* src/Core/Banshee.Core/Banshee.IO/IFile.cs:
	* src/Core/Banshee.Core/Banshee.IO/File.cs:
	* src/Core/Banshee.Core/Banshee.IO.SystemIO/File.cs:
	* src/Backends/Banshee.Unix/Banshee.IO.Unix/File.cs: Add Copy method.

	* src/Core/Banshee.Core/Banshee.Base/Paths.cs: Factory MakePathRelative
	out, not-library specific.

	* src/Core/Banshee.Services/Banshee.Library/LibraryImportManager.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseImportManager.cs:
	Add a couple virtual properties for making the relative-Uri stuff
	PrimarySource agnostic.

	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs:
	Make the process of making a Uri relative and reconstructing it from the
	relative path saved in the db generic so it can be used by other
	PrimarySources.  Scope ContainsUri method to one or more primary sources,
	since it's fine if a track is on a DAP and in the library.

	* src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs: Add methods
	for making the Uri of a track relative (if possible).  Add default
	DeleteTrackRange implementation pulled from LibrarySource, but make it
	call a virtual DeleteTrack method that each PrimarySource can implement.

	* src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs:
	* src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs: Override
	DeleteTrack method to delete files from disk.

	* src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs: Don't show the
	context menu at all if it has no visible items.  Fix crasher with the
	playlist menu b/c of recent icon changes.

	* tests/Makefile.am:
	* tests/Banshee.Core/TaglibReadWriteTests.cs: Test our read/write tags to
	file code. Commented out b/c abock doesn't want the 390KB of music files
	in svn.

	* tests/Hyena/QueryTests.cs: Changes to AssertForEach method.


Added:
   trunk/banshee/tests/Banshee.Core/TaglibReadWriteTests.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Backends/Banshee.Unix/Banshee.IO.Unix/File.cs
   trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Paths.cs
   trunk/banshee/src/Core/Banshee.Core/Banshee.IO.SystemIO/File.cs
   trunk/banshee/src/Core/Banshee.Core/Banshee.IO/File.cs
   trunk/banshee/src/Core/Banshee.Core/Banshee.IO/IFile.cs
   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.Services/Banshee.Library/LibrarySource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
   trunk/banshee/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/MassStorageSource.cs
   trunk/banshee/tests/Hyena/QueryTests.cs
   trunk/banshee/tests/Makefile.am

Modified: trunk/banshee/src/Backends/Banshee.Unix/Banshee.IO.Unix/File.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Unix/Banshee.IO.Unix/File.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.Unix/Banshee.IO.Unix/File.cs	Mon Apr  7 01:41:19 2008
@@ -78,6 +78,11 @@
         {
             Mono.Unix.Native.Stdlib.rename (from.LocalPath, to.LocalPath);
         }
+
+        public void Copy (SafeUri from, SafeUri to, bool overwrite)
+        {
+            System.IO.File.Copy (from.LocalPath, to.LocalPath, overwrite);
+        }
         
         public Stream OpenRead (SafeUri uri)
         {

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Paths.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Paths.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.Base/Paths.cs	Mon Apr  7 01:41:19 2008
@@ -53,20 +53,18 @@
             return result;
         }
         
-        public static string MakePathRelativeToLibrary (string path)
+        public static string MakePathRelative (string path, string to)
         {
-            if (String.IsNullOrEmpty (path)) {
+            if (String.IsNullOrEmpty (path) || String.IsNullOrEmpty (to)) {
                 return null;
             }
             
-            string library_location = CachedLibraryLocation;
-            
-            if (path.Length < library_location.Length + 1) {
+            if (path.Length < to.Length + 1) {
                 return null;
             }
             
-            return path.StartsWith (library_location)
-                ? path.Substring (library_location.Length + 1)
+            return path.StartsWith (to)
+                ? path.Substring (to.Length + 1)
                 : null;
         }
         

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.IO.SystemIO/File.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.IO.SystemIO/File.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.IO.SystemIO/File.cs	Mon Apr  7 01:41:19 2008
@@ -49,6 +49,11 @@
         {
             System.IO.File.Move (from.LocalPath, to.LocalPath);
         }
+
+        public void Copy (SafeUri from, SafeUri to, bool overwrite)
+        {
+            System.IO.File.Copy (from.LocalPath, to.LocalPath, overwrite);
+        }
         
         public long GetSize (SafeUri uri)
         {

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.IO/File.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.IO/File.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.IO/File.cs	Mon Apr  7 01:41:19 2008
@@ -49,6 +49,11 @@
     	    Provider.File.Move (from, to);
     	}
 
+    	public static void Copy (SafeUri from, SafeUri to, bool overwrite)
+    	{
+    	    Provider.File.Copy (from, to, overwrite);
+    	}
+
     	public static long GetSize (SafeUri uri)
     	{
     	    return Provider.File.GetSize (uri);

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.IO/IFile.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.IO/IFile.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.IO/IFile.cs	Mon Apr  7 01:41:19 2008
@@ -37,6 +37,7 @@
         void Delete (SafeUri uri);
         bool Exists (SafeUri uri);
         void Move (SafeUri from, SafeUri to);
+        void Copy (SafeUri from, SafeUri to, bool overwrite);
         long GetSize (SafeUri uri);
         
         System.IO.Stream OpenRead (SafeUri uri);

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 01:41:19 2008
@@ -93,14 +93,19 @@
         protected bool can_copy_to_library = false;
         private Dictionary<int, int> counts;
         private ErrorSource error_source;
+        protected string primary_source_ids;
+        protected string base_directory;
     
-        public DatabaseImportManager (PrimarySource psource) : this (psource.ErrorSource, delegate { return psource; })
+        public DatabaseImportManager (PrimarySource psource) :
+            this (psource.ErrorSource, delegate { return psource; }, psource.DbId.ToString (), psource.BaseDirectory)
         {
         }
 
-        public DatabaseImportManager (ErrorSource error_source, TrackPrimarySourceChooser chooser) : this (chooser)
+        public DatabaseImportManager (ErrorSource error_source, TrackPrimarySourceChooser chooser, string primarySourceIds, string baseDirectory) : this (chooser)
         {
             this.error_source = error_source;
+            primary_source_ids = primarySourceIds;
+            base_directory = baseDirectory;
         }
 
         public DatabaseImportManager (TrackPrimarySourceChooser chooser)
@@ -109,10 +114,18 @@
             counts = new Dictionary<int, int> ();
         }
 
-        protected virtual ErrorSource ErrorSource { 
+        protected virtual ErrorSource ErrorSource {
             get { return error_source; }
         }
 
+        protected virtual string PrimarySourceIds {
+            get { return primary_source_ids; }
+        }
+
+        protected virtual string BaseDirectory {
+            get { return base_directory; }
+        }
+
         protected override void OnImportRequested (string path)
         {
             if (!IsWhiteListedFile (path)) {
@@ -141,7 +154,9 @@
         {
             DatabaseTrackInfo track = null;
             
-            if (DatabaseTrackInfo.ContainsUri (uri)) {
+            if (DatabaseTrackInfo.ContainsUri (uri, Paths.MakePathRelative (uri.AbsolutePath, BaseDirectory) ?? uri.AbsoluteUri, PrimarySourceIds)) {
+                // TODO add DatabaseTrackInfo.SyncedStamp property, and if the file has been
+                // updated since the last sync, fetch its metadata into the db.
                 IncrementProcessedCount (null);
                 return null;
             }

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 01:41:19 2008
@@ -49,10 +49,14 @@
 
 namespace Banshee.Collection.Database
 {
+    public enum TrackUriType : int {
+        AbsolutePath = 0,
+        RelativePath = 1,
+        AbsoluteUri = 2
+    }
+
     public class DatabaseTrackInfo : TrackInfo, ICacheableItem
     {
-        private bool? artist_changed = null, album_changed = null;
-        
         private static BansheeModelProvider<DatabaseTrackInfo> provider = new BansheeModelProvider<DatabaseTrackInfo> (
             ServiceManager.DbConnection, "CoreTracks"
         );
@@ -61,11 +65,9 @@
             get { return provider; }
         }
 
-        private enum UriType : int {
-            AbsolutePath,
-            RelativePath,
-            AbsoluteUri
-        }
+        private bool? artist_changed = null, album_changed = null;
+        private bool uri_fields_dirty = false;
+        private bool updating_uri = false;
         
         public DatabaseTrackInfo () : base ()
         {
@@ -143,10 +145,14 @@
             get { return track_id; }
         }
 
-        [DatabaseColumn ("PrimarySourceID")]
         private int primary_source_id;
+        [DatabaseColumn ("PrimarySourceID")]
         public int PrimarySourceId {
             get { return primary_source_id; }
+            set {
+                primary_source_id = value;
+                UpdateUri ();
+            }
         }
 
         public PrimarySource PrimarySource {
@@ -205,58 +211,47 @@
             get { return music_brainz_id; }
             set { music_brainz_id = value; }
         }
+
+        public override SafeUri Uri {
+            get { return base.Uri; }
+            set {
+                base.Uri = value;
+                uri_fields_dirty = true;
+            }
+        }
         
         private string uri_field;
         [DatabaseColumn ("Uri")]
-        private string uri {
+        private string UriField {
             get {
-                return
-                    uri_field ??
-                    (Uri == null
-                        ? null
-                        : (Paths.MakePathRelativeToLibrary (Uri.AbsolutePath) ?? Uri.AbsoluteUri)
-                    );
+                if (uri_fields_dirty) {
+                    PrimarySource.UriToFields (Uri, out uri_type, out uri_field);
+                    uri_fields_dirty = !updating_uri;
+                }
+                return uri_field;
             }
             set {
                 uri_field = value;
-                if (uri_type_field.HasValue) {
-                    SetUpUri ();
-                }
+                UpdateUri ();
             }
         }
         
-        private int? uri_type_field;
+        private bool uri_type_set;
+        private TrackUriType uri_type;
         [DatabaseColumn ("UriType")]
-        private int uri_type {
+        private TrackUriType UriType {
             get {
-                return uri_type_field.HasValue
-                    ? uri_type_field.Value
-                    : (Uri == null
-                        ? (int)UriType.RelativePath
-                        : (Paths.MakePathRelativeToLibrary (Uri.AbsolutePath) != null
-                            ? (int)UriType.RelativePath
-                            : (int)UriType.AbsoluteUri));
-            }
-            set {
-                uri_type_field = value;
-                if (uri_field != null) {
-                    SetUpUri ();
+                if (uri_fields_dirty) {
+                    PrimarySource.UriToFields (Uri, out uri_type, out uri_field);
+                    uri_fields_dirty = false;
                 }
+                return uri_type;
             }
-        }
-        
-        bool set_up;
-        private void SetUpUri ()
-        {
-            if (set_up) {
-                return;
-            }
-            set_up = true;
-            
-            if (uri_type_field.Value == (int)UriType.RelativePath) {
-                uri_field = System.IO.Path.Combine (Paths.CachedLibraryLocation, uri_field);
+            set {
+                uri_type = value;
+                uri_type_set = true;
+                UpdateUri ();
             }
-            Uri = new SafeUri (uri_field);
         }
         
         [DatabaseColumn]
@@ -403,16 +398,13 @@
             set { cache_model_id = value; }
         }
 
-
-        private static HyenaSqliteCommand check_command = new HyenaSqliteCommand (
-            "SELECT COUNT(*) FROM CoreTracks WHERE Uri = ? OR Uri = ?"
-        );
-        
-        public static bool ContainsUri (SafeUri uri)
+        private void UpdateUri ()
         {
-            string relative_path = Paths.MakePathRelativeToLibrary (uri.AbsolutePath) ?? uri.AbsoluteUri;
-            return ServiceManager.DbConnection.Query<int> (
-                check_command.ApplyValues (relative_path, uri.AbsoluteUri)) > 0;
+            if (Uri == null && uri_type_set && UriField != null && PrimarySource != null) {
+                updating_uri = true;
+                Uri = PrimarySource.UriAndTypeToSafeUri (UriType, UriField);
+                updating_uri = false;
+            }
         }
         
         public SafeUri CopyToLibrary ()
@@ -451,6 +443,15 @@
             
             return null;
         }
+
+        private static HyenaSqliteCommand check_command = new HyenaSqliteCommand (
+            "SELECT COUNT(*) FROM CoreTracks WHERE PrimarySourceId IN (?) AND (Uri = ? OR Uri = ?)"
+        );
+        
+        public static bool ContainsUri (SafeUri uri, string relative_path, string primary_sources)
+        {
+            return ServiceManager.DbConnection.Query<int> (check_command.ApplyValues (primary_sources, relative_path, uri.AbsoluteUri)) > 0;
+        }
     }
 }
 

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 01:41:19 2008
@@ -56,6 +56,19 @@
             get { return ServiceManager.SourceManager.MusicLibrary.ErrorSource; }
         }
 
+        protected override string PrimarySourceIds {
+            get {
+                if (primary_source_ids == null) {
+                    primary_source_ids = String.Format ("{0}, {1}", ServiceManager.SourceManager.VideoLibrary.DbId, ServiceManager.SourceManager.MusicLibrary.DbId);
+                }
+                return primary_source_ids;
+            }
+        }
+
+        protected override string BaseDirectory {
+            get { return ServiceManager.SourceManager.VideoLibrary.BaseDirectory; }
+        }
+
         protected static PrimarySource DefaultTrackPrimarySourceChooser (DatabaseTrackInfo track)
         {
             if ((track.MediaAttributes & TrackMediaAttributes.VideoStream) != 0) {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs	Mon Apr  7 01:41:19 2008
@@ -52,28 +52,18 @@
             Properties.SetString ("RemoveTracksActionLabel", Catalog.GetString ("Remove From Library"));
             AfterInitialized ();
         }
-        
-        protected override void DeleteTrackRange (TrackListDatabaseModel model, RangeCollection.Range range)
-        {
-            // Remove from file system
-            for (int i = range.Start; i <= range.End; i++) {
-                DatabaseTrackInfo track = model [i] as DatabaseTrackInfo;
-                if (track == null)
-                    continue;
 
-                try {
-                    try {
-                        Banshee.IO.Utilities.DeleteFileTrimmingParentDirectories (track.Uri);
-                    } catch (System.IO.FileNotFoundException) {
-                    } catch (System.IO.DirectoryNotFoundException) {
-                    }
-                } catch (Exception e) {
-                    ErrorSource.AddMessage (e.Message, track.Uri.ToString ());
-                }
-            }
+        public override string BaseDirectory {
+            get { return Paths.CachedLibraryLocation; }
+        }
 
-            // Remove from database
-            RemoveTrackRange (model, range);
+        protected override void DeleteTrack (DatabaseTrackInfo track)
+        {
+            try {
+                Banshee.IO.Utilities.DeleteFileTrimmingParentDirectories (track.Uri);
+            } catch (System.IO.FileNotFoundException) {
+            } catch (System.IO.DirectoryNotFoundException) {
+            }
         }
 
         public override bool AcceptsInputFromSource (Source source)

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs	Mon Apr  7 01:41:19 2008
@@ -28,8 +28,9 @@
 
 using System;
 using System.Collections.Generic;
-
 using Mono.Unix;
+
+using Hyena;
 using Hyena.Data;
 using Hyena.Query;
 using Hyena.Data.Sqlite;
@@ -111,6 +112,27 @@
             return (primary_sources.ContainsKey (id)) ? primary_sources[id] : null;
         }
 
+        public virtual SafeUri UriAndTypeToSafeUri (TrackUriType type, string uri_field)
+        {
+            if (type == TrackUriType.RelativePath && BaseDirectory != null)
+                return new SafeUri (System.IO.Path.Combine (BaseDirectory, uri_field));
+            else
+                return new SafeUri (uri_field);
+        }
+
+        public virtual void UriToFields (SafeUri uri, out TrackUriType type, out string uri_field)
+        {
+            uri_field = Paths.MakePathRelative (uri.AbsolutePath, BaseDirectory);
+            type = (uri_field == null) ? TrackUriType.AbsoluteUri : TrackUriType.RelativePath;
+            if (uri_field == null) {
+                uri_field = uri.AbsoluteUri;
+            }
+        }
+
+        public virtual string BaseDirectory {
+            get { return null; }
+        }
+
         protected PrimarySource (string generic_name, string name, string id, int order) : base (generic_name, name, id, order)
         {
             type_unique_id = id;
@@ -243,6 +265,31 @@
             );
         }
 
+        protected override void DeleteTrackRange (TrackListDatabaseModel model, RangeCollection.Range range)
+        {
+            // Remove from file system
+            for (int i = range.Start; i <= range.End; i++) {
+                DatabaseTrackInfo track = model [i] as DatabaseTrackInfo;
+                if (track == null)
+                    continue;
+
+                try {
+                    DeleteTrack (track);
+                } catch (Exception e) {
+                    Log.Exception (e);
+                    ErrorSource.AddMessage (e.Message, track.Uri.ToString ());
+                }
+            }
+
+            // Remove from database
+            RemoveTrackRange (model, range);
+        }
+
+        protected virtual void DeleteTrack (DatabaseTrackInfo track)
+        {
+            throw new Exception ("PrimarySource DeleteTrack method not implemented");
+        }
+
         protected override void PruneArtistsAlbums ()
         {
             ServiceManager.DbConnection.Execute (prune_artists_albums_command);

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui/TrackActions.cs	Mon Apr  7 01:41:19 2008
@@ -219,7 +219,7 @@
                     );
 
                     UpdateAction ("RemoveTracksAction", is_track_source && track_source.CanRemoveTracks, has_selection, source);
-                    UpdateAction ("DeleteTracksFromDriveAction", is_track_source && track_source.CanDeleteTracks, has_selection && is_track_source , source);
+                    UpdateAction ("DeleteTracksFromDriveAction", is_track_source && track_source.CanDeleteTracks, has_selection, source);
                     UpdateAction ("RemoveTracksFromLibraryAction", source.Parent is LibrarySource, has_selection, null);
                     
                     UpdateAction ("TrackPropertiesAction", in_database, has_selection, null);
@@ -261,6 +261,19 @@
             ResetRating ();
 
             Gtk.Menu menu = action_service.UIManager.GetWidget ("/TrackContextMenu") as Menu;
+            if (menu == null || menu.Children.Length == 0) {
+                return;
+            }
+
+            int visible_children = 0;
+            foreach (Widget child in menu)
+                if (child.Visible)
+                    visible_children++;
+
+            if (visible_children == 0) {
+                return;
+            }
+
             menu.Show (); 
             menu.Popup (null, null, null, 0, Gtk.Global.CurrentEventTime);
         }
@@ -277,7 +290,6 @@
         // Generates the menu of playlists to which you can add the selected tracks.
         private void OnAddToPlaylistMenu (object o, EventArgs args)
         {
-            Gdk.Pixbuf pl_pb = Gdk.Pixbuf.LoadFromResource ("source-playlist-16.png");
             Source active_source = ServiceManager.SourceManager.ActiveSource;
 
             // TODO find just the menu that was activated instead of modifying all proxies
@@ -301,7 +313,7 @@
                         }
                         
                         PlaylistMenuItem item = new PlaylistMenuItem (playlist);
-                        item.Image = new Gtk.Image (pl_pb);
+                        item.Image = new Gtk.Image ("playlist-source", IconSize.Menu);
                         item.Activated += OnAddToExistingPlaylist;
                         item.Sensitive = playlist != active_source;
                         submenu.Append (item);

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 01:41:19 2008
@@ -32,6 +32,8 @@
 using Mono.Unix;
 
 using Hyena;
+using Hyena.Collections;
+
 using Banshee.Base;
 using Banshee.ServiceStack;
 using Banshee.Sources;
@@ -92,6 +94,19 @@
             return true;
         }
 
+        protected override void DeleteTrack (DatabaseTrackInfo track)
+        {
+            try {
+                Banshee.IO.Utilities.DeleteFileTrimmingParentDirectories (track.Uri);
+            } catch (System.IO.FileNotFoundException) {
+            } catch (System.IO.DirectoryNotFoundException) {
+            }
+        }
+
+        public override string BaseDirectory {
+            get { return volume.MountPoint; }
+        }
+
         protected string IsAudioPlayerPath {
             get { return System.IO.Path.Combine (volume.MountPoint, ".is_audio_player"); }
         }

Added: trunk/banshee/tests/Banshee.Core/TaglibReadWriteTests.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/tests/Banshee.Core/TaglibReadWriteTests.cs	Mon Apr  7 01:41:19 2008
@@ -0,0 +1,136 @@
+using System;
+using NUnit.Framework;
+
+using Mono.Addins;
+using Banshee.Base;
+using Banshee.Collection;
+using Banshee.Streaming;
+using Banshee.Configuration.Schema;
+
+[TestFixture]
+public class TaglibReadWriteTests
+{
+    /*
+    static string [] files, blank_files;
+    static string pwd;
+
+    static TaglibReadWriteTests () {
+        pwd = Mono.Unix.UnixDirectoryInfo.GetCurrentDirectory ();
+        AddinManager.Initialize (pwd + "/../bin/");
+        Banshee.Configuration.ConfigurationClient.Initialize ();
+
+        files = new string [] {
+            pwd + "/data/test1.ogg",
+            // TODO this flac file doesn't have metadata yet
+            //"data/test2.flac",
+            pwd + "/data/test3.mp3",
+        };
+
+        blank_files = new string [] {
+            pwd + "/data/no_metadata1.ogg",
+            // TODO this flac file doesn't have metadata yet
+            //"data/test2.flac",
+            pwd + "/data/no_metadata3.mp3",
+        };
+    }
+
+    [Test]
+    public void ReadMetadata ()
+    {
+        QueryTests.AssertForEach<string> (files, delegate (string uri) {
+            VerifyRead (new SafeUri (uri));
+        });
+    }
+
+    [Test]
+    public void UpdateMetadata ()
+    {
+        WriteMetadata (files, true);
+    }
+
+    [Test]
+    public void CreateMetadata ()
+    {
+        WriteMetadata (blank_files, false);
+    }
+
+    private static void WriteMetadata (string [] files, bool verify_start_state)
+    {
+        SafeUri newuri = null;
+        bool write_metadata = LibrarySchema.WriteMetadata.Get();
+        LibrarySchema.WriteMetadata.Set (true);
+        try {
+            QueryTests.AssertForEach<string> (files, delegate (string uri) {
+                string [] p = uri.Split ('.');
+                string extension = p[p.Length - 1];
+                newuri = new SafeUri (pwd + "/data/test_write." + extension);
+
+                Banshee.IO.File.Copy (new SafeUri (uri), newuri, true);
+
+                if (verify_start_state) {
+                    VerifyRead (newuri);
+                }
+
+                ChangeAndVerify (newuri);
+            });
+        } finally {
+            LibrarySchema.WriteMetadata.Set (write_metadata);
+            if (newuri != null)
+                Banshee.IO.File.Delete (newuri);
+        }
+    }
+
+#region Utility methods
+
+    private static void VerifyRead (SafeUri uri)
+    {
+        TagLib.File file = StreamTagger.ProcessUri (uri);
+        TrackInfo track = new TrackInfo ();
+        StreamTagger.TrackInfoMerge (track, file);
+
+        Assert.AreEqual ("TestTitle", track.TrackTitle);
+        Assert.AreEqual ("TestArtist", track.ArtistName);
+        Assert.AreEqual ("TestAlbum", track.AlbumTitle);
+        Assert.AreEqual ("TestGenre", track.Genre);
+        Assert.AreEqual (2, track.TrackNumber);
+        Assert.AreEqual (2, track.Disc);
+        Assert.AreEqual (2001, track.Year);
+    }
+
+    private static void ChangeAndVerify (SafeUri uri)
+    {
+        TagLib.File file = StreamTagger.ProcessUri (uri);
+        TrackInfo track = new TrackInfo ();
+        StreamTagger.TrackInfoMerge (track, file);
+
+        // Make changes
+        track.TrackTitle = "My Title";
+        track.ArtistName = "My Artist";
+        track.AlbumTitle = "My Album";
+        track.Genre = "My Genre";
+        track.TrackNumber = 4;
+        track.Disc = 4;
+        track.Year = 1999;
+
+        // Save changes
+        new SaveTrackMetadataJob (track).Run ();
+
+        // Read changes
+        file = StreamTagger.ProcessUri (uri);
+        track = new TrackInfo ();
+        StreamTagger.TrackInfoMerge (track, file);
+
+        // Verify changes
+        Assert.AreEqual ("My Title", track.TrackTitle);
+        Assert.AreEqual ("My Artist", track.ArtistName);
+        Assert.AreEqual ("My Album", track.AlbumTitle);
+        Assert.AreEqual ("My Genre", track.Genre);
+        Assert.AreEqual (4, track.TrackNumber);
+        Assert.AreEqual (4, track.Disc);
+        Assert.AreEqual (1999, track.Year);
+    }
+
+#endregion
+    */
+
+}

Modified: trunk/banshee/tests/Hyena/QueryTests.cs
==============================================================================
--- trunk/banshee/tests/Hyena/QueryTests.cs	(original)
+++ trunk/banshee/tests/Hyena/QueryTests.cs	Mon Apr  7 01:41:19 2008
@@ -77,11 +77,12 @@
         System.Text.StringBuilder sb = new System.Text.StringBuilder ();
         foreach (T o in objects) {
             try { runner (o); }
-            catch (Exception e) { sb.AppendFormat ("{0}\n", e.Message); }
+            catch (AssertionException e) { sb.AppendFormat ("Failed processing {0}: {1}\n", o, e.Message); }
+            catch (Exception e) { sb.AppendFormat ("Failed processing {0}: {1}\n", o, e.ToString ()); }
         }
 
         if (sb.Length > 0)
-            Assert.Fail (sb.ToString ());
+            Assert.Fail ("\n" + sb.ToString ());
     }
 
     private static void UserQueryParsesAndGenerates (string query)

Modified: trunk/banshee/tests/Makefile.am
==============================================================================
--- trunk/banshee/tests/Makefile.am	(original)
+++ trunk/banshee/tests/Makefile.am	Mon Apr  7 01:41:19 2008
@@ -10,7 +10,8 @@
 	$(srcdir)/Hyena/RangeCollectionTests.cs \
 	$(srcdir)/Hyena/StringUtilTests.cs \
 	$(srcdir)/Hyena/SqliteCommandTests.cs \
-	$(srcdir)/Hyena/QueryTests.cs
+	$(srcdir)/Hyena/QueryTests.cs \
+	$(srcdir)/Banshee.Core/TaglibReadWriteTests.cs
 
 #	Banshee.Core/KernelTests.cs
 #	Banshee.Core/FileNamePatternTests.cs



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