[gnome-music/wip/carlosg/tracker3: 63/68] trackerwrapper: Make favorite property updates go through tracker



commit 1f9e3d52746891bae0db151179921b1c1a61b972
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jun 14 15:50:51 2020 +0200

    trackerwrapper: Make favorite property updates go through tracker
    
    This property cannot be written back via grilo with the Tracker3 ownership
    changes. This should be stored in the local store, thus it's better to
    handle it via the trackerwrapper writeback methods.

 gnomemusic/coresong.py       |  4 ++--
 gnomemusic/trackerwrapper.py | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index 56535e3b..cc3ebef9 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -101,8 +101,8 @@ class CoreSong(GObject.GObject):
             return
 
         self.props.media.set_favourite(self._favorite)
-        self._coregrilo.writeback(
-            self.props.media, [Grl.METADATA_KEY_FAVOURITE])
+        self._coregrilo.writeback_tracker(
+            self.props.media, deque(["favorite"]))
 
     @GObject.Property(type=bool, default=False)
     def selected(self):
diff --git a/gnomemusic/trackerwrapper.py b/gnomemusic/trackerwrapper.py
index 15fd49f3..29e86acf 100644
--- a/gnomemusic/trackerwrapper.py
+++ b/gnomemusic/trackerwrapper.py
@@ -565,6 +565,35 @@ class TrackerWrapper(GObject.GObject):
         self._tracker.query_async(
             query_album_exists, None, _album_exists_cb, None)
 
+    def _update_favorite(self, media):
+        if (media.get_favourite()):
+            update = """
+            INSERT DATA {
+                <%(urn)s> a nmm:MusicPiece ;
+                          nao:hasTag nao:predefined-tag-favorite .
+            }
+            """.replace("\n", "").strip() % {
+                "urn": media.get_id(),
+            }
+        else:
+            update = """
+            DELETE DATA {
+                <%(urn)s> nao:hasTag nao:predefined-tag-favorite .
+            }
+            """.replace("\n", "").strip() % {
+                "urn": media.get_id(),
+            }
+
+        def _update_favorite_cb(conn, res):
+            try:
+                conn.update_finish(res)
+            except GLib.Error as e:
+                self._log.warning("Unable to update favorite: {}".format(
+                    e.message))
+
+        self._tracker.update_async(
+            update, GLib.PRIORITY_LOW, None, _update_favorite_cb)
+
     def _update_album(self, media, tags):
         query_delete = """
         DELETE {
@@ -652,6 +681,8 @@ class TrackerWrapper(GObject.GObject):
             self._update_reference(media, MbReference.RELEASE, tags)
         elif tag == "mb-release-group-id":
             self._update_reference(media, MbReference.RELEASE_GROUP, tags)
+        elif tag == "favorite":
+            self._update_favorite(media)
         else:
             self._log.warning("Unknown tag: '{}'".format(tag))
             self.update_tags(media, tags)


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