[gnome-music/wip/mschraal/core: 175/190] coremodel: Make album playlist react to changes
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core: 175/190] coremodel: Make album playlist react to changes
- Date: Sun, 7 Jul 2019 21:48:08 +0000 (UTC)
commit 76d8e468ecf8e97593c37730ba7641cbf6e52aa4
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Jul 3 01:04:55 2019 +0200
coremodel: Make album playlist react to changes
gnomemusic/coremodel.py | 54 +++++++++++++++++++++++++++++++++++++------------
subprojects/gfm | 2 +-
2 files changed, 42 insertions(+), 14 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index f611d485..eead4383 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -36,6 +36,8 @@ class CoreModel(GObject.GObject):
def __init__(self, coreselection):
super().__init__()
+ self._flatten_model = None
+
self._model = Gio.ListStore.new(CoreSong)
self._songliststore = SongListStore(self._model)
@@ -121,22 +123,48 @@ class CoreModel(GObject.GObject):
with model.freeze_notify():
if playlist_type == PlayerPlaylist.Type.ALBUM:
+
self._playlist_model.remove_all()
+ proxy_model = Gio.ListStore.new(Gio.ListModel)
+
+ def _on_items_changed(model, position, removed, added):
+ if removed > 0:
+ for i in list(range(removed)):
+ self._playlist_model.remove(position)
+
+ if added > 0:
+ for i in list(range(added)):
+ coresong = model[position + i]
+ song = CoreSong(
+ coresong.props.media, self._coreselection,
+ self._grilo)
+
+ self._playlist_model.insert(position + i, song)
+
+ song.bind_property(
+ "state", coresong, "state",
+ GObject.BindingFlags.SYNC_CREATE)
for disc in model:
- for model_song in disc.props.model:
- song = CoreSong(
- model_song.props.media, self._coreselection,
- self._grilo)
-
- self._playlist_model.append(song)
- song.bind_property(
- "state", model_song, "state",
- GObject.BindingFlags.SYNC_CREATE)
-
- song_id = coresong.props.media.get_id()
- if song.props.media.get_id() == song_id:
- song.props.state = SongWidget.State.PLAYING
+ proxy_model.append(disc.props.model)
+
+ self._flatten_model = Gfm.FlattenListModel.new(
+ CoreSong, proxy_model)
+ self._flatten_model.connect("items-changed", _on_items_changed)
+
+ for model_song in self._flatten_model:
+ song = CoreSong(
+ model_song.props.media, self._coreselection,
+ self._grilo)
+
+ self._playlist_model.append(song)
+ song.bind_property(
+ "state", model_song, "state",
+ GObject.BindingFlags.SYNC_CREATE)
+
+ song_id = coresong.props.media.get_id()
+ if song.props.media.get_id() == song_id:
+ song.props.state = SongWidget.State.PLAYING
self.emit("playlist-loaded")
elif playlist_type == PlayerPlaylist.Type.ARTIST:
diff --git a/subprojects/gfm b/subprojects/gfm
index e6412581..956deaca 160000
--- a/subprojects/gfm
+++ b/subprojects/gfm
@@ -1 +1 @@
-Subproject commit e64125815c835ef9ef62b13471d5f554850b6c85
+Subproject commit 956deaca5ac104f5329bfb542c05d4a63578ee08
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]