[gnome-boxes] notificationbar: Seperate classes for Notifications



commit f43cdc474686039c661709b97e92ae9e4e894322
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Feb 5 22:41:08 2014 +0000

    notificationbar: Seperate classes for Notifications
    
    Put notifications themselves into seperate classes/modules.

 src/Makefile.am                     |    2 +
 src/app.vala                        |    4 +-
 src/auth-notification.vala          |   80 +++++++++++++++++++
 src/libvirt-machine-properties.vala |    2 +-
 src/notification.vala               |   51 ++++++++++++
 src/notificationbar.vala            |  147 ++++++-----------------------------
 src/ovirt-broker.vala               |    4 +-
 7 files changed, 163 insertions(+), 127 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 239b86b..26c95a5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -92,6 +92,7 @@ gnome_boxes_SOURCES =                         \
        $(BUILT_SOURCES)                        \
        clutter-widget.vala                     \
        app.vala                                \
+       auth-notification.vala                  \
        collection-view.vala                    \
        collection.vala                         \
        display-page.vala                       \
@@ -110,6 +111,7 @@ gnome_boxes_SOURCES =                               \
        main.vala                               \
        media-manager.vala                      \
        mini-graph.vala                         \
+       notification.vala                       \
        notificationbar.vala                    \
        os-database.vala                        \
        properties.vala                         \
