[gnome-music/wip/jfelder/mpris-cleanup: 1/19] mpris: Do not interact with playlist view



commit 1e7ed3ea77d2ed1b4db4916262ffdbc94ff4cb51
Author: Jean Felder <jfelder src gnome org>
Date:   Mon Apr 15 08:54:41 2019 +0200

    mpris: Do not interact with playlist view
    
    MPRIS should not directly interact with a view.

 gnomemusic/mpris.py              | 11 ++++++-----
 gnomemusic/playlists.py          | 12 ++++++++++++
 gnomemusic/views/playlistview.py |  5 ++++-
 3 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 634e7565..e64aa429 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -32,7 +32,6 @@ from gnomemusic.grilo import grilo
 from gnomemusic.gstplayer import Playback
 from gnomemusic.player import PlayerPlaylist, RepeatMode
 from gnomemusic.playlists import Playlists
-from gnomemusic.utils import View
 import gnomemusic.utils as utils
 
 logger = logging.getLogger(__name__)
@@ -263,9 +262,11 @@ class MPRIS(DBusInterface):
         self.player_toolbar = app.get_active_window()._player_toolbar
         self.player_toolbar.connect(
             'thumbnail-updated', self._on_thumbnail_updated)
-        playlists = Playlists.get_default()
-        playlists.connect('playlist-created', self._on_playlists_count_changed)
-        playlists.connect('playlist-deleted', self._on_playlists_count_changed)
+        self._playlists = Playlists.get_default()
+        self._playlists.connect(
+            'playlist-created', self._on_playlists_count_changed)
+        self._playlists.connect(
+            'playlist-deleted', self._on_playlists_count_changed)
         grilo.connect('ready', self._on_grilo_ready)
         self._stored_playlists = []
         self._player_previous_type = None
@@ -656,7 +657,7 @@ class MPRIS(DBusInterface):
 
     def ActivatePlaylist(self, playlist_path):
         playlist_id = self._get_playlist_from_dbus_path(playlist_path).get_id()
-        self.app._window.views[View.PLAYLIST].activate_playlist(playlist_id)
+        self._playlists.activate_playlist(playlist_id)
 
     def GetPlaylists(self, index, max_count, order, reverse):
         """Gets a set of playlists (MPRIS Method).
diff --git a/gnomemusic/playlists.py b/gnomemusic/playlists.py
index c5cde0c0..2599d940 100644
--- a/gnomemusic/playlists.py
+++ b/gnomemusic/playlists.py
@@ -108,6 +108,7 @@ class SmartPlaylists:
 class Playlists(GObject.GObject):
 
     __gsignals__ = {
+        'activate-playlist': (GObject.SignalFlags.RUN_FIRST, None, (str,)),
         'playlist-created': (
             GObject.SignalFlags.RUN_FIRST, None, (Grl.Media,)
         ),
@@ -452,3 +453,14 @@ class Playlists(GObject.GObject):
                 return True
 
         return False
+
+    @log
+    def activate_playlist(self, playlist_id):
+        """Activates a playlist.
+
+        Selects a playlist and start playing.
+
+        :param str playlist_id: playlist id
+        """
+        # FIXME: just a proxy
+        self.emit('activate-playlist', playlist_id)
diff --git a/gnomemusic/views/playlistview.py b/gnomemusic/views/playlistview.py
index 8179e0ed..761e440c 100644
--- a/gnomemusic/views/playlistview.py
+++ b/gnomemusic/views/playlistview.py
@@ -131,6 +131,8 @@ class PlaylistView(BaseView):
         playlists.connect('playlist-updated', self._on_playlist_update)
         playlists.connect(
             'song-added-to-playlist', self._on_song_added_to_playlist)
+        playlists.connect(
+            'activate-playlist', self._on_playlist_activation_request)
 
         self.show_all()
 
@@ -485,13 +487,14 @@ class PlaylistView(BaseView):
                 break
 
     @log
-    def activate_playlist(self, playlist_id):
+    def _on_playlist_activation_request(self, klass, playlist_id):
         """Selects and starts playing a playlist.
 
         If the view has not been populated yet, populate it and then
         select the requested playlist. Otherwise, directly select the
         requested playlist and start playing.
 
+        :param Playlists klass: Playlists object
         :param str playlist_id: requested playlist id
         """
         if not self._init:


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