[gnome-music/wip/mschraal/coremodel-flatten-search-models: 29/32] coremodel: Use flattened wrapper models for all searches




commit b3e1e3abe256638240da348a743091cc03071ba0
Author: Marinus Schraal <mschraal gnome org>
Date:   Mon Aug 31 23:21:16 2020 +0200

    coremodel: Use flattened wrapper models for all searches
    
    Using per-wrapper models for searches makes for a lot cleaner object
    handling within the wrappers. This was already the case for songs, not
    yet for albums and artists. This commit fixes that omission.

 gnomemusic/coremodel.py                       | 60 +++++++++++++++++----------
 gnomemusic/grilowrappers/grltrackerwrapper.py | 17 +++++---
 2 files changed, 51 insertions(+), 26 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 2a3f7967a..49d7adc64 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -22,7 +22,9 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
+from __future__ import annotations
 import math
+import typing
 
 import gi
 gi.require_version("Gfm", "0.1")
@@ -35,23 +37,25 @@ from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
 from gnomemusic.player import PlayerPlaylist
 from gnomemusic.songliststore import SongListStore
 from gnomemusic.widgets.songwidget import SongWidget
+if typing.TYPE_CHECKING:
+    from gnomemusic.application import Application
 import gnomemusic.utils as utils
 
 
 class CoreModel(GObject.GObject):
-    """Provides all the list models used in Music
+    """Provides all the global list models used in Music
 
     Music is using a hierarchy of data objects with list models to
     contain the information about the users available music. This
     hierarchy is filled mainly through Grilo, with the exception of
     playlists which are a Tracker only feature.
 
-    There are three main models: one for artist info, one for albums
-    and one for songs. The data objects within these are CoreArtist,
-    CoreAlbum and CoreSong respectively.
+    There are three main models: one for artists, one for albums and
+    one for songs. The data objects within these are CoreArtist,
+    CoreAlbum and CoreSong respectively. These models are flattened
+    list models filled by the wrappers.
 
-    The data objects contain filtered lists of the three main models.
-    This makes the hierarchy as follows.
+    The object hierarchy is as follows.
 
     CoreArtist -> CoreAlbum -> CoreDisc -> CoreSong
 
@@ -73,7 +77,7 @@ class CoreModel(GObject.GObject):
 
     _recent_size = 21
 
