[gnome-music/wip/jfelder/playback-status-v3: 9/10] playbackpopover: Introduce PlaybackPopover



commit 58d32a02f5fe3c4df6398c2f2e23e780bef0b92a
Author: Jean Felder <jfelder src gnome org>
Date:   Mon Sep 10 08:45:20 2018 +0200

    playbackpopover: Introduce PlaybackPopover
    
    The PlaybackPopover allows to keep track of the current playset.
    When a playset is started from the album view, it displays an
    AlbumWidget in PLAYBACK mode. If a playset is started from Artists,
    Songs or Playlist view, it displays a LinearPlayBox.
    Playbackpopover also contains a RepeatBox widget to change the repeat
    mode.
    PlaybackPopover is automatically updated when the current song, repeat
    mode or playset changes.

 data/org.gnome.Music.gresource.xml    |   1 +
 data/ui/PlaybackPopover.ui            |  22 ++++++++
 gnomemusic/grilo.py                   |   7 +++
 gnomemusic/query.py                   |  11 ++++
 gnomemusic/widgets/playbackpopover.py | 102 +++++++++++++++++++++++++++++++++-
 gnomemusic/widgets/playertoolbar.py   |   4 ++
 po/POTFILES.in                        |   1 +
 7 files changed, 147 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 9ec0b196..ebe6f69d 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -16,6 +16,7 @@
     <file preprocess="xml-stripblanks">ui/FilterView.ui</file>
     <file preprocess="xml-stripblanks">ui/HeaderBar.ui</file>
     <file preprocess="xml-stripblanks">ui/LinearPlaybackWindow.ui</file>
+    <file preprocess="xml-stripblanks">ui/PlaybackPopover.ui</file>
     <file preprocess="xml-stripblanks">ui/PlayerToolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistContextMenu.ui</file>
     <file preprocess="xml-stripblanks">ui/PlaylistControls.ui</file>
diff --git a/data/ui/PlaybackPopover.ui b/data/ui/PlaybackPopover.ui
new file mode 100644
index 00000000..75aca461
--- /dev/null
+++ b/data/ui/PlaybackPopover.ui
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="PlaybackPopover" parent="GtkPopover">
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkHeaderBar" id="_headerbar">
+            <property name="visible">True</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox" id="_main_box">
+            <property name="orientation">vertical</property>
+            <property name="visible">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 65d0373f..457645a3 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -420,6 +420,13 @@ class Grilo(GObject.GObject):
         self.search_source.query(query, self.METADATA_THUMBNAIL_KEYS, options,
                                  callback)
 
+    @log
+    def get_album_with_id(self, album_id, callback):
+        options = self.options.copy()
+        query = Query.get_album_for_album_id(album_id)
+
+        self.tracker.query(query, self.METADATA_KEYS, options, callback, None)
+
     @log
     def get_playlist_with_id(self, playlist_id, callback):
         options = self.options.copy()
diff --git a/gnomemusic/query.py b/gnomemusic/query.py
index ac7707f8..0f62cb8a 100644
--- a/gnomemusic/query.py
+++ b/gnomemusic/query.py
@@ -630,6 +630,17 @@ class Query():
         }
         return query
 
