[gnome-music/wip/jfelder/playlists-core-rewrite-prep-work: 11/19] playlists: Introduce a ready property



commit 25813f2b686d143bcc61708dcfa10f1454db5617
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Dec 1 11:39:09 2016 -0200

    playlists: Introduce a ready property
    
    The Playlists:ready property informs us whether we're still
    fetching the playlists or not. This property will be consumed
    by the Playlists view to show a loading notification.

 gnomemusic/playlists.py | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/playlists.py b/gnomemusic/playlists.py
index b91c0870..ca0315b1 100644
--- a/gnomemusic/playlists.py
+++ b/gnomemusic/playlists.py
@@ -203,7 +203,12 @@ class Playlists(GObject.GObject):
 
         self._pls_todelete = {}
 
-        grilo.connect('ready', self._on_grilo_ready)
+        self._ready = False
+
+        self._loading_counter = len(self._smart_playlists)
+        self._user_playlists_ready = False
+
+        grilo.connect("ready", self._on_grilo_ready)
 
     @log
     def _on_grilo_ready(self, data=None):
@@ -241,6 +246,8 @@ class Playlists(GObject.GObject):
             cursor.next_async(None, playlist_id_fetched_cb, playlist)
 
         self._tracker = grilo.tracker_sparql
+        self.notify("ready")
+
         # Start fetching all the smart playlists
         for playlist in self._smart_playlists.values():
             self._tracker.query_async(
@@ -256,6 +263,8 @@ class Playlists(GObject.GObject):
             self, source, param, item, remaining=0, data=None):
         """Fill in the list of playlists currently available"""
         if not item:
+            self._user_playlists_ready = True
+            self._check_ready()
             return
 
         playlist = Playlist(
@@ -387,6 +396,10 @@ class Playlists(GObject.GObject):
         self._playlists_model.insert_sorted(
             smart_playlist, Playlist.compare_playlist_func)
 
+        # Check if we're ready
+        self._loading_counter = self._loading_counter - 1
+        self._check_ready()
+
     @log
     def update_all_smart_playlists(self):
         for playlist in self._smart_playlists.values():
@@ -623,3 +636,15 @@ class Playlists(GObject.GObject):
         self._playlists_model.insert(index, playlist)
 
         return index
+
+    @GObject.Property(
+        type=bool, default=False, flags=GObject.ParamFlags.READABLE)
+    def ready(self):
+        return self._ready
+
+    def _check_ready(self):
+        ready = (self._user_playlists_ready
+                 and self._loading_counter == 0)
+        if ready != self._ready:
+            self._ready = ready
+            self.notify("ready")


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