[gnome-music/wip/jfelder/mpris-cleanup: 6/17] mpris: Simplify query playlists logic



commit ff1925a922b8d2f25c149c2ee0bd9383a80ebe95
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Jun 7 15:53:27 2019 +0200

    mpris: Simplify query playlists logic
    
    Merge _query_playlists and _reload_playlists functions. Indeed,
    _query_playlists is only called by _reload_playlists.

 gnomemusic/mpris.py | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index e9a9fa6c..f9914d07 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -436,18 +436,6 @@ class MPRIS(DBusInterface):
                 return playlist
         return None
 
-    @log
-    def _query_playlists(self, callback):
-        playlists = []
-
-        def populate_callback(source, param, item, remaining=0, data=None):
-            if item:
-                playlists.append(item)
-            else:
-                callback(playlists)
-
-        grilo.populate_playlists(0, populate_callback)
-
     @log
     def _get_active_playlist(self):
         """Get Active Maybe_Playlist
@@ -555,13 +543,17 @@ class MPRIS(DBusInterface):
 
     @log
     def _reload_playlists(self):
-        def query_playlists_callback(playlists):
-            self._stored_playlists = playlists
-            self.PropertiesChanged(
-                MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE,
-                {'PlaylistCount': GLib.Variant('u', len(playlists)), }, [])
+        def _populate_cb(source, param, item, remaining=0, data=None):
+            if item:
+                self._stored_playlists.append(item)
+            else:
+                playlists_nr = len(self._stored_playlists)
+                self.PropertiesChanged(
+                    MPRIS.MEDIA_PLAYER2_PLAYLISTS_IFACE,
+                    {'PlaylistCount': GLib.Variant('u', playlists_nr), }, [])
 
-        self._query_playlists(query_playlists_callback)
+        self._stored_playlists = []
+        grilo.populate_playlists(0, _populate_cb)
 
     @log
     def _on_playlists_count_changed(self, playlists, item):


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