+    @staticmethod
+    def get_album_with_id(playlist_id):
+        query = """
+    ?playlist a nmm:Playlist .
+    FILTER (
+        tracker:id(?playlist) = %(playlist_id)s
+    )
+    """.replace('\n', ' ').strip() % {'playlist_id': playlist_id}
+
+        return Query.playlists(query)
+
     @staticmethod
     def get_playlist_with_id(playlist_id):
         query = """
diff --git a/gnomemusic/widgets/playbackpopover.py b/gnomemusic/widgets/playbackpopover.py
index c48d7283..79ea552b 100644
--- a/gnomemusic/widgets/playbackpopover.py
+++ b/gnomemusic/widgets/playbackpopover.py
@@ -22,10 +22,16 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
-from gi.repository import Gtk
+from gi.repository import GObject, Gtk
+from gettext import gettext as _
 
 from gnomemusic import log
+from gnomemusic.grilo import grilo
+from gnomemusic.player import PlayerPlaylist
+from gnomemusic.widgets.albumwidget import AlbumWidget
+from gnomemusic.widgets.repeatbox import RepeatBox
 from gnomemusic.widgets.songwidget import WidgetState, TwoLineWidget
+import gnomemusic.utils as utils
 
 
 @Gtk.Template(resource_path='/org/gnome/Music/ui/LinearPlaybackWindow.ui')
@@ -129,3 +135,97 @@ class LinearPlaybackWindow(Gtk.ScrolledWindow):
     def _on_row_activated(self, klass, row):
         index = row.get_index()
         self._player.play(index - self._current_index)
+
+
+@Gtk.Template(resource_path='/org/gnome/Music/ui/PlaybackPopover.ui')
+class PlaybackPopover(Gtk.Popover):
+    """Popover showing the following tracks in the current playlist"""
+
+    __gtype_name__ = 'PlaybackPopover'
+
+    __gsignals__ = {
+        'current-changed':
+        (GObject.SignalFlags.RUN_FIRST, None, (Gtk.TreeIter,)),
+    }
+
+    _headerbar = Gtk.Template.Child()
+    _main_box = Gtk.Template.Child()
+
+    def __repr__(self):
+        return '<PlaybackPopover>'
+
+    @log
+    def __init__(self, player, button):
+        super().__init__(relative_to=button)
+
+        self._player = player
+        button.connect('toggled', self._on_button_toggled)
+        self._player.connect('playlist-changed', self._on_playlist_changed)
+
+        self._album_playback = AlbumWidget(
+            player, self, AlbumWidget.Mode.PLAYBACK)
+        self._main_box.add(self._album_playback)
+
+        self._linear_playback = LinearPlaybackWindow(self._player)
+        self._main_box.add(self._linear_playback)
+
+        repeat_box = RepeatBox(self._player)
+        self._main_box.add(repeat_box)
+
+    @log
+    def _on_button_toggled(self, klass):
+        self.popup()
+
+    @log
+    def _set_title(self, title_suffix):
+        header = _("Playing")
+        self._headerbar.props.title = header + " " + title_suffix
+
+    @log
+    def _display_album_widget(self, source, param, item, count, error, data):
+        if not item:
+            return
+
+        self._album_playback.update(item)
+        self._set_title(utils.get_album_title(item))
+        self._linear_playback.hide()
+        self._album_playback.show()
+
+    @log
+    def _update_playlist_title(self, source, param, item, count, error, data):
+        if not item:
+            return
+        self._set_title(utils.get_media_title(item))
+
+    @log
+    def _update_linear_mode_title(self):
+        playlist_type = self._player.get_playlist_type()
+        if playlist_type == PlayerPlaylist.Type.PLAYLIST:
+            pl_id = self._player.get_playlist_id()
+            grilo.get_playlist_with_id(pl_id, self._update_playlist_title)
+        elif playlist_type == PlayerPlaylist.Type.ARTIST:
+            self._set_title(self._player.get_playlist_id())
+        else:
+            self._set_title(_("Songs"))
+
+    @log
+    def _on_playlist_changed(self, klass, data=None):
+        playlist_type = self._player.get_playlist_type()
+        linear_playlists = [
+            PlayerPlaylist.Type.ARTIST,
+            PlayerPlaylist.Type.PLAYLIST,
+            PlayerPlaylist.Type.SONGS]
+
+        if playlist_type == PlayerPlaylist.Type.ALBUM:
+            album_id = self._player.get_playlist_id()
+            grilo.get_album_with_id(album_id, self._display_album_widget)
+
+        elif playlist_type in linear_playlists:
+            self._album_playback.hide()
+            self._linear_playback.update()
+            self._update_linear_mode_title()
+            self._linear_playback.show()
+
+        else:
+            self._album_playback.hide()
+            self._linear_playback.hide()
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 7c0b69ca..a4a2c0b9 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -30,6 +30,7 @@ from gnomemusic.albumartcache import Art
 from gnomemusic.gstplayer import Playback
 from gnomemusic.player import RepeatMode
 from gnomemusic.widgets.coverstack import CoverStack  # noqa: F401
+from gnomemusic.widgets.playbackpopover import PlaybackPopover
 from gnomemusic.widgets.smoothscale import SmoothScale  # noqa: F401
 from gnomemusic.widgets.twolinetip import TwoLineTip
 import gnomemusic.utils as utils
@@ -80,6 +81,9 @@ class PlayerToolbar(Gtk.ActionBar):
 
         self._sync_repeat_image()
 
+        self._playback_popover = PlaybackPopover(
+            self._player, self._nowplaying_button)
+
         self._player.connect('clock-tick', self._on_clock_tick)
         self._player.connect('song-changed', self._update_view)
         self._player.connect('prev-next-invalidated', self._sync_prev_next)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 15aaaf14..4c81c2a0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -35,6 +35,7 @@ gnomemusic/widgets/artistalbumwidget.py
 gnomemusic/widgets/disclistboxwidget.py
 gnomemusic/widgets/headerbar.py
 gnomemusic/widgets/notificationspopup.py
+gnomemusic/widgets/playbackpopover.py
 gnomemusic/widgets/playertoolbar.py
 gnomemusic/widgets/playlistcontrols.py
 gnomemusic/widgets/playlistdialog.py


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]