[easytag/wip/future-gtk: 9/17] Convert EtFileArea to a template widget



commit bad0da2ead8a67e281317e7b8b23e31a0cecd3f7
Author: David King <amigadave amigadave com>
Date:   Sat May 2 08:33:54 2015 +0100

    Convert EtFileArea to a template widget

 data/file_area.ui |  320 +++++++++++++++++++++++++++--------------------------
 src/file_area.c   |  117 +++++++-------------
 2 files changed, 204 insertions(+), 233 deletions(-)
---
diff --git a/data/file_area.ui b/data/file_area.ui
index e60ce50..27903e4 100644
--- a/data/file_area.ui
+++ b/data/file_area.ui
@@ -1,76 +1,32 @@
 <interface domain="easytag">
-    <requires lib="gtk+" version="3.4"/>
-    <object class="GtkGrid" id="file_grid">
-        <property name="border-width">6</property>
-        <property name="column-spacing">6</property>
-        <property name="row-spacing">6</property>
+    <requires lib="gtk+" version="3.10"/>
+    <template class="EtFileArea" parent="GtkBin">
         <property name="visible">True</property>
         <child>
-            <object class="GtkLabel" id="file_label">
-                <property name="halign">start</property>
-                <property name="label" translatable="yes">File</property>
-                <property name="visible">True</property>
-                <attributes>
-                    <attribute name="weight" value="bold"/>
-                </attributes>
-            </object>
-            <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">0</property>
-                <property name="width">2</property>
-            </packing>
-        </child>
-        <child>
-            <object class="GtkLabel" id="index_label">
-                <property name="label" translatable="yes">0/0:</property>
-                <property name="margin-left">12</property>
-                <property name="visible">True</property>
-            </object>
-            <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">1</property>
-            </packing>
-        </child>
-        <child>
-            <object class="GtkEntry" id="filename_entry">
-                <property name="hexpand">True</property>
-                <property name="visible">True</property>
-            </object>
-            <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">1</property>
-            </packing>
-        </child>
-        <child>
-            <object class="GtkGrid" id="header_grid">
+            <object class="GtkGrid" id="file_grid">
+                <property name="border-width">6</property>
                 <property name="column-spacing">6</property>
-                <property name="margin-left">12</property>
-                <property name="visible">true</property>
-                <child>
-                    <object class="GtkLabel" id="version_label">
-                        <property name="halign">end</property>
-                        <property name="label" translatable="yes">Encoder:</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="left-attach">0</property>
-                        <property name="top-attach">0</property>
-                    </packing>
-                </child>
+                <property name="row-spacing">6</property>
+                <property name="visible">True</property>
                 <child>
-                    <object class="GtkLabel" id="version_value_label">
+                    <object class="GtkLabel" id="file_label">
                         <property name="halign">start</property>
+                        <property name="label" translatable="yes">File</property>
                         <property name="visible">True</property>
+                        <attributes>
+                            <attribute name="weight" value="bold"/>
+                        </attributes>
                     </object>
                     <packing>
-                        <property name="left-attach">1</property>
+                        <property name="left-attach">0</property>
                         <property name="top-attach">0</property>
+                        <property name="width">2</property>
                     </packing>
                 </child>
                 <child>
-                    <object class="GtkLabel" id="bitrate_label">
-                        <property name="halign">end</property>
-                        <property name="label" translatable="yes">Bitrate:</property>
+                    <object class="GtkLabel" id="index_label">
+                        <property name="label" translatable="yes">0/0:</property>
+                        <property name="margin-left">12</property>
                         <property name="visible">True</property>
                     </object>
                     <packing>
@@ -79,9 +35,10 @@
                     </packing>
                 </child>
                 <child>
-                    <object class="GtkLabel" id="bitrate_value_label">
-                        <property name="halign">start</property>
+                    <object class="GtkEntry" id="name_entry">
+                        <property name="hexpand">True</property>
                         <property name="visible">True</property>
+                        <signal name="populate-popup" handler="on_entry_populate_popup"/>
                     </object>
                     <packing>
                         <property name="left-attach">1</property>
