[gnome-music/wip/mschraal/core: 56/190] coremodel: New style PlayerPlaylist album handling



commit 6534d38f809cf83b97901c2d8199a0e42bbc1a87
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Jun 5 10:51:45 2019 +0200

    coremodel: New style PlayerPlaylist album handling
    
    Have a specific model for Playlist (not based on self._model).

 gnomemusic/coremodel.py            | 70 +++++++++-----------------------------
 gnomemusic/widgets/albumwidget2.py |  5 +--
 2 files changed, 20 insertions(+), 55 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 3ec7338e..ac51454b 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -8,6 +8,7 @@ from gnomemusic.coreartist import CoreArtist
 from gnomemusic.coregrilo import CoreGrilo
 from gnomemusic.coresong import CoreSong
 from gnomemusic.grilo import grilo
+from gnomemusic.player import PlayerPlaylist
 from gnomemusic.widgets.songwidget import SongWidget
 
 
@@ -31,7 +32,7 @@ class CoreModel(GObject.GObject):
         self._album_model = Gio.ListStore()
         self._artist_model = Gio.ListStore.new(CoreArtist)
 
-        self._playlist_model = Dazzle.ListModelFilter.new(self._model)
+        self._playlist_model = Gio.ListStore.new(CoreSong)
         self._playlist_model_sort = Gfm.SortListModel.new(self._playlist_model)
 
         self._album_store = None
@@ -94,64 +95,27 @@ class CoreModel(GObject.GObject):
     def get_playlist_model(self):
         return self._playlist_model_sort
 
-    def set_playlist_model(self, type, album_media, coresong):
-        song_ids = []
+    def set_playlist_model(self, playlist_type, album_media, coresong, model):
+        with model.freeze_notify():
 
-        def _filter_func(core_song):
-            return core_song.props.media.get_id() in song_ids
-
-        def _sort_func(song_a, song_b):
-            sort_disc = (song_a.props.media.get_album_disc_number()
-                          - song_b.props.media.get_album_disc_number())
-            if sort_disc == 0:
-                return song_a.props.track_number - song_b.props.track_number
-
-            return sort_disc
-
-        def _callback(source, dunno, media, something, something2):
-            if media is None:
-                self._playlist_model.set_filter_func(_filter_func)
-                self._playlist_model_sort.set_sort_func(
-                    self._wrap_list_store_sort_func(_sort_func))
-                for song in self._playlist_model:
-                    if song.props.media.get_id() == coresong.get_id():
-                        song.props.state = SongWidget.State.PLAYING
-                        break
-                self.emit("playlist-loaded")
-                return
+            if playlist_type == PlayerPlaylist.Type.ALBUM:
+                self._playlist_model.remove_all()
 
-            song_ids.append(media.get_id())
+                for disc in model:
+                    for model_song in disc.model:
+                        song = CoreSong(model_song.props.media)
 
-        self._grilo.populate_album_songs(album_media, _callback)
+                        self._playlist_model.append(song)
+                        song.bind_property(
+                            "state", model_song, "state",
+                            GObject.BindingFlags.SYNC_CREATE)
 
+                        media_id = model_song.props.media.get_id()
 
-        # albums_ids = []
+                        if song.props.media.get_id() == coresong.get_id():
+                            song.props.state = SongWidget.State.PLAYING
 
-        # model_filter = Dazzle.ListModelFilter.new(self._model)
-        # model_filter = Gfm.FilterListModel.new(self._model)
-        # model_filter.set_filter_func(lambda a: False)
-        # model_sort = Gfm.SortListModel.new_for_type(CoreSong)
-
-        # def _filter_func(core_song):
-        #     return core_song.props.media.get_id() in albums_ids
-
-        # def _reverse_sort(song_a, song_b, data=None):
-        #     return song_b.props.track_number - song_a.props.track_number
-
-        # def _callback(source, dunno, media, something, something2):
-        #     if media is None:
-        #         model_filter.set_filter_func(_filter_func)
-        #         model_sort.set_model(model_filter)
-        #         model_sort.set_sort_func(
-        #             self._wrap_list_store_sort_func(_reverse_sort))
-        #         return
-
-        #     albums_ids.append(media.get_id())
-
-        # For POC sake, use old grilo
-        # grilo.populate_album_songs(media, _callback)
-
-        # return model_sort
+                self.emit("playlist-loaded")
 
     def get_album_disc(self, media, discnr, model):
         albums_ids = []
diff --git a/gnomemusic/widgets/albumwidget2.py b/gnomemusic/widgets/albumwidget2.py
index 9f5f3542..c231c86f 100644
--- a/gnomemusic/widgets/albumwidget2.py
+++ b/gnomemusic/widgets/albumwidget2.py
@@ -171,7 +171,7 @@ class AlbumWidget2(Gtk.EventBox):
 
         coresong = listboxrow.get_child()
         self._parent_view._window._app._coremodel.set_playlist_model(
-            PlayerPlaylist.Type.ALBUM, album, coresong)
+            PlayerPlaylist.Type.ALBUM, album, coresong, self._album_model)
         # self._player.set_playlist(
         #     PlayerPlaylist.Type.ALBUM, self._album_name, old_model,
         #     activated_iter)
@@ -203,7 +203,8 @@ class AlbumWidget2(Gtk.EventBox):
         signal_id = self._parent_view._window._app._coremodel.connect(
             "playlist-loaded", _on_playlist_loaded)
         self._parent_view._window._app._coremodel.set_playlist_model(
-            PlayerPlaylist.Type.ALBUM, self._album, song_widget._media)
+            PlayerPlaylist.Type.ALBUM, self._album, song_widget._media,
+            self._album_model)
 
         return True
 


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