[gnome-music] Remove filtering - we're using queries/search now



commit fd3191ea809dedd691ad79d78b8574b9f337fdcd
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Tue Apr 8 14:16:25 2014 +0200

    Remove filtering - we're using queries/search now

 gnomemusic/mpris.py     |    2 +-
 gnomemusic/searchbar.py |   19 -------------
 gnomemusic/view.py      |   66 ++++++++++++++++++++---------------------------
 gnomemusic/widgets.py   |    6 +---
 4 files changed, 31 insertions(+), 62 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index e3125ca..63f0515 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -278,7 +278,7 @@ class MediaPlayer2Service(dbus.service.Object):
         elif self.first_song_handler == 0:
             window = self.app.get_active_window()
             window._stack.set_visible_child(window.views[2])
-            model = window.views[2].filter
+            model = window.views[2]._model
             if model.iter_n_children(None):
                 _iter = model.get_iter_first()
                 self._play_first_song(model, model.get_path(_iter), _iter)
diff --git a/gnomemusic/searchbar.py b/gnomemusic/searchbar.py
index ab196ff..06812cd 100644
--- a/gnomemusic/searchbar.py
+++ b/gnomemusic/searchbar.py
@@ -222,29 +222,12 @@ class Searchbar(Gd.Revealer):
     def _search_entry_tag_button_clicked(self, entry, tag):
         tag.manager.reset_to_default()
 
-    def set_view_filter(self, model, itr, user_data):
-        if self._search_entry.get_property("visible"):
-            search_string = self._search_entry.get_text().lower()
-            media = model.get_value(itr, 5)
-            searchable_fields = [model.get_value(itr, 2),
-                                 model.get_value(itr, 3)]
-            if media and media.get_url():
-                searchable_fields.append(media.get_title())
-            for field in searchable_fields:
-                if field and search_string in field.lower():
-                    return True
-            return False
-        return True
-
     @log
     def prepare_search_filter(self, widget, data):
         self.view = self.stack_switcher.get_stack().get_visible_child()
         if self.view.header_bar._state == 0:
             # album was selected on album view, view needs to be redefined
             self.view = self.view._albumWidget
-        if not hasattr(self.view.filter, "visible_function_set"):
-            self.view.filter.set_visible_func(self.set_view_filter)
-            self.view.filter.visible_function_set = True
 
     @log
     def search_entry_timeout(self, widget):
@@ -258,8 +241,6 @@ class Searchbar(Gd.Revealer):
         if self.view:
             self.view._model.clear()
             grilo.search(self.search_term, self.view._add_item)
-        #if self.view:
-        #    self.view.filter.refilter()
 
     @log
     def show_bar(self, show):
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 2edcb03..9918ed7 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -68,7 +68,6 @@ class ViewContainer(Gtk.Stack):
         nowPlayingIconName = 'media-playback-start-rtl-symbolic'
     errorIconName = 'dialog-error-symbolic'
     starIconName = 'starred-symbolic'
-    filter = None
 
     @log
     def __init__(self, title, header_bar, selection_toolbar, view_type, use_sidebar=False, sidebar=None):
@@ -99,8 +98,7 @@ class ViewContainer(Gtk.Stack):
             shadow_type=Gtk.ShadowType.NONE
         )
         self.view.set_view_type(view_type)
-        self.filter = self._model.filter_new(None)
-        self.view.set_model(self.filter)
+        self.view.set_model(self._model)
         self.vadjustment = self.view.get_vadjustment()
         self.selection_toolbar = selection_toolbar
         box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
@@ -365,8 +363,7 @@ class Albums(ViewContainer):
 
     @log
     def _on_item_activated(self, widget, id, path):
-        child_path = self.filter.convert_path_to_child_path(path)
-        _iter = self._model.get_iter(child_path)
+        _iter = self._model.get_iter(path)
         title = self._model.get_value(_iter, 2)
         artist = self._model.get_value(_iter, 3)
         item = self._model.get_value(_iter, 5)
