[gnome-music/wip/jfelder/searchbar-child: 1/8] search: Introduce child state



commit 96320225ce9af1b5101c120cd0d72fa03de786d1
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Nov 15 12:29:24 2018 +0100

    search: Introduce child state
    
    Child state from search mode is enabled when clicking on an album or
    artist result.
    This prevents to expose Searchbar handling in SearchView.

 gnomemusic/search.py            | 2 ++
 gnomemusic/views/searchview.py  | 9 +++------
 gnomemusic/widgets/searchbar.py | 9 ++++++++-
 3 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/search.py b/gnomemusic/search.py
index 78000f76..4f0ea215 100644
--- a/gnomemusic/search.py
+++ b/gnomemusic/search.py
@@ -33,7 +33,9 @@ class Search():
            NONE: No ongoing search.
            RESULT: Search with result.
            NO_RESULT: Search without result.
+           CHILD: clicked on an album or artist from Search
         """
         NONE = 0
         RESULT = 1
         NO_RESULT = 2
+        CHILD = 3
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 88eefe2d..0304c39d 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -55,9 +55,6 @@ class SearchView(BaseView):
     def __init__(self, window, player):
         super().__init__('search', None, window)
 
-        # FIXME: Searchbar handling does not belong here.
-        self._searchbar = window._searchbar
-
         self._add_list_renderers()
         self.player = player
         self._head_iters = [None, None, None, None]
@@ -100,7 +97,7 @@ class SearchView(BaseView):
 
     @log
     def _back_button_clicked(self, widget, data=None):
-        self._searchbar.reveal(True, False)
+        self.props.search_state = Search.State.RESULT
 
         if self.get_visible_child() == self._artist_albums_widget:
             self._artist_albums_widget.destroy()
@@ -138,7 +135,7 @@ class SearchView(BaseView):
             self._headerbar.props.title = title
             self._headerbar.props.subtitle = artist
             self.set_visible_child(self._album_widget)
-            self.props.search_state = Search.State.NONE
+            self.props.search_state = Search.State.CHILD
 
         elif self.model[_iter][12] == 'artist':
             artist = self.model[_iter][2]
@@ -159,7 +156,7 @@ class SearchView(BaseView):
             self._headerbar.props.title = artist
             self._headerbar.props.subtitle = ''
             self.set_visible_child(self._artist_albums_widget)
-            self.props.search_state = Search.State.NONE
+            self.props.search_state = Search.State.CHILD
         elif self.model[_iter][12] == 'song':
             if self.model[_iter][11] != ValidationStatus.FAILED:
                 c_iter = self._songs_model.convert_child_iter_to_iter(_iter)[1]
diff --git a/gnomemusic/widgets/searchbar.py b/gnomemusic/widgets/searchbar.py
index c106fde9..9a763eb5 100644
--- a/gnomemusic/widgets/searchbar.py
+++ b/gnomemusic/widgets/searchbar.py
@@ -339,6 +339,7 @@ class Searchbar(Gtk.SearchBar):
         self._dropdown = DropDown()
         self._dropdown.initialize_filters(self)
         self.connect('notify::search-state', self._search_state_changed)
+        self._previous_search_state = Search.State.NONE
 
     @Gtk.Template.Callback()
     @log
@@ -402,7 +403,8 @@ class Searchbar(Gtk.SearchBar):
     def _search_state_changed(self, klass, data):
         search_state = self.props.search_state
 
-        if search_state == Search.State.NONE:
+        if (search_state == Search.State.NONE
+                or search_state == Search.State.CHILD):
             self.reveal(False)
         elif search_state == Search.State.NO_RESULT:
             self._set_error_style(True)
@@ -410,6 +412,11 @@ class Searchbar(Gtk.SearchBar):
         else:
             self._set_error_style(False)
             self.props.stack.props.visible_child_name = 'search'
+            # display searchbar when switching back to results
+            if self._previous_search_state == Search.State.CHILD:
+                self.reveal(True, False)
+
+        self._previous_search_state = search_state
 
     @log
     def _set_error_style(self, error):


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