[gnome-bluetooth/wip/fixes: 1/2] pairing-dialog: use a template to create the UI



commit dced8e71ef3ce20f9a9357e6890b14697dfb0bcc
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Fri Dec 19 14:49:13 2014 +0100

    pairing-dialog: use a template to create the UI

 lib/Makefile.am                                    |    8 +-
 lib/bluetooth-pairing-dialog.c                     |   40 ++-----
 lib/bluetooth-pairing-dialog.ui                    |  127 ++++++++++++++++++++
 ...tings.gresource.xml => bluetooth.gresource.xml} |    1 +
 lib/settings.ui                                    |  102 +---------------
 5 files changed, 145 insertions(+), 133 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index c110c27..36e4738 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -4,13 +4,13 @@ BUILT_SOURCES =
 
 lib_LTLIBRARIES = libgnome-bluetooth.la
 
-resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/settings.gresource.xml)
-bluetooth-settings-resources.c: settings.gresource.xml $(resource_files)
+resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/bluetooth.gresource.xml)
+bluetooth-settings-resources.c: bluetooth.gresource.xml $(resource_files)
        $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name 
bluetooth_settings $<
-bluetooth-settings-resources.h: settings.gresource.xml $(resource_files)
+bluetooth-settings-resources.h: bluetooth.gresource.xml $(resource_files)
        $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name 
bluetooth_settings $<
 
-EXTRA_DIST += settings.gresource.xml settings.ui
+EXTRA_DIST += bluetooth.gresource.xml settings.ui bluetooth-paring-dialog.ui
 BUILT_SOURCES += bluetooth-settings-resources.c bluetooth-settings-resources.h
 
 # will be scanned for introspection annotation, but won't be installed
