Commit 76d8e468 authored by Marinus Schraal's avatar Marinus Schraal

coremodel: Make album playlist react to changes

parent 4f7a4f6f
......@@ -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:
......
Subproject commit e64125815c835ef9ef62b13471d5f554850b6c85
Subproject commit 956deaca5ac104f5329bfb542c05d4a63578ee08
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