[gnome-music/wip/mschraal/core: 46/86] coresong: Make Grl.Media a prop



commit 68321c2b11b52e337606ca2d0e1f119c92cc17ba
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu May 9 17:59:11 2019 +0200

    coresong: Make Grl.Media a prop

 gnomemusic/coremodel.py            |  4 ++--
 gnomemusic/coresong.py             | 37 ++++++++++++++++++-------------------
 gnomemusic/widgets/albumwidget2.py |  4 ++--
 3 files changed, 22 insertions(+), 23 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index d7071a9c..12c7ac01 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -33,7 +33,7 @@ class CoreModel(GObject.GObject):
         model_filter.set_filter_func(lambda a: False)
 
         def _filter_func(core_song):
-            return core_song._media.get_id() in albums_ids
+            return core_song.props.media.get_id() in albums_ids
 
         def _reverse_sort(song_a, song_b):
             return song_b.props.track_number - song_a.props.track_number
@@ -72,7 +72,7 @@ class CoreModel(GObject.GObject):
                     self._album_store.remove(i)
                     break
         
-        print("pop1", self._hash.pop(old_song._media.get_id()))
         print("pop2", self._url_hash.pop(media.get_url()))
+        print("pop1", self._hash.pop(old_song.props.media.get_id()))
 
                 # print("ITEM IN MODEL", media.get_id(), self._url_hash[media.get_url()]._media.get_id())
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index 8e47f67d..8b4b7f2b 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -15,6 +15,7 @@ class CoreSong(GObject.GObject):
     album_disc_number = GObject.Property(type=int)
     artist = GObject.Property(type=str)
     duration = GObject.Property(type=int)
+    media = GObject.Property(type=Grl.Media)
     play_count = GObject.Property(type=int)
     selected = GObject.Property(type=bool, default=False)
     title = GObject.Property(type=str)
@@ -25,18 +26,17 @@ class CoreSong(GObject.GObject):
     def __init__(self, media):
         super().__init__()
 
-        self._media = media
-
         self._favorite = False
 
+        self.props.media = media
         self.props.album = utils.get_album_title(media)
-        self.props.album_disc_number = self._media.get_album_disc_number()
+        self.props.album_disc_number = media.get_album_disc_number()
         self.props.artist = utils.get_artist_name(media)
-        self.props.favorite = self._media.get_favourite()
-        self.props.play_count = self._media.get_play_count()
-        self.props.title = utils.get_media_title(self._media)
-        self.props.track_number = self._media.get_track_number()
-        self.props.url = self._media.get_url()
+        self.props.favorite = media.get_favourite()
+        self.props.play_count = media.get_play_count()
+        self.props.title = utils.get_media_title(media)
+        self.props.track_number = media.get_track_number()
+        self.props.url = media.get_url()
 
         if self.props.favorite:
             print("favorite", self.props.title)
@@ -51,23 +51,22 @@ class CoreSong(GObject.GObject):
 
         # 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()
+        old_fav = self.props.media.get_favourite()
         if old_fav == self._favorite:
             return
 
-        self._media.set_favourite(self._favorite)
-        grilo.toggle_favorite(self._media, True)
+        self.props.media.set_favourite(self._favorite)
+        grilo.toggle_favorite(self.props.media, True)
 
     @log
     def update(self, media):
-        self._media = media
-
+        self.props.media = media
         self.props.album = utils.get_album_title(media)
-        self.props.album_disc_number = self._media.get_album_disc_number()
+        self.props.album_disc_number = media.get_album_disc_number()
         self.props.artist = utils.get_artist_name(media)
-        self.props.favorite = self._media.get_favourite()
-        self.props.play_count = self._media.get_play_count()
-        self.props.title = utils.get_media_title(self._media)
-        self.props.track_number = self._media.get_track_number()
-        self.props.url = self._media.get_url()
+        self.props.favorite = media.get_favourite()
+        self.props.play_count = media.get_play_count()
+        self.props.title = utils.get_media_title(media)
+        self.props.track_number = media.get_track_number()
+        self.props.url = media.get_url()
 
diff --git a/gnomemusic/widgets/albumwidget2.py b/gnomemusic/widgets/albumwidget2.py
index e4cc177c..3043ceb0 100644
--- a/gnomemusic/widgets/albumwidget2.py
+++ b/gnomemusic/widgets/albumwidget2.py
@@ -89,7 +89,7 @@ class AlbumWidget2(Gtk.EventBox):
 
     @log
     def _create_widget(self, song):
-        song_widget = SongWidget(song._media)
+        song_widget = SongWidget(song.props.media)
 
         song.bind_property(
             "favorite", song_widget, "favorite",
@@ -169,7 +169,7 @@ class AlbumWidget2(Gtk.EventBox):
 
         for song in self._model:
             if song.props.selected:
-                selected_songs.append(song._media)
+                selected_songs.append(song.props.media)
 
         return selected_songs
 


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