[gtk+/composite-templates-new: 13/32] GtkLockButton: Define children with a GtkBuilder template



commit 7b1316dc219d73e0b3ba7dd77d70b8a5005993fc
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sat Mar 23 17:52:48 2013 +0900

    GtkLockButton: Define children with a GtkBuilder template

 gtk/Makefile.am       |    1 +
 gtk/gtk.gresource.xml |    1 +
 gtk/gtklockbutton.c   |   31 +++++++----------------
 gtk/gtklockbutton.ui  |   64 +++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/tests/templates.c |   14 ++++++++++
 po/POTFILES.in        |    1 +
 6 files changed, 91 insertions(+), 21 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 0f39748..7311eb2 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1098,6 +1098,7 @@ COMPOSITE_TEMPLATES =                     \
        gtkaboutdialog.ui               \
        gtkdialog.ui                    \
        gtkinfobar.ui                   \
+       gtklockbutton.ui                \
        gtkmessagedialog.ui
 
 #
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index 1aef6c6..e1c44dd 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -14,6 +14,7 @@
     <file>gtkaboutdialog.ui</file>
     <file>gtkdialog.ui</file>
     <file>gtkinfobar.ui</file>
+    <file>gtklockbutton.ui</file>
     <file>gtkmessagedialog.ui</file>
   </gresource>
 </gresources>
diff --git a/gtk/gtklockbutton.c b/gtk/gtklockbutton.c
index 962b4a9..b8a1621 100644
--- a/gtk/gtklockbutton.c
+++ b/gtk/gtklockbutton.c
@@ -108,7 +108,6 @@ gtk_lock_button_finalize (GObject *object)
 
   g_object_unref (priv->icon_lock);
   g_object_unref (priv->icon_unlock);
-  g_object_unref (priv->label_group);
 
   if (priv->cancellable != NULL)
     {
@@ -226,26 +225,7 @@ gtk_lock_button_init (GtkLockButton *button)
                                                      GTK_TYPE_LOCK_BUTTON,
                                                      GtkLockButtonPrivate);
 
-  priv->label_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
-  priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-  gtk_widget_set_halign (priv->box, GTK_ALIGN_CENTER);
-  gtk_widget_set_valign (priv->box, GTK_ALIGN_CENTER);
-  gtk_widget_show (priv->box);
-  gtk_container_add (GTK_CONTAINER (button), priv->box);
-  priv->image = gtk_image_new ();
-  gtk_box_pack_start (GTK_BOX (priv->box), priv->image, FALSE, FALSE, 0);
-  gtk_widget_show (priv->image);
-  priv->label_lock = gtk_label_new ("");
-  gtk_misc_set_alignment (GTK_MISC (priv->label_lock), 0, 0.5);
-  gtk_widget_set_no_show_all (priv->label_lock, TRUE);
-  gtk_widget_show (priv->label_lock);
-  gtk_box_pack_start (GTK_BOX (priv->box), priv->label_lock, FALSE, FALSE, 0);
-  gtk_size_group_add_widget (priv->label_group, priv->label_lock);
-  priv->label_unlock = gtk_label_new ("");
-  gtk_misc_set_alignment (GTK_MISC (priv->label_unlock), 0, 0.5);
-  gtk_widget_set_no_show_all (priv->label_unlock, TRUE);
-  gtk_box_pack_start (GTK_BOX (priv->box), priv->label_unlock, FALSE, FALSE, 0);
-  gtk_size_group_add_widget (priv->label_group, priv->label_unlock);
+  gtk_widget_init_template (GTK_WIDGET (button));
 
   names[0] = "changes-allow-symbolic";
   names[1] = "changes-allow";
@@ -328,6 +308,15 @@ gtk_lock_button_class_init (GtkLockButtonClass *klass)
                          G_PARAM_CONSTRUCT |
                          G_PARAM_STATIC_STRINGS));
 
+  /* Bind class to template
+   */
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtklockbutton.ui");
+  gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, box);
+  gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, image);
+  gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, label_lock);
+  gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, label_unlock);
+  gtk_widget_class_bind_child (widget_class, GtkLockButtonPrivate, label_group);
+
   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LOCK_BUTTON_ACCESSIBLE);
 }
 
diff --git a/gtk/gtklockbutton.ui b/gtk/gtklockbutton.ui
new file mode 100644
index 0000000..5229a38
--- /dev/null
+++ b/gtk/gtklockbutton.ui
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <!-- interface-requires gtk+ 3.6 -->
+  <template class="GtkLockButton" parent="GtkButton">
+    <property name="visible">True</property>
+    <property name="can_focus">True</property>
+    <property name="receives_default">True</property>
+    <child>
+      <object class="GtkBox" id="box">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">center</property>
+        <property name="valign">center</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkImage" id="image">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="stock">gtk-missing-image</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_lock">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="no_show_all">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Lock</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_unlock">
+            <property name="can_focus">False</property>
+            <property name="no_show_all">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">Unlock</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+  <object class="GtkSizeGroup" id="label_group">
+    <property name="mode">both</property>
+    <widgets>
+      <widget name="label_lock"/>
+      <widget name="label_unlock"/>
+    </widgets>
+  </object>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index 56d09a6..fb43fbc 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -75,6 +75,19 @@ test_info_bar_basic (void)
   gtk_widget_destroy (infobar);
 }
 
+static void
+test_lock_button_basic (void)
+{
+  GtkWidget *button;
+  GPermission *permission;
+
+  permission = g_simple_permission_new (TRUE);
+  button = gtk_lock_button_new (permission);
+  g_assert (GTK_IS_LOCK_BUTTON (button));
+  gtk_widget_destroy (button);
+  g_object_unref (permission);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -92,6 +105,7 @@ main (int argc, char **argv)
   g_test_add_func ("/Template/GtkMessageDialog/Basic", test_message_dialog_basic);
   g_test_add_func ("/Template/GtkAboutDialog/Basic", test_about_dialog_basic);
   g_test_add_func ("/Template/GtkInfoBar/Basic", test_info_bar_basic);
+  g_test_add_func ("/Template/GtkLockButton/Basic", test_lock_button_basic);
 
   return g_test_run();
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b011511..fce4726 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -277,4 +277,5 @@ modules/printbackends/test/gtkprintbackendtest.c
 [type: gettext/glade]gtk/gtkaboutdialog.ui
 [type: gettext/glade]gtk/gtkdialog.ui
 [type: gettext/glade]gtk/gtkinfobar.ui
+[type: gettext/glade]gtk/gtklockbutton.ui
 [type: gettext/glade]gtk/gtkmessagedialog.ui


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