Commit 72c225b8 authored by Marinus Schraal's avatar Marinus Schraal

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 become empty.

Instead make the signal handler smarter and splice the changes in
one go.
parent 4eec26ef
...@@ -232,10 +232,7 @@ class CoreModel(GObject.GObject): ...@@ -232,10 +232,7 @@ class CoreModel(GObject.GObject):
return return
def _on_items_changed(model, position, removed, added): def _on_items_changed(model, position, removed, added):
if removed > 0: songs_list = []
for i in list(range(removed)):
if added > 0: if added > 0:
for i in list(range(added)): for i in list(range(added)):
coresong = model[position + i] coresong = model[position + i]
...@@ -243,8 +240,6 @@ class CoreModel(GObject.GObject): ...@@ -243,8 +240,6 @@ class CoreModel(GObject.GObject):, self._coreselection,, self._coreselection,
self.props.grilo) self.props.grilo)
self._playlist_model.insert(position + i, song)
song.bind_property( song.bind_property(
"state", coresong, "state", "state", coresong, "state",
GObject.BindingFlags.SYNC_CREATE) GObject.BindingFlags.SYNC_CREATE)
...@@ -253,6 +248,10 @@ class CoreModel(GObject.GObject): ...@@ -253,6 +248,10 @@ class CoreModel(GObject.GObject):
GObject.BindingFlags.BIDIRECTIONAL GObject.BindingFlags.BIDIRECTIONAL
| GObject.BindingFlags.SYNC_CREATE) | GObject.BindingFlags.SYNC_CREATE)
self._playlist_model.splice(position, removed, songs_list)
played_states = [SongWidget.State.PLAYING, SongWidget.State.PLAYED] played_states = [SongWidget.State.PLAYING, SongWidget.State.PLAYED]
for song in self._playlist_model: for song in self._playlist_model:
if song.props.state in played_states: if song.props.state in played_states:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment