[gnome-music/wip/mschraal/core: 44/92] coresong: Pass favorite through here and do writeback



commit a2dd8d0cee33daa1247027e005714ba44b37c2ad
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed May 8 22:26:18 2019 +0200

    coresong: Pass favorite through here and do writeback

 gnomemusic/coresong.py             | 12 +++++++++++-
 gnomemusic/grilo.py                | 18 ++++++++++--------
 gnomemusic/widgets/albumwidget2.py |  5 +++++
 gnomemusic/widgets/songwidget.py   | 10 ++++++++--
 4 files changed, 34 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index ad52490b..c11d3fd1 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -3,6 +3,7 @@ gi.require_version('Grl', '0.3')
 from gi.repository import Grl, GObject
 
 from gnomemusic import log
+from gnomemusic.grilo import grilo
 import gnomemusic.utils as utils
 
 
@@ -25,7 +26,7 @@ class CoreSong(GObject.GObject):
 
         self._media = media
 
-        self._favorte = False
+        self._favorite = False
 
         self.props.album = utils.get_album_title(media)
         self.props.album_disc_number = self._media.get_album_disc_number()
@@ -46,3 +47,12 @@ class CoreSong(GObject.GObject):
     @favorite.setter
     def favorite(self, favorite):
         self._favorite = favorite
+
+        # FIXME: I think some old code is triggering the signal and
+        # going haywire. So just check if there is anything to update.
+        old_fav = self._media.get_favourite()
+        if old_fav == self._favorite:
+            return
+
+        self._media.set_favourite(self._favorite)
+        grilo.toggle_favorite(self._media, True)
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index d089ecd8..d05268d8 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -469,19 +469,21 @@ class Grilo(GObject.GObject):
             self._store_metadata, media, Grl.METADATA_KEY_LAST_PLAYED)
 
     @log
-    def toggle_favorite(self, media):
+    def toggle_favorite(self, media, override=False):
         """Toggles favorite status for media item
 
         Toggles favorite status and writes it back to the tracker store
         :param media: A Grilo media item
         """
-        if media.get_favourite():
-            # For now keep unsetting the lyrics to deal with how
-            # previous versions dealt with favorites.
-            media.set_lyrics("")
-            media.set_favourite(False)
-        else:
-            media.set_favourite(True)
+        print("favorite for media", media)
+        if not override:
+            if media.get_favourite():
+                # For now keep unsetting the lyrics to deal with how
+                # previous versions dealt with favorites.
+                media.set_lyrics("")
+                media.set_favourite(False)
+            else:
+                media.set_favourite(True)
 
         # FIXME: Do this as an idle call, otherwise it may not return
         # and block other sources. This seems to point to a problem in
diff --git a/gnomemusic/widgets/albumwidget2.py b/gnomemusic/widgets/albumwidget2.py
index 308f4220..12b5da4b 100644
--- a/gnomemusic/widgets/albumwidget2.py
+++ b/gnomemusic/widgets/albumwidget2.py
@@ -123,6 +123,11 @@ class AlbumWidget2(Gtk.EventBox):
     def _create_widget(self, song):
         song_widget = SongWidget(song._media)
 
+        song.bind_property(
+            "favorite", song_widget, "favorite",
+            GObject.BindingFlags.BIDIRECTIONAL
+            | GObject.BindingFlags.SYNC_CREATE)
+
         return song_widget
 
     @log
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 78c87181..498fbbb9 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -55,6 +55,7 @@ class SongWidget(Gtk.EventBox):
         'selection-changed': (GObject.SignalFlags.RUN_FIRST, None, ()),
     }
 
+    favorite = GObject.Property(type=bool, default=False)
     selected = GObject.Property(type=bool, default=False)
     show_duration = GObject.Property(type=bool, default=True)
     show_favorite = GObject.Property(type=bool, default=True)
@@ -100,8 +101,8 @@ class SongWidget(Gtk.EventBox):
 
         time = utils.seconds_to_string(media.get_duration())
         self._duration_label.set_text(time)
-
-        self._star_image.props.favorite = media.get_favourite()
+        print(media.get_favourite())
+        # self._star_image.props.favorite = media.get_favourite()
 
         self._select_button.set_visible(False)
 
@@ -126,6 +127,11 @@ class SongWidget(Gtk.EventBox):
             GObject.BindingFlags.SYNC_CREATE)
         self._number_label.set_no_show_all(True)
 
+        self.bind_property(
+            "favorite", self._star_image, "favorite",
+            GObject.BindingFlags.BIDIRECTIONAL
+            | GObject.BindingFlags.SYNC_CREATE)
+
     @Gtk.Template.Callback()
     @log
     def _on_selection_changed(self, klass, value):


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