diff --git a/mcg/client.py b/mcg/client.py index ca9102d..762361c 100644 --- a/mcg/client.py +++ b/mcg/client.py @@ -243,15 +243,21 @@ class Client(Base): def play_album(self, album): - """Play the given album.""" + """Add the given album to the queue and play it immediately.""" self._logger.info("play album") self._add_action(self._play_album, album) - def play_albums(self, albums): - """Play multiple albums.""" + def queue_album(self, album): + """Add the given album to the queue.""" + self._logger.info("play album") + self._add_action(self._queue_album, album) + + + def queue_albums(self, albums): + """Add the given albums to the queue.""" self._logger.info("play albums") - self._add_action(self._play_albums, albums) + self._add_action(self._queue_albums, albums) def seek(self, pos, time): @@ -559,8 +565,16 @@ class Client(Base): def _play_album(self, album): + track_ids = self._queue_album(album) + if track_ids: + self._logger.info("play track %d", track_ids[0]) + self._call('playid', track_ids[0]) + + + def _queue_album(self, album): + track_ids = [] if album in self._albums: - track_ids = [] + self._logger.info("add album %s", album) for track in self._albums[album].get_tracks(): self._logger.info("addid: %r", track.get_file()) track_id = None @@ -570,26 +584,13 @@ class Client(Base): self._logger.debug("track id: %r", track_id) if track_id is not None: track_ids.append(track_id) - if self._state != 'play' and track_ids: - self._call('playid', track_ids[0]) + return track_ids - def _play_albums(self, albums): + def _queue_albums(self, albums): track_ids = [] for album in albums: - self._logger.info("add album %s", album) - if album in self._albums: - for track in self._albums[album].get_tracks(): - self._logger.info("addid: %r", track.get_file()) - track_id = None - track_id_response = self._parse_dict(self._call('addid', track.get_file())) - if 'id' in track_id_response: - track_id = track_id_response['id'] - self._logger.debug("track id: %r", track_id) - if track_id is not None: - track_ids.append(track_id) - if self._state != 'play' and track_ids: - self._call('playid', track_ids[0]) + track_ids.extend(self._queue_album(album)) def _seek(self, pos, time): diff --git a/mcg/widgets.py b/mcg/widgets.py index c33905c..468da5d 100644 --- a/mcg/widgets.py +++ b/mcg/widgets.py @@ -167,7 +167,8 @@ class Window(): self._panels[Window._PANEL_INDEX_PLAYLIST].connect('play', self.on_playlist_panel_play) 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('play-multiple', self.on_library_panel_play_multiple) + self._panels[Window._PANEL_INDEX_LIBRARY].connect('queue', self.on_library_panel_queue) + self._panels[Window._PANEL_INDEX_LIBRARY].connect('queue-multiple', self.on_library_panel_queue_multiple) self._panels[Window._PANEL_INDEX_LIBRARY].connect('item-size-changed', self.on_library_panel_item_size_changed) self._panels[Window._PANEL_INDEX_LIBRARY].connect('sort-order-changed', self.on_library_panel_sort_order_changed) self._panels[Window._PANEL_INDEX_LIBRARY].connect('sort-type-changed', self.on_library_panel_sort_type_changed) @@ -337,8 +338,12 @@ class Window(): self._mcg.play_album(album) - def on_library_panel_play_multiple(self, widget, albums): - self._mcg.play_albums(albums) + def on_library_panel_queue(self, widget, album): + self._mcg.queue_album(album) + + + def on_library_panel_queue_multiple(self, widget, albums): + self._mcg.queue_albums(albums) def on_library_panel_item_size_changed(self, widget, size): @@ -1464,7 +1469,8 @@ class LibraryPanel(GObject.GObject): __gsignals__ = { 'update': (GObject.SIGNAL_RUN_FIRST, None, ()), 'play': (GObject.SIGNAL_RUN_FIRST, None, (str,)), - 'play-multiple': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), + 'queue': (GObject.SIGNAL_RUN_FIRST, None, (str,)), + 'queue-multiple': (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), 'item-size-changed': (GObject.SIGNAL_RUN_FIRST, None, (int,)), 'sort-order-changed': (GObject.SIGNAL_RUN_FIRST, None, (int,)), 'sort-type-changed': (GObject.SIGNAL_RUN_FIRST, None, (Gtk.SortType,)) @@ -1539,10 +1545,10 @@ class LibraryPanel(GObject.GObject): self._library_grid.set_tooltip_column(1) # Action bar (normal) actionbar = builder.get_object('library-actionbar') - cancel_button = Gtk.Button('cancel') + cancel_button = Gtk.Button("cancel") cancel_button.connect('clicked', self.on_selection_cancel_clicked) actionbar.pack_start(cancel_button) - add_button = Gtk.Button('add') + add_button = Gtk.Button("queue") add_button.connect('clicked', self.on_selection_add_clicked) actionbar.pack_end(add_button) @@ -1556,9 +1562,12 @@ class LibraryPanel(GObject.GObject): self._standalone_image = builder.get_object('library-standalone-image') # Action bar (standalone) actionbar_standalone = builder.get_object('library-standalone-actionbar') - play_button = Gtk.Button('play') + play_button = Gtk.Button("play") play_button.connect('clicked', self.on_standalone_play_clicked) actionbar_standalone.pack_end(play_button) + queue_button = Gtk.Button("queue") + queue_button.connect('clicked', self.on_standalone_queue_clicked) + actionbar_standalone.pack_end(queue_button) def get(self): @@ -1720,7 +1729,7 @@ class LibraryPanel(GObject.GObject): def on_selection_add_clicked(self, widget): hashes = [album.get_hash() for album in self._selected_albums] - self.emit('play-multiple', hashes) + self.emit('queue-multiple', hashes) self._select_button.set_active(False) @@ -1733,6 +1742,11 @@ class LibraryPanel(GObject.GObject): self._close_standalone() + def on_standalone_queue_clicked(self, widget): + self.emit('queue', self._selected_albums[0].get_hash()) + self._close_standalone() + + def on_standalone_close_clicked(self, widget): self._close_standalone()