[gnome-music/wip/mschraal/core: 131/208] coreartist: Create a model



commit c51f825db0f3a6a6228873d2d5146bc52be78f65
Author: Marinus Schraal <mschraal gnome org>
Date:   Mon Jun 24 01:35:13 2019 +0200

    coreartist: Create a model
    
    Pass around Grl.Media instead of CoreArtist for calls we use
    inside CoreArtist now.

 gnomemusic/coreartist.py                     | 9 +++++++--
 gnomemusic/coremodel.py                      | 4 ++--
 gnomemusic/grilowrappers/grldleynasource.py  | 2 +-
 gnomemusic/grilowrappers/grltrackersource.py | 6 +++---
 gnomemusic/views/artistsview.py              | 6 ++++--
 5 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/coreartist.py b/gnomemusic/coreartist.py
index 5666123f..53244430 100644
--- a/gnomemusic/coreartist.py
+++ b/gnomemusic/coreartist.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
@@ -13,14 +13,19 @@ class CoreArtist(GObject.GObject):
 
     artist = GObject.Property(type=str)
     media = GObject.Property(type=Grl.Media)
+    model = GObject.Property(type=Gio.ListModel, default=None)
     selected = GObject.Property(type=bool, default=False)
 
     @log
-    def __init__(self, media):
+    def __init__(self, media, coremodel):
         super().__init__()
 
+        self._coremodel = coremodel
+
         self.update(media)
 
+        self.props.model = self._coremodel.get_artists_model_full(media)
+
     @log
     def update(self, media):
         self.props.media = media
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index a1194756..344fd97d 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -120,8 +120,8 @@ class CoreModel(GObject.GObject):
 
         return disc_model_sort
 
-    def get_artists_model_full(self, artist_media):
-        albums = self._grilo.get_artist_albums(artist_media)
+    def get_artists_model_full(self, media):
+        albums = self._grilo.get_artist_albums(media)
 
         albums_model = Gio.ListStore()
         albums_model_sort = Gfm.SortListModel.new(albums_model)
diff --git a/gnomemusic/grilowrappers/grldleynasource.py b/gnomemusic/grilowrappers/grldleynasource.py
index 41447e69..aa911780 100644
--- a/gnomemusic/grilowrappers/grldleynasource.py
+++ b/gnomemusic/grilowrappers/grldleynasource.py
@@ -79,7 +79,7 @@ class GrlDLeynaSource(GObject.GObject):
             print("NO MEDIA", source, op_id, media, error)
             return
 
-        artist = CoreArtist(media)
+        artist = CoreArtist(media, self._coremodel)
         artist.props.artist = media.get_title() + " (upnp)"
         self._artists_model.append(artist)
         print(
diff --git a/gnomemusic/grilowrappers/grltrackersource.py b/gnomemusic/grilowrappers/grltrackersource.py
index 3c3b590e..4d29e55a 100644
--- a/gnomemusic/grilowrappers/grltrackersource.py
+++ b/gnomemusic/grilowrappers/grltrackersource.py
@@ -336,11 +336,11 @@ class GrlTrackerSource(GObject.GObject):
             print("NO MEDIA", source, op_id, media, error)
             return
 
-        artist = CoreArtist(media)
+        artist = CoreArtist(media, self._coremodel)
         self._artists_model.append(artist)
 
-    def get_artist_albums(self, artist):
-        artist_id = artist.props.media.get_id()
+    def get_artist_albums(self, media):
+        artist_id = media.get_id()
         print("ID", artist_id)
 
         query = """
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index c9117378..1f7cd49b 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -118,13 +118,15 @@ class ArtistsView(BaseView):
 
         # Prepare a new artist_albums_widget here
         coreartist = row.props.artist
-        model = self._window._app._coremodel.get_artists_model_full(coreartist)
+        model = self._window._app._coremodel.get_artists_model_full(
+            coreartist.props.media)
 
         new_artist_albums_widget = Gtk.Frame(
             shadow_type=Gtk.ShadowType.NONE, hexpand=True)
         self._view.add(new_artist_albums_widget)
 
-        albums = self._window._app._coremodel.get_artist_albums(coreartist)
+        albums = self._window._app._coremodel.get_artist_albums(
+            coreartist.props.media)
         artist_albums = ArtistAlbumsWidget(
             coreartist, albums, self.player, self._window, False, model)
         new_artist_albums_widget.add(artist_albums)


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