[gnome-music/wip/mschraal/core: 125/164] songsview: Initial port to core



commit 1e2f9a87eb63b8bd34c0862ff985668ef3dd7a8d
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Jun 26 21:20:02 2019 +0200

    songsview: Initial port to core
    
    Just shows the view. Does addition/removal.

 gnomemusic/coremodel.py                      |  5 ++++
 gnomemusic/grilowrappers/grltrackersource.py |  5 ++++
 gnomemusic/songliststore.py                  | 43 ++++++++++++++++++++++++++++
 gnomemusic/views/songsview.py                | 33 +++++----------------
 gnomemusic/widgets/starhandlerwidget.py      |  1 -
 5 files changed, 60 insertions(+), 27 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index c79ea315..5d04bfd4 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -10,6 +10,7 @@ from gnomemusic.coredisc import CoreDisc
 from gnomemusic.coregrilo import CoreGrilo
 from gnomemusic.coresong import CoreSong
 from gnomemusic.player import PlayerPlaylist
+from gnomemusic.songliststore import SongListStore
 from gnomemusic.widgets.songwidget import SongWidget
 
 # The basic premisis is that an album (CoreAlbum) consist of a
@@ -38,6 +39,7 @@ class CoreModel(GObject.GObject):
         super().__init__()
 
         self._model = Gio.ListStore.new(CoreSong)
+        self._songliststore = SongListStore(self._model)
 
         self._coreselection = coreselection
 
@@ -194,3 +196,6 @@ class CoreModel(GObject.GObject):
         albums = self._grilo.get_artist_albums(artist)
 
         return albums
+
+    def get_songs_model(self):
+        return self._songliststore.props.model
diff --git a/gnomemusic/grilowrappers/grltrackersource.py b/gnomemusic/grilowrappers/grltrackersource.py
index bb523102..1cace357 100644
--- a/gnomemusic/grilowrappers/grltrackersource.py
+++ b/gnomemusic/grilowrappers/grltrackersource.py
@@ -210,6 +210,11 @@ class GrlTrackerSource(GObject.GObject):
             # print("NO MEDIA", source, op_id, media, error)
             return
 
+        # FIXME: Figure out why we get double additions.
+        if media.get_id() in self._hash.keys():
+            print("ALREADY ADDED")
+            return
+
         song = CoreSong(media, self._core_selection)
         self._model.append(song)
         self._hash[media.get_id()] = song
diff --git a/gnomemusic/songliststore.py b/gnomemusic/songliststore.py
new file mode 100644
index 00000000..78db9321
--- /dev/null
+++ b/gnomemusic/songliststore.py
@@ -0,0 +1,43 @@
+from gi.repository import GObject, Gtk, GdkPixbuf
+
+
+class SongListStore(Gtk.ListStore):
+
+    model = GObject.Property(type=Gtk.ListStore, default=None)
+
+    def __init__(self, model):
+        super().__init__()
+
+        self._model = model
+
+        self.props.model = Gtk.ListStore(
+            GObject.TYPE_STRING,
+            GObject.TYPE_STRING,
+            GObject.TYPE_STRING,
+            GObject.TYPE_STRING,
+            GdkPixbuf.Pixbuf,
+            GObject.TYPE_OBJECT,
+            GObject.TYPE_BOOLEAN,
+            GObject.TYPE_INT,
+            GObject.TYPE_STRING,
+            GObject.TYPE_INT,
+            GObject.TYPE_BOOLEAN,
+            GObject.TYPE_INT
+        )
+
+        self._model.connect("items-changed", self._on_items_changed)
+
+    def _on_items_changed(self, model, position, removed, added):
+        if removed > 0:
+            for i in list(range(removed)):
+                path = Gtk.TreePath.new_from_string("{}".format(position))
+                iter_ = self._gtk_model.get_iter(path)
+                self._gtk_model.remove(iter_)
+
+        if added > 0:
+            for i in list(range(added)):
+                coresong = self._model[position]
+                self.props.model.insert_with_valuesv(
+                    position, [2, 3, 5, 9],
+                    [coresong.props.title, coresong.props.artist, coresong,
+                     coresong.props.favorite])
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index 0f2a5090..d280cb48 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -28,7 +28,7 @@ from gi.repository import Gdk, Gtk, Pango
 
 from gnomemusic import log
 from gnomemusic.grilo import grilo
