[gnome-music/wip/mschraal/core: 89/118] coredisc: Move more stuff here



commit 93823c34f23208bfa9ec6d53fe05b9de9ce5ef3b
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Jun 21 17:11:51 2019 +0200

    coredisc: Move more stuff here

 gnomemusic/coredisc.py             | 31 +++++++++++++++++++++++++++----
 gnomemusic/coremodel.py            | 14 ++++----------
 gnomemusic/widgets/albumwidget2.py |  2 +-
 3 files changed, 32 insertions(+), 15 deletions(-)
---
diff --git a/gnomemusic/coredisc.py b/gnomemusic/coredisc.py
index 97e44c63..61534eba 100644
--- a/gnomemusic/coredisc.py
+++ b/gnomemusic/coredisc.py
@@ -1,5 +1,5 @@
 import gi
-from gi.repository import GObject, Gio, Gfm, Grl, GLib
+from gi.repository import Dazzle, GObject, Gio, Gfm, Grl, GLib
 from gi._gi import pygobject_new_full
 
 from gnomemusic.coregrilo import CoreGrilo
@@ -8,26 +8,49 @@ from gnomemusic.coresong import CoreSong
 
 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, model):
+    def __init__(self, media, nr, coremodel):
         super().__init__()
 
-        self.props.model = model
+        self._coremodel = coremodel
+        self.props.disc_nr = nr
+
+        filter_model = Dazzle.ListModelFilter.new(self._coremodel.get_model())
+        filter_model.set_filter_func(lambda a: False)
+        self._sort_model = Gfm.SortListModel.new(filter_model)
+        self._sort_model.set_sort_func(self._wrap_sort_func(self._disc_sort))
+
+        self.props.model = self._sort_model
         self.update(media)
 
         self.props.model.connect("items-changed", self._on_list_items_changed)
 
+        self._coremodel._get_album_disc(
+            self.props.media, self.props.disc_nr, filter_model)
+
     def update(self, media):
         self.props.media = media
 
     def _on_list_items_changed(self, model, pos, removed, added):
-        print("items changed")
         duration = 0
 
         for coresong in model:
             duration += coresong.props.duration
 
         self.props.duration = duration
+
+    def _disc_sort(self, song_a, song_b):
+        return song_a.props.track_number - song_b.props.track_number
+
+    def _wrap_sort_func(self, func):
+
+        def wrap(a, b, *user_data):
+            a = pygobject_new_full(a, False)
+            b = pygobject_new_full(b, False)
+            return func(a, b, *user_data)
+
+        return wrap
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 6711dd4a..f668bb24 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -103,22 +103,16 @@ class CoreModel(GObject.GObject):
             return song_a.props.track_number - song_b.props.track_number
 
         for disc in discs:
-            model_filter = Dazzle.ListModelFilter.new(self._model)
-            model_filter.set_filter_func(lambda a: False)
             nr = disc.get_album_disc_number()
-            self._get_album_disc(media, nr, model_filter)
 
-            model_sort = Gfm.SortListModel.new(model_filter)
-            model_sort.set_sort_func(
-                self._wrap_list_store_sort_func(_disc_sort))
-
-            coredisc = CoreDisc(disc, model_sort)
+            print("DISC", disc, disc.get_title(), disc.get_album_disc_number())
+            print("MEDI", media, media.get_title(), media.get_album_disc_number())
+            coredisc = CoreDisc(media, nr, self)
 
             disc_model.append(coredisc)
 
         def _disc_order_sort(disc_a, disc_b):
-            return (disc_a.media.get_album_disc_number()
-                    - disc_b.media.get_album_disc_number())
+            return disc_a.props.disc_nr - disc_b.props.disc_nr
 
         disc_model_sort.set_sort_func(
             self._wrap_list_store_sort_func(_disc_order_sort))
diff --git a/gnomemusic/widgets/albumwidget2.py b/gnomemusic/widgets/albumwidget2.py
index bbb962a9..40f3634a 100644
--- a/gnomemusic/widgets/albumwidget2.py
+++ b/gnomemusic/widgets/albumwidget2.py
@@ -92,7 +92,7 @@ class AlbumWidget2(Gtk.EventBox):
 
     def _create_widget(self, disc):
         disc_box = self._create_disc_box(
-            disc.media.get_album_disc_number(), disc.model)
+            disc.props.disc_nr, disc.model)
 
         self.bind_property(
             "selection-mode", disc_box, "selection-mode",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]