[totem/wip/hadess/more-gtkbuilder: 5/6] playlist: Use GtkBuilder template




commit 7c6090afcb64428cd36cc8e198c1740682b33c4c
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Feb 9 21:29:41 2022 +0100

    playlist: Use GtkBuilder template
    
    And remove some UI niceties in the (hidden) debug window.

 data/meson.build         |  1 -
 data/playlist.ui         | 11 ++++++-----
 data/totem.gresource.xml |  1 +
 src/totem-playlist.c     | 42 ++++++------------------------------------
 4 files changed, 13 insertions(+), 42 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 3462b90dd..ce9790ed2 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -37,7 +37,6 @@ else
 endif
 
 ui_files = files(
-  'playlist.ui',
   'shortcuts.ui',
   'totem.ui',
   'uri.ui'
diff --git a/data/playlist.ui b/data/playlist.ui
index 5f12c3f44..d1f02a44a 100644
--- a/data/playlist.ui
+++ b/data/playlist.ui
@@ -25,17 +25,18 @@
       <column type="gint64"/>
     </columns>
   </object>
-  <object class="GtkVBox" id="vbox4">
+  <template class="TotemPlaylist" parent="GtkBox">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="spacing">0</property>
+    <property name="orientation">vertical</property>
     <child>
-      <object class="GtkScrolledWindow" id="scrolledwindow1">
+      <object class="GtkScrolledWindow" id="scrolled_window">
         <property name="visible">True</property>
         <property name="can_focus">True</property>
         <property name="shadow_type">in</property>
         <child>
-          <object class="GtkTreeView" id="treeview1">
+          <object class="GtkTreeView" id="treeview">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="model">playlist_list_store</property>
@@ -53,7 +54,7 @@
       </packing>
     </child>
     <child>
-      <object class="GtkToolbar" id="toolbar1">
+      <object class="GtkToolbar" id="toolbar">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="icon_size">1</property>
@@ -143,5 +144,5 @@
         <property name="position">1</property>
       </packing>
     </child>
-  </object>
+  </template>
 </interface>
diff --git a/data/totem.gresource.xml b/data/totem.gresource.xml
index 53395d1fb..897ff8189 100644
--- a/data/totem.gresource.xml
+++ b/data/totem.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gnome/totem/ui">
     <file compressed="true">totem-preferences-dialog.ui</file>
+    <file compressed="true">playlist.ui</file>
   </gresource>
 </gresources>
diff --git a/src/totem-playlist.c b/src/totem-playlist.c
index e856daf19..b2e8d1250 100644
--- a/src/totem-playlist.c
+++ b/src/totem-playlist.c
@@ -877,13 +877,7 @@ totem_playlist_dispose (GObject *object)
 static void
 totem_playlist_init (TotemPlaylist *playlist)
 {
-       GtkWidget *container;
-       GtkBuilder *xml;
-       GtkWidget *widget;
-       GtkStyleContext *context;
-
-       gtk_orientable_set_orientation (GTK_ORIENTABLE (playlist),
-                                       GTK_ORIENTATION_VERTICAL);
+       gtk_widget_init_template (GTK_WIDGET (playlist));
 
        playlist->parser = totem_pl_parser_new ();
 
@@ -905,37 +899,10 @@ totem_playlist_init (TotemPlaylist *playlist)
                        G_CALLBACK (totem_playlist_entry_parsed),
                        playlist);
 
-       xml = totem_interface_load ("playlist.ui", TRUE, NULL, playlist);
-
-       if (xml == NULL)
-               return;
-
        gtk_widget_add_events (GTK_WIDGET (playlist), GDK_KEY_PRESS_MASK);
        g_signal_connect (G_OBJECT (playlist), "key_press_event",
                          G_CALLBACK (totem_playlist_key_press), playlist);
 
-       /* Buttons */
-       playlist->remove_button = GTK_WIDGET (gtk_builder_get_object (xml, "remove_button"));
-
-       /* Join treeview and buttons */
-       widget = GTK_WIDGET (gtk_builder_get_object (xml, ("scrolledwindow1")));
-       context = gtk_widget_get_style_context (widget);
-       gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
-       widget = GTK_WIDGET (gtk_builder_get_object (xml, ("toolbar1")));
-       context = gtk_widget_get_style_context (widget);
-       gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
-
-       /* Reparent the vbox */
-       container = GTK_WIDGET (gtk_builder_get_object (xml, "vbox4"));
-       g_object_ref (container);
-       gtk_box_pack_start (GTK_BOX (playlist),
-                       container,
-                       TRUE,       /* expand */
-                       TRUE,       /* fill */
-                       0);         /* padding */
-       g_object_unref (container);
-
-       playlist->treeview = GTK_WIDGET (gtk_builder_get_object (xml, "treeview1"));
        init_treeview (playlist->treeview, playlist);
        playlist->model = gtk_tree_view_get_model
                (GTK_TREE_VIEW (playlist->treeview));
@@ -948,8 +915,6 @@ totem_playlist_init (TotemPlaylist *playlist)
        init_config (playlist);
 
        gtk_widget_show_all (GTK_WIDGET (playlist));
-
-       g_object_unref (xml);
 }
 
 GtkWidget*
@@ -2115,6 +2080,7 @@ static void
 totem_playlist_class_init (TotemPlaylistClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        object_class->set_property = totem_playlist_set_property;
        object_class->get_property = totem_playlist_get_property;
@@ -2182,4 +2148,8 @@ totem_playlist_class_init (TotemPlaylistClass *klass)
                                         g_param_spec_boolean ("repeat", "Repeat",
                                                               "Whether repeat mode is enabled.", FALSE,
                                                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+       gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/totem/ui/playlist.ui");
+       gtk_widget_class_bind_template_child (widget_class, TotemPlaylist, remove_button);
+       gtk_widget_class_bind_template_child (widget_class, TotemPlaylist, treeview);
 }


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