-from gnomemusic.player import ValidationStatus, PlayerPlaylist
+from gnomemusic.player import PlayerPlaylist
 from gnomemusic.views.baseview import BaseView
 import gnomemusic.utils as utils
 
@@ -52,6 +52,7 @@ class SongsView(BaseView):
         :param GtkWidget window: The main window
         :param player: The main player object
         """
+        self._window = window
         super().__init__('songs', _("Songs"), window)
 
         self._offset = 0
@@ -65,6 +66,8 @@ class SongsView(BaseView):
         self.player.connect('song-changed', self._update_model)
         self.player.connect('song-validated', self._on_song_validated)
 
+        self._view.show()
+
     @log
     def _setup_view(self):
         view_container = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
@@ -73,7 +76,7 @@ class SongsView(BaseView):
         self._view = Gtk.TreeView()
         self._view.props.headers_visible = False
         self._view.props.valign = Gtk.Align.START
-        self._view.props.model = self.model
+        self._view.props.model = self._window._app._coremodel.get_songs_model()
         self._view.props.activate_on_single_click = True
 
         self._ctrl = Gtk.GestureMultiPress().new(self._view)
@@ -140,7 +143,7 @@ class SongsView(BaseView):
     def _on_list_widget_duration_render(self, col, cell, model, itr, data):
         item = model[itr][5]
         if item:
-            seconds = item.get_duration()
+            seconds = item.props.duration
             track_time = utils.seconds_to_string(seconds)
             cell.props.text = '{}'.format(track_time)
 
@@ -150,7 +153,7 @@ class SongsView(BaseView):
 
         item = model[_iter][5]
         if item:
-            cell.props.text = utils.get_album_title(item)
+            cell.props.text = item.props.album
 
     def _on_list_widget_icon_render(self, col, cell, model, itr, data):
         if not self.player.playing_playlist(PlayerPlaylist.Type.SONGS, None):
@@ -256,32 +259,10 @@ class SongsView(BaseView):
         iter_ = self.model.get_iter_from_string(str(index))
         self.model[iter_][11] = status
 
-    def _add_item(self, source, param, item, remaining=0, data=None):
-        """Adds track item to the model"""
-        if not item and not remaining:
-            self._view.set_model(self.model)
-            self._window.notifications_popup.pop_loading()
-            self._view.show()
-            return
-
-        self._offset += 1
-        item.set_title(utils.get_media_title(item))
-        artist = utils.get_artist_name(item)
-
-        if not item.get_url():
-            return
-
-        self.model.insert_with_valuesv(
-            -1, [2, 3, 5, 9],
-            [utils.get_media_title(item), artist, item, item.get_favourite()])
-
     @log
     def _populate(self, data=None):
         """Populates the view"""
         self._init = True
-        if grilo.tracker:
-            self._window.notifications_popup.push_loading()
-            grilo.populate_songs(self._offset, self._add_item)
 
     @log
     def get_selected_songs(self, callback=None):
diff --git a/gnomemusic/widgets/starhandlerwidget.py b/gnomemusic/widgets/starhandlerwidget.py
index f9698598..021cfbdd 100644
--- a/gnomemusic/widgets/starhandlerwidget.py
+++ b/gnomemusic/widgets/starhandlerwidget.py
@@ -25,7 +25,6 @@
 from gi.repository import GObject, Gtk
 
 from gnomemusic import log
-from gnomemusic.grilo import grilo
 from gnomemusic.playlists import Playlists, SmartPlaylists
 
 playlists = Playlists.get_default()


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