[gnome-music/wip/mschraal/core: 139/177] coremodel: Make album discs retrieval async



commit d148726264cb4a867072fd00dc6bb3d3343305b3
Author: Marinus Schraal <mschraal gnome org>
Date:   Sat Jun 29 14:30:49 2019 +0200

    coremodel: Make album discs retrieval async

 gnomemusic/coregrilo.py                      |  7 +++----
 gnomemusic/coremodel.py                      | 13 ++-----------
 gnomemusic/grilowrappers/grltrackersource.py | 23 ++++++++++++++++-------
 3 files changed, 21 insertions(+), 22 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index fad36f0e..e4e8fb98 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -37,7 +37,6 @@ class CoreGrilo(GObject.GObject):
                 source, self._model, self._albums_model,
                 self._artists_model, self._coremodel, self._coreselection,
                 self)
-            self._tracker_source = new_wrapper
         elif source.props.source_id[:10] == "grl-dleyna":
             new_wrapper = GrlDLeynaSource(
                 source, self._model, self._albums_model,
@@ -55,9 +54,9 @@ class CoreGrilo(GObject.GObject):
         for wrapper in self._wrappers:
             wrapper.get_artist_albums(artist, filter_model)
 
-    def get_album_disc_numbers(self, media):
-        # FIXME: Iterate the wrappers
-        return self._tracker_source.get_album_disc_numbers(media)
+    def get_album_discs(self, media, disc_model):
+        for wrapper in self._wrappers:
+            wrapper.get_album_discs(media, disc_model)
 
     def populate_album_disc_songs(self, media, discnr, callback):
         for wrapper in self._wrappers:
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index fac0d316..212b9317 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -5,7 +5,6 @@ from gi._gi import pygobject_new_full
 
 from gnomemusic import log
 from gnomemusic.coreartist import CoreArtist
-from gnomemusic.coredisc import CoreDisc
 from gnomemusic.coregrilo import CoreGrilo
 from gnomemusic.coresong import CoreSong
 from gnomemusic.player import PlayerPlaylist
@@ -96,25 +95,17 @@ class CoreModel(GObject.GObject):
 
     @log
     def get_album_model(self, media):
-        discs = self._grilo.get_album_disc_numbers(media)
-
         disc_model = Gio.ListStore()
         disc_model_sort = Gfm.SortListModel.new(disc_model)
 
-        def _disc_sort(song_a, song_b):
-            return song_a.props.track_number - song_b.props.track_number
-
-        for disc in discs:
-            nr = disc.get_album_disc_number()
-            coredisc = CoreDisc(media, nr, self)
-            disc_model.append(coredisc)
-
         def _disc_order_sort(disc_a, disc_b):
             return disc_a.props.disc_nr - disc_b.props.disc_nr
 
         disc_model_sort.set_sort_func(
             self._wrap_list_store_sort_func(_disc_order_sort))
 
+        self._grilo.get_album_discs(media, disc_model)
+
         return disc_model_sort
 
     def get_artists_model_full(self, media):
diff --git a/gnomemusic/grilowrappers/grltrackersource.py b/gnomemusic/grilowrappers/grltrackersource.py
index 09b60a26..c1b960af 100644
--- a/gnomemusic/grilowrappers/grltrackersource.py
+++ b/gnomemusic/grilowrappers/grltrackersource.py
@@ -4,6 +4,7 @@ from gi.repository import Grl, GObject
 
 from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.coreartist import CoreArtist
+from gnomemusic.coredisc import CoreDisc
 from gnomemusic.coresong import CoreSong
 
 
@@ -390,13 +391,25 @@ class GrlTrackerSource(GObject.GObject):
 
         self._source.query(query, self.METADATA_KEYS, options, query_cb)
 
-    def get_album_disc_numbers(self, media):
+    def get_album_discs(self, media, disc_model):
         album_id = media.get_id()
-        print("album id ", album_id)
+
+        def _disc_nr_cb(source, op_id, media, user_data, error):
+            if error:
+                print("ERROR", error)
+                return
+
+            if not media:
+                return
+
+            disc_nr = media.get_album_disc_number()
+            coredisc = CoreDisc(media, disc_nr, self._coremodel)
+            disc_model.append(coredisc)
 
         query = """
         SELECT DISTINCT
             rdf:type(?song)
+            tracker:id(?album) AS ?id
             nmm:setNumber(nmm:musicAlbumDisc(?song)) as ?album_disc_number
         WHERE
         {
@@ -410,11 +423,7 @@ class GrlTrackerSource(GObject.GObject):
 
         options = self._fast_options.copy()
 
-        discs = self._source.query_sync(query, self.METADATA_KEYS, options)
-
-        print("DISCS", discs)
-
-        return discs
+        self._source.query(query, self.METADATA_KEYS, options, _disc_nr_cb)
 
     def populate_album_disc_songs(self, media, disc_nr, _callback):
         album_id = media.get_id()


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