[gnome-music/wip/jfelder/async-writeback] coregrilo: Use the async version of grl_source_store_metadata



commit f91ff87c968c8b29044ab20794506bc7b3cd6ba4
Author: Jean Felder <jfelder src gnome org>
Date:   Fri Jan 31 11:07:37 2020 +0100

    coregrilo: Use the async version of grl_source_store_metadata
    
    grl_source_store_metadata is used by the Tracker source to update
    information of a song (for example its play count).
    
    The sync version is used because of an introspection annotation
    issue. This is fixed since grilo version 0.3.12.
    The async version can now be used.
    
    See: https://gitlab.gnome.org/GNOME/grilo/merge_requests/53

 gnomemusic/coregrilo.py | 29 ++++++++++++-----------------
 meson.build             |  2 +-
 2 files changed, 13 insertions(+), 18 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index ed2c9993..9f687e9e 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -171,29 +171,24 @@ class CoreGrilo(GObject.GObject):
         for wrapper in self._wrappers.values():
             wrapper.populate_album_disc_songs(media, discnr, callback)
 
-    def _store_metadata(self, source, media, key):
-        """Convenience function to store metadata
+    def writeback(self, media, key):
+        """Store the values associated with the keys.
 
-        Wrap the metadata store call in a idle_add compatible form.
-        :param source: A Grilo source object
-        :param media: A Grilo media item
-        :param key: A Grilo metadata key
+        :param Grl.Media media: A Grilo media item
+        :param int key: a Grilo metadata key
         """
-        # FIXME: Doing this async crashes.
-        try:
-            source.store_metadata_sync(
-                media, [key], Grl.WriteFlags.NORMAL)
-        except GLib.Error as error:
+        def _store_metadata_cb(source, media, failed_keys, data, error):
             # FIXME: Do not print.
-            print("Error {}: {}".format(error.domain, error.message))
-
-        return GLib.SOURCE_REMOVE
+            if error is not None:
+                print("Error {}: {}".format(error.domain, error.message))
+            if failed_keys:
+                print("Unable to update the following keys", failed_keys)
 
-    def writeback(self, media, key):
         for wrapper in self._wrappers.values():
             if media.get_source() == wrapper.source.props.source_id:
-                GLib.idle_add(
-                    self._store_metadata, wrapper.props.source, media, key)
+                wrapper.props.source.store_metadata(
+                    media, [key], Grl.WriteFlags.NORMAL, _store_metadata_cb,
+                    None)
                 break
 
     def search(self, text):
diff --git a/meson.build b/meson.build
index a9310adf..1f4122b1 100644
--- a/meson.build
+++ b/meson.build
@@ -45,7 +45,7 @@ dependency('libsoup-2.4')
 dependency('tracker-sparql-2.0', version: '>= 2.3.0')
 dependency('pygobject-3.0', version: '>= 3.29.1')
 dependency('py3cairo', version: '>= 1.14.0')
-dependency('grilo-0.3', version: '>= 0.3.9', fallback: ['grilo', 'libgrl_dep'])
+dependency('grilo-0.3', version: '>= 0.3.12', fallback: ['grilo', 'libgrl_dep'])
 dependency('grilo-plugins-0.3', version: '>= 0.3.10', fallback: ['grilo-plugins', 'grilo_plugins_dep'])
 
 subproject('libgd',


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