@@ -89,106 +46,155 @@
                     </packing>
                 </child>
                 <child>
-                    <object class="GtkLabel" id="samplerate_label">
-                        <property name="halign">end</property>
-                        <property name="label" translatable="yes">Sample rate:</property>
-                        <property name="visible">True</property>
+                    <object class="GtkGrid" id="header_grid">
+                        <property name="column-spacing">6</property>
+                        <property name="margin-left">12</property>
+                        <property name="visible">true</property>
+                        <child>
+                            <object class="GtkLabel" id="version_label">
+                                <property name="halign">end</property>
+                                <property name="label" translatable="yes">Encoder:</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">0</property>
+                                <property name="top-attach">0</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="version_value_label">
+                                <property name="halign">start</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">1</property>
+                                <property name="top-attach">0</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="bitrate_label">
+                                <property name="halign">end</property>
+                                <property name="label" translatable="yes">Bitrate:</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">0</property>
+                                <property name="top-attach">1</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="bitrate_value_label">
+                                <property name="halign">start</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">1</property>
+                                <property name="top-attach">1</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="samplerate_label">
+                                <property name="halign">end</property>
+                                <property name="label" translatable="yes">Sample rate:</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">0</property>
+                                <property name="top-attach">2</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="samplerate_value_label">
+                                <property name="halign">start</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">1</property>
+                                <property name="top-attach">2</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkSeparator" id="field_separator">
+                                <property name="orientation">vertical</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="height">3</property>
+                                <property name="left-attach">2</property>
+                                <property name="top-attach">0</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="mode_label">
+                                <property name="halign">end</property>
+                                <property name="label" translatable="yes">Mode:</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">3</property>
+                                <property name="top-attach">0</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="mode_value_label">
+                                <property name="halign">start</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">4</property>
+                                <property name="top-attach">0</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="size_label">
+                                <property name="halign">end</property>
+                                <property name="label" translatable="yes">Size:</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">3</property>
+                                <property name="top-attach">1</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="size_value_label">
+                                <property name="halign">start</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">4</property>
+                                <property name="top-attach">1</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="duration_label">
+                                <property name="halign">end</property>
+                                <property name="label" translatable="yes">Duration:</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">3</property>
+                                <property name="top-attach">2</property>
+                            </packing>
+                        </child>
+                        <child>
+                            <object class="GtkLabel" id="duration_value_label">
+                                <property name="halign">start</property>
+                                <property name="visible">True</property>
+                            </object>
+                            <packing>
+                                <property name="left-attach">4</property>
+                                <property name="top-attach">2</property>
+                            </packing>
+                        </child>
                     </object>
                     <packing>
                         <property name="left-attach">0</property>
-                        <property name="top-attach">2</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkLabel" id="samplerate_value_label">
-                        <property name="halign">start</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="left-attach">1</property>
-                        <property name="top-attach">2</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkSeparator" id="field_separator">
-                        <property name="orientation">vertical</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="height">3</property>
-                        <property name="left-attach">2</property>
-                        <property name="top-attach">0</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkLabel" id="mode_label">
-                        <property name="halign">end</property>
-                        <property name="label" translatable="yes">Mode:</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="left-attach">3</property>
-                        <property name="top-attach">0</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkLabel" id="mode_value_label">
-                        <property name="halign">start</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="left-attach">4</property>
-                        <property name="top-attach">0</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkLabel" id="size_label">
-                        <property name="halign">end</property>
-                        <property name="label" translatable="yes">Size:</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="left-attach">3</property>
-                        <property name="top-attach">1</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkLabel" id="size_value_label">
-                        <property name="halign">start</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="left-attach">4</property>
-                        <property name="top-attach">1</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkLabel" id="duration_label">
-                        <property name="halign">end</property>
-                        <property name="label" translatable="yes">Duration:</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="left-attach">3</property>
-                        <property name="top-attach">2</property>
-                    </packing>
-                </child>
-                <child>
-                    <object class="GtkLabel" id="duration_value_label">
-                        <property name="halign">start</property>
-                        <property name="visible">True</property>
-                    </object>
-                    <packing>
-                        <property name="left-attach">4</property>
-                        <property name="top-attach">2</property>
+                        <property name="top-attach">3</property>
+                        <property name="width">2</property>
                     </packing>
                 </child>
             </object>
