[gnome-music/wip/mschraal/core] songwidget: Rework property bindings and do not call grilo directly



commit cc2286f5fa5596950870e3f9f7487a2aab1c85ce
Author: Marinus Schraal <mschraal gnome org>
Date:   Mon Jul 1 23:39:54 2019 +0200

    songwidget: Rework property bindings and do not call grilo directly

 gnomemusic/views/searchview.py          | 18 ------------------
 gnomemusic/widgets/disclistboxwidget.py | 13 -------------
 gnomemusic/widgets/songwidget.py        | 15 +++++++--------
 3 files changed, 7 insertions(+), 39 deletions(-)
---
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index f62c4c55..46ae75fa 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -106,19 +106,6 @@ class SearchView(BaseView):
     def _create_song_widget(self, coresong):
         song_widget = SongWidget(coresong)
 
-        coresong.bind_property(
-            "favorite", song_widget, "favorite",
-            GObject.BindingFlags.BIDIRECTIONAL
-            | GObject.BindingFlags.SYNC_CREATE)
-        coresong.bind_property(
-            "selected", song_widget, "selected",
-            GObject.BindingFlags.BIDIRECTIONAL
-            | GObject.BindingFlags.SYNC_CREATE)
-        coresong.bind_property(
-            "state", song_widget, "state",
-            GObject.BindingFlags.BIDIRECTIONAL
-            | GObject.BindingFlags.SYNC_CREATE)
-
         self.bind_property(
             "selection-mode", song_widget, "selection-mode",
             GObject.BindingFlags.BIDIRECTIONAL
@@ -157,11 +144,6 @@ class SearchView(BaseView):
         song_widget.props.show_song_number = False
         song_widget.coreartist = coreartist
 
-        coresong.bind_property(
-            "selected", song_widget, "selected",
-            GObject.BindingFlags.BIDIRECTIONAL
-            | GObject.BindingFlags.SYNC_CREATE)
-
         self.bind_property(
             "selection-mode", song_widget, "selection-mode",
             GObject.BindingFlags.BIDIRECTIONAL
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 3c9f8f25..2254ee5a 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -153,19 +153,6 @@ class DiscBox(Gtk.Box):
         song_widget = SongWidget(coresong)
         self._songs.append(song_widget)
 
-        coresong.bind_property(
-            "favorite", song_widget, "favorite",
-            GObject.BindingFlags.BIDIRECTIONAL
-            | GObject.BindingFlags.SYNC_CREATE)
-        coresong.bind_property(
-            "selected", song_widget, "selected",
-            GObject.BindingFlags.BIDIRECTIONAL
-            | GObject.BindingFlags.SYNC_CREATE)
-        coresong.bind_property(
-            "state", song_widget, "state",
-            GObject.BindingFlags.BIDIRECTIONAL
-            | GObject.BindingFlags.SYNC_CREATE)
-
         self.bind_property(
             "selection-mode", song_widget, "selection-mode",
             GObject.BindingFlags.BIDIRECTIONAL
diff --git a/gnomemusic/widgets/songwidget.py b/gnomemusic/widgets/songwidget.py
index 52680e1a..3c6694ca 100644
--- a/gnomemusic/widgets/songwidget.py
+++ b/gnomemusic/widgets/songwidget.py
@@ -32,7 +32,6 @@ from gi.repository.Dazzle import BoldingLabel  # noqa: F401
 from gnomemusic import log
 from gnomemusic import utils
 from gnomemusic.coresong import CoreSong
-from gnomemusic.grilo import grilo
 from gnomemusic.playlists import Playlists, SmartPlaylists
 from gnomemusic.widgets.starimage import StarImage  # noqa: F401
 
@@ -57,7 +56,6 @@ class SongWidget(Gtk.EventBox):
     }
 
     coresong = GObject.Property(type=CoreSong, default=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)
@@ -88,7 +86,6 @@ class SongWidget(Gtk.EventBox):
         super().__init__()
 
         self.props.coresong = coresong
-        self.props.favorite = self.props.coresong.props.favorite
         self._media = self.props.coresong.props.media
         self._selection_mode = False
         self._state = SongWidget.State.UNPLAYED
@@ -112,7 +109,7 @@ class SongWidget(Gtk.EventBox):
             'media-playback-start-symbolic', Gtk.IconSize.SMALL_TOOLBAR)
         self._play_icon.set_no_show_all(True)
 
-        self.bind_property(
+        self.props.coresong.bind_property(
             'selected', self._select_button, 'active',
             GObject.BindingFlags.BIDIRECTIONAL
             | GObject.BindingFlags.SYNC_CREATE)
@@ -127,12 +124,15 @@ class SongWidget(Gtk.EventBox):
         self.bind_property(
             'show-song-number', self._number_label, 'visible',
             GObject.BindingFlags.SYNC_CREATE)
-        self._number_label.set_no_show_all(True)
-
-        self.bind_property(
+        self.props.coresong.bind_property(
             "favorite", self._star_image, "favorite",
             GObject.BindingFlags.BIDIRECTIONAL
             | GObject.BindingFlags.SYNC_CREATE)
+        self.props.coresong.bind_property(
+            "state", self, "state",
+            GObject.BindingFlags.SYNC_CREATE)
+
+        self._number_label.props.no_show_all = True
 
     @Gtk.Template.Callback()
     @log
@@ -150,7 +150,6 @@ class SongWidget(Gtk.EventBox):
         self._star_image.props.favorite = favorite
 
         # TODO: Rework and stop updating widgets from here directly.
-        grilo.set_favorite(self._media, favorite)
         self._playlists.update_smart_playlist(SmartPlaylists.Favorites)
 
         return True


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