[gnome-boxes] auth-notification: Move UI setup to .ui file



commit c5e68ee05a0c69fbcaa46943022fcb9277d858ce
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Feb 6 13:19:35 2014 +0000

    auth-notification: Move UI setup to .ui file

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/auth-notification.ui   |  125 ++++++++++++++++++++++++++++++++++++++++
 src/auth-notification.vala     |  105 ++++++++++++++-------------------
 3 files changed, 170 insertions(+), 61 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 3257a5a..8d1bde1 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -6,6 +6,7 @@
     <file>icons/boxes-create.png</file>
     <file>icons/boxes-dark.png</file>
     <file>icons/boxes-gray.png</file>
+    <file preprocess="xml-stripblanks">ui/auth-notification.ui</file>
     <file preprocess="xml-stripblanks">ui/display-page.ui</file>
     <file preprocess="xml-stripblanks">ui/display-toolbar.ui</file>
     <file preprocess="xml-stripblanks">ui/empty-boxes.ui</file>
diff --git a/data/ui/auth-notification.ui b/data/ui/auth-notification.ui
new file mode 100644
index 0000000..50d8bf6
--- /dev/null
+++ b/data/ui/auth-notification.ui
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.9 -->
+  <template class="BoxesAuthNotification" parent="GdNotification">
+    <property name="visible">True</property>
+    <property name="valign">start</property>
+    <property name="timeout">-1</property>
+
+    <child>
+      <object class="GtkGrid" id="grid">
+        <property name="visible">True</property>
+        <property name="column-spacing">12</property>
+        <property name="row-spacing">6</property>
+        <property name="border-width">6</property>
+
+        <child>
+          <object class="GtkLabel" id="title_label">
+            <property name="visible">True</property>
+            <property name="use-markup">True</property>
+            <property name="halign">start</property>
+            <property name="margin-bottom">18</property>
+          </object>
+
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">0</property>
+            <property name="width">2</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="username_label">
+            <property name="visible">True</property>
+            <property name="use-underline">True</property>
+            <property name="margin-left">12</property>
+            <property name="label" translatable="yes">_Username</property>
+            <property name="mnemonic-widget">username_entry</property>
+          </object>
+
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkEntry" id="username_entry">
+            <property name="visible">True</property>
+            <signal name="focus-in-event" handler="on_entry_focus_in_event"/>
+            <signal name="focus-out-event" handler="on_entry_focus_out_event"/>
+            <signal name="map" handler="on_username_entry_map"/>
+            <signal name="activate" handler="on_username_entry_activated"/>
+          </object>
+
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="password_label">
+            <property name="visible">True</property>
+            <property name="use-underline">True</property>
+            <property name="margin-left">12</property>
+            <property name="label" translatable="yes">_Password</property>
+            <property name="mnemonic-widget">password_entry</property>
+          </object>
+
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkEntry" id="password_entry">
+            <property name="visible">True</property>
+            <property name="visibility">False</property>
+            <signal name="focus-in-event" handler="on_entry_focus_in_event"/>
+            <signal name="focus-out-event" handler="on_entry_focus_out_event"/>
+            <signal name="activate" handler="on_password_entry_activated"/>
+          </object>
+
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkButton" id="auth_button">
+            <property name="visible">True</property>
+            <property name="halign">end</property>
+            <signal name="clicked" handler="on_auth_button_clicked"/>
+
+            <child>
+              <object class="GtkLabel" id="auth_button_label">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Sign In</property>
+              </object>
+            </child>
+          </object>
+
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">3</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/auth-notification.vala b/src/auth-notification.vala
index ec7669c..eb753da 100644
--- a/src/auth-notification.vala
+++ b/src/auth-notification.vala
@@ -1,80 +1,63 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 using Gtk;
 
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/auth-notification.ui")]
 private class Boxes.AuthNotification: Gd.Notification {
     public delegate void AuthFunc (string username, string password);
 
+    [GtkChild]
+    private Gtk.Label title_label;
+    [GtkChild]
+    private Gtk.Entry username_entry;
+    [GtkChild]
+    private Gtk.Entry password_entry;
+    [GtkChild]
+    private Gtk.Button auth_button;
+
+    private AuthFunc? auth_func;
+
     public AuthNotification (string                         auth_string,
                              owned AuthFunc?                auth_func,
                              owned Notification.CancelFunc? cancel_func) {
-        valign = Gtk.Align.START;
-        timeout = -1;
-        show_close_button = false;
+        show_close_button = false; // FIXME: Seems setting this from .UI file doesn't work
+        title_label.label = "<span font-weight=\"bold\">" + _("Sign In to %s").printf(auth_string) + 
"</span>";
 
-        var title_label = new Gtk.Label (null);
-        string title_str = "<span font-weight=\"bold\">" + _("Sign In to %s").printf(auth_string) + 
"</span>";
+        this.auth_func = (owned) auth_func;
+    }
 
-        title_label.set_markup (title_str);
-        title_label.halign = Gtk.Align.START;
-        title_label.margin_bottom = 18;
+    [GtkCallback]
+    private bool on_entry_focus_in_event () {
+        App.app.searchbar.enable_key_handler = false;
 
-        var username_label = new Gtk.Label.with_mnemonic (_("_Username"));
-        var username_entry = new Gtk.Entry ();
-        username_entry.focus_in_event.connect ( () => {
-            App.app.searchbar.enable_key_handler = false;
-            return false;
-        });
-        username_entry.focus_out_event.connect ( () => {
-            App.app.searchbar.enable_key_handler = true;
-            return false;
-        });
-        username_entry.map.connect ( () => {
-            username_entry.grab_focus ();
-        });
-        username_label.mnemonic_widget = username_entry;
-        username_label.margin_left = 12;
-        var password_label = new Gtk.Label.with_mnemonic (_("_Password"));
-        var password_entry = new Gtk.Entry ();
-        password_entry.visibility = false;
-        password_entry.focus_in_event.connect ( () => {
-            App.app.searchbar.enable_key_handler = false;
-            return false;
-        });
-        password_entry.focus_out_event.connect ( () => {
-            App.app.searchbar.enable_key_handler = true;
-            return false;
-        });
-        password_label.mnemonic_widget = password_entry;
-        password_label.margin_left = 12;
+        return false;
+    }
 
-        var auth_button = new Button.from_stock (_("Sign In"));
-        auth_button.halign = Gtk.Align.END;
+    [GtkCallback]
+    private bool on_entry_focus_out_event () {
+        App.app.searchbar.enable_key_handler = true;
 
-        auth_button.clicked.connect ( () => {
-            if (auth_func != null)
-                 auth_func (username_entry.get_text (), password_entry.get_text ());
-            dismiss ();
-        });
+        return false;
+    }
 
-        username_entry.activate.connect (() => {
-            password_entry.grab_focus ();
-        });
-        password_entry.activate.connect (() => {
-            auth_button.activate ();
-        });
+    [GtkCallback]
+    private void on_username_entry_map () {
+        username_entry.grab_focus ();
+    }
+
+    [GtkCallback]
+    private void on_username_entry_activated () {
+        password_entry.grab_focus ();
+    }
 
-        var grid = new Gtk.Grid ();
-        grid.column_spacing = 12;
-        grid.row_spacing = 6;
-        grid.border_width = 6;
-        grid.attach (title_label, 0, 0, 2, 1);
-        grid.attach (username_label, 0, 1, 1, 1);
-        grid.attach (username_entry, 1, 1, 1, 1);
-        grid.attach (password_label, 0, 2, 1, 1);
-        grid.attach (password_entry, 1, 2, 1, 1);
-        grid.attach (auth_button, 1, 3, 1, 1);
-        add (grid);
+    [GtkCallback]
+    private void on_password_entry_activated () {
+        auth_button.activate ();
+    }
 
-        show_all ();
+    [GtkCallback]
+    private void on_auth_button_clicked () {
+        if (auth_func != null)
+            auth_func (username_entry.get_text (), password_entry.get_text ());
+        dismiss ();
     }
 }


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