@@ -395,7 +392,7 @@ class Albums(ViewContainer):
             self.items_selected = []
             self.items_selected_callback = callback
             self.albums_index = 0
-            self.albums_selected = [self.filter.get_value(self.filter.get_iter(path), 5)
+            self.albums_selected = [self._model.get_value(self._model.get_iter(path), 5)
                                     for path in self.view.get_selection()]
             if len(self.albums_selected):
                 self._get_selected_album_songs()
@@ -445,28 +442,25 @@ class Songs(ViewContainer):
 
     @log
     def _on_item_activated(self, widget, id, path):
-        _iter = self.filter.get_iter(path)
-        child_iter = self.filter.convert_iter_to_child_iter(_iter)
-        if self._model.get_value(child_iter, 8) != self.errorIconName:
-            self.player.set_playlist('Songs', None, self.filter, _iter, 5)
+        _iter = self._model.get_iter(path)
+        if self._model.get_value(_iter, 8) != self.errorIconName:
+            self.player.set_playlist('Songs', None, self._model, _iter, 5)
             self.player.set_playing(True)
 
     @log
     def update_model(self, player, playlist, currentIter):
         if self.iter_to_clean:
             self._model.set_value(self.iter_to_clean, 10, False)
-        if playlist != self.filter:
+        if playlist != self._model:
             return False
 
-        child_iter = self.filter.convert_iter_to_child_iter(currentIter)
-        self._model.set_value(child_iter, 10, True)
-        path = self._model.get_path(child_iter)
+        self._model.set_value(currentIter, 10, True)
+        path = self._model.get_path(currentIter)
         self.view.get_generic_view().scroll_to_path(path)
-        if self._model.get_value(child_iter, 8) != self.errorIconName:
-            self.iter_to_clean = child_iter.copy()
+        if self._model.get_value(currentIter, 8) != self.errorIconName:
+            self.iter_to_clean = currentIter.copy()
         return False
 
-    @log
     def _add_item(self, source, param, item, remaining=0):
         if not item:
             return
@@ -574,7 +568,7 @@ class Songs(ViewContainer):
 
     @log
     def get_selected_track_uris(self, callback):
-        callback([self.filter.get_value(self.filter.get_iter(path), 5).get_url()
+        callback([self._model.get_value(self._model.get_iter(path), 5).get_url()
                   for path in self.view.get_selection()])
 
 
@@ -656,8 +650,7 @@ class Artists (ViewContainer):
 
     @log
     def _on_item_activated(self, widget, item_id, path):
-        child_path = self.filter.convert_path_to_child_path(path)
-        _iter = self._model.get_iter(child_path)
+        _iter = self._model.get_iter(path)
         self._last_selection = _iter
         artist = self._model.get_value(_iter, 2)
         albums = self._artists[artist.lower()]['albums']
@@ -740,11 +733,11 @@ class Artists (ViewContainer):
         self.albums_selected = []
 
         for path in self.view.get_selection():
-            _iter = self.filter.get_iter(path)
-            artist = self.filter.get_value(_iter, 2)
+            _iter = self._model.get_iter(path)
+            artist = self._model.get_value(_iter, 2)
             albums = self._artists[artist.lower()]['albums']
-            if (self.filter.get_string_from_iter(_iter) !=
-                    self.filter.get_string_from_iter(self._allIter)):
+            if (self._model.get_string_from_iter(_iter) !=
+                    self._model.get_string_from_iter(self._allIter)):
                 self.albums_selected.extend(albums)
 
         if len(self.albums_selected):
@@ -952,13 +945,12 @@ class Playlist(ViewContainer):
     def update_model(self, player, playlist, currentIter):
         if self.iter_to_clean:
             self.iter_to_clean_model.set_value(self.iter_to_clean, 10, False)
-        if playlist != self.filter:
+        if playlist != self._model:
             return False
 
-        child_iter = self.filter.convert_iter_to_child_iter(currentIter)
-        self._model.set_value(child_iter, 10, True)
-        if self._model.get_value(child_iter, 8) != self.errorIconName:
-            self.iter_to_clean = child_iter.copy()
+        self._model.set_value(currentIter, 10, True)
+        if self._model.get_value(currentIter, 8) != self.errorIconName:
+            self.iter_to_clean = currentIter.copy()
             self.iter_to_clean_model = self._model
         return False
 
@@ -969,10 +961,9 @@ class Playlist(ViewContainer):
 
     @log
     def _on_item_activated(self, widget, id, path):
-        _iter = self.filter.get_iter(path)
-        child_iter = self.filter.convert_iter_to_child_iter(_iter)
-        if self._model.get_value(child_iter, 8) != self.errorIconName:
-            self.player.set_playlist('Playlist', self.current_playlist, self.filter, _iter, 5)
+        _iter = self._model.get_iter(path)
+        if self._model.get_value(_iter, 8) != self.errorIconName:
+            self.player.set_playlist('Playlist', self.current_playlist, self._model, _iter, 5)
             self.player.set_playing(True)
 
     @log
@@ -991,11 +982,11 @@ class Playlist(ViewContainer):
         cached_playlist = self.player.running_playlist('Playlist', playlist)
         if cached_playlist:
             self._model = cached_playlist.get_model()
-            self.filter = cached_playlist
+            self._model = cached_playlist
             currentTrack = self.player.playlist.get_iter(self.player.currentTrack.get_path())
             self.update_model(self.player, cached_playlist,
                               currentTrack)
-            self.view.set_model(self.filter)
+            self.view.set_model(self._model)
             self.songs_count = self._model.iter_n_children(None)
             self._update_songs_count()
         else:
@@ -1012,8 +1003,7 @@ class Playlist(ViewContainer):
                 GObject.TYPE_BOOLEAN,
                 GObject.TYPE_BOOLEAN
             )
-            self.filter = self._model.filter_new(None)
-            self.view.set_model(self.filter)
+            self.view.set_model(self._model)
             playlists.parse_playlist(playlist, self._add_item)
             self.songs_count = 0
             self._update_songs_count()
@@ -1158,5 +1148,5 @@ class Playlist(ViewContainer):
 
     @log
     def get_selected_track_uris(self, callback):
-        callback([self.filter.get_value(self.filter.get_iter(path), 5).get_url()
+        callback([self._model.get_value(self._model.get_iter(path), 5).get_url()
                   for path in self.view.get_selection()])
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index 33e4412..12fed80 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -64,7 +64,6 @@ class AlbumWidget(Gtk.EventBox):
     tracks = []
     duration = 0
     symbolicIcon = ALBUM_ART_CACHE.get_default_icon(256, 256)
-    filter = None
 
     @log
     def __init__(self, player):
@@ -101,7 +100,7 @@ class AlbumWidget(Gtk.EventBox):
 
     @log
     def _on_item_activated(self, widget, id, path):
-        child_path = self.filter.convert_path_to_child_path(path)
+        child_path = self.model.convert_path_to_child_path(path)
         _iter = self.model.get_iter(child_path)
         if(self.model.get_value(_iter, 7) != ERROR_ICON_NAME):
             if (self.iterToClean and self.player.playlistId == self.album):
@@ -201,8 +200,7 @@ class AlbumWidget(Gtk.EventBox):
             'clicked', self._on_header_cancel_button_clicked)
         self.view.connect('view-selection-changed',
                           self._on_view_selection_changed)
-        self.filter = self.model.filter_new(None)
-        self.view.set_model(self.filter)
+        self.view.set_model(self.model)
         escaped_artist = GLib.markup_escape_text(artist)
         escaped_album = GLib.markup_escape_text(album)
         self.ui.get_object('artist_label').set_markup(escaped_artist)


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