[gnome-music] grilo: Allow passing data to custom queries and search



commit 9eb48fda57113e6d8f1931ac85c067e0068a29c2
Author: Arnel Borja <arnelborja src gnome org>
Date:   Sat May 3 21:27:04 2014 +0800

    grilo: Allow passing data to custom queries and search
    
    Since searches overlap while the user types, we have to pass data to
    queries to know if an item is for the currently running query.
    
    Update callbacks to add the data argument.

 gnomemusic/grilo.py   |   21 ++++++++++-----------
 gnomemusic/view.py    |   12 ++++++------
 gnomemusic/widgets.py |   12 +++++-------
 3 files changed, 21 insertions(+), 24 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index f095c89..ca58804 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -165,29 +165,28 @@ class Grilo(GObject.GObject):
         self.populate_items(Query.album_songs(album_id), 0, callback, count)
 
     @log
-    def populate_custom_query(self, query, callback, count=-1):
-        self.populate_items(query, 0, callback, count)
+    def populate_custom_query(self, query, callback, count=-1, data=None):
+        self.populate_items(query, 0, callback, count, data)
 
     @log
-    def populate_items(self, query, offset, callback, count=-1):
+    def populate_items(self, query, offset, callback, count=-1, data=None):
         options = self.options.copy()
         options.set_skip(offset)
         if count != -1:
             options.set_count(count)
 
-        def _callback(source, param, item, remaining, data, offset):
-            callback(source, param, item, remaining)
-        self.tracker.query(query, self.METADATA_KEYS, options, _callback, None)
+        def _callback(source, param, item, remaining, data, error):
+            callback(source, param, item, remaining, data)
+        self.tracker.query(query, self.METADATA_KEYS, options, _callback, data)
 
     @log
-    def search(self, q, callback):
+    def search(self, q, callback, data=None):
         options = self.options.copy()
 
         @log
-        def _search_callback(src, param, item, id, offset, data):
-            if item is not None:
-                callback(src, param, item)
-        self.search_source.search(q, self.METADATA_KEYS, options, _search_callback, None)
+        def _search_callback(source, param, item, remaining, data, error):
+            callback(source, param, item, remaining, data)
+        self.search_source.search(q, self.METADATA_KEYS, options, _search_callback, data)
 
     @log
     def get_media_from_uri(self, uri, callback):
diff --git a/gnomemusic/view.py b/gnomemusic/view.py
index 1847234..ad010a4 100644
--- a/gnomemusic/view.py
+++ b/gnomemusic/view.py
@@ -275,7 +275,7 @@ class ViewContainer(Gtk.Stack):
             self._model.set(_iter, [8, 10], [self.errorIconName, True])
 
     @log
-    def _add_item(self, source, param, item, remaining=0):
+    def _add_item(self, source, param, item, remaining=0, data=None):
         if not item:
             return
         self._offset += 1
@@ -407,7 +407,7 @@ class Albums(ViewContainer):
         self.albums_index += 1
 
     @log
-    def _add_selected_item(self, source, param, item, remaining=0):
+    def _add_selected_item(self, source, param, item, remaining=0, data=None):
         if item:
             self.items_selected.append(item.get_url())
         if remaining == 0:
@@ -463,7 +463,7 @@ class Songs(ViewContainer):
             self.iter_to_clean = currentIter.copy()
         return False
 
-    def _add_item(self, source, param, item, remaining=0):
+    def _add_item(self, source, param, item, remaining=0, data=None):
         if not item:
             return
         self._offset += 1
@@ -691,7 +691,7 @@ class Artists (ViewContainer):
         GLib.idle_add(self.artistAlbumsStack.set_visible_child, new_artistAlbumsWidget)
 
     @log
-    def _add_item(self, source, param, item, remaining=0):
+    def _add_item(self, source, param, item, remaining=0, data=None):
         if item is None:
             return
         self._offset += 1
@@ -753,7 +753,7 @@ class Artists (ViewContainer):
         self.albums_index += 1
 
     @log
-    def _add_selected_item(self, source, param, item, remaining=0):
+    def _add_selected_item(self, source, param, item, remaining=0, data=None):
         if item:
             self.items_selected.append(item.get_url())
         if remaining == 0:
@@ -1011,7 +1011,7 @@ class Playlist(ViewContainer):
             self._update_songs_count()
 
     @log
-    def _add_item(self, source, param, item, remaining=0):
+    def _add_item(self, source, param, item, remaining=0, data=None):
         self._add_item_to_model(item, self._model)
 
     @log
diff --git a/gnomemusic/widgets.py b/gnomemusic/widgets.py
index 12fed80..ae56319 100644
--- a/gnomemusic/widgets.py
+++ b/gnomemusic/widgets.py
@@ -192,8 +192,7 @@ class AlbumWidget(Gtk.EventBox):
         else:
             self.duration = 0
             self._create_model()
-            GLib.idle_add(grilo.populate_album_songs, item.get_id(),
-                          self._on_populate_album_songs)
+            GLib.idle_add(grilo.populate_album_songs, item.get_id(), self.add_item)
         header_bar._select_button.connect(
             'toggled', self._on_header_select_button_toggled)
         header_bar._cancel_button.connect(
@@ -252,7 +251,7 @@ class AlbumWidget(Gtk.EventBox):
             self.model.set(_iter, [7, 9], [ERROR_ICON_NAME, True])
 
     @log
-    def _on_populate_album_songs(self, source, prefs, track, remaining):
+    def add_item(self, source, prefs, track, remaining, data=None):
         if track:
             self.tracks.append(track)
             self.duration = self.duration + track.get_duration()
@@ -433,7 +432,7 @@ class AllArtistsAlbums(ArtistAlbums):
                           self._offset, self.add_item, -1)
 
     @log
-    def add_item(self, source, param, item, remaining=0):
+    def add_item(self, source, param, item, remaining=0, data=None):
         if item:
             self._offset += 1
             self.add_album(item)
@@ -465,8 +464,7 @@ class ArtistAlbumWidget(Gtk.HBox):
                 str(album.get_creation_date().get_year())
             )
         self.tracks = []
-        GLib.idle_add(grilo.populate_album_songs,
-                      album.get_id(), self.get_songs)
+        GLib.idle_add(grilo.populate_album_songs, album.get_id(), self.add_item)
         self.pack_start(self.ui.get_object('ArtistAlbumWidget'), True, True, 0)
         self.show_all()
 
@@ -481,7 +479,7 @@ class ArtistAlbumWidget(Gtk.HBox):
             song_widget.can_be_played = False
 
     @log
-    def get_songs(self, source, prefs, track, remaining):
+    def add_item(self, source, prefs, track, remaining, data=None):
         if track:
             self.tracks.append(track)
         else:


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