[gnome-music/wip/mschraal/gtk4-v2: 63/65] DiscBox partial port to ListView




commit 057a85845433d4b4e7590cfccb04165141ef8d9c
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Apr 25 16:01:52 2021 +0200

    DiscBox partial port to ListView

 data/org.gnome.Music.gresource.xml      |  1 +
 data/ui/DiscBox.ui                      |  8 ++---
 data/ui/SongListItem.ui                 | 54 +++++++++++++++++++++++++++++++++
 gnomemusic/coresong.py                  |  4 +++
 gnomemusic/widgets/disclistboxwidget.py |  9 ++++--
 5 files changed, 69 insertions(+), 7 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 55b06072e..d4ffe5453 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -35,6 +35,7 @@
     <file preprocess="xml-stripblanks">ui/SearchView.ui</file>
     <file preprocess="xml-stripblanks">ui/SelectionBarMenuButton.ui</file>
     <file preprocess="xml-stripblanks">ui/SelectionToolbar.ui</file>
+    <file preprocess="xml-stripblanks">ui/SongListItem.ui</file>
     <file preprocess="xml-stripblanks">ui/SongsView.ui</file>
     <file preprocess="xml-stripblanks">ui/SongWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/TwoLineTip.ui</file>
diff --git a/data/ui/DiscBox.ui b/data/ui/DiscBox.ui
index 6bcb7ea6a..81929e816 100644
--- a/data/ui/DiscBox.ui
+++ b/data/ui/DiscBox.ui
@@ -25,14 +25,12 @@
           </object>
         </child>
         <child>
-          <object class="GtkListBox" id="_list_box">
-            <property name="visible">True</property>
+          <object class="GtkListView" id="_list_view">
             <property name="can_focus">False</property>
             <property name="valign">start</property>
-            <property name="selection_mode">none</property>
-            <signal name="row-activated" handler="_song_activated" swapped="no"/>
+            <property name="single_click_activate">True</property>
             <style>
-              <class name="songs-list"/>
+              <class name="rich-list"/>
             </style>
           </object>
         </child>
diff --git a/data/ui/SongListItem.ui b/data/ui/SongListItem.ui
new file mode 100644
index 000000000..7477a404d
--- /dev/null
+++ b/data/ui/SongListItem.ui
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="4.0"/>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkBox">
+        <property name="orientation">horizontal</property>
+        <child>
+          <object class="GtkBox">
+            <property name="homogeneous">True</property>
+            <child>
+              <object class="GtkLabel" id="_number_label">
+                <binding name="label">
+                  <lookup name="track_number" type="CoreSong">
+                    <lookup name="item">GtkListItem</lookup>
+                  </lookup>
+                </binding>
+                <property name="can_focus">False</property>
+                <property name="halign">end</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <binding name="label">
+              <lookup name="title" type="CoreSong">
+                <lookup name="item">GtkListItem</lookup>
+              </lookup>
+            </binding>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="_duration_label">
+            <property name="halign">end</property>
+            <property name="hexpand">True</property>
+            <property name="single_line_mode">True</property>
+            <binding name="label">
+              <lookup name="duration" type="CoreSong">
+                <lookup name="item">GtkListItem</lookup>
+              </lookup>
+            </binding>
+            <attributes>
+              <attribute name="font-features" value="tnum=1"/>
+            </attributes>
+          </object>
+        </child>
+      </object>
+    </property>
+  </template>
+</interface>
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index 064a6f8d7..c0ee731a0 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -43,9 +43,12 @@ class CoreSong(GObject.GObject):
     """Exposes a Grl.Media with relevant data as properties
     """
 
+    __gtype_name__ = "CoreSong"
+
     album = GObject.Property(type=str)
     album_disc_number = GObject.Property(type=int)
     artist = GObject.Property(type=str)
+    coresong = GObject.Property(type=object, default=None)
     duration = GObject.Property(type=int)
     media = GObject.Property(type=Grl.Media)
     grlid = GObject.Property(type=str, default=None)
@@ -77,6 +80,7 @@ class CoreSong(GObject.GObject):
         self._favorite: bool = False
         self._selected: bool = False
         self._thumbnail: Optional[str] = None
+        self.props.coresong = self
 
         self.props.grlid = media.get_source() + media.get_id()
         self._is_tracker: bool = media.get_source() == "grl-tracker3-source"
diff --git a/gnomemusic/widgets/disclistboxwidget.py b/gnomemusic/widgets/disclistboxwidget.py
index 77ee0d871..ba002de30 100644
--- a/gnomemusic/widgets/disclistboxwidget.py
+++ b/gnomemusic/widgets/disclistboxwidget.py
@@ -43,7 +43,7 @@ class DiscBox(Gtk.ListBoxRow):
     __gtype_name__ = 'DiscBox'
 
     _disc_label = Gtk.Template.Child()
-    _list_box = Gtk.Template.Child()
+    _list_view = Gtk.Template.Child()
 
     __gsignals__ = {
         'song-activated': (GObject.SignalFlags.RUN_FIRST, None, (Gtk.Widget,))
@@ -68,7 +68,12 @@ class DiscBox(Gtk.ListBoxRow):
             'show-disc-label', self._disc_label, 'visible',
             GObject.BindingFlags.SYNC_CREATE)
 
-        self._list_box.bind_model(self._model, self._create_widget)
+        multi_selection_model = Gtk.MultiSelection.new(self._model)
+        self._list_view.props.model = multi_selection_model
+
+        list_item_factory = Gtk.BuilderListItemFactory(
+            resource="/org/gnome/Music/ui/SongListItem.ui")
+        self._list_view.props.factory = list_item_factory
 
     def select_all(self):
         """Select all songs"""


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