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



commit 4d60404eb54db29c26bd81eff2447c8e57582b3d
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 ead41126..058b3945 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
 
@@ -119,8 +119,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 9bd31e6b..27075a03 100644
--- a/gnomemusic/widgets/albumcover.py
+++ b/gnomemusic/widgets/albumcover.py
@@ -85,6 +85,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
 
@@ -94,6 +100,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]