[banshee] [Dap.Ipod] Update metadata in Manual Sync mode (bgo#589196)



commit 70380e3920da9264dca773a522b856bfd3461e64
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Sun Sep 19 15:29:51 2010 +0200

    [Dap.Ipod] Update metadata in Manual Sync mode (bgo#589196)
    
    This patch basically takes care of implementing the UpdateMetadata()
    call exposed virtually by PrimarySource to make the changes belong
    to the PerformSync operation, and overrides HasEditableTrackProperties
    to true for the SaveTrackMetadaService to be able to hook on the
    source to flush changes to files (these changes wouldn't actually
    be visible by the iPod but it's still good to flush them to maintain
    them in sync with what is in the iPod database, just in case some
    user copies/imports them from the device).

 .../Banshee.Dap.Ipod/IpodSource.cs                 |   49 +++++++++++++++++++-
 .../Banshee.Dap.Ipod/IpodTrackInfo.cs              |   13 ++++-
 2 files changed, 58 insertions(+), 4 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs b/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs
index e79bb12..ec928fe 100644
--- a/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs
+++ b/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodSource.cs
@@ -35,6 +35,7 @@ using Mono.Unix;
 using IPod;
 
 using Hyena;
+using Hyena.Query;
 using Banshee.Base;
 using Banshee.ServiceStack;
 using Banshee.Sources;
@@ -401,6 +402,27 @@ namespace Banshee.Dap.Ipod
 
 #region Syncing
 
+        public override void UpdateMetadata (DatabaseTrackInfo track)
+        {
+            lock (sync_mutex) {
+                IpodTrackInfo ipod_track;
+                if (!tracks_map.TryGetValue (track.TrackId, out ipod_track)) {
+                    return;
+                }
+
+                ipod_track.UpdateInfo (track);
+                tracks_to_update.Enqueue (ipod_track);
+            }
+        }
+
+        protected override void OnTracksChanged (params QueryField[] fields)
+        {
+            if (tracks_to_update.Count > 0 && !Sync.Syncing) {
+                QueueSync ();
+            }
+            base.OnTracksChanged (fields);
+        }
+
         protected override void OnTracksAdded ()
         {
             if (!IsAdding && tracks_to_add.Count > 0 && !Sync.Syncing) {
@@ -418,6 +440,7 @@ namespace Banshee.Dap.Ipod
         }
 
         private Queue<IpodTrackInfo> tracks_to_add = new Queue<IpodTrackInfo> ();
+        private Queue<IpodTrackInfo> tracks_to_update = new Queue<IpodTrackInfo> ();
         private Queue<IpodTrackInfo> tracks_to_remove = new Queue<IpodTrackInfo> ();
 
         private uint sync_timeout_id = 0;
@@ -586,7 +609,18 @@ namespace Banshee.Dap.Ipod
                 OnUserNotifyUpdated ();
             }
 
-            // TODO sync updated metadata to changed tracks
+            while (tracks_to_update.Count > 0) {
+                IpodTrackInfo track = null;
+                lock (sync_mutex) {
+                    track = tracks_to_update.Dequeue ();
+                }
+
+                try {
+                    track.CommitToIpod (ipod_device);
+                } catch (Exception e) {
+                    Log.Exception ("Cannot save track to iPod", e);
+                }
+            }
 
             while (tracks_to_remove.Count > 0) {
                 IpodTrackInfo track = null;
@@ -702,11 +736,22 @@ namespace Banshee.Dap.Ipod
         public bool SyncNeeded {
             get {
                 lock (sync_mutex) {
-                    return tracks_to_add.Count > 0 || tracks_to_remove.Count > 0;
+                    return tracks_to_add.Count > 0 ||
+                        tracks_to_update.Count > 0 ||
+                        tracks_to_remove.Count > 0;
+
                 }
             }
         }
 
+        public override bool HasEditableTrackProperties {
+            get {
+                // we want child sources to be able to edit metadata and the
+                // savetrackmetadataservice to take in account this source
+                return true;
+            }
+        }
+
 #endregion
 
     }
diff --git a/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodTrackInfo.cs b/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodTrackInfo.cs
index a2be748..9d83e30 100644
--- a/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodTrackInfo.cs
+++ b/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/IpodTrackInfo.cs
@@ -61,10 +61,19 @@ namespace Banshee.Dap.Ipod
 
         public IpodTrackInfo (TrackInfo track)
         {
+            CanSaveToDatabase = true;
+
             if (track is IpodTrackInfo) {
                 this.track = ((IpodTrackInfo)track).IpodTrack;
                 LoadFromIpodTrack ();
             } else {
+                UpdateInfo (track);
+            }
+        }
+
+        public void UpdateInfo (TrackInfo track)
+        {
+            if (!(track is IpodTrackInfo)) {
                 AlbumArtist = track.AlbumArtist;
                 AlbumTitle = track.AlbumTitle;
                 ArtistName = track.ArtistName;
@@ -100,9 +109,9 @@ namespace Banshee.Dap.Ipod
                     description = podcast_info.Description;
                     ReleaseDate = podcast_info.ReleaseDate;
                 }
+            } else {
+                throw new ArgumentException ("Shouldn't update an IpodTrackInfo from an IpodTrackInfo");
             }
-
-            CanSaveToDatabase = true;
         }
 
         private void LoadFromIpodTrack ()



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