[gnome-music/wip/mschraal/core: 67/92] artistsview: Somewhat working



commit dd02e3cc329e72dd29bd56d16cd23023e54219a8
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri May 31 17:09:52 2019 +0200

    artistsview: Somewhat working

 gnomemusic/coregrilo.py                      |  5 +++++
 gnomemusic/coremodel.py                      |  5 +++++
 gnomemusic/grilowrappers/grltrackersource.py | 30 ++++++++++++++++++++++++++++
 gnomemusic/utils.py                          |  3 +++
 gnomemusic/views/artistsview.py              | 20 +++++++++++++++++++
 5 files changed, 63 insertions(+)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 0aa8462d..9b627adf 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -48,3 +48,8 @@ class CoreGrilo(GObject.GObject):
 
     def _on_source_removed(self, registry, source):
         print("removed,", source.props.source_id)
+
+    def get_artist_albums(self, artist):
+        # FIXME: Iterate the wrappers
+        print(self._tracker_source)
+        return self._tracker_source.get_artist_albums(artist)
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index f617d7c9..34f92ef0 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -79,6 +79,11 @@ class CoreModel(GObject.GObject):
     def get_artists_model(self):
         return self._artist_model
 
+    def get_artist_albums(self, artist):
+        albums = self._grilo.get_artist_albums(artist)
+
+        return albums
+
     @log
     def _on_media_removed(self, klass, media):
         try:
diff --git a/gnomemusic/grilowrappers/grltrackersource.py b/gnomemusic/grilowrappers/grltrackersource.py
index c371c18b..7e6ad7f5 100644
--- a/gnomemusic/grilowrappers/grltrackersource.py
+++ b/gnomemusic/grilowrappers/grltrackersource.py
@@ -221,3 +221,33 @@ class GrlTrackerSource(GObject.GObject):
 
         artist = CoreArtist(media)
         self._artists_model.append(artist)
+
+    def get_artist_albums(self, artist):
+        artist_id = artist.props.media.get_id()
+        print("ID", artist_id)
+
+        query = """
+        SELECT DISTINCT
+            rdf:type(?album)
+            tracker:id(?album) AS ?id
+        WHERE
+        {
+            ?album a nmm:MusicAlbum .
+            OPTIONAL { ?album  nmm:albumArtist ?album_artist . }
+            ?song a nmm:MusicPiece;
+                nmm:musicAlbum ?album;
+                nmm:performer ?artist .
+            FILTER ( tracker:id(?album_artist) = %(artist_id)s
+                     || tracker:id(?artist) = %(artist_id)s )
+        }
+        """.replace('\n', ' ').strip() % {
+            'artist_id': int(artist_id)
+        }
+
+        options = self._fast_options.copy()
+
+        albums = self._source.query_sync(query, self.METADATA_KEYS, options)
+
+        print("ALBUMS", albums)
+
+        return albums
diff --git a/gnomemusic/utils.py b/gnomemusic/utils.py
index bae746e7..fd75fb0f 100644
--- a/gnomemusic/utils.py
+++ b/gnomemusic/utils.py
@@ -89,6 +89,9 @@ def get_media_title(item):
 
     if not title:
         url = item.get_url()
+        # FIXME
+        if url is None:
+            return "NO URL"
         file_ = Gio.File.new_for_uri(url)
         fileinfo = file_.query_info(
             "standard::display-name", Gio.FileQueryInfoFlags.NONE, None)
diff --git a/gnomemusic/views/artistsview.py b/gnomemusic/views/artistsview.py
index 2b02de0a..40631494 100644
--- a/gnomemusic/views/artistsview.py
+++ b/gnomemusic/views/artistsview.py
@@ -116,6 +116,26 @@ class ArtistsView(BaseView):
             return
 
         print(row.props.artist.props.artist, row, row.get_child())
+
+        # Prepare a new artist_albums_widget here
+        artist = row.props.artist.props.artist
+        artist_media = row.props.artist.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(row.props.artist)
+        artist_albums = ArtistAlbumsWidget(
+            artist, albums, self.player, self._window)
+        # self._artists[artist.casefold()]['widget'] = artist_albums
+        new_artist_albums_widget.add(artist_albums)
+        new_artist_albums_widget.show()
+
+        # Replace previous widget
+        self._artist_albums_widget = new_artist_albums_widget
+        self._view.set_visible_child(new_artist_albums_widget)
+
         return
         self._last_selected_row = row
         artist = row.props.text


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