[gnome-music/wip/jfelder/playback-status-v4: 15/22] coremodel: Replace active_playlist property with active_media



commit 76da456235d3539dd8744a19509b751d01d9c180
Author: Jean Felder <jfelder src gnome org>
Date:   Sun Jan 12 00:35:24 2020 +0100

    coremodel: Replace active_playlist property with active_media

 gnomemusic/coremodel.py                         |  5 -----
 gnomemusic/grilowrappers/grltrackerplaylists.py |  8 ++++----
 gnomemusic/mpris.py                             |  9 ++++-----
 gnomemusic/views/playlistsview.py               | 12 ++++++------
 gnomemusic/widgets/playlistswidget.py           |  1 -
 5 files changed, 14 insertions(+), 21 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 88369887..3e8a5bc9 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -69,7 +69,6 @@ class CoreModel(GObject.GObject):
         "smart-playlist-change": (GObject.SignalFlags.RUN_FIRST, None, ())
     }
 
-    active_playlist = GObject.Property(type=Playlist, default=None)
     songs_available = GObject.Property(type=bool, default=False)
 
     _recent_size = 21
@@ -230,10 +229,6 @@ class CoreModel(GObject.GObject):
             self._player_signal_id = None
             self._current_playlist_model = None
 
-        if (playlist_type != PlayerPlaylist.Type.PLAYLIST
-                and self.props.active_playlist is not None):
-            self.props.active_playlist = None
-
         songs_added = []
 
         if playlist_type == PlayerPlaylist.Type.ALBUM:
diff --git a/gnomemusic/grilowrappers/grltrackerplaylists.py b/gnomemusic/grilowrappers/grltrackerplaylists.py
index b59eefae..58c8094f 100644
--- a/gnomemusic/grilowrappers/grltrackerplaylists.py
+++ b/gnomemusic/grilowrappers/grltrackerplaylists.py
@@ -258,10 +258,10 @@ class GrlTrackerPlaylists(GObject.GObject):
         * it is being played (active_playlist)
         * it is visible in PlaylistsView
         """
-        active_playlist = self._coremodel.props.active_playlist
-        if (active_playlist is not None
-                and active_playlist.props.is_smart is True):
-            active_playlist.update()
+        active_media = self._coremodel.props.active_media
+        if (isinstance(active_media, Playlist)
+                and active_media.props.is_smart):
+            active_media.update()
         else:
             self._coremodel.emit("smart-playlist-change")
 
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index a7c26328..4c10bc39 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -28,6 +28,7 @@ import re
 from gi.repository import Gio, GLib
 
 from gnomemusic.albumartcache import lookup_art_file_from_cache
+from gnomemusic.grilowrappers.grltrackerplaylists import Playlist
 from gnomemusic.gstplayer import Playback
 from gnomemusic.player import PlayerPlaylist, RepeatMode
 from gnomemusic.widgets.songwidget import SongWidget
@@ -494,12 +495,11 @@ class MPRIS(DBusInterface):
         :returns: playlist existence and its structure
         :rtype: tuple
         """
-        current_playlist = self._coremodel.props.active_playlist
-        if current_playlist is None:
+        current_media = self._coremodel.props.active_media
+        if not isinstance(current_media, Playlist):
             return (False, ("/", "", ""))
 
-        mpris_playlist = self._get_mpris_playlist_from_playlist(
-            current_playlist)
+        mpris_playlist = self._get_mpris_playlist_from_playlist(current_media)
         return (True, mpris_playlist)
 
     def _on_current_song_changed(self, player):
@@ -750,7 +750,6 @@ class MPRIS(DBusInterface):
 
         loaded_id = self._coremodel.connect(
             "playlist-loaded", _on_playlist_loaded)
-        self._coremodel.props.active_playlist = playlist
         self._coremodel.props.active_media = playlist
 
     def _activate_playlist(self, playlist_path):
diff --git a/gnomemusic/views/playlistsview.py b/gnomemusic/views/playlistsview.py
index 21247067..915fc0b1 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -64,7 +64,7 @@ class PlaylistsView(Gtk.Box):
         self._sidebar.bind_model(self._model, self._add_playlist_to_sidebar)
 
         self._coremodel.connect(
-            "notify::active-playlist", self._on_active_playlist_changed)
+            "notify::active-media", self._on_active_media_changed)
 
         self._model.connect("items-changed", self._on_playlists_model_changed)
         self._on_playlists_model_changed(self._model, 0, 0, 0)
@@ -114,19 +114,19 @@ class PlaylistsView(Gtk.Box):
 
         self.notify("current-playlist")
 
-    def _on_active_playlist_changed(self, klass, val):
+    def _on_active_media_changed(self, klass, val):
         """Selects the active playlist when an MPRIS client
            has changed it.
         """
-        playlist = self._coremodel.props.active_playlist
+        active_media = self._coremodel.props.active_media
         selection = self._sidebar.get_selected_row()
-        if (playlist is None
-                or playlist == selection.props.playlist):
+        if (not isinstance(active_media, Playlist)
+                or active_media == selection.props.playlist):
             return
 
         playlist_row = None
         for row in self._sidebar:
-            if row.props.playlist == playlist:
+            if row.props.playlist == active_media:
                 playlist_row = row
                 break
 
diff --git a/gnomemusic/widgets/playlistswidget.py b/gnomemusic/widgets/playlistswidget.py
index b5ec2b41..a4ff0947 100644
--- a/gnomemusic/widgets/playlistswidget.py
+++ b/gnomemusic/widgets/playlistswidget.py
@@ -117,7 +117,6 @@ class PlaylistsWidget(Gtk.Box):
         current_playlist = self._playlists_view.props.current_playlist
         signal_id = self._coremodel.connect(
             "playlist-loaded", _on_playlist_loaded)
-        self._coremodel.props.active_playlist = current_playlist
         self._coremodel.props.active_media = current_playlist
 
     def _on_song_widget_moved(self, target, source_position):


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