[gnome-music/wip/jfelder/playback-status-v4: 11/12] playbackpopover: Introduce PlaybackPopover



commit cb5642535a3fa80f3aeec98cd31a23c25c1bea8a
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. It 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/widgets/playbackpopover.py | 97 ++++++++++++++++++++++++++++++++++-
 gnomemusic/widgets/playertoolbar.py   |  5 ++
 po/POTFILES.in                        |  1 +
 5 files changed, 125 insertions(+), 1 deletion(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 04ffc19f..8e55b224 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -22,6 +22,7 @@
     <file preprocess="xml-stripblanks">ui/LinearPlaybackWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/LoadingNotification.ui</file>
     <file preprocess="xml-stripblanks">ui/NotificationsPopup.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/widgets/playbackpopover.py b/gnomemusic/widgets/playbackpopover.py
index e93eeaed..4fb25503 100644
--- a/gnomemusic/widgets/playbackpopover.py
+++ b/gnomemusic/widgets/playbackpopover.py
@@ -22,8 +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 enum import IntEnum
+from gettext import gettext as _
 
+from gi.repository import GObject, Gtk
+
+from gnomemusic.coreartist import CoreArtist
+from gnomemusic.coresong import CoreSong
+from gnomemusic.player import PlayerPlaylist
+from gnomemusic.widgets.albumwidget import AlbumWidget
+from gnomemusic.widgets.repeatbox import RepeatBox
 from gnomemusic.widgets.songwidget import WidgetState
 from gnomemusic.widgets.twolinewidget import TwoLineWidget
 
@@ -77,3 +85,90 @@ class LinearPlaybackWidget(Gtk.ScrolledWindow):
         self._player.play(coresong)
         current_coresong.props.state = WidgetState.PLAYED
         coresong.props.state = WidgetState.PLAYING
+
+
+@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"
+
+    _headerbar = Gtk.Template.Child()
+    _main_box = Gtk.Template.Child()
+
+    class Mode(IntEnum):
+        """Playback mode"""
+        LINEAR = 0
+        ALBUM = 1
+
+    def __init__(self, application):
+        """Instantiate LinearPlaybackWidget
+
+        :param Application application: Application object
+        """
+        super().__init__()
+
+        self._coremodel = application.props.coremodel
+        self._coremodel.connect("playlist-loaded", self._on_playlist_changed)
+
+        player = application.props.player
+        self._album_wiget = AlbumWidget(application, AlbumWidget.Mode.PLAYBACK)
+        self._main_box.add(self._album_wiget)
+
+        self._linear_playback = LinearPlaybackWidget(application)
+        self._main_box.add(self._linear_playback)
+
+        repeat_box = RepeatBox(player)
+        self._main_box.add(repeat_box)
+
+        self._playlist_type = None
+        self._mode = PlaybackPopover.Mode.LINEAR
+        self._set_linear_mode()
+
+    @GObject.Property(type=int, default=0, minimum=0, maximum=1)
+    def mode(self):
+        """Get the playback mode
+
+        :returns: The view state
+        :rtype: int
+        """
+        return self._mode
+
+    @mode.setter
+    def mode(self, value):
+        """Set the playback mode
+
+        :param int value: new playback mode
+        """
+        self._mode = value
+        if self._mode == PlaybackPopover.Mode.LINEAR:
+            self._set_linear_mode()
+        elif self._mode == PlaybackPopover.Mode.ALBUM:
+            self._set_album_mode()
+
+    def _set_linear_mode(self):
+        self._album_wiget.hide()
+        self._linear_playback.show()
+
+    def _set_album_mode(self):
+        self._linear_playback.hide()
+        self._album_wiget.update(self._coremodel.props.active_media)
+        self._album_wiget.show()
+
+    def _on_playlist_changed(self, coremodel, playlist_type):
+        self._playlist_type = playlist_type
+        if playlist_type == PlayerPlaylist.Type.ALBUM:
+            self.props.mode = PlaybackPopover.Mode.ALBUM
+        else:
+            self.props.mode = PlaybackPopover.Mode.LINEAR
+
+        active_media = self._coremodel.props.active_media
+        if isinstance(active_media, CoreSong):
+            pl_title = _("Songs")
+        elif isinstance(active_media, CoreArtist):
+            pl_title = active_media.props.artist
+        else:
+            pl_title = active_media.props.title
+
+        title = _("Playing {}".format(pl_title))
+        self._headerbar.props.title = title
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index e060f02d..0e0fe3e6 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -29,6 +29,7 @@ from gnomemusic.albumartcache import Art
 from gnomemusic.gstplayer import Playback
 from gnomemusic.player import Player, 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
@@ -98,6 +99,10 @@ class PlayerToolbar(Gtk.ActionBar):
         self._player = player
         self._progress_scale.props.player = self._player
 
+        # FIXME
+        self._playback_popover = PlaybackPopover(
+            self._player._app, self._nowplaying_button)
+
         self._player.connect('song-changed', self._update_view)
         self._player.connect(
             'notify::repeat-mode', self._on_repeat_mode_changed)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index dc53fe14..8a00b41f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -39,6 +39,7 @@ gnomemusic/widgets/disclistboxwidget.py
 gnomemusic/widgets/headerbar.py
 gnomemusic/widgets/lastfmdialog.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]