[gnome-music/wip/mschraal/core: 31/42] coremodel: Use dzl listmodelfilter



commit 91c6968b827f53da4ff3a0b251cbf9c32d17b591
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu May 9 17:11:39 2019 +0200

    coremodel: Use dzl listmodelfilter

 gnomemusic/coremodel.py | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index c67dc922..d7071a9c 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -1,4 +1,6 @@
-from gi.repository import GObject, Gio
+import gi
+gi.require_version('Dazzle', '1.0')
+from gi.repository import Dazzle, GObject, Gio
 
 from gnomemusic import log
 from gnomemusic.coregrilo import CoreGrilo
@@ -25,26 +27,28 @@ class CoreModel(GObject.GObject):
 
     @log
     def get_album_model(self, media):
-        self._album_store = Gio.ListStore()
-        album_id = media.get_id()
+        albums_ids = []
+
+        model_filter = Dazzle.ListModelFilter.new(self._model)
+        model_filter.set_filter_func(lambda a: False)
+
+        def _filter_func(core_song):
+            return core_song._media.get_id() in albums_ids
 
         def _reverse_sort(song_a, song_b):
             return song_b.props.track_number - song_a.props.track_number
 
         def _callback(source, dunno, media, something, something2):
             if media is None:
-                self._album_store.sort(_reverse_sort)
+                model_filter.set_filter_func(_filter_func)
                 return
 
-            print("media", media)
-
-            song = self._hash[media.get_id()]
-            self._album_store.append(song)
+            albums_ids.append(media.get_id())
 
         # For POC sake, use old grilo
         grilo.populate_album_songs(media, _callback)
 
-        return self._album_store
+        return model_filter
 
     @log
     def _on_media_removed(self, klass, media):


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