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
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
'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()
'playlist-created', self._on_playlists_count_changed)
'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()[View.PLAYLIST].activate_playlist(playlist_id)
def GetPlaylists(self, index, max_count, order, reverse):
"""Gets a set of playlists (MPRIS Method).
......@@ -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
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):
playlists.connect('playlist-updated', self._on_playlist_update)
'song-added-to-playlist', self._on_song_added_to_playlist)
'activate-playlist', self._on_playlist_activation_request)
......@@ -485,13 +487,14 @@ class PlaylistsView(BaseView):
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:
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