[gnome-music/wip/jfelder/gtk4-v3: 59/112] DiscBox partial port to ListView




commit 6ed1fa14f9cf3741591175e4196901631237b4c5
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                 |  6 ++---
 data/ui/SongListItem.ui            | 54 ++++++++++++++++++++++++++++++++++++++
 gnomemusic/coresong.py             |  2 ++
 gnomemusic/widgets/discbox.py      |  9 +++++--
 5 files changed, 66 insertions(+), 6 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 207c9b46a..a4fb2de95 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/SongWidgetMenu.ui</file>
diff --git a/data/ui/DiscBox.ui b/data/ui/DiscBox.ui
index 164d8dcbe..21afd0343 100644
--- a/data/ui/DiscBox.ui
+++ b/data/ui/DiscBox.ui
@@ -25,12 +25,10 @@
           </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="content"/>
             </style>
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 585f28e8d..2722aa47d 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -49,6 +49,7 @@ class CoreSong(GObject.GObject):
     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)
@@ -81,6 +82,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/discbox.py b/gnomemusic/widgets/discbox.py
index 487ac52e1..fa9f3f9ef 100644
--- a/gnomemusic/widgets/discbox.py
+++ b/gnomemusic/widgets/discbox.py
@@ -46,7 +46,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,))
@@ -78,7 +78,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]