-            <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">3</property>
-                <property name="width">2</property>
-            </packing>
         </child>
-    </object>
+    </template>
 </interface>
diff --git a/src/file_area.c b/src/file_area.c
index b0028c0..e14f584 100644
--- a/src/file_area.c
+++ b/src/file_area.c
@@ -1,5 +1,5 @@
 /* EasyTAG - tag editor for audio files
- * Copyright (C) 2014  David King <amigadave amigadave com>
+ * Copyright (C) 2014-2015  David King <amigadave amigadave com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -73,76 +73,9 @@ on_file_show_header_changed (EtFileArea *self,
 }
 
 static void
-create_file_area (EtFileArea *self)
+et_file_area_init (EtFileArea *self)
 {
-    EtFileAreaPrivate *priv;
-    GtkBuilder *builder;
-    GError *error = NULL;
-    GtkWidget *grid;
-
-    priv = et_file_area_get_instance_private (self);
-
-    builder = gtk_builder_new ();
-    gtk_builder_add_from_resource (builder,
-                                   "/org/gnome/EasyTAG/file_area.ui",
-                                   &error);
-
-    if (error != NULL)
-    {
-        g_error ("Unable to get file area from resource: %s",
-                 error->message);
-    }
-
-    grid = GTK_WIDGET (gtk_builder_get_object (builder, "file_grid"));
-    gtk_container_add (GTK_CONTAINER (self), grid);
-
-    priv->file_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                           "file_label"));
-
-    priv->index_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                            "index_label"));
-
-    /* Filename. */
-    priv->name_entry = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                           "filename_entry"));
-
-    g_signal_connect (priv->name_entry, "populate-popup",
-                      G_CALLBACK (on_entry_populate_popup), NULL);
-
-    /* File information. */
-    priv->header_grid = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                            "header_grid"));
-    priv->version_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                              "version_label"));
-    priv->version_value_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                                    "version_value_label"));
-
-    priv->bitrate_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                              "bitrate_label"));
-    priv->bitrate_value_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                                    "bitrate_value_label"));
-
-    priv->samplerate_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                                 "samplerate_label"));
-    priv->samplerate_value_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                                       "samplerate_value_label"));
-
-    priv->mode_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                           "mode_label"));
-    priv->mode_value_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                                 "mode_value_label"));
-
-    priv->size_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                           "size_label"));
-    priv->size_value_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                                 "size_value_label"));
-
-    priv->duration_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                               "duration_label"));
-    priv->duration_value_label = GTK_WIDGET (gtk_builder_get_object (builder,
-                                                                     "duration_value_label"));
-
-    g_object_unref (builder);
+    gtk_widget_init_template (GTK_WIDGET (self));
 
     g_signal_connect_swapped (MainSettings, "changed::file-show-header",
                               G_CALLBACK (on_file_show_header_changed), self);
@@ -150,14 +83,46 @@ create_file_area (EtFileArea *self)
 }
 
 static void
-et_file_area_init (EtFileArea *self)
-{
-    create_file_area (self);
-}
-
-static void
 et_file_area_class_init (EtFileAreaClass *klass)
 {
+    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+    gtk_widget_class_set_template_from_resource (widget_class,
+                                                 "/org/gnome/EasyTAG/file_area.ui");
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  file_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  index_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  name_entry);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  header_grid);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  version_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  version_value_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  bitrate_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  bitrate_value_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  samplerate_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  samplerate_value_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  mode_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  mode_value_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  size_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  size_value_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  duration_label);
+    gtk_widget_class_bind_template_child_private (widget_class, EtFileArea,
+                                                  duration_value_label);
+    gtk_widget_class_bind_template_callback (widget_class,
+                                             on_entry_populate_popup);
 }
 
 /*


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