diff --git a/src/app.vala b/src/app.vala
index 9da8541..ea3305c 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -831,14 +831,14 @@ private class Boxes.App: GLib.Object, Boxes.UI {
         foreach (var item in selected_items)
             collection.remove_item (item);
 
-        Notificationbar.OKFunc undo = () => {
+        Notification.OKFunc undo = () => {
             debug ("Box deletion cancelled by user, re-adding to view");
             foreach (var selected in selected_items) {
                 collection.add_item (selected);
             }
         };
 
-        Notificationbar.CancelFunc really_remove = () => {
+        Notification.CancelFunc really_remove = () => {
             debug ("Box deletion, deleting now");
             foreach (var selected in selected_items) {
                 var machine = selected as Machine;
diff --git a/src/auth-notification.vala b/src/auth-notification.vala
new file mode 100644
index 0000000..ec7669c
--- /dev/null
+++ b/src/auth-notification.vala
@@ -0,0 +1,80 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+private class Boxes.AuthNotification: Gd.Notification {
+    public delegate void AuthFunc (string username, string password);
+
+    public AuthNotification (string                         auth_string,
+                             owned AuthFunc?                auth_func,
+                             owned Notification.CancelFunc? cancel_func) {
+        valign = Gtk.Align.START;
+        timeout = -1;
+        show_close_button = false;
+
+        var title_label = new Gtk.Label (null);
+        string title_str = "<span font-weight=\"bold\">" + _("Sign In to %s").printf(auth_string) + 
"</span>";
+
+        title_label.set_markup (title_str);
+        title_label.halign = Gtk.Align.START;
+        title_label.margin_bottom = 18;
+
+        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;
+
+        var auth_button = new Button.from_stock (_("Sign In"));
+        auth_button.halign = Gtk.Align.END;
+
+        auth_button.clicked.connect ( () => {
+            if (auth_func != null)
+                 auth_func (username_entry.get_text (), password_entry.get_text ());
+            dismiss ();
+        });
+
+        username_entry.activate.connect (() => {
+            password_entry.grab_focus ();
+        });
+        password_entry.activate.connect (() => {
+            auth_button.activate ();
+        });
+
+        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);
+
+        show_all ();
+    }
+}
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 25d4933..84cc1e7 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -511,7 +511,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
 
         shutdown_timeout = Timeout.add_seconds (5, () => {
             // Seems guest ignored ACPI shutdown, lets force shutdown with user's consent
-            Notificationbar.OKFunc really_force_shutdown = () => {
+            Notification.OKFunc really_force_shutdown = () => {
                 notification = null;
                 machine.force_shutdown (false);
             };
diff --git a/src/notification.vala b/src/notification.vala
new file mode 100644
index 0000000..38703b0
--- /dev/null
+++ b/src/notification.vala
@@ -0,0 +1,51 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+using Gtk;
+
+private class Boxes.Notification: Gd.Notification {
+    public const int DEFAULT_TIMEOUT = 6;
+
+    public delegate void OKFunc ();
+    public delegate void CancelFunc ();
+
+    public Notification (string            message,
+                         MessageType       message_type,
+                         string?           ok_label,
+                         owned OKFunc?     ok_func,
+                         owned CancelFunc? cancel_func,
+                         int               timeout) {
+        valign = Gtk.Align.START;
+        this.timeout = timeout;
+
+        bool ok_pressed = false;
+        dismissed.connect ( () => {
+            if (!ok_pressed && cancel_func != null)
+                cancel_func ();
+        });
+
+        var grid = new Gtk.Grid ();
+        grid.set_orientation (Gtk.Orientation.HORIZONTAL);
+        grid.margin_left = 12;
+        grid.margin_right = 12;
+        grid.column_spacing = 12;
+        grid.valign = Gtk.Align.CENTER;
+        add (grid);
+
+        var message_label = new Label (message);
+        grid.add (message_label);
+
+        if (ok_label != null) {
+            var ok_button = new Button.with_mnemonic (ok_label);
+            ok_button.halign = Gtk.Align.END;
+            grid.add (ok_button);
+
+            ok_button.clicked.connect ( () => {
+                ok_pressed = true;
+                if (ok_func != null)
+                    ok_func ();
+                dismiss ();
+            });
+        }
+
+        show_all ();
+    }
+}
diff --git a/src/notificationbar.vala b/src/notificationbar.vala
index dcbfca9..c892905 100644
--- a/src/notificationbar.vala
+++ b/src/notificationbar.vala
@@ -6,10 +6,6 @@ private class Boxes.Notificationbar: GLib.Object {
 
     public Clutter.Actor actor { get { return gtk_actor; } }
 
-    public delegate void OKFunc ();
-    public delegate void CancelFunc ();
-    public delegate void AuthenticateFunc (string username, string password);
-
     private GtkClutter.Actor gtk_actor;
     private Gtk.Grid top_grid;
 
@@ -40,18 +36,18 @@ private class Boxes.Notificationbar: GLib.Object {
         });
     }
 
-    public Gd.Notification display_for_action (string            message,
-                                               string            action_label,
-                                               owned OKFunc      action_func,
-                                               owned CancelFunc? ignore_func = null,
-                                               int               timeout = DEFAULT_TIMEOUT) {
+    public Gd.Notification display_for_action (string                         message,
+                                               string                         action_label,
+                                               owned Notification.OKFunc      action_func,
+                                               owned Notification.CancelFunc? ignore_func = null,
+                                               int                            timeout = DEFAULT_TIMEOUT) {
         return display (message, MessageType.INFO, action_label, (owned) action_func, (owned) ignore_func, 
timeout);
     }
 
-    public Gd.Notification display_for_authentication (string broker_name,
-                                                       owned AuthenticateFunc? auth_func,
-                                                       owned CancelFunc? cancel_func) {
-        Notificationbar.OKFunc next_auth_step = () => {
+    public Gd.Notification display_for_authentication (string                           broker_name,
+                                                       owned AuthNotification.AuthFunc? auth_func,
+                                                       owned Notification.CancelFunc?   cancel_func) {
+        Notification.OKFunc next_auth_step = () => {
             display_for_auth_next (broker_name, (owned) auth_func, (owned) cancel_func);
         };
         return display_for_action (_("Not connected to %s").printf (broker_name),
@@ -60,13 +56,10 @@ private class Boxes.Notificationbar: GLib.Object {
                                    (owned) cancel_func, -1);
     }
 
-    private Gd.Notification display_for_auth_next (string auth_string,
-                                                   owned AuthenticateFunc? auth_func,
-                                                   owned CancelFunc? cancel_func) {
-        var notification = new Gd.Notification ();
-        notification.valign = Gtk.Align.START;
-        notification.timeout = -1;
-        notification.show_close_button = false;
+    private Gd.Notification display_for_auth_next (string                           auth_string,
+                                                   owned AuthNotification.AuthFunc? auth_func,
+                                                   owned Notification.CancelFunc?   cancel_func) {
+        var notification = new Boxes.AuthNotification (auth_string, (owned) auth_func, (owned) cancel_func);
 
         active_notifications.prepend (notification);
 
@@ -74,72 +67,7 @@ private class Boxes.Notificationbar: GLib.Object {
             active_notifications.remove (notification);
         });
 
-        var title_label = new Gtk.Label (null);
-        string title_str = "<span font-weight=\"bold\">" + _("Sign In to %s").printf(auth_string) + 
"</span>";
-
-        title_label.set_markup (title_str);
-        title_label.halign = Gtk.Align.START;
-        title_label.margin_bottom = 18;
-
-        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;
-
-        var auth_button = new Button.from_stock (_("Sign In"));
-        auth_button.halign = Gtk.Align.END;
-
-        auth_button.clicked.connect ( () => {
-            if (auth_func != null)
-                 auth_func (username_entry.get_text (), password_entry.get_text ());
-            notification.dismiss ();
-        });
-
-        username_entry.activate.connect (() => {
-            password_entry.grab_focus ();
-        });
-        password_entry.activate.connect (() => {
-            auth_button.activate ();
-        });
-
-        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);
-        notification.add (grid);
-
         add_notification (notification);
-        notification.show_all ();
 
         return notification;
     }
@@ -162,51 +90,26 @@ private class Boxes.Notificationbar: GLib.Object {
             App.app.display_page.add_notification (w);
     }
 
-    private Gd.Notification display (string            message,
-                                     MessageType       message_type,
-                                     string?           ok_label,
-                                     owned OKFunc?     ok_func,
-                                     owned CancelFunc? cancel_func,
-                                     int               timeout) {
-        var notification = new Gd.Notification ();
-        notification.valign = Gtk.Align.START;
-        notification.timeout = timeout;
+    private Gd.Notification display (string                         message,
+                                     MessageType                    message_type,
+                                     string?                        ok_label,
+                                     owned Notification.OKFunc?     ok_func,
+                                     owned Notification.CancelFunc? cancel_func,
+                                     int                            timeout) {
+        var notification = new Boxes.Notification (message,
+                                                   message_type,
+                                                   ok_label,
+                                                   (owned) ok_func,
+                                                   (owned) cancel_func,
+                                                   timeout);
 
         active_notifications.prepend (notification);
 
-        bool ok_pressed = false;
         notification.dismissed.connect ( () => {
-            if (!ok_pressed && cancel_func != null)
-                cancel_func ();
             active_notifications.remove (notification);
         });
 
-        var grid = new Gtk.Grid ();
-        grid.set_orientation (Gtk.Orientation.HORIZONTAL);
-        grid.margin_left = 12;
-        grid.margin_right = 12;
-        grid.column_spacing = 12;
-        grid.valign = Gtk.Align.CENTER;
-        notification.add (grid);
-
-        var message_label = new Label (message);
-        grid.add (message_label);
-
-        if (ok_label != null) {
-            var ok_button = new Button.with_mnemonic (ok_label);
-            ok_button.halign = Gtk.Align.END;
-            grid.add (ok_button);
-
-            ok_button.clicked.connect ( () => {
-                ok_pressed = true;
-                if (ok_func != null)
-                    ok_func ();
-                notification.dismiss ();
-            });
-        }
-
         add_notification (notification);
-        notification.show_all ();
 
         return notification;
     }
diff --git a/src/ovirt-broker.vala b/src/ovirt-broker.vala
index d403141..d66ac9e 100644
--- a/src/ovirt-broker.vala
+++ b/src/ovirt-broker.vala
@@ -45,12 +45,12 @@ private class Boxes.OvirtBroker : Boxes.Broker {
             if (retrying)
                 return false;
 
-            Notificationbar.AuthenticateFunc auth_cb = (username, password) => {
+            AuthNotification.AuthFunc auth_cb = (username, password) => {
                 proxy.username = username;
                 proxy.password = password;
                 auth.unpause ();
             };
-            Notificationbar.CancelFunc cancel_cb = () => {
+            Notification.CancelFunc cancel_cb = () => {
                 // Make sure we are not stuck waiting for authentication to
                 // finish, otherwise yield add_source() will never return
                 auth.unpause ();


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