[gnome-music/wip/mschraal/coremodel-use-flattened-main-models: 6/7] coremodel: Flatten the core models



commit 687fac82a7bcf5853fa511a9973511dec1552e93
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Jun 12 14:03:02 2020 +0200

    coremodel: Flatten the core models
    
    The core songs, albums and artists models are filled by the Grilo source
    wrappers directly. This is feasible with just Tracker being the main
    source in use. However, when adding new sources it becomes cumbersome to
    have all sources manipulate the core listmodels directly.
    
    Instead make the core listmodel a FlattenListModel. A source can now
    use it's own local listmodel and easily manipulate this, without having
    to deal with any of the other sources items.

 gnomemusic/coremodel.py                       | 31 ++++++++++++++++++++++++---
 gnomemusic/grilowrappers/grltrackerwrapper.py | 11 ++++++----
 2 files changed, 35 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 75a1e21c..ca91001f 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -28,6 +28,7 @@ import gi
 gi.require_version("Gfm", "0.1")
 from gi.repository import GObject, Gio, Gfm, Gtk
 
+from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.coreartist import CoreArtist
 from gnomemusic.coresong import CoreSong
 from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
@@ -83,17 +84,23 @@ class CoreModel(GObject.GObject):
         self._current_playlist_model = None
         self._previous_playlist_model = None
 
-        self._songs_model = Gio.ListStore.new(CoreSong)
+        self._songs_model_proxy = Gio.ListStore.new(Gio.ListModel)
+        self._songs_model = Gfm.FlattenListModel.new(
+            CoreSong, self._songs_model_proxy)
         self._songliststore = SongListStore(self._songs_model)
 
         self._application = application
 
-        self._albums_model = Gio.ListStore()
+        self._albums_model_proxy = Gio.ListStore.new(Gio.ListModel)
+        self._albums_model = Gfm.FlattenListModel.new(
+            CoreAlbum, self._albums_model_proxy)
         self._albums_model_sort = Gfm.SortListModel.new(self._albums_model)
         self._albums_model_sort.set_sort_func(
             utils.wrap_list_store_sort_func(self._albums_sort))
 
-        self._artists_model = Gio.ListStore.new(CoreArtist)
+        self._artists_model_proxy = Gio.ListStore.new(Gio.ListModel)
+        self._artists_model = Gfm.FlattenListModel.new(
+            CoreArtist, self._artists_model_proxy)
         self._artists_model_sort = Gfm.SortListModel.new(self._artists_model)
         self._artists_model_sort.set_sort_func(
             utils.wrap_list_store_sort_func(self._artist_sort))
@@ -297,16 +304,34 @@ class CoreModel(GObject.GObject):
     def songs(self):
         return self._songs_model
 
+    @GObject.Property(
+        type=Gfm.FlattenListModel, default=None,
+        flags=GObject.ParamFlags.READABLE)
+    def songs_proxy(self):
+        return self._songs_model_proxy
+
     @GObject.Property(
         type=Gio.ListStore, default=None, flags=GObject.ParamFlags.READABLE)
     def albums(self):
         return self._albums_model
 
+    @GObject.Property(
+        type=Gfm.FlattenListModel, default=None,
+        flags=GObject.ParamFlags.READABLE)
+    def albums_proxy(self):
+        return self._albums_model_proxy
+
     @GObject.Property(
         type=Gio.ListStore, default=None, flags=GObject.ParamFlags.READABLE)
     def artists(self):
         return self._artists_model
 
+    @GObject.Property(
+        type=Gfm.FlattenListModel, default=None,
+        flags=GObject.ParamFlags.READABLE)
+    def artists_proxy(self):
+        return self._artists_model_proxy
+
     @GObject.Property(
         type=Gio.ListStore, default=None, flags=GObject.ParamFlags.READABLE)
     def playlist(self):
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 0cde75e4..952eb15a 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -24,7 +24,7 @@
 
 import gi
 gi.require_versions({"Gfm": "0.1", "Grl": "0.3", 'Tracker': "2.0"})
-from gi.repository import Gfm, Grl, GLib, GObject, Tracker
+from gi.repository import Gfm, Gio, Grl, GLib, GObject, Tracker
 
 from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.coreartist import CoreArtist
@@ -73,11 +73,14 @@ class GrlTrackerWrapper(GObject.GObject):
         self._application = application
         self._coremodel = application.props.coremodel
         self._log = application.props.log
-        self._songs_model = self._coremodel.props.songs
+        self._songs_model = Gio.ListStore.new(CoreSong)
+        self._coremodel.props.songs_proxy.append(self._songs_model)
         self._source = None
-        self._albums_model = self._coremodel.props.albums
+        self._albums_model = Gio.ListStore.new(CoreAlbum)
+        self._coremodel.props.albums_proxy.append(self._albums_model)
         self._album_ids = {}
-        self._artists_model = self._coremodel.props.artists
+        self._artists_model = Gio.ListStore.new(CoreArtist)
+        self._coremodel.props.artists_proxy.append(self._artists_model)
         self._artist_ids = {}
         self._hash = {}
         self._song_search_proxy = self._coremodel.props.songs_search_proxy


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