From 950bd54804e102c0a1b7bb60c242732f033c5a49 Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 7 Aug 2016 21:13:07 +0200 Subject: [PATCH] PlaylistPanel: implement removing of albums (resolves #3) --- mcg/client.py | 13 +++++++++++++ mcg/widgets.py | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/mcg/client.py b/mcg/client.py index 3c6714e..6201391 100644 --- a/mcg/client.py +++ b/mcg/client.py @@ -195,6 +195,12 @@ class Client(Base): self._add_action(self._clear_playlist) + def remove_album_from_playlist(self, album): + """Remove the given album from the playlist.""" + self._logger.info("remove album from playlist") + self._add_action(self._remove_album_from_playlist, album) + + def playpause(self): """Play or pauses the current state.""" self._logger.info("playpause") @@ -443,6 +449,13 @@ class Client(Base): self._call('clear') + def _remove_album_from_playlist(self, album): + self._call_list('command_list_begin') + for track in album.get_tracks(): + self._call_list('deleteid', track.get_id()) + self._call('command_list_end') + + def _playpause(self): """Action: Perform the real play/pause command.""" #status = self._parse_dict(self._call('status')) diff --git a/mcg/widgets.py b/mcg/widgets.py index f6df826..405ecfe 100644 --- a/mcg/widgets.py +++ b/mcg/widgets.py @@ -93,6 +93,7 @@ class Window(): self._panels[Window._PANEL_INDEX_COVER].connect('tracklist-size-changed', self.on_cover_panel_tracklist_size_changed) self._panels[Window._PANEL_INDEX_COVER].connect('set-song', self.on_cover_panel_set_song) self._panels[Window._PANEL_INDEX_PLAYLIST].connect('clear-playlist', self.on_playlist_panel_clear_playlist) + self._panels[Window._PANEL_INDEX_PLAYLIST].connect('remove', self.on_playlist_panel_remove) self._panels[Window._PANEL_INDEX_LIBRARY].connect('update', self.on_library_panel_update) self._panels[Window._PANEL_INDEX_LIBRARY].connect('play', self.on_library_panel_play) self._panels[Window._PANEL_INDEX_LIBRARY].connect('item-size-changed', self.on_library_panel_item_size_changed) @@ -189,6 +190,10 @@ class Window(): self._mcg.clear_playlist() + def on_playlist_panel_remove(self, widget, album): + self._mcg.remove_album_from_playlist(album) + + def on_cover_panel_toggle_fullscreen(self, widget): if not self._fullscreened: self._appwindow.fullscreen() @@ -934,7 +939,8 @@ class CoverPanel(GObject.GObject): class PlaylistPanel(GObject.GObject): __gsignals__ = { - 'clear-playlist': (GObject.SIGNAL_RUN_FIRST, None, ()) + 'clear-playlist': (GObject.SIGNAL_RUN_FIRST, None, ()), + 'remove': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)) } @@ -980,6 +986,9 @@ class PlaylistPanel(GObject.GObject): self._standalone_image = builder.get_object('playlist-standalone-image') # Action bar action_bar = builder.get_object('playlist-standalone-actionbar') + remove_button = Gtk.Button('remove') + remove_button.connect('clicked', self.on_standalone_remove_clicked) + action_bar.pack_end(remove_button) def get(self): @@ -1032,6 +1041,10 @@ class PlaylistPanel(GObject.GObject): self._appwindow.set_titlebar(self._headerbar) + def on_standalone_remove_clicked(self, widget): + self.emit('remove', self._selected_albums[0]) + + def set_item_size(self, item_size): if self._item_size != item_size: self._item_size = item_size