[banshee] [Dap] Infrastructure for saving metadata (Manual Sync) (bgo#589196)



commit e219b0dfc19e0a883c65f8dd1ce64615fa81fe41
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Sun Sep 19 14:52:56 2010 +0200

    [Dap] Infrastructure for saving metadata (Manual Sync) (bgo#589196)
    
    This patch makes it possible for Dap sources to save metadata
    changes that the user may perform after the sync has been done.
    It basically adds a virtual call for the DapSource to override
    and tweaks the SaveTrackMetadataJob to also take in account
    tracks that were never synced before (for writing the changes
    into the file too, besides the changes that the DapSource may
    need to flush into its database or file system, if any).
    
    Next patches to land will be iPod support, and AppleDevice support.
    Hopefully I can have time to work on Android support later on.

 .../DatabaseTrackInfo.cs                           |    2 +
 .../Banshee.Metadata/SaveTrackMetadataJob.cs       |    4 +-
 .../Banshee.Sources/PrimarySource.cs               |    4 ++
 src/Dap/Banshee.Dap/Banshee.Dap.csproj             |    1 +
 src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs  |    2 +-
 .../Banshee.Dap/Banshee.Dap/MediaGroupSource.cs    |    7 ++-
 .../Banshee.Dap/Banshee.Dap/MusicGroupSource.cs    |   20 ++++++++
 src/Dap/Banshee.Dap/Banshee.Dap/SyncPlaylist.cs    |   52 ++++++++++++++++++++
 src/Dap/Banshee.Dap/Makefile.am                    |    1 +
 9 files changed, 89 insertions(+), 4 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
index f513ff3..9761fcb 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
@@ -177,6 +177,8 @@ namespace Banshee.Collection.Database
 
         public void Save (bool notify, params QueryField [] fields_changed)
         {
+            PrimarySource.UpdateMetadata (this);
+
             // If either the artist or album changed,
             if (ArtistId == 0 || AlbumId == 0 || artist_changed == true || album_changed == true) {
                 DatabaseArtistInfo artist = Artist;
diff --git a/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs b/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
index 6709b71..3f92112 100644
--- a/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
+++ b/src/Core/Banshee.Services/Banshee.Metadata/SaveTrackMetadataJob.cs
@@ -59,9 +59,9 @@ namespace Banshee.Metadata
 
             string range = String.Join (",", db_ids);
 
-            //FIXME: should we add the case in which LastSyncedStamp IS NULL?
             string condition = String.Format (
-                @"DateUpdatedStamp > LastSyncedStamp
+                @"(DateUpdatedStamp > LastSyncedStamp OR
+                  (DateUpdatedStamp IS NOT NULL AND LastSyncedStamp IS NULL))
                   AND PrimarySourceID IN ({0})", range);
 
             CountCommand = new HyenaSqliteCommand (
diff --git a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
index 4a14bf5..08d8ce1 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
@@ -316,6 +316,10 @@ namespace Banshee.Sources
             );
         }
 
+        public virtual void UpdateMetadata (DatabaseTrackInfo track)
+        {
+        }
+
         public virtual void CopyTrackTo (DatabaseTrackInfo track, SafeUri uri, BatchUserJob job)
         {
             Log.WarningFormat ("CopyTrackTo not implemented for source {0}", this);
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap.csproj b/src/Dap/Banshee.Dap/Banshee.Dap.csproj
index 87b04fe..d1826c5 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap.csproj
+++ b/src/Dap/Banshee.Dap/Banshee.Dap.csproj
@@ -114,6 +114,7 @@
     <Compile Include="Banshee.Dap.Gui\PurchasedMusicActions.cs" />
     <Compile Include="Banshee.Dap.Gui\LibrarySyncOptions.cs" />
     <Compile Include="Banshee.Dap\DapPriorityNode.cs" />
+    <Compile Include="Banshee.Dap\SyncPlaylist.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Banshee.Dap.addin.xml">
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs b/src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs
index ac8f164..482659d 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs
@@ -224,7 +224,7 @@ namespace Banshee.Dap
                         if (from.Count == 0) {
                             continue;
                         }
-                        PlaylistSource to = new PlaylistSource (from.Name, sync.Dap);
+                        var to = new SyncPlaylist (from.Name, sync.Dap, this);
                         to.Save ();
 
                         ServiceManager.DbConnection.Execute (
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/MediaGroupSource.cs b/src/Dap/Banshee.Dap/Banshee.Dap/MediaGroupSource.cs
index 593ea92..1873c50 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/MediaGroupSource.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/MediaGroupSource.cs
@@ -43,7 +43,7 @@ namespace Banshee.Dap
 {
     public abstract class MediaGroupSource : SmartPlaylistSource
     {
-        private DapSource parent;
+        protected DapSource parent;
 
         public MediaGroupSource (DapSource parent, string name) : base (name, parent)
         {
@@ -119,5 +119,10 @@ namespace Banshee.Dap
         public long BytesUsed {
             get { return DatabaseTrackModel.UnfilteredFileSize; }
         }
+
+        public override bool HasEditableTrackProperties {
+            // not be able to sync metadata by default, override if needed
+            get { return false; }
+        }
     }
 }
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/MusicGroupSource.cs b/src/Dap/Banshee.Dap/Banshee.Dap/MusicGroupSource.cs
index d39a76a..b75aa53 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/MusicGroupSource.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/MusicGroupSource.cs
@@ -30,6 +30,7 @@ using System;
 using Mono.Unix;
 
 using Banshee.Collection;
+using Banshee.ServiceStack;
 
 namespace Banshee.Dap
 {
@@ -41,5 +42,24 @@ namespace Banshee.Dap
             Properties.SetStringList ("Icon.Name", Banshee.ServiceStack.ServiceManager.SourceManager.MusicLibrary.Properties.GetStringList ("Icon.Name"));
             ConditionSql = Banshee.ServiceStack.ServiceManager.SourceManager.MusicLibrary.AttributesCondition;
         }
+
+        public override bool HasEditableTrackProperties {
+            get {
+                // dap capabilities dictate first
+                if (!parent.HasEditableTrackProperties) {
+                    return false;
+                }
+
+                // we only allow editing in Manual Sync Mode
+                // (Auto Sync Mode will require to edit the original tracks)
+                foreach (var libsync in parent.Sync.Libraries) {
+                    if (libsync.Library.Equals (ServiceManager.SourceManager.MusicLibrary)) {
+                        return !libsync.Enabled;
+                    }
+                }
+
+                return false;
+            }
+        }
     }
 }
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/SyncPlaylist.cs b/src/Dap/Banshee.Dap/Banshee.Dap/SyncPlaylist.cs
new file mode 100644
index 0000000..090bed5
--- /dev/null
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/SyncPlaylist.cs
@@ -0,0 +1,52 @@
+// 
+// SyncPlaylist.cs
+// 
+// Author:
+//   Andrés G. Aragoneses <knocte gmail com>
+// 
+// Copyright (c) 2010 Andrés G. Aragoneses
+// 
+// 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 Banshee.Playlist;
+using Banshee.Sources;
+
+namespace Banshee.Dap
+{
+    public class SyncPlaylist : PlaylistSource
+    {
+        public SyncPlaylist (string name, PrimarySource parent, DapLibrarySync libsync) : base (name, parent)
+        {
+            this.libsync = libsync;
+        }
+
+        private DapLibrarySync libsync;
+
+        public override bool HasEditableTrackProperties {
+            get {
+                // we don't want the user editing the target of a sync, but the origin
+                return !libsync.Enabled;
+                // NOTE: we could have implemented this simply as "return false" because
+                // when switching from AutoSync to ManualSync the playlists are nuked,
+                // but it's not clear if it's the intended behavior! (check out BGO#626113)
+            }
+        }
+    }
+}
diff --git a/src/Dap/Banshee.Dap/Makefile.am b/src/Dap/Banshee.Dap/Makefile.am
index 864be76..11b9038 100644
--- a/src/Dap/Banshee.Dap/Makefile.am
+++ b/src/Dap/Banshee.Dap/Makefile.am
@@ -22,6 +22,7 @@ SOURCES =  \
 	Banshee.Dap/MusicGroupSource.cs \
 	Banshee.Dap/PodcastGroupSource.cs \
 	Banshee.Dap/RemovableSource.cs \
+	Banshee.Dap/SyncPlaylist.cs \
 	Banshee.Dap/VideoGroupSource.cs
 
 RESOURCES =  \



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