[gnome-music] Adding a view for searches with no result
- From: Vadim Rutkovsky <vrutkovsky src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] Adding a view for searches with no result
- Date: Tue, 23 Jun 2015 10:56:12 +0000 (UTC)
commit ed1059b25b3aa46baf05c34a6949a9dc03a67d17
Author: Hapoofesgeli <Hapoofesgeli openmailbox org>
Date: Fri Jun 19 18:11:14 2015 +0430
Adding a view for searches with no result
https://bugzilla.gnome.org/show_bug.cgi?id=744464
gnomemusic/view.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++---
gnomemusic/window.py | 15 ++++++++++--
2 files changed, 64 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 04725f3..856dece 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -91,8 +91,8 @@ class ViewContainer(Gtk.Stack):
)
self.view.set_view_type(view_type)
self.view.set_model(self.model)
- box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
- box.pack_start(self.view, True, True, 0)
+ self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+ self._box.pack_start(self.view, True, True, 0)
if use_sidebar:
self.stack = Gtk.Stack(
transition_type=Gtk.StackTransitionType.SLIDE_RIGHT,
@@ -102,11 +102,11 @@ class ViewContainer(Gtk.Stack):
if sidebar:
self.stack.add_named(sidebar, 'sidebar')
else:
- self.stack.add_named(box, 'sidebar')
+ self.stack.add_named(self._box, 'sidebar')
self.stack.set_visible_child_name('dummy')
self._grid.add(self.stack)
if not use_sidebar or sidebar:
- self._grid.add(box)
+ self._grid.add(self._box)
self.star_handler = Widgets.StarHandler(self, 9)
self.view.click_handler = self.view.connect('item-activated', self._on_item_activated)
@@ -1310,7 +1310,36 @@ class Playlist(ViewContainer):
for path in self.view.get_selection()])
+class EmptySearch(ViewContainer):
+ @log
+ def __init__(self, window, player):
+ ViewContainer.__init__(self, 'emptysearch', None, window, Gd.MainViewType.LIST)
+ self._artistAlbumsWidget = None
+ self.player = player
+
+ builder = Gtk.Builder()
+ builder.add_from_resource('/org/gnome/Music/NoMusic.ui')
+ widget = builder.get_object('container')
+ widget.set_vexpand(True)
+ widget.set_hexpand(True)
+ widget.get_children()[1].get_children()[1].set_text("Try a different search")
+ widget.show_all()
+ self._box.add(widget)
+
+ @log
+ def _back_button_clicked(self, widget, data=None):
+ self.header_bar.searchbar.show_bar(True, False)
+ if self.get_visible_child() == self._artistAlbumsWidget:
+ self._artistAlbumsWidget.destroy()
+ self._artistAlbumsWidget = None
+ self.set_visible_child(self._grid)
+
+
class Search(ViewContainer):
+ __gsignals__ = {
+ 'no-music-found': (GObject.SIGNAL_RUN_FIRST, None, ())
+ }
+
@log
def __init__(self, window, player):
ViewContainer.__init__(self, 'search', None, window, Gd.MainViewType.LIST)
@@ -1327,6 +1356,8 @@ class Search(ViewContainer):
self.player = player
self.head_iters = [None, None, None, None]
self.songs_model = self.model
+ self.previous_view = None
+ self.connect('no-music-found', self._no_music_found_callback)
self.albums_selected = []
self._albums = {}
@@ -1342,6 +1373,12 @@ class Search(ViewContainer):
self.items_selected_callback = None
@log
+ def _no_music_found_callback(self, view):
+ self.window._stack.set_visible_child_name('emptysearch')
+ self.window._stack.get_child_by_name('emptysearch')._artistAlbumsWidget =\
+ self._artistAlbumsWidget
+
+ @log
def _back_button_clicked(self, widget, data=None):
self.header_bar.searchbar.show_bar(True, False)
if self.get_visible_child() == self._artistAlbumsWidget:
@@ -1432,10 +1469,21 @@ class Search(ViewContainer):
if data is None:
return
+ # We need to remember the view before the search view
+ if self.window.curr_view != self.window.views[5] and \
+ self.window.prev_view != self.window.views[5]:
+ self.previous_view = self.window.prev_view
+
if remaining == 0:
self.window.notification.dismiss()
self.view.show()
+ if (self.model.iter_n_children(self.head_iters[0])+
+ self.model.iter_n_children(self.head_iters[1])+
+ self.model.iter_n_children(self.head_iters[2])+
+ self.model.iter_n_children(self.head_iters[3]) == 0) and remaining == 0:
+ self.emit('no-music-found')
+
model, category = data
if not item or model != self.model:
return
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 0b40a96..6c8c363 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -261,6 +261,7 @@ class Window(Gtk.ApplicationWindow):
self.views.append(Views.Songs(self, self.player))
self.views.append(Views.Playlist(self, self.player))
self.views.append(Views.Search(self, self.player))
+ self.views.append(Views.EmptySearch(self, self.player))
for i in self.views:
if i.title:
@@ -427,9 +428,15 @@ class Window(Gtk.ApplicationWindow):
self.curr_view == self.views[3]:
self.curr_view.stack.set_visible_child_name('dummy')
self.curr_view.stack.set_visible_child_name('sidebar')
- if self.curr_view != self.views[4]:
+ if self.curr_view != self.views[4] and self.curr_view != self.views[5]:
self.toolbar.searchbar.show_bar(False)
+ # Toggle the selection button for the EmptySearch view
+ if self.curr_view == self.views[5] or \
+ self.prev_view == self.views[5]:
+ self.toolbar._select_button.set_sensitive(
+ not self.toolbar._select_button.get_sensitive())
+
@log
def _toggle_view(self, btn, i):
self._stack.set_visible_child(self.views[i])
@@ -438,9 +445,11 @@ class Window(Gtk.ApplicationWindow):
def _on_search_toggled(self, button, data=None):
self.toolbar.searchbar.show_bar(button.get_active(),
self.curr_view != self.views[4])
- if not button.get_active() and self.curr_view == self.views[4] and \
+ if not button.get_active() and \
+ (self.curr_view == self.views[4] or self.curr_view == self.views[5])and \
self.toolbar._state == ToolbarState.MAIN:
- self._stack.set_visible_child(self.prev_view)
+ # We should get back to the view before the search
+ self._stack.set_visible_child(self.views[4].previous_view)
if self.toolbar._selectionMode:
self.toolbar.set_selection_mode(False)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]