Commit a2444ee1 authored by Jean Felder's avatar Jean Felder Committed by Jean Felder

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.
parent ee01fd6e
...@@ -27,7 +27,6 @@ from gnomemusic.gstplayer import Playback ...@@ -27,7 +27,6 @@ from gnomemusic.gstplayer import Playback
from gnomemusic.player import PlayerPlaylist, RepeatMode from gnomemusic.player import PlayerPlaylist, RepeatMode
from gnomemusic.grilo import grilo from gnomemusic.grilo import grilo
from gnomemusic.playlists import Playlists from gnomemusic.playlists import Playlists
from gnomemusic.utils import View
import gnomemusic.utils as utils import gnomemusic.utils as utils
from gi.repository import GLib from gi.repository import GLib
...@@ -247,9 +246,11 @@ class MediaPlayer2Service(Server): ...@@ -247,9 +246,11 @@ class MediaPlayer2Service(Server):
self.player_toolbar = app.get_active_window()._player_toolbar self.player_toolbar = app.get_active_window()._player_toolbar
self.player_toolbar.connect( self.player_toolbar.connect(
'thumbnail-updated', self._on_thumbnail_updated) 'thumbnail-updated', self._on_thumbnail_updated)
playlists = Playlists.get_default() self._playlists = Playlists.get_default()
playlists.connect('playlist-created', self._on_playlists_count_changed) self._playlists.connect(
playlists.connect('playlist-deleted', self._on_playlists_count_changed) 'playlist-created', self._on_playlists_count_changed)
self._playlists.connect(
'playlist-deleted', self._on_playlists_count_changed)
grilo.connect('ready', self._on_grilo_ready) grilo.connect('ready', self._on_grilo_ready)
self._stored_playlists = [] self._stored_playlists = []
self._player_previous_type = None self._player_previous_type = None
...@@ -637,7 +638,7 @@ class MediaPlayer2Service(Server): ...@@ -637,7 +638,7 @@ class MediaPlayer2Service(Server):
def ActivatePlaylist(self, playlist_path): def ActivatePlaylist(self, playlist_path):
playlist_id = self._get_playlist_from_dbus_path(playlist_path).get_id() 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): def GetPlaylists(self, index, max_count, order, reverse):
"""Gets a set of playlists (MPRIS Method). """Gets a set of playlists (MPRIS Method).
......
...@@ -108,6 +108,7 @@ class SmartPlaylists: ...@@ -108,6 +108,7 @@ class SmartPlaylists:
class Playlists(GObject.GObject): class Playlists(GObject.GObject):
__gsignals__ = { __gsignals__ = {
'activate-playlist': (GObject.SignalFlags.RUN_FIRST, None, (str,)),
'playlist-created': ( 'playlist-created': (
GObject.SignalFlags.RUN_FIRST, None, (Grl.Media,) GObject.SignalFlags.RUN_FIRST, None, (Grl.Media,)
), ),
...@@ -452,3 +453,14 @@ class Playlists(GObject.GObject): ...@@ -452,3 +453,14 @@ class Playlists(GObject.GObject):
return True return True
return False 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)
...@@ -131,6 +131,8 @@ class PlaylistsView(BaseView): ...@@ -131,6 +131,8 @@ class PlaylistsView(BaseView):
playlists.connect('playlist-updated', self._on_playlist_update) playlists.connect('playlist-updated', self._on_playlist_update)
playlists.connect( playlists.connect(
'song-added-to-playlist', self._on_song_added_to_playlist) 'song-added-to-playlist', self._on_song_added_to_playlist)
playlists.connect(
'activate-playlist', self._on_playlist_activation_request)
self.show_all() self.show_all()
...@@ -485,13 +487,14 @@ class PlaylistsView(BaseView): ...@@ -485,13 +487,14 @@ class PlaylistsView(BaseView):
break break
@log @log
def activate_playlist(self, playlist_id): def _on_playlist_activation_request(self, klass, playlist_id):
"""Selects and starts playing a playlist. """Selects and starts playing a playlist.
If the view has not been populated yet, populate it and then If the view has not been populated yet, populate it and then
select the requested playlist. Otherwise, directly select the select the requested playlist. Otherwise, directly select the
requested playlist and start playing. requested playlist and start playing.
:param Playlists klass: Playlists object
:param str playlist_id: requested playlist id :param str playlist_id: requested playlist id
""" """
if not self._init: if not self._init:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment