[gnome-music/wip/garnacho/performance-improvements: 5/5] view: Remove "All artists" entry from "Artist" view



commit c3769c85934caf2c78203e5392abe3137c437f14
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Feb 15 16:21:19 2015 +0100

    view: Remove "All artists" entry from "Artist" view
    
    On (not so) large music collections, having this option present and
    selected by default brings in a widget count explosion, making the UI look
    slow on scrolling, or operations involving forall() on containers, like
    style changes when focusing/unfocusing the window.
    
    Furthermore, grilo operations are not cancelled when selecting another
    artist from the list on the left, so items won't be populated until the
    "all artists" queries have finished. This means the user still has to
    wait for that operation to finish regardless of selecting an specific
    artist.
    
    Just avoid this by removing the "All artists" option, even if less neat
    looking, the "Albums" view already offers a global view. This involves
    significantly less grilo/tracker queries and widgets on the window
    happening by default on the "Artists" view.

 gnomemusic/view.py    |   40 +++++++++++++---------------------------
 gnomemusic/widgets.py |   24 ------------------------
 2 files changed, 13 insertions(+), 51 deletions(-)
---
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 0bffbfe..a7e49e0 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -70,6 +70,7 @@ class ViewContainer(Gtk.Stack):
         self._adjustmentChangedId = 0
         self._scrollbarVisibleId = 0
         self.old_vsbl_range = None
+        self._last_selection = None
         self._model = Gtk.ListStore(
             GObject.TYPE_STRING,
             GObject.TYPE_STRING,
@@ -601,22 +602,10 @@ class Artists (ViewContainer):
 
     @log
     def _populate(self, data=None):
-        selection = self.view.get_generic_view().get_selection()
-        if not selection.get_selected()[1]:
-            self._allIter = self._model.insert_with_valuesv(-1, [2], [_("All Artists")])
-            self._last_selection = self._allIter
-            self._artists[_("All Artists").casefold()] =\
-                {'iter': self._allIter, 'albums': [], 'widget': None}
-            selection.select_path(self._model.get_path(self._allIter))
         self._init = True
         self.populate()
 
     @log
-    def add_all_artists_entry(self):
-        self.view.emit('item-activated', '0',
-                       self._model.get_path(self._allIter))
-
-    @log
     def _add_list_renderers(self):
         list_widget = self.view.get_generic_view()
 
@@ -668,17 +657,10 @@ class Artists (ViewContainer):
         )
         self.artistAlbumsStack.add(new_artistAlbumsWidget)
 
-        artistAlbums = None
-        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
-            )
-        else:
-            artistAlbums = Widgets.ArtistAlbums(
-                artist, albums, self.player,
-                self.header_bar, self.selection_toolbar
-            )
+        artistAlbums = Widgets.ArtistAlbums(
+            artist, albums, self.player,
+            self.header_bar, self.selection_toolbar
+        )
         self._artists[artist.casefold()]['widget'] = artistAlbums
         new_artistAlbumsWidget.add(artistAlbums)
         new_artistAlbumsWidget.show()
@@ -691,7 +673,6 @@ 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.view.show()
             return
         self._offset += 1
@@ -702,6 +683,13 @@ class Artists (ViewContainer):
             _iter = self._model.insert_with_valuesv(-1, [2], [artist])
             self._artists[artist.casefold()] = {'iter': _iter, 'albums': [], 'widget': None}
 
+            # Select the first item after we're finished with it
+            prev = self._model.iter_previous(_iter)
+            if (prev is not None and self._last_selection is None):
+                selection = self.view.get_generic_view().get_selection()
+                selection.select_iter(prev)
+                self.view.emit('item-activated', '0', self._model.get_path(prev))
+
         self._artists[artist.casefold()]['albums'].append(item)
 
     @log
@@ -744,9 +732,7 @@ class Artists (ViewContainer):
             _iter = self._model.get_iter(path)
             artist = self._model.get_value(_iter, 2)
             albums = self._artists[artist.casefold()]['albums']
-            if (self._model.get_string_from_iter(_iter) !=
-                    self._model.get_string_from_iter(self._allIter)):
-                self.albums_selected.extend(albums)
+            self.albums_selected.extend(albums)
 
         if len(self.albums_selected):
             self._get_selected_album_songs()
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index 4787a59..ff76080 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -486,30 +486,6 @@ class ArtistAlbums(Gtk.Box):
             self.header_bar._selection_menu_label.set_text(_("Click on items to select them"))
 
 
-class AllArtistsAlbums(ArtistAlbums):
-
-    @log
-    def __init__(self, player, header_bar, selection_toolbar, selectionModeAllowed=False):
-        ArtistAlbums.__init__(self, _("All Artists"), [], player,
-                              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)
-
-    @log
-    def add_item(self, source, param, item, remaining=0, data=None):
-        if item:
-            self._offset += 1
-            self.add_album(item)
-            self.show_all()
-
-
 class ArtistAlbumWidget(Gtk.Box):
 
     __gsignals__ = {


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