[gnome-music/wip/jfelder/search-selection-reset: 7/9] albumsview: Fix albumwidget headerbar



commit c91e03a496846a257fd7350cf802d32500f99d0f
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Feb 27 20:26:16 2019 +0100

    albumsview: Fix albumwidget headerbar

 gnomemusic/views/albumsview.py    | 23 +++++++++++++++++++----
 gnomemusic/widgets/albumwidget.py | 10 +++++++++-
 gnomemusic/window.py              |  2 +-
 3 files changed, 29 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index 4e0edf4f..818d7f89 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -40,7 +40,7 @@ class AlbumsView(BaseView):
         return '<AlbumsView>'
 
     @log
-    def __init__(self, window, player):
+    def __init__(self, window, player, search):
         super().__init__('albums', _("Albums"), window)
 
         self.player = player
@@ -51,6 +51,10 @@ class AlbumsView(BaseView):
         self.items_selected = []
         self.items_selected_callback = None
 
+        self._search = search
+        self._search.connect(
+            "notify::search-mode-enabled", self._on_search_mode_changed)
+
     @log
     def _on_changes_pending(self, data=None):
         if (self._init and not self.props.selection_mode):
@@ -66,6 +70,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._search.props.search_mode_enabled
+                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 +108,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..450bbf88 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,8 @@ 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):
+        return self._album
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 6738e43d..5236a8de 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -243,7 +243,7 @@ class Window(Gtk.ApplicationWindow):
         self._headerbar.props.stack = self._stack
         self._searchbar.show()
 
-        self.views[View.ALBUM] = AlbumsView(self, self._player)
+        self.views[View.ALBUM] = AlbumsView(self, self._player, self._search)
         self.views[View.ARTIST] = ArtistsView(self, self._player)
         self.views[View.SONG] = SongsView(self, self._player)
         self.views[View.PLAYLIST] = PlaylistView(self, self._player)


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