[gnome-music/wip/mschraal/core: 72/190] Make CoreAlbum central over Grl.Media



commit 636cf702be7e6a01e9f05d33b92db70944435bf1
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu Jun 20 00:41:45 2019 +0200

    Make CoreAlbum central over Grl.Media

 gnomemusic/corealbum.py            |  3 ++-
 gnomemusic/views/albumsview.py     | 14 +++++++-------
 gnomemusic/widgets/albumcover.py   | 30 ++++++++++++++++--------------
 gnomemusic/widgets/albumwidget2.py | 18 +++++++++---------
 4 files changed, 34 insertions(+), 31 deletions(-)
---
diff --git a/gnomemusic/corealbum.py b/gnomemusic/corealbum.py
index 010997c9..b9c126de 100644
--- a/gnomemusic/corealbum.py
+++ b/gnomemusic/corealbum.py
@@ -1,6 +1,6 @@
 import gi
 gi.require_version('Grl', '0.3')
-from gi.repository import Grl, GObject
+from gi.repository import Gio, Grl, GObject
 
 from gnomemusic import log
 from gnomemusic.grilo import grilo
@@ -12,6 +12,7 @@ class CoreAlbum(GObject.GObject):
     """
 
     artist = GObject.Property(type=str)
+    model = GObject.Property(type=Gio.ListModel, default=None)
     media = GObject.Property(type=Grl.Media)
     selected = GObject.Property(type=bool, default=False)
     title = GObject.Property(type=str)
diff --git a/gnomemusic/views/albumsview.py b/gnomemusic/views/albumsview.py
index d397a84d..92a0a1bf 100644
--- a/gnomemusic/views/albumsview.py
+++ b/gnomemusic/views/albumsview.py
@@ -108,9 +108,9 @@ class AlbumsView(BaseView):
         self._view.show()
 
     @log
-    def _create_widget(self, album):
-        album_widget = AlbumCover(album.props.media)
-        print(album.props.artist)
+    def _create_widget(self, corealbum):
+        album_widget = AlbumCover(corealbum)
+
         return album_widget
 
     @log
@@ -123,7 +123,7 @@ class AlbumsView(BaseView):
         if self.props.selection_mode:
             return
 
-        item = child.props.media
+        item = child.props.corealbum
         # Update and display the album widget if not in selection mode
         self._album_widget.update(item)
 
@@ -131,10 +131,10 @@ class AlbumsView(BaseView):
         self.set_visible_child(self._album_widget)
 
     @log
-    def _set_album_headerbar(self, album):
+    def _set_album_headerbar(self, corealbum):
         self._headerbar.props.state = HeaderBar.State.CHILD
-        self._headerbar.props.title = utils.get_album_title(album)
-        self._headerbar.props.subtitle = utils.get_artist_name(album)
+        self._headerbar.props.title = corealbum.props.title
+        self._headerbar.props.subtitle = corealbum.props.artist
 
     @log
     def _populate(self, data=None):
diff --git a/gnomemusic/widgets/albumcover.py b/gnomemusic/widgets/albumcover.py
index f76ecb65..9cfe21d3 100644
--- a/gnomemusic/widgets/albumcover.py
+++ b/gnomemusic/widgets/albumcover.py
@@ -29,6 +29,7 @@ from gi.repository import Gdk, GLib, GObject, Grl, Gtk
 from gnomemusic import log
 from gnomemusic import utils
 from gnomemusic.albumartcache import Art
+from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.widgets.twolinetip import TwoLineTip
 
 
@@ -58,7 +59,7 @@ class AlbumCover(Gtk.FlowBoxChild):
         return '<AlbumCover>'
 
     @log
-    def __init__(self, media):
+    def __init__(self, corealbum):
         """Initialize the AlbumCover
 
         :param Grl.Media media: The media object to use
@@ -67,15 +68,15 @@ class AlbumCover(Gtk.FlowBoxChild):
 
         AlbumCover._nr_albums += 1
 
-        self._media = media
+        self._corealbum = corealbum
 
         self._tooltip = TwoLineTip()
 
-        artist = utils.get_artist_name(media)
-        title = utils.get_media_title(media)
+        artist = self._corealbum.props.artist
+        title = self._corealbum.props.title
 
-        self._tooltip.props.title = utils.get_artist_name(media)
-        self._tooltip.props.subtitle = utils.get_media_title(media)
+        self._tooltip.props.title = artist
+        self._tooltip.props.subtitle = title
 
         self._artist_label.props.label = artist
         self._title_label.props.label = title
@@ -101,18 +102,19 @@ class AlbumCover(Gtk.FlowBoxChild):
         # quick first show with a placeholder cover and then a
         # reasonably responsive view while loading the actual
         # covers.
+        # FIXME: Pass CoreAlbum to CoverStack.
         GLib.timeout_add(
-            50 * self._nr_albums, self._cover_stack.update, media,
-            priority=GLib.PRIORITY_LOW)
+            50 * self._nr_albums, self._cover_stack.update,
+            self._corealbum.props.media, priority=GLib.PRIORITY_LOW)
 
-    @GObject.Property(type=Grl.Media, flags=GObject.ParamFlags.READABLE)
-    def media(self):
-        """Media item used in AlbumCover
+    @GObject.Property(type=CoreAlbum, flags=GObject.ParamFlags.READABLE)
+    def corealbum(self):
+        """CoreAlbum object used in AlbumCover
 
-        :returns: The media used
-        :rtype: Grl.Media
+        :returns: The album used
+        :rtype: CoreAlbum
         """
-        return self._media
+        return self._corealbum
 
     @Gtk.Template.Callback()
     @log
diff --git a/gnomemusic/widgets/albumwidget2.py b/gnomemusic/widgets/albumwidget2.py
index 8a1710dc..7477d8ad 100644
--- a/gnomemusic/widgets/albumwidget2.py
+++ b/gnomemusic/widgets/albumwidget2.py
@@ -56,17 +56,17 @@ class AlbumWidget2(Gtk.EventBox):
         self._album_name = None
 
     @log
-    def update(self, album):
+    def update(self, corealbum):
         """Update the album widget.
 
-        :param Grl.Media album: The grilo media album
+        :param CoreAlbum album: The CoreAlbum object
         """
-        self._cover_stack.update(album)
+        self._cover_stack.update(corealbum.props.media)
 
         self._duration = 0
 
-        self._album_name = utils.get_album_title(album)
-        artist = utils.get_artist_name(album)
+        self._album_name = corealbum.props.title
+        artist = corealbum.props.artist
 
         self._title_label.props.label = self._album_name
         self._title_label.props.tooltip_text = self._album_name
@@ -74,15 +74,15 @@ class AlbumWidget2(Gtk.EventBox):
         self._artist_label.props.label = artist
         self._artist_label.props.tooltip_text = artist
 
-        year = utils.get_media_year(album)
+        year = utils.get_media_year(corealbum.props.media)
         if not year:
             year = '----'
         self._released_info_label.props.label = year
 
-        self._set_composer_label(album)
+        self._set_composer_label(corealbum.props.media)
 
-        self._album = album
-        self._album_model = self._parent_view._window._app._coremodel.get_album_model(album)
+        self._album = corealbum.props.media
+        self._album_model = self._parent_view._window._app._coremodel.get_album_model(self._album)
         self._listbox.bind_model(self._album_model, self._create_widget)
 
     def _create_widget(self, disc):


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