[gnome-music/wip/mschraal/core: 50/93] Make DiscListBox a Gtk.ListBox again, works for artistsview



commit bdc063004b2700e1b0d9f607781d5869eaba2f32
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Jun 2 10:24:14 2019 +0200

    Make DiscListBox a Gtk.ListBox again, works for artistsview

 data/ui/AlbumWidget.ui                  |  4 ++--
 data/ui/ArtistAlbumWidget.ui            |  3 ++-
 gnomemusic/coremodel.py                 | 34 +++++++++++++++++++++++++++++----
 gnomemusic/widgets/albumwidget.py       | 10 +++++-----
 gnomemusic/widgets/artistalbumwidget.py | 20 ++++++++++++++-----
 gnomemusic/widgets/disclistboxwidget.py |  4 ++--
 6 files changed, 56 insertions(+), 19 deletions(-)
---
diff --git a/data/ui/AlbumWidget.ui b/data/ui/AlbumWidget.ui
index 04f70b03..49e7b7f9 100644
--- a/data/ui/AlbumWidget.ui
+++ b/data/ui/AlbumWidget.ui
@@ -229,10 +229,10 @@
                     <property name="margin_top">48</property>
                     <property name="margin_bottom">64</property>
                     <property name="margin_end">32</property>
-                    <property name="orientation">vertical</property>
+                    <!-- <property name="orientation">vertical</property> -->
                     <property name="selection_mode_allowed">True</property>
                     <property name="visible">True</property>
-                    <signal name="selection-changed" handler="_on_selection_changed" swapped="no"/>
+                    <!-- <signal name="selection-changed" handler="_on_selection_changed" swapped="no"/> -->
                   </object>
                 </child>
               </object>
diff --git a/data/ui/ArtistAlbumWidget.ui b/data/ui/ArtistAlbumWidget.ui
index 6f92a7b4..29aff23e 100644
--- a/data/ui/ArtistAlbumWidget.ui
+++ b/data/ui/ArtistAlbumWidget.ui
@@ -66,7 +66,8 @@
           <object class="DiscListBox" id="_disc_list_box">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
+            <property name="selection-mode">0</property>
+            <!-- <property name="orientation">vertical</property> -->
           </object>
           <packing>
             <property name="position">1</property>
diff --git a/gnomemusic/coremodel.py b/gnomemusic/coremodel.py
index 179d8239..0f790e18 100644
--- a/gnomemusic/coremodel.py
+++ b/gnomemusic/coremodel.py
@@ -10,6 +10,11 @@ from gnomemusic.coresong import CoreSong
 from gnomemusic.grilo import grilo
 
 
+class CoreDisc(GObject.GObject):
+        media = None
+        model = None
+
+
 class CoreModel(GObject.GObject):
 
     @log
@@ -46,15 +51,36 @@ class CoreModel(GObject.GObject):
     def get_album_model(self, media):
         discs = self._grilo.get_album_disc_numbers(media)
 
-        disc_list = []
+        disc_model = Gio.ListStore()
+        disc_model_sort = Gfm.SortListModel.new(disc_model)
+
+        def _disc_sort(song_a, song_b):
+            return song_a.props.track_number - song_b.props.track_number
+
         for disc in discs:
-            nr = disc.get_album_disc_number()
             model_filter = Dazzle.ListModelFilter.new(self._model)
             model_filter.set_filter_func(lambda a: False)
-            disc_list.append(model_filter)
+            nr = disc.get_album_disc_number()
             self.get_album_disc(media, nr, model_filter)
 
-        return disc_list
+            model_sort = Gfm.SortListModel.new(model_filter)
+            model_sort.set_sort_func(
+                self._wrap_list_store_sort_func(_disc_sort))
+
+            coredisc = CoreDisc()
+            coredisc.media = disc
+            coredisc.model = model_sort
+
+            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())
+
+        disc_model_sort.set_sort_func(
+            self._wrap_list_store_sort_func(_disc_order_sort))
+
+        return disc_model_sort
 
         # albums_ids = []
 
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 1eea57f0..afbf8116 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -160,11 +160,11 @@ class AlbumWidget(Gtk.EventBox):
         self._running_info_label.props.label = ngettext(
             "{} minute", "{} minutes", mins).format(mins)
 
-    @Gtk.Template.Callback()
-    @log
-    def _on_selection_changed(self, widget):
-        n_items = len(self._disc_listbox.get_selected_items())
-        self.props.selected_items_count = n_items
+    # @Gtk.Template.Callback()
+    # @log
+    # def _on_selection_changed(self, widget):
+    #     n_items = len(self._disc_listbox.get_selected_items())
+    #     self.props.selected_items_count = n_items
 
     @log
     def _create_disc_box(self, disc_nr, disc_songs):
diff --git a/gnomemusic/widgets/artistalbumwidget.py b/gnomemusic/widgets/artistalbumwidget.py
index 6827e081..4ed09ccb 100644
--- a/gnomemusic/widgets/artistalbumwidget.py
+++ b/gnomemusic/widgets/artistalbumwidget.py
@@ -94,14 +94,24 @@ class ArtistAlbumWidget(Gtk.Box):
         if self._cover_size_group:
             self._cover_size_group.add_widget(self._cover_stack)
 
-        albums_list = window._app._coremodel.get_album_model(self._media)
+        # albums_list = window._app._coremodel.get_album_model(self._media)
 
-        for album in albums_list:
-            disc = self._create_disc_box(0, album)
-            self._disc_list_box.add(disc)
-            self._disc_list_box.show()
+        # for album in albums_list:
+        #     disc = self._create_disc_box(0, album)
+        #     self._disc_list_box.add(disc)
+        #     self._disc_list_box.show()
         # grilo.populate_album_songs(self._media, self._add_item)
 
+        disc_model = window._app._coremodel.get_album_model(self._media)
+
+        self._disc_list_box.bind_model(disc_model, self._create_widget)
+
+    def _create_widget(self, disc):
+        disc_box = self._create_disc_box(
+            disc.media.get_album_disc_number(), disc.model)
+
+        return disc_box
+
     @log
     def _create_disc_box(self, disc_nr, album_model):
         disc_box = DiscBox(None, album_model)
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index f5f2598c..689ca08a 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -299,7 +299,7 @@ class DiscBox(Gtk.Box):
         return True
 
 
-class DiscListBox(Gtk.Box):
+class DiscListBox(Gtk.ListBox):
     """A ListBox widget containing all discs of a particular
     album
     """
@@ -317,7 +317,7 @@ class DiscListBox(Gtk.Box):
     @log
     def __init__(self):
         """Initialize"""
-        super().__init__(orientation=Gtk.Orientation.VERTICAL)
+        super().__init__() # orientation=Gtk.Orientation.VERTICAL)
 
         self._selection_mode = False
         self._selected_items = []


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