[gnome-music/wip/mschraal/triggered-art-update: 2/2] Triggered loading somewhat working.



commit 261ac68c79e8cf1bf7e0fb4e513832fb99a75546
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu Sep 27 23:38:35 2018 +0200

    Triggered loading somewhat working.
    
    Look away, I'm hideous.

 gnomemusic/albumartcache.py      | 26 ++++++++++++++++++++++----
 gnomemusic/grilo.py              |  3 +++
 gnomemusic/widgets/coverstack.py |  4 +++-
 3 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index e814b8c7..d620c0a5 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -235,6 +235,7 @@ class Art(GObject.GObject):
         remote_art = RemoteArt()
         remote_art.connect('retrieved', self._remote_art_retrieved)
         remote_art.connect('unavailable', self._remote_art_unavailable)
+        remote_art.connect('no-sources', self._remote_art_no_sources)
         remote_art.query(self._media)
 
     @log
@@ -249,6 +250,10 @@ class Art(GObject.GObject):
         self._add_to_blacklist()
         self._no_art_available()
 
+    @log
+    def _remote_art_no_sources(self, klass):
+        self._no_art_available()
+
     @log
     def _no_art_available(self):
         self._surface = DefaultIcon().get(
@@ -599,7 +604,8 @@ class RemoteArt(GObject.GObject):
 
     __gsignals__ = {
         'retrieved': (GObject.SignalFlags.RUN_FIRST, None, ()),
-        'unavailable': (GObject.SignalFlags.RUN_FIRST, None, ())
+        'unavailable': (GObject.SignalFlags.RUN_FIRST, None, ()),
+        'no-sources': (GObject.SignalFlags.RUN_FIRST, None, ())
     }
 
     def __repr__(self):
@@ -620,10 +626,22 @@ class RemoteArt(GObject.GObject):
         """
         self._album = utils.get_album_title(media)
         self._artist = utils.get_artist_name(media)
+        self._media = media
 
-        # FIXME: It seems this Grilo query does not always return,
-        # especially on queries with little info.
-        grilo.get_album_art_for_item(media, self._remote_album_art)
+        if not grilo.props.cover_sources:
+            print("NO SOURCES for", self._artist, self._album)
+            self.emit('no-sources')
+            grilo.connect(
+                'notify::cover-sources', self._on_grilo_cover_sources_changed)
+        else:
+            # FIXME: It seems this Grilo query does not always return,
+            # especially on queries with little info.
+            grilo.get_album_art_for_item(media, self._remote_album_art)
+
+    def _on_grilo_cover_sources_changed(self, klass, data):
+        print("COVER SOURCES CHANGED")
+        if grilo.props.cover_sources:
+            grilo.get_album_art_for_item(self._media, self._remote_album_art)
 
     @log
     def _delete_callback(self, src, result, data):
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index c904b6a7..8f3e27f3 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -80,6 +80,7 @@ class Grilo(GObject.GObject):
     _theaudiodb_api_key = "195003"
 
     sources = GObject.Property()
+    cover_sources = GObject.Property(type=bool, default=False)
 
     def __repr__(self):
         return '<Grilo>'
@@ -207,6 +208,8 @@ class Grilo(GObject.GObject):
     @log
     def _trigger_art_update(self):
         self._thumbnail_sources_timeout = None
+        if len(self._thumbnail_sources) > 0:
+            self.props.cover_sources = True
         print("UPDATE", self._thumbnail_sources)
 
         return GLib.SOURCE_REMOVE
diff --git a/gnomemusic/widgets/coverstack.py b/gnomemusic/widgets/coverstack.py
index 6950908c..d261fd5b 100644
--- a/gnomemusic/widgets/coverstack.py
+++ b/gnomemusic/widgets/coverstack.py
@@ -68,6 +68,7 @@ class CoverStack(Gtk.Stack):
 
         self.props.size = size
         self.props.transition_type = Gtk.StackTransitionType.CROSSFADE
+        self.props.transition_duration = 1000
         self.props.visible_child_name = "loading"
 
         self.show_all()
@@ -103,12 +104,12 @@ class CoverStack(Gtk.Stack):
         self._active_child = self.props.visible_child_name
 
         art = Art(self.props.size, media, self.props.scale_factor)
+        # if not self._handler_id:
         self._handler_id = art.connect('finished', self._art_retrieved)
         art.lookup()
 
     @log
     def _art_retrieved(self, klass):
-        klass.disconnect(self._handler_id)
         if self._active_child == "B":
             self._cover_a.props.surface = klass.surface
             self.props.visible_child_name = "A"
@@ -116,4 +117,5 @@ class CoverStack(Gtk.Stack):
             self._cover_b.props.surface = klass.surface
             self.props.visible_child_name = "B"
 
+        self._active_child = self.props.visible_child_name
         self.emit('updated')


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