[gnome-music] Show loading notification on long operations (e.g. All Artists)



commit 31e0e20d276972b8432712853170c3935b6c257e
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Mon Feb 16 16:28:09 2015 +0100

    Show loading notification on long operations (e.g. All Artists)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=729525

 gnomemusic/view.py    |   19 ++++++++++++++-----
 gnomemusic/widgets.py |   12 ++++++++----
 gnomemusic/window.py  |   21 +++++++++++++++++----
 3 files changed, 39 insertions(+), 13 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 4bf4a43..b7585ce 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -212,6 +212,7 @@ class ViewContainer(Gtk.Stack):
     def _add_item(self, source, param, item, remaining=0, data=None):
         if not item:
             if remaining == 0:
+                self.window.notification.dismiss()
                 self.view.show()
             return
         self._offset += 1
@@ -340,6 +341,7 @@ class Albums(ViewContainer):
     @log
     def populate(self):
         if grilo.tracker:
+            self.window._init_loading_notification()
             GLib.idle_add(grilo.populate_albums, self._offset, self._add_item)
 
     @log
@@ -436,6 +438,7 @@ class Songs(ViewContainer):
     def _add_item(self, source, param, item, remaining=0, data=None):
         if not item:
             if remaining == 0:
+                self.window.notification.dismiss()
                 self.view.show()
             return
         self._offset += 1
@@ -547,6 +550,7 @@ class Songs(ViewContainer):
     def populate(self):
         self._init = True
         if grilo.tracker:
+            self.window._init_loading_notification()
             GLib.idle_add(grilo.populate_songs, self._offset, self._add_item)
 
     @log
@@ -673,12 +677,12 @@ class Artists (ViewContainer):
         if (self._model.get_string_from_iter(_iter) ==
                 self._model.get_string_from_iter(self._allIter)):
             artistAlbums = Widgets.AllArtistsAlbums(
-                self.player, self.header_bar, self.selection_toolbar
+                self.player, self.header_bar, self.selection_toolbar, self.window
             )
         else:
             artistAlbums = Widgets.ArtistAlbums(
                 artist, albums, self.player,
-                self.header_bar, self.selection_toolbar
+                self.header_bar, self.selection_toolbar, self.window
             )
         self._artists[artist.casefold()]['widget'] = artistAlbums
         new_artistAlbumsWidget.add(artistAlbums)
@@ -692,7 +696,7 @@ class Artists (ViewContainer):
     def _add_item(self, source, param, item, remaining=0, data=None):
         if item is None:
             if remaining == 0:
-                #self.add_all_artists_entry()
+                self.window.notification.dismiss()
                 self.view.show()
             return
         self._offset += 1
@@ -708,6 +712,7 @@ class Artists (ViewContainer):
     @log
     def populate(self):
         if grilo.tracker:
+            self.window._init_loading_notification()
             GLib.idle_add(grilo.populate_artists, self._offset, self._add_item)
 
     @log
@@ -974,6 +979,7 @@ class Playlist(ViewContainer):
     @log
     def _populate(self):
         self._init = True
+        self.window._init_loading_notification()
         self.populate()
 
     @log
@@ -996,6 +1002,7 @@ class Playlist(ViewContainer):
     @log
     def _add_playlist_item_to_model(self, item):
         if not item:
+            self.window.notification.dismiss()
             self.emit('playlists-loaded')
             return
         _iter = self.playlists_model.insert_with_valuesv(
@@ -1194,7 +1201,7 @@ class Playlist(ViewContainer):
 
     @log
     def _on_delete_activate(self, menuitem, data=None):
-        self.window._init_notification()
+        self.window._init_playlist_removal_notification()
         self.delete_selected_playlist()
 
     @log
@@ -1346,7 +1353,7 @@ class Search(ViewContainer):
 
             self._artistAlbumsWidget = Widgets.ArtistAlbums(
                 artist, albums, self.player,
-                self.header_bar, self.selection_toolbar, True
+                self.header_bar, self.selection_toolbar, self.window, True
             )
             self.add(self._artistAlbumsWidget)
 
@@ -1400,6 +1407,7 @@ class Search(ViewContainer):
             return
 
         if remaining == 0:
+            self.window.notification.dismiss()
             self.view.show()
 
         model, category = data
@@ -1483,6 +1491,7 @@ class Search(ViewContainer):
 
     @log
     def populate(self):
+        self.window._init_loading_notification()
         self.header_bar.set_state(ToolbarState.MAIN)
 
     @log
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index 4787a59..0a1ccc0 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -343,11 +343,12 @@ class ArtistAlbums(Gtk.Box):
 
     @log
     def __init__(self, artist, albums, player,
-                 header_bar, selection_toolbar, selectionModeAllowed=False):
+                 header_bar, selection_toolbar, window, selectionModeAllowed=False):
         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
         self.player = player
         self.artist = artist
         self.albums = albums
