[gnome-music/wip/mschraal/coresong-thumbnail-prop: 21/35] Simple cache



commit 25c0055293c83f36064eebae8fb6f99629bccf9f
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu Nov 28 15:44:53 2019 +0100

    Simple cache

 gnomemusic/corealbum.py          | 19 +++++++++++++++++--
 gnomemusic/widgets/albumcover.py | 10 ++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/corealbum.py b/gnomemusic/corealbum.py
index 24517658..5b2cc481 100644
--- a/gnomemusic/corealbum.py
+++ b/gnomemusic/corealbum.py
@@ -23,8 +23,8 @@
 # delete this exception statement from your version.
 
 import gi
-gi.require_version("Grl", "0.3")
-from gi.repository import Gio, Grl, GObject
+gi.require_versions({"Grl": "0.3", "MediaArt": "2.0"})
+from gi.repository import Gio, Grl, GObject, MediaArt
 
 import gnomemusic.utils as utils
 
@@ -122,8 +122,23 @@ class CoreAlbum(GObject.GObject):
         if self._thumbnail == None:
             self._thumbnail = "loading"
 
+            self._in_cache()
+
         return self._thumbnail
 
     @thumbnail.setter
     def thumbnail(self, value):
+        if self._thumbnail == value:
+            return
+
         self._thumbnail = value
+
+    def _in_cache(self):
+        success, thumb_file = MediaArt.get_file(
+            self.props.artist, self.props.title, "album")
+
+        if (not success
+                or not thumb_file.query_exists()):
+            return False
+
+        self.props.thumbnail = thumb_file.get_path()
diff --git a/gnomemusic/widgets/albumcover.py b/gnomemusic/widgets/albumcover.py
index bd895893..28c205e1 100644
--- a/gnomemusic/widgets/albumcover.py
+++ b/gnomemusic/widgets/albumcover.py
@@ -93,6 +93,12 @@ class AlbumCover(Gtk.FlowBoxChild):
 
         self.show()
 
+        self._corealbum.connect(
+            "notify::thumbnail", self._on_thumbnail_changed)
+
+    def _on_thumbnail_changed(self, klass, param):
+        print(self._corealbum.props.title, self._corealbum.props.thumbnail)
+
     def retrieve(self):
         """Start retrieving the actual album cover
 
@@ -102,6 +108,10 @@ class AlbumCover(Gtk.FlowBoxChild):
         if self._retrieved:
             return
 
+        print(
+            "retrieve", self._corealbum.props.title,
+            self._corealbum.props.thumbnail)
+
         self._retrieved = True
         self._cover_stack.update(self._corealbum)
 


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