[banshee] Fix album art support for MTP devices when using libmtp8 (BGO #560520)



commit 6bd11890524f19b47a8e6836aad494da5363d9d8
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Wed Apr 29 17:05:52 2009 -0500

    Fix album art support for MTP devices when using libmtp8 (BGO #560520)
---
 src/Core/Banshee.Core/Resources/translators.xml    |    1 -
 .../Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs   |   24 +++++++++--
 src/Libraries/Mtp/Mtp/Album.cs                     |   42 +++++++++++++-------
 3 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/src/Core/Banshee.Core/Resources/translators.xml b/src/Core/Banshee.Core/Resources/translators.xml
index faf438c..f2e6377 100644
--- a/src/Core/Banshee.Core/Resources/translators.xml
+++ b/src/Core/Banshee.Core/Resources/translators.xml
@@ -30,7 +30,6 @@
     <person>Philipp Kerling</person>
     <person>Andre Klapper</person>
     <person>Mario Blättermann</person>
-    <person>Hendrik Richter</person>
   </language>
   <language code="dz" name="Dzongkha">
     <person>yumkee lhamo</person>
diff --git a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
index 5833f3e..6bd23cf 100644
--- a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
+++ b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
@@ -169,6 +169,15 @@ namespace Banshee.Dap.Mtp
                     return;
                 }*/
 
+                // Delete any empty albums
+                lock (mtp_device) {
+                    foreach (Album album in mtp_device.GetAlbums ()) {
+                        if (album.Count == 0) {
+                            album.Remove ();
+                        }
+                    }
+                }
+
                 int [] source_ids = new int [] { DbId };
                 foreach (Track mtp_track in files) {
                     int track_id;
@@ -326,9 +335,9 @@ namespace Banshee.Dap.Mtp
 
                 // Add/update album art
                 if (!video) {
-                    string key = MakeAlbumKey (track.ArtistName, track.AlbumTitle);
+                    string key = MakeAlbumKey (track.AlbumArtist, track.AlbumTitle);
                     if (!album_cache.ContainsKey (key)) {
-                        Album album = new Album (mtp_device, track.AlbumTitle, track.ArtistName, track.Genre);
+                        Album album = new Album (mtp_device, track.AlbumTitle, track.AlbumArtist, track.Genre, track.Composer);
                         album.AddTrack (mtp_track);
 
                         if (supports_jpegs && can_sync_albumart) {
@@ -342,7 +351,12 @@ namespace Banshee.Dap.Mtp
                                     Banshee.Collection.Gui.ArtworkManager.DisposePixbuf (pic);
                                 }
                                 album_cache[key] = album;
-                            } catch {}
+                            } catch (Exception e) {
+                                Log.Debug ("Failed to create MTP Album", e.Message);
+                            }
+                        } else {
+                            album.Save ();
+                            album_cache[key] = album;
                         }
                     } else {
                         Album album = album_cache[key];
@@ -432,9 +446,9 @@ namespace Banshee.Dap.Mtp
             Dispose ();
         }
 
-        private static string MakeAlbumKey (string artist, string album)
+        private static string MakeAlbumKey (string album_artist, string album)
         {
-            return String.Format ("{0}_{1}", artist, album);
+            return String.Format ("{0}_{1}", album_artist, album);
         }
 
         public static readonly SchemaEntry<bool> NeverSyncAlbumArtSchema = new SchemaEntry<bool>(
diff --git a/src/Libraries/Mtp/Mtp/Album.cs b/src/Libraries/Mtp/Mtp/Album.cs
index 6ebc90f..e0d00e6 100644
--- a/src/Libraries/Mtp/Mtp/Album.cs
+++ b/src/Libraries/Mtp/Mtp/Album.cs
@@ -43,30 +43,37 @@ namespace Mtp
 
         public override string Name {
             get { return album.name; }
-            set {
-                album.name = value;
-            }
+            set { album.name = value; }
         }
 
         public string Artist {
             get { return album.artist; }
-            set {
-                album.artist = value;
-            }
+            set { album.artist = value; }
         }
 
         public string Genre {
             get { return album.genre; }
+            set { album.genre = value; }
+        }
+
+        public string Composer {
+            get {
+#if LIBMTP8
+                return album.composer;
+#else
+                return null;
+#endif
+            }
             set {
-                album.genre = value;
+#if LIBMTP8
+                album.composer = value;
+#endif
             }
         }
 
         public override uint Count {
             get { return album.no_tracks; }
-            protected set {
-                album.no_tracks = value;
-            }
+            protected set { album.no_tracks = value; }
         }
 
         protected override IntPtr TracksPtr {
@@ -74,14 +81,14 @@ namespace Mtp
             set { album.tracks = value; }
         }
 
-        public Album (MtpDevice device, string name, string artist, string genre) : base (device, name)
+        public Album (MtpDevice device, string name, string artist, string genre, string composer) : base (device, name)
         {
-            this.album = new AlbumStruct ();
-            TracksPtr = IntPtr.Zero;
             Name = name;
             Artist = artist;
             Genre = genre;
+            Composer = composer;
             Count = 0;
+            TracksPtr = IntPtr.Zero;
         }
 
         internal Album (MtpDevice device, AlbumStruct album) : base (device, album.tracks, album.no_tracks)
@@ -111,7 +118,7 @@ namespace Mtp
                 cover.filetype = FileType.JPEG;
 
                 if (FileSample.LIBMTP_Send_Representative_Sample (Device.Handle, AlbumId, ref cover) != 0) {
-                    //Console.WriteLine ("failed to send representative sample file");
+                    //Console.WriteLine ("Failed to send representative sample file for album {0} (id {1})", Name, AlbumId);
                 }
                 Marshal.FreeHGlobal (cover.data);
             }
@@ -190,12 +197,17 @@ namespace Mtp
         [MarshalAs(UnmanagedType.LPStr)]
         public string artist;
 
+#if LIBMTP8
+        [MarshalAs(UnmanagedType.LPStr)]
+        public string composer;
+#endif
+
         [MarshalAs(UnmanagedType.LPStr)]
         public string genre;
 
         public IntPtr tracks;
         public uint no_tracks;
 
-        public IntPtr next; // LIBMTP_album_t*
+        public IntPtr next;
     }
 }



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