[gnome-music] albumartcache: fall back to full options correctly



commit a7c95b4938883d3f2e14e840449ad6ac1a190dd2
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Wed Apr 16 17:18:08 2014 +0200

    albumartcache: fall back to full options correctly

 gnomemusic/albumArtCache.py |   23 +++++++++++------------
 gnomemusic/grilo.py         |   32 +++++++++++++++++++-------------
 gnomemusic/view.py          |    1 +
 3 files changed, 31 insertions(+), 25 deletions(-)
---
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index b870ea7..40c738b 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -146,15 +146,15 @@ class AlbumArtCache:
 
     @log
     def lookup_worker(self, item, width, height, callback, itr, artist, album):
-            try:
-                width = width or -1
-                height = height or -1
-                path = MediaArt.get_path(artist, album, "album", None)[0]
-                if not os.path.exists(path):
-                    self.cached_thumb_not_found(item, album, artist, path, callback, itr)
-                self.read_cached_pixbuf(path, width, height, callback, itr)
-            except Exception as e:
-                logger.warn("Error: %s" % e)
+        try:
+            width = width or -1
+            height = height or -1
+            path = MediaArt.get_path(artist, album, "album", None)[0]
+            if not os.path.exists(path):
+                self.cached_thumb_not_found(item, album, artist, path, callback, itr)
+            self.read_cached_pixbuf(path, width, height, callback, itr)
+        except Exception as e:
+            logger.warn("Error: %s" % e)
 
     @log
     def read_cached_pixbuf(self, path, width, height, callback, itr):
@@ -167,7 +167,6 @@ class AlbumArtCache:
     @log
     def finish(self, pixbuf, path, callback, itr):
         try:
-            grilo.reset_fast_options()
             callback(pixbuf, path, itr)
         except Exception as e:
             logger.warn("Error: %s" % e)
@@ -177,8 +176,8 @@ class AlbumArtCache:
         try:
             uri = item.get_thumbnail()
             if uri is None:
-                grilo.set_full_options()
-                uri = item.get_thumbnail()
+                new_item = grilo.get_album_art_for_album_id(item.get_id())[0]
+                uri = new_item.get_thumbnail()
                 if uri is None:
                     logger.warn("can't find URL for album '%s' by %s" % (album, artist))
                     self.finish(None, path, callback, itr)
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index db6e086..d3ff075 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -46,6 +46,11 @@ class Grilo(GObject.GObject):
         Grl.METADATA_KEY_CREATION_DATE,
         Grl.METADATA_KEY_THUMBNAIL]
 
+    METADATA_THUMBNAIL_KEYS = [
+        Grl.METADATA_KEY_ID,
+        Grl.METADATA_KEY_THUMBNAIL,
+    ]
+
     CHANGED_MEDIA_MAX_ITEMS = 500
     CHANGED_MEDIA_SIGNAL_TIMEOUT = 2000
 
@@ -56,7 +61,13 @@ class Grilo(GObject.GObject):
                                                   "gnome-music", "playlists"])
         if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)):
             GLib.mkdir_with_parents(self.playlist_path, int("0755", 8))
-        self.reset_fast_options()
+        self.options = Grl.OperationOptions()
+        self.options.set_flags(Grl.ResolutionFlags.FAST_ONLY |
+                               Grl.ResolutionFlags.IDLE_RELAY)
+
+        self.full_options = Grl.OperationOptions()
+        self.full_options.set_flags(Grl.ResolutionFlags.FULL |
+                                    Grl.ResolutionFlags.IDLE_RELAY)
 
         self.sources = {}
         self.tracker = None
@@ -75,18 +86,6 @@ class Grilo(GObject.GObject):
             logger.debug("tracker found")
 
     @log
-    def set_full_options(self):
-        self.options = Grl.OperationOptions()
-        self.options.set_flags(Grl.ResolutionFlags.FULL |
-                               Grl.ResolutionFlags.IDLE_RELAY)
-
-    @log
-    def reset_fast_options(self):
-        self.options = Grl.OperationOptions()
-        self.options.set_flags(Grl.ResolutionFlags.FAST_ONLY |
-                               Grl.ResolutionFlags.IDLE_RELAY)
-
-    @log
     def _on_content_changed(self, mediaSource, changedMedias, changeType, locationUnknown):
         try:
             for media in changedMedias:
@@ -197,6 +196,13 @@ class Grilo(GObject.GObject):
 
         self.tracker.query(query, self.METADATA_KEYS, options, _callback, None)
 
+    @log
+    def get_album_art_for_album_id(self, album_id):
+        options = self.full_options.copy()
+        query = Query.get_album_for_id(album_id)
+        return self.tracker.query_sync(query, self.METADATA_THUMBNAIL_KEYS, options)
+
+
 Grl.init(None)
 
 grilo = Grilo()
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index bee691b..f267fcb 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -296,6 +296,7 @@ class ViewContainer(Gtk.Stack):
             self._model.set_value(
                 _iter, 4,
                 icon)
+            self.view.queue_draw()
 
     @log
     def _add_list_renderers(self):


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