banshee r4395 - in trunk/banshee: . src/Core/Banshee.Core/Banshee.IO src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Collection src/Core/Banshee.ThickClient/Banshee.Gui.Dialogs



Author: rubenv
Date: Mon Aug 18 09:00:33 2008
New Revision: 4395
URL: http://svn.gnome.org/viewvc/banshee?rev=4395&view=rev

Log:
2008-08-15  Ruben Vermeersch  <ruben savanne be>

	* src/Core/Banshee.Core/Banshee.IO/Utilities.cs: Split
	TrimEmptyDirectories out of DeleteFileTrimmingParentDirectories, useful in
	case  you don't need the Delete.

	* src/Core/Banshee.Services/Banshee.Collection/MoveOnInfoSaveJob.cs:
	Added. Moves a file after changing the metadata. This maintains the
	FileNamePattern even after changing metadata.

	* src/Core/Banshee.Services/Makefile.am: Add the new file to the build.

	* src/Core/Banshee.ThickClient/Banshee.Gui.Dialogs/TrackEditor.cs: Queue a
	MoveOnInfoSaveJob when saving.


Added:
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection/MoveOnInfoSaveJob.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Core/Banshee.IO/Utilities.cs
   trunk/banshee/src/Core/Banshee.Services/Makefile.am
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Dialogs/TrackEditor.cs

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.IO/Utilities.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.IO/Utilities.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.IO/Utilities.cs	Mon Aug 18 09:00:33 2008
@@ -37,7 +37,11 @@
         public static void DeleteFileTrimmingParentDirectories (SafeUri uri)
         {
             Banshee.IO.File.Delete (uri);
-            
+            TrimEmptyDirectories (uri);
+        }
+
+        public static void TrimEmptyDirectories (SafeUri uri)
+        {
             try {
                 string old_dir = System.IO.Path.GetDirectoryName (uri.LocalPath);
                 while (old_dir != null && old_dir != String.Empty) {

Added: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection/MoveOnInfoSaveJob.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection/MoveOnInfoSaveJob.cs	Mon Aug 18 09:00:33 2008
@@ -0,0 +1,77 @@
+//
+// MoveOnInfoSaveJob.cs
+//
+// Author:
+//   Ruben Vermeersch <ruben savanne be>
+//
+// Copyright (C) 2006-2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+
+using Mono.Unix;
+
+using Banshee.Base;
+using Banshee.Configuration.Schema;
+
+namespace Banshee.Collection
+{
+    public class MoveOnInfoSaveJob : Banshee.Kernel.IInstanceCriticalJob
+    {
+        private TrackInfo track;
+
+        public string Name {
+            get { return String.Format (Catalog.GetString ("Renaming {0}"), track.TrackTitle); }
+        }
+
+        public MoveOnInfoSaveJob (TrackInfo track)
+        {
+            this.track = track;
+        }
+
+        public void Run ()
+        {
+            if (!LibrarySchema.MoveOnInfoSave.Get ()) {
+                Hyena.Log.Debug ("Skipping scheduled rename, preference disabled after scheduling");
+                return;
+            }
+
+            SafeUri old_uri = track.Uri;
+            bool in_library = old_uri.AbsolutePath.StartsWith (Paths.CachedLibraryLocationWithSeparator);
+
+            if (!in_library) {
+                return;
+            }
+
+            string new_filename = FileNamePattern.BuildFull (track, Path.GetExtension (old_uri.ToString ()));
+            SafeUri new_uri = new SafeUri (new_filename);
+
+            if (!new_uri.Equals (old_uri) && !Banshee.IO.File.Exists (new_uri)) {
+                Banshee.IO.File.Move (old_uri, new_uri);
+                Banshee.IO.Utilities.TrimEmptyDirectories (old_uri);
+                track.Uri = new_uri;
+                track.Save ();
+            }
+        }
+    }
+}

Modified: trunk/banshee/src/Core/Banshee.Services/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Makefile.am	Mon Aug 18 09:00:33 2008
@@ -33,6 +33,7 @@
 	Banshee.Collection/ImportManager.cs \
 	Banshee.Collection/MemoryTrackListModel.cs \
 	Banshee.Collection/ModelHelper.cs \
+	Banshee.Collection/MoveOnInfoSaveJob.cs \
 	Banshee.Collection/SelectAllSelection.cs \
 	Banshee.Collection/TrackListModel.cs \
 	Banshee.Configuration/DatabaseConfigurationClient.cs \

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Dialogs/TrackEditor.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Dialogs/TrackEditor.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.Dialogs/TrackEditor.cs	Mon Aug 18 09:00:33 2008
@@ -658,6 +658,10 @@
                 SaveToFile (track);
             }
 
+            if (LibrarySchema.MoveOnInfoSave.Get ()) {
+                MoveSavedFile (track);
+            }
+
             if (track.Track == ServiceManager.PlayerEngine.CurrentTrack) {
                 ServiceManager.PlayerEngine.TrackInfoUpdated ();
             }
@@ -667,6 +671,11 @@
         {
             Banshee.Kernel.Scheduler.Schedule (new SaveTrackMetadataJob (track.Track), Banshee.Kernel.JobPriority.Highest);
         }
+
+        private void MoveSavedFile (EditorTrack track)
+        {
+            Banshee.Kernel.Scheduler.Schedule (new MoveOnInfoSaveJob (track.Track), Banshee.Kernel.JobPriority.Highest);
+        }
     }
 }
 



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