[gnome-music/wip/jfelder/mpris-playlists-cleanup: 7/9] mpris: Do not interact with playlists view
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/mpris-playlists-cleanup: 7/9] mpris: Do not interact with playlists view
- Date: Fri, 31 May 2019 17:58:53 +0000 (UTC)
commit 7aa9cd55fc072aaafd5655349e1446dc0b840024
Author: Jean Felder <jfelder src gnome org>
Date: Mon Apr 15 08:54:41 2019 +0200
mpris: Do not interact with playlists view
The playlists interface from MPRIS has a method (ActivatePlaylist) to
select and play a playlist. This method directly calls the
"activate_playlist" method from PlaylistView. This is a bad design as
MPRIS should not directly interact with a view.
This is fixed by adding an "activate-playlist" signal to the
Playlists. Then, PlaylistView listens to this signal in order to
update the view and start the playlist accordingly.
gnomemusic/mpris.py | 11 ++++++-----
gnomemusic/playlists.py | 12 ++++++++++++
gnomemusic/views/playlistsview.py | 5 ++++-
3 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index c60f1268..896f6c1b 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -27,7 +27,6 @@ from gnomemusic.gstplayer import Playback
from gnomemusic.player import PlayerPlaylist, RepeatMode
from gnomemusic.grilo import grilo
from gnomemusic.playlists import Playlists
-from gnomemusic.utils import View
import gnomemusic.utils as utils
from gi.repository import GLib
@@ -247,9 +246,11 @@ class MediaPlayer2Service(Server):
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
@@ -637,7 +638,7 @@ class MediaPlayer2Service(Server):
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/playlistsview.py b/gnomemusic/views/playlistsview.py
index aad54a63..3e8e150d 100644
--- a/gnomemusic/views/playlistsview.py
+++ b/gnomemusic/views/playlistsview.py
@@ -131,6 +131,8 @@ class PlaylistsView(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 PlaylistsView(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]