+        self.window = window
         self.selectionMode = False
         self.selectionModeAllowed = selectionModeAllowed
         self.selection_toolbar = selection_toolbar
@@ -385,6 +386,7 @@ class ArtistAlbums(Gtk.Box):
         self.pack_start(self._scrolledWindow, True, True, 0)
 
         self.hide()
+        self.window._init_loading_notification()
 
         for album in albums:
             is_last_album = False
@@ -395,6 +397,7 @@ class ArtistAlbums(Gtk.Box):
         self.player.connect('playlist-item-changed', self.update_model)
 
     def _on_last_album_displayed(self, data=None):
+        self.window.notification.dismiss()
         self.show_all()
 
     @log
@@ -494,20 +497,21 @@ class AllArtistsAlbums(ArtistAlbums):
                               header_bar, selection_toolbar, selectionModeAllowed)
         self._offset = 0
         self._populate()
-        self.show()
 
     @log
     def _populate(self, data=None):
         if grilo.tracker:
             GLib.idle_add(grilo.populate_albums,
-                          self._offset, self.add_item, -1)
+                          self._offset, self.add_item)
 
     @log
     def add_item(self, source, param, item, remaining=0, data=None):
+        if remaining == 0:
+            self._on_last_album_displayed()
+
         if item:
             self._offset += 1
             self.add_album(item)
-            self.show_all()
 
 
 class ArtistAlbumWidget(Gtk.Box):
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 710d670..b262086 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -305,7 +305,7 @@ class Window(Gtk.ApplicationWindow):
         self._stack.get_visible_child().queue_draw()
 
     @log
-    def _init_notification(self):
+    def _init_playlist_removal_notification(self):
         self.notification = Gd.Notification()
         self.notification.set_timeout(20)
 
@@ -322,15 +322,28 @@ class Window(Gtk.ApplicationWindow):
         self.notification.show_all()
         self._overlay.add_overlay(self.notification)
 
-        self.notification.connect("dismissed", self._notification_dismissed)
+        self.notification.connect("dismissed", self._playlist_removal_notification_dismissed)
         undo_button.connect("clicked", self._undo_deletion)
 
     @log
-    def _notification_dismissed(self, widget):
+    def _playlist_removal_notification_dismissed(self, widget):
         if self.views[3].really_delete:
             Views.playlists.delete_playlist(self.views[3].pl_todelete)
 
     @log
+    def _init_loading_notification(self):
+        self.notification = Gd.Notification()
+        grid = Gtk.Grid()
+        grid.set_column_spacing(8)
+        self.notification.add(grid)
+        spinner = Gtk.Spinner()
+        grid.add(spinner)
+        grid.add(Gtk.Label.new(_("Loading")))
+        spinner.start()
+        self.notification.show_all()
+        self._overlay.add_overlay(self.notification)
+
+    @log
     def _undo_deletion(self, widget):
         self.views[3].really_delete = False
         self.notification.dismiss()
@@ -355,7 +368,7 @@ class Window(Gtk.ApplicationWindow):
         else:
             if (event.keyval == Gdk.KEY_Delete):
                 if self._stack.get_visible_child() == self.views[3]:
-                    self._init_notification()
+                    self._init_playlist_removal_notification()
                     self.views[3].delete_selected_playlist()
             # Close search bar after Esc is pressed
             if event.keyval == Gdk.KEY_Escape:


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