-    def __init__(self, application):
+    def __init__(self, application: Application) -> None:
         """Initiate the CoreModel object
 
         :param Application application: The Application instance to use
@@ -116,19 +120,23 @@ class CoreModel(GObject.GObject):
         self._songs_search_flatten = Gfm.FlattenListModel.new(CoreSong)
         self._songs_search_flatten.set_model(self._songs_search_proxy)
 
-        self._albums_search_model = Gfm.FilterListModel.new(
-            self._albums_model)
-        self._albums_search_model.set_filter_func(lambda a: False)
+        self._albums_search_proxy: Gio.Liststore = Gio.ListStore.new(
+            Gfm.FilterListModel)
+        self._albums_search_flatten: Gfm.FlattenListModel = (
+            Gfm.FlattenListModel.new(CoreAlbum))
+        self._albums_search_flatten.set_model(self._albums_search_proxy)
 
         self._albums_search_filter = Gfm.FilterListModel.new(
-            self._albums_search_model)
+            self._albums_search_flatten)
 
-        self._artists_search_model = Gfm.FilterListModel.new(
-            self._artists_model)
-        self._artists_search_model.set_filter_func(lambda a: False)
+        self._artists_search_proxy: Gio.Liststore = Gio.ListStore.new(
+            Gfm.FilterListModel)
+        self._artists_search_flatten: Gfm.FlattenListModel = (
+            Gfm.FlattenListModel.new(CoreArtist))
+        self._artists_search_flatten.set_model(self._artists_search_proxy)
 
         self._artists_search_filter = Gfm.FilterListModel.new(
-            self._artists_search_model)
+            self._artists_search_flatten)
 
         self._playlists_model = Gio.ListStore.new(Playlist)
         self._playlists_model_filter = Gfm.FilterListModel.new(
@@ -421,10 +429,10 @@ class CoreModel(GObject.GObject):
         return self._songs_search_proxy
 
     @GObject.Property(
-        type=Gfm.FilterListModel, default=None,
+        type=Gfm.FlattenListModel, default=None,
         flags=GObject.ParamFlags.READABLE)
-    def albums_search(self):
-        return self._albums_search_model
+    def albums_search(self) -> Gfm.FlattenListModel:
+        return self._albums_search_flatten
 
     @GObject.Property(
         type=Gfm.FilterListModel, default=None,
@@ -433,10 +441,15 @@ class CoreModel(GObject.GObject):
         return self._albums_search_filter
 
     @GObject.Property(
-        type=Gfm.FilterListModel, default=None,
+        type=Gio.ListStore, default=None, flags=GObject.ParamFlags.READABLE)
+    def albums_search_proxy(self) -> Gio.ListStore:
+        return self._albums_search_proxy
+
+    @GObject.Property(
+        type=Gfm.FlattenListModel, default=None,
         flags=GObject.ParamFlags.READABLE)
-    def artists_search(self):
-        return self._artists_search_model
+    def artists_search(self) -> Gfm.FlattenListModel:
+        return self._artists_search_flatten
 
     @GObject.Property(
         type=Gfm.FilterListModel, default=None,
@@ -444,6 +457,11 @@ class CoreModel(GObject.GObject):
     def artists_search_filter(self):
         return self._artists_search_filter
 
+    @GObject.Property(
+        type=Gio.ListStore, default=None, flags=GObject.ParamFlags.READABLE)
+    def artists_search_proxy(self) -> Gio.ListStore:
+        return self._artists_search_proxy
+
     @GObject.Property(
         type=Gtk.ListStore, default=None, flags=GObject.ParamFlags.READABLE)
     def songs_gtkliststore(self):
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 72e477be3..c72a34e36 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -117,9 +117,6 @@ class GrlTrackerWrapper(GObject.GObject):
         self._artist_ids: Dict[str, CoreArtist] = {}
         self._hash: Dict[str, CoreSong] = {}
         self._song_search_proxy: Gio.ListStore = cm.props.songs_search_proxy
-        self._album_search_model: Gfm.FilterListModel = cm.props.albums_search
-        self._artist_search_model: Gfm.FilterListModel = (
-            cm.props.artists_search)
         self._batch_changed_media_ids: Dict[
             Grl.SourceChangeType, List[str]] = {}
         self._content_changed_timeout: int = 0
@@ -132,6 +129,16 @@ class GrlTrackerWrapper(GObject.GObject):
         self._song_search_tracker.set_filter_func(lambda a: False)
         self._song_search_proxy.append(self._song_search_tracker)
 
+        self._albums_search: Gfm.FilterListModel = Gfm.FilterListModel.new(
+            self._albums_model)
+        self._albums_search.set_filter_func(lambda a: False)
+        cm.props.albums_search_proxy.append(self._albums_search)
+
+        self._artists_search: Gfm.FilterListModel = Gfm.FilterListModel.new(
+            self._artists_model)
+        self._artists_search.set_filter_func(lambda a: False)
+        cm.props.artists_search_proxy.append(self._artists_search)
+
         self._fast_options: Grl.OperationOptions = Grl.OperationOptions()
         self._fast_options.set_resolution_flags(
             Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY)
@@ -967,7 +974,7 @@ class GrlTrackerWrapper(GObject.GObject):
                 return
 
             if not media:
-                self._artist_search_model.set_filter_func(artist_filter)
+                self._artists_search.set_filter_func(artist_filter)
                 self._notificationmanager.pop_loading()
                 return
 
@@ -1036,7 +1043,7 @@ class GrlTrackerWrapper(GObject.GObject):
                 return
 
             if not media:
-                self._album_search_model.set_filter_func(album_filter)
+                self._albums_search.set_filter_func(album_filter)
                 self._notificationmanager.pop_loading()
                 return
 


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