diff --git a/lib/bluetooth-pairing-dialog.c b/lib/bluetooth-pairing-dialog.c
index 0bd57bc..20c7cd8 100644
--- a/lib/bluetooth-pairing-dialog.c
+++ b/lib/bluetooth-pairing-dialog.c
@@ -37,7 +37,6 @@
 typedef struct _BluetoothPairingDialogPrivate BluetoothPairingDialogPrivate;
 
 struct _BluetoothPairingDialogPrivate {
-       GtkBuilder           *builder;
        GtkWidget            *title;
        GtkWidget            *help_label;
        GtkWidget            *label_pin;
@@ -53,8 +52,6 @@ struct _BluetoothPairingDialogPrivate {
 
 G_DEFINE_TYPE_WITH_PRIVATE(BluetoothPairingDialog, bluetooth_pairing_dialog, GTK_TYPE_DIALOG)
 
-#define WID(s) GTK_WIDGET (gtk_builder_get_object (priv->builder, s))
-
 enum {
        CONFIRMATION_PAGE,
        DISPLAY_PAGE,
@@ -250,20 +247,7 @@ text_changed_cb (GObject    *gobject,
 static void
 bluetooth_pairing_dialog_init (BluetoothPairingDialog *self)
 {
-       BluetoothPairingDialogPrivate *priv = BLUETOOTH_PAIRING_DIALOG_GET_PRIVATE (self);
-       GError *error = NULL;
-
-       g_resources_register (bluetooth_settings_get_resource ());
-       priv->builder = gtk_builder_new ();
-       gtk_builder_set_translation_domain (priv->builder, GETTEXT_PACKAGE);
-       gtk_builder_add_from_resource (priv->builder,
-                                       "/org/gnome/bluetooth/settings.ui",
-                                       &error);
-       if (error != NULL) {
-               g_warning ("Could not load ui: %s", error->message);
-               g_error_free (error);
-               return;
-       }
+       gtk_widget_init_template (GTK_WIDGET (self));
 
        gtk_widget_set_size_request (GTK_WIDGET (self), 380, -1);
        gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
@@ -274,11 +258,9 @@ bluetooth_pairing_dialog_constructed (GObject *object)
 {
        BluetoothPairingDialog *self = BLUETOOTH_PAIRING_DIALOG (object);
        BluetoothPairingDialogPrivate *priv = BLUETOOTH_PAIRING_DIALOG_GET_PRIVATE (self);
-       GtkWidget *container, *header;
+       GtkWidget *header;
        GtkStyleContext *context;
 
-       container = gtk_dialog_get_content_area (GTK_DIALOG (self));
-
        /* Header */
        header = gtk_dialog_get_header_bar (GTK_DIALOG (self));
        priv->title = gtk_label_new ("");
@@ -308,18 +290,10 @@ bluetooth_pairing_dialog_constructed (GObject *object)
        g_signal_connect (G_OBJECT (priv->cancel), "clicked",
                          G_CALLBACK (response_cb), self);
        gtk_header_bar_pack_start (GTK_HEADER_BAR (header), priv->cancel);
-       gtk_widget_show_all (header);
-       gtk_window_set_titlebar (GTK_WINDOW (self), header);
        gtk_widget_grab_default (GTK_WIDGET (priv->done));
 
-       gtk_container_add (GTK_CONTAINER (container), WID ("pairing_dialog_box"));
-       priv->help_label = WID ("help_label");
-       priv->label_pin = WID ("label_pin");
-       priv->entry_pin = WID ("entry_pin");
        g_signal_connect (G_OBJECT (priv->entry_pin), "notify::text",
                          G_CALLBACK (text_changed_cb), self);
-       priv->pin_notebook = WID ("pin_notebook");
-       gtk_widget_set_no_show_all (priv->pin_notebook, TRUE);
 
        context = gtk_widget_get_style_context (priv->done);
        gtk_style_context_add_class (context, "suggested-action");
@@ -332,7 +306,6 @@ bluetooth_pairing_dialog_finalize (GObject *object)
 {
        BluetoothPairingDialogPrivate *priv = BLUETOOTH_PAIRING_DIALOG_GET_PRIVATE (BLUETOOTH_PAIRING_DIALOG 
(object));
 
-       g_clear_object (&priv->builder);
        g_free (priv->pin);
 
        G_OBJECT_CLASS(bluetooth_pairing_dialog_parent_class)->finalize(object);
@@ -342,11 +315,20 @@ static void
 bluetooth_pairing_dialog_class_init (BluetoothPairingDialogClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
        object_class->constructed = bluetooth_pairing_dialog_constructed;
        object_class->finalize = bluetooth_pairing_dialog_finalize;
+
+       /* Bind class to template */
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    "/org/gnome/bluetooth/bluetooth-pairing-dialog.ui");
+       gtk_widget_class_bind_template_child_private (widget_class, BluetoothPairingDialog, help_label);
+       gtk_widget_class_bind_template_child_private (widget_class, BluetoothPairingDialog, pin_notebook);
+       gtk_widget_class_bind_template_child_private (widget_class, BluetoothPairingDialog, entry_pin);
+       gtk_widget_class_bind_template_child_private (widget_class, BluetoothPairingDialog, label_pin);
 }
 
 /**
diff --git a/lib/bluetooth-pairing-dialog.ui b/lib/bluetooth-pairing-dialog.ui
new file mode 100644
index 0000000..74043d6
--- /dev/null
+++ b/lib/bluetooth-pairing-dialog.ui
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <template class="BluetoothPairingDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="pairing_dialog_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">50</property>
+            <property name="margin_end">50</property>
+            <property name="margin_top">24</property>
+            <property name="margin_bottom">30</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkLabel" id="help_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label">Please enter the following PIN on 'Foobar':</property>
+                <property name="justify">center</property>
+                <property name="wrap">True</property>
+                <property name="width_chars">40</property>
+                <property name="max_width_chars">40</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkNotebook" id="pin_notebook">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="no_show_all">True</property>
+                <property name="margin_top">24</property>
+                <property name="show_tabs">False</property>
+                <property name="show_border">False</property>
+                <child>
+                  <object class="GtkAspectFrame" id="aspectframe1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label_xalign">0</property>
+                    <property name="shadow_type">none</property>
+                    <child>
+                      <object class="GtkEntry" id="entry_pin">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="margin_start">25</property>
+                        <property name="margin_end">25</property>
+                        <property name="max_length">6</property>
+                        <property name="activates_default">True</property>
+                        <property name="width_chars">6</property>
+                        <property name="xalign">0.5</property>
+                        <property name="input_purpose">digits</property>
+                        <property name="input_hints">GTK_INPUT_HINT_NO_SPELLCHECK | 
GTK_INPUT_HINT_NONE</property>
+                        <style>
+                          <class name="pin-entry"/>
+                        </style>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label_pin">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label">123456</property>
+                    <style>
+                      <class name="pin-label"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label_placeholder">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/lib/settings.gresource.xml b/lib/bluetooth.gresource.xml
similarity index 71%
rename from lib/settings.gresource.xml
rename to lib/bluetooth.gresource.xml
index 58813cf..7d238d1 100644
--- a/lib/settings.gresource.xml
+++ b/lib/bluetooth.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gnome/bluetooth">
     <file preprocess="xml-stripblanks">settings.ui</file>
+    <file preprocess="xml-stripblanks">bluetooth-pairing-dialog.ui</file>
   </gresource>
 </gresources>
diff --git a/lib/settings.ui b/lib/settings.ui
index a4b568a..315be43 100644
--- a/lib/settings.ui
+++ b/lib/settings.ui
@@ -1,98 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.0 on Thu Dec  5 15:20:37 2013 -->
+<!-- Generated with glade 3.18.3 -->
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkBox" id="pairing_dialog_box">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="margin_start">50</property>
-    <property name="margin_end">50</property>
-    <property name="margin_top">24</property>
-    <property name="margin_bottom">30</property>
-    <property name="orientation">vertical</property>
-    <child>
-      <object class="GtkLabel" id="help_label">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <!-- placeholder text: never appears in the actual UI -->
-        <property name="label">Please enter the following PIN on 'Foobar':</property>
-        <property name="justify">center</property>
-        <property name="wrap">True</property>
-        <property name="width_chars">40</property>
-        <property name="max_width_chars">40</property>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="fill">True</property>
-        <property name="position">0</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkNotebook" id="pin_notebook">
-        <property name="visible">True</property>
-        <property name="can_focus">True</property>
-        <property name="margin_top">24</property>
-        <property name="show_tabs">False</property>
-        <property name="show_border">False</property>
-        <child>
-          <object class="GtkAspectFrame" id="aspectframe1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label_xalign">0</property>
-            <property name="shadow_type">none</property>
-            <child>
-              <object class="GtkEntry" id="entry_pin">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="margin_start">25</property>
-                <property name="margin_end">25</property>
-                <property name="max_length">6</property>
-                <property name="width_chars">6</property>
-                <property name="xalign">0.5</property>
-                <property name="input_purpose">digits</property>
-                <property name="input_hints">GTK_INPUT_HINT_NO_SPELLCHECK | GTK_INPUT_HINT_NONE</property>
-                <property name="activates-default">True</property>
-                <style>
-                  <class name="pin-entry"/>
-                </style>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label_pin">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label">123456</property>
-            <style>
-              <class name="pin-label"/>
-            </style>
-          </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label_placeholder">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label"></property>
-          </object>
-          <packing>
-            <property name="position">2</property>
-          </packing>
-        </child>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="fill">True</property>
-        <property name="position">1</property>
-      </packing>
-    </child>
-    <child>
-      <placeholder/>
-    </child>
-  </object>
+  <requires lib="gtk+" version="3.0"/>
   <object class="GtkBox" id="properties_vbox">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -462,11 +371,4 @@
     <property name="orientation">vertical</property>
     <property name="spacing">3</property>
   </object>
-  <object class="GtkSizeGroup" id="sizegroup1">
-    <property name="mode">both</property>
-    <widgets>
-      <widget name="entry_pin"/>
-      <widget name="label_pin"/>
-    </widgets>
-  </object>
 </interface>


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