[gnome-music/wip/mschraal/core: 92/118] coredisc: Make model on-demand
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core: 92/118] coredisc: Make model on-demand
- Date: Wed, 26 Jun 2019 13:07:44 +0000 (UTC)
commit 3764b5dedd0a3bc014ec752d9bfea860196bb37b
Author: Marinus Schraal <mschraal gnome org>
Date: Sat Jun 22 00:38:39 2019 +0200
coredisc: Make model on-demand
gnomemusic/coredisc.py | 36 ++++++++++++++++++++++--------------
gnomemusic/coremodel.py | 2 +-
2 files changed, 23 insertions(+), 15 deletions(-)
---
diff --git a/gnomemusic/coredisc.py b/gnomemusic/coredisc.py
index a8e9319d..4c6bfbf1 100644
--- a/gnomemusic/coredisc.py
+++ b/gnomemusic/coredisc.py
@@ -11,32 +11,40 @@ class CoreDisc(GObject.GObject):
disc_nr = GObject.Property(type=int, default=0)
duration = GObject.Property(type=int, default=None)
media = GObject.Property(type=Grl.Media, default=None)
- model = GObject.Property(type=Gio.ListModel, default=None)
def __init__(self, media, nr, coremodel):
super().__init__()
self._coremodel = coremodel
+ self._filter_model = None
+ self._model = None
self._old_album_ids = []
+ self._sort_model = None
+
+ self.update(media)
self.props.disc_nr = nr
- self._filter_model = Dazzle.ListModelFilter.new(
- self._coremodel.get_model())
- self._filter_model.set_filter_func(lambda a: False)
- self._sort_model = Gfm.SortListModel.new(self._filter_model)
- self._sort_model.set_sort_func(self._wrap_sort_func(self._disc_sort))
+ def update(self, media):
+ self.props.media = media
- self.props.model = self._sort_model
- self.update(media)
+ @GObject.Property(type=Gio.ListModel, default=None)
+ def model(self):
+ if self._model is None:
+ self._filter_model = Dazzle.ListModelFilter.new(
+ self._coremodel.get_model())
+ self._filter_model.set_filter_func(lambda a: False)
+ self._sort_model = Gfm.SortListModel.new(self._filter_model)
+ self._sort_model.set_sort_func(self._wrap_sort_func(self._disc_sort))
- self._coremodel.get_model().connect(
- "items-changed", self._on_core_changed)
+ self._model = self._sort_model
- self._get_album_disc(
- self.props.media, self.props.disc_nr, self._filter_model)
+ self._coremodel.get_model().connect(
+ "items-changed", self._on_core_changed)
- def update(self, media):
- self.props.media = media
+ self._get_album_disc(
+ self.props.media, self.props.disc_nr, self._filter_model)
+
+ return self._model
def _on_core_changed(self, model, position, removed, added):
self._get_album_disc(
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 0cbebe81..24ad6866 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -147,7 +147,7 @@ class CoreModel(GObject.GObject):
self._playlist_model.remove_all()
for disc in model:
- for model_song in disc.model:
+ for model_song in disc.props.model:
song = CoreSong(model_song.props.media)
self._playlist_model.append(song)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]