[gnome-music/wip/mschraal/playlists-fixes: 8/10] coremodel: Splice playlist model on changes
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/playlists-fixes: 8/10] coremodel: Splice playlist model on changes
- Date: Fri, 28 Feb 2020 19:37:14 +0000 (UTC)
commit 9757652dae92d525165b2d3de2bb9875c55b0aae
Author: Marinus Schraal <mschraal gnome org>
Date: Sat Feb 22 16:23:24 2020 +0100
coremodel: Splice playlist model on changes
When reacting to the items-changed signal on the current playlist model,
all items were removed & added one at a time. This would result in
changes possibly stopping the playing playlist, as the playlist could
effectively could become empty.
Instead make the signal handler smarter and splice the changes in
one go.
gnomemusic/coremodel.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 17eb5167..2b5d7c12 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -232,10 +232,7 @@ class CoreModel(GObject.GObject):
return
def _on_items_changed(model, position, removed, added):
- if removed > 0:
- for i in list(range(removed)):
- self._playlist_model.remove(position)
-
+ songs_list = []
if added > 0:
for i in list(range(added)):
coresong = model[position + i]
@@ -253,6 +250,10 @@ class CoreModel(GObject.GObject):
GObject.BindingFlags.BIDIRECTIONAL
| GObject.BindingFlags.SYNC_CREATE)
+ songs_list.append(song)
+
+ self._playlist_model.splice(position, removed, songs_list)
+
played_states = [SongWidget.State.PLAYING, SongWidget.State.PLAYED]
for song in self._playlist_model:
if song.props.state in played_states:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]