[gnome-music/wip/jfelder/search-selection-reset: 9/11] albumsview: Correctly restore the headerbar after a search
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/search-selection-reset: 9/11] albumsview: Correctly restore the headerbar after a search
- Date: Wed, 3 Apr 2019 19:30:03 +0000 (UTC)
commit 6e104750425b6ffe57c22581850172f523f60f39
Author: Jean Felder <jfelder src gnome org>
Date: Wed Feb 27 20:26:16 2019 +0100
albumsview: Correctly restore the headerbar after a search
When launching a search from an AlbumWidget, the main stack switcher becomes
visible when leaving search mode.
This issue is solved by listening to search mode changes. When leaving
search-mode, if an AlbumWidget was visible, the headerbar is correctly
restored. In order to do so, the current album has to be stored as a
GObject property.
gnomemusic/views/albumsview.py | 22 +++++++++++++++++++---
gnomemusic/widgets/albumwidget.py | 15 ++++++++++++++-
gnomemusic/window.py | 3 +++
3 files changed, 36 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index 4e0edf4f..33fe4f94 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -36,6 +36,8 @@ import gnomemusic.utils as utils
class AlbumsView(BaseView):
+ search_mode_active = GObject.Property(type=bool, default=False)
+
def __repr__(self):
return '<AlbumsView>'
@@ -51,6 +53,9 @@ class AlbumsView(BaseView):
self.items_selected = []
self.items_selected_callback = None
+ self.connect(
+ "notify::search-mode-active", self._on_search_mode_changed)
+
@log
def _on_changes_pending(self, data=None):
if (self._init and not self.props.selection_mode):
@@ -66,6 +71,13 @@ class AlbumsView(BaseView):
and grilo.changes_pending['Albums']):
self._on_changes_pending()
+ @log
+ def _on_search_mode_changed(self, klass, param):
+ if (not self.props.search_mode_active
+ and self._headerbar.props.stack.props.visible_child == self
+ and self.get_visible_child() == self._album_widget):
+ self._set_album_headerbar(self._album_widget.props.album)
+
@log
def _setup_view(self):
self._view = Gtk.FlowBox(
@@ -97,11 +109,15 @@ class AlbumsView(BaseView):
# Update and display the album widget if not in selection mode
self._album_widget.update(item)
- self._headerbar.props.state = HeaderBar.State.CHILD
- self._headerbar.props.title = utils.get_album_title(item)
- self._headerbar.props.subtitle = utils.get_artist_name(item)
+ self._set_album_headerbar(item)
self.set_visible_child(self._album_widget)
+ @log
+ def _set_album_headerbar(self, album):
+ self._headerbar.props.state = HeaderBar.State.CHILD
+ self._headerbar.props.title = utils.get_album_title(album)
+ self._headerbar.props.subtitle = utils.get_artist_name(album)
+
@log
def populate(self):
self._window.notifications_popup.push_loading()
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index ecdc2c93..f380ad2e 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -23,7 +23,7 @@
# delete this exception statement from your version.
from gettext import ngettext
-from gi.repository import GdkPixbuf, GObject, Gtk
+from gi.repository import GdkPixbuf, GObject, Grl, Gtk
from gnomemusic import log
from gnomemusic.albumartcache import Art
@@ -71,6 +71,7 @@ class AlbumWidget(Gtk.EventBox):
"""
super().__init__()
+ self._album = None
self._songs = []
self._cover_stack.props.size = Art.Size.LARGE
@@ -143,6 +144,8 @@ class AlbumWidget(Gtk.EventBox):
self._set_composer_label(album)
+ self._album = album
+
self._player.connect('song-changed', self._update_model)
grilo.populate_album_songs(album, self.add_item)
@@ -280,3 +283,13 @@ class AlbumWidget(Gtk.EventBox):
:rtype: list
"""
return self._disc_listbox.get_selected_items()
+
+ @GObject.Property(
+ type=Grl.Media, default=False, flags=GObject.ParamFlags.READABLE)
+ def album(self):
+ """Get the current album.
+
+ :returns: the current album
+ :rtype: Grl.Media
+ """
+ return self._album
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 3ed1e6b7..904ebfcd 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -283,6 +283,9 @@ class Window(Gtk.ApplicationWindow):
self._search.bind_property(
"search-mode-active", self.views[View.SEARCH],
"search-mode-active", GObject.BindingFlags.BIDIRECTIONAL)
+ self._search.bind_property(
+ "search-mode-active", self.views[View.ALBUM],
+ "search-mode-active", GObject.BindingFlags.SYNC_CREATE)
@log
def _select_all(self, action=None, param=None):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]