[gnome-music/wip/jfelder/searchview-new-style: 3/9] coremodel: Add grilo as property



commit 6a8f868d47e8b37d1689811ba54c511de3d54d5b
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Aug 4 12:13:06 2019 +0200

    coremodel: Add grilo as property
    
    Grilo sometimes needs to be directly accessed, add it as a property for
    easy access.

 gnomemusic/albumartcache.py |  2 +-
 gnomemusic/coredisc.py      |  2 +-
 gnomemusic/coremodel.py     | 26 +++++++++++++++-----------
 gnomemusic/window.py        |  7 ++++---
 4 files changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index ec7ca541..13b6678b 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -598,7 +598,7 @@ class RemoteArt(GObject.GObject):
         # CoreAlbum or CoreSong about and then retrieves the CoreGrilo
         # instance.
         try:
-            self._grilo = self._coresong._coremodel._grilo
+            self._grilo = self._coresong._coremodel.props.grilo
         except AttributeError:
             self._grilo = self._coresong._grilo
 
diff --git a/gnomemusic/coredisc.py b/gnomemusic/coredisc.py
index 781bf0ea..bfba600f 100644
--- a/gnomemusic/coredisc.py
+++ b/gnomemusic/coredisc.py
@@ -111,7 +111,7 @@ class CoreDisc(GObject.GObject):
 
             album_ids.append(media.get_source() + media.get_id())
 
-        self._coremodel._grilo.populate_album_disc_songs(
+        self._coremodel.props.grilo.populate_album_disc_songs(
             media, discnr, _callback)
 
     @GObject.Property(
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index ff8f5a38..a8ae3147 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -72,6 +72,7 @@ class CoreModel(GObject.GObject):
         "playlists-loaded": (GObject.SignalFlags.RUN_FIRST, None, ()),
     }
 
+    grilo = GObject.Property(type=CoreGrilo, default=None)
     songs_available = GObject.Property(type=bool, default=False)
 
     def __init__(self, coreselection):
@@ -125,7 +126,10 @@ class CoreModel(GObject.GObject):
         self._playlists_model_sort.set_sort_func(
             self._wrap_list_store_sort_func(self._playlists_sort))
 
-        self._grilo = CoreGrilo(self, self._coreselection)
+        self.props.grilo = CoreGrilo(self, self._coreselection)
+        # FIXME: Not all instances of internal _grilo use have been
+        # fixed.
+        self._grilo = self.props.grilo
 
         self._model.connect("items-changed", self._on_songs_items_changed)
 
@@ -189,7 +193,7 @@ class CoreModel(GObject.GObject):
         disc_model_sort.set_sort_func(
             self._wrap_list_store_sort_func(_disc_order_sort))
 
-        self._grilo.get_album_discs(media, disc_model)
+        self.props.grilo.get_album_discs(media, disc_model)
 
         return disc_model_sort
 
@@ -199,7 +203,7 @@ class CoreModel(GObject.GObject):
 
         albums_model_sort = Gfm.SortListModel.new(albums_model_filter)
 
-        self._grilo.get_artist_albums(media, albums_model_filter)
+        self.props.grilo.get_artist_albums(media, albums_model_filter)
 
         def _album_sort(album_a, album_b):
             return album_a.props.year > album_b.props.year
@@ -228,7 +232,7 @@ class CoreModel(GObject.GObject):
                     coresong = model[position + i]
                     song = CoreSong(
                         coresong.props.media, self._coreselection,
-                        self._grilo)
+                        self.props.grilo)
 
                     self._playlist_model.insert(position + i, song)
 
@@ -256,7 +260,7 @@ class CoreModel(GObject.GObject):
                 for model_song in self._flatten_model:
                     song = CoreSong(
                         model_song.props.media, self._coreselection,
-                        self._grilo)
+                        self.props.grilo)
 
                     self._playlist_model.append(song)
                     song.bind_property(
@@ -282,7 +286,7 @@ class CoreModel(GObject.GObject):
                 for model_song in self._flatten_model:
                     song = CoreSong(
                         model_song.props.media, self._coreselection,
-                        self._grilo)
+                        self.props.grilo)
 
                     self._playlist_model.append(song)
                     song.bind_property(
@@ -331,7 +335,7 @@ class CoreModel(GObject.GObject):
                 for model_song in model:
                     song = CoreSong(
                         model_song.props.media, self._coreselection,
-                        self._grilo)
+                        self.props.grilo)
 
                     self._playlist_model.append(song)
 
@@ -351,7 +355,7 @@ class CoreModel(GObject.GObject):
 
         :param Playlist playlist: playlist
         """
-        self._grilo.stage_playlist_deletion(playlist)
+        self.props.grilo.stage_playlist_deletion(playlist)
 
     def finish_playlist_deletion(self, playlist, deleted):
         """Finishes playlist deletion.
@@ -359,7 +363,7 @@ class CoreModel(GObject.GObject):
         :param Playlist playlist: playlist
         :param bool deleted: indicates if the playlist has been deleted
         """
-        self._grilo.finish_playlist_deletion(playlist, deleted)
+        self.props.grilo.finish_playlist_deletion(playlist, deleted)
 
     def create_playlist(self, playlist_title, callback):
         """Creates a new user playlist.
@@ -367,7 +371,7 @@ class CoreModel(GObject.GObject):
         :param str playlist_title: playlist title
         :param callback: function to perform once, the playlist is created
         """
-        self._grilo.create_playlist(playlist_title, callback)
+        self.props.grilo.create_playlist(playlist_title, callback)
 
     def activate_playlist(self, playlist):
         """Activates a playlist.
@@ -380,7 +384,7 @@ class CoreModel(GObject.GObject):
         self.emit("activate-playlist", playlist)
 
     def search(self, text):
-        self._grilo.search(text)
+        self.props.grilo.search(text)
 
     @GObject.Property(
         type=Gio.ListStore, default=None, flags=GObject.ParamFlags.READABLE)
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 69f0c0b6..8b096f55 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -173,7 +173,7 @@ class Window(Gtk.ApplicationWindow):
         self._app.props.coremodel.connect(
             "notify::songs-available", self._on_songs_available)
 
-        self._app.props.coremodel._grilo.connect(
+        self._app.props.coremodel.props.grilo.connect(
             "notify::tracker-available", self._on_tracker_available)
 
         if self._app.props.coremodel.props.songs_available:
@@ -185,7 +185,7 @@ class Window(Gtk.ApplicationWindow):
     def _switch_to_empty_view(self):
         did_initial_state = self._settings.get_boolean('did-initial-state')
 
-        state = self._app.props.coremodel._grilo.props.tracker_available
+        state = self._app.props.coremodel.props.grilo.props.tracker_available
         empty_view = self.views[View.EMPTY]
         if state == TrackerState.UNAVAILABLE:
             empty_view.props.state = EmptyView.State.NO_TRACKER
@@ -206,7 +206,8 @@ class Window(Gtk.ApplicationWindow):
             self._switch_to_empty_view()
 
     def _on_tracker_available(self, klass, value):
-        new_state = self._app.props.coremodel._grilo.props.tracker_available
+        grilo = self._app.props.coremodel.props.grilo
+        new_state = grilo.props.tracker_available
 
         if new_state != TrackerState.AVAILABLE:
             self._switch_to_empty_view()


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