[gnome-boxes] More generic notification bar



commit c9505f2dc0648789ee3bcc42344ef8bb71fd391b
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Jan 31 17:18:58 2012 +0200

    More generic notification bar
    
    Now its also possible to display errors through notification bar and new
    types of messages are now trivial to add. It is also now visible in all
    UI states except for 'DISPLAY'. Do we want it there?
    
    Not sure if this is an issue for us but the colors of Gtk.InfoBar remain
    always the same regardless of type of message. While we do set the
    appropriate message type on the Gtk.InfoBar, we set our own style on it
    as well. So if we need this, we need to figure how to set different
    styles for different message types.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=668792

 src/app.vala             |    6 ++--
 src/notificationbar.vala |   60 ++++++++++++++++++++++++++++++---------------
 2 files changed, 43 insertions(+), 23 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index e40fa02..983d97c 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -472,12 +472,12 @@ private class Boxes.App: Boxes.UI {
         foreach (var item in selected_items)
             view.remove_item (item);
 
-        Notificationbar.ActionFunc undo = () => {
+        Notificationbar.OKFunc undo = () => {
             foreach (var selected in selected_items)
                 view.add_item (selected);
         };
 
-        Notificationbar.IgnoreFunc really_remove = () => {
+        Notificationbar.CancelFunc really_remove = () => {
             foreach (var selected in selected_items) {
                 var machine = selected as Machine;
 
@@ -486,7 +486,7 @@ private class Boxes.App: Boxes.UI {
             }
         };
 
-        notificationbar.display (Gtk.Stock.UNDO, message, (owned) undo, (owned) really_remove);
+        notificationbar.display_for_action (message, Gtk.Stock.UNDO, (owned) undo, (owned) really_remove);
     }
 
     private bool on_key_pressed (Widget widget, Gdk.EventKey event) {
diff --git a/src/notificationbar.vala b/src/notificationbar.vala
index 2fce919..9d77a6e 100644
--- a/src/notificationbar.vala
+++ b/src/notificationbar.vala
@@ -5,13 +5,13 @@ private class Boxes.Notificationbar: GLib.Object {
     public Clutter.Actor actor { get; private set; }
     public static const float spacing = 60.0f;
 
-    public delegate void ActionFunc ();
-    public delegate void IgnoreFunc ();
+    public delegate void OKFunc ();
+    public delegate void CancelFunc ();
 
     private App app;
     private InfoBar info_bar;
-    private Label label;
-    private Button action_button;
+    private Label message_label;
+    private Button ok_button;
 
     private uint timeout_id;
     private ulong response_id;
@@ -22,12 +22,32 @@ private class Boxes.Notificationbar: GLib.Object {
         setup_action_notify ();
     }
 
-    public void display (string            action_label,
-                         string            action_message,
-                         owned ActionFunc  action_func,
-                         owned IgnoreFunc? ignore_func = null) {
-        action_button.label = action_label;
-        label.label = action_message;
+    public void display_for_action (string            message,
+                                    string            action_label,
+                                    owned OKFunc      action_func,
+                                    owned CancelFunc? ignore_func = null) {
+        display (message, MessageType.INFO, action_label, (owned) action_func, (owned) ignore_func);
+    }
+
+    public void display_error (string message) {
+        display (message, MessageType.ERROR);
+    }
+
+    private void display (string            message,
+                          MessageType       message_type,
+                          string?           ok_label = null,
+                          owned OKFunc?     ok_func = null,
+                          owned CancelFunc? cancel_func = null) {
+        if (ok_label != null) {
+            ok_button.label = ok_label;
+            info_bar.spacing = 120;
+            ok_button.show ();
+        } else {
+            info_bar.spacing = 60;
+            ok_button.hide ();
+        }
+        message_label.label = message;
+        info_bar.message_type = message_type;
 
         // Replace running notification, if any
         if (timeout_id != 0) {
@@ -50,10 +70,11 @@ private class Boxes.Notificationbar: GLib.Object {
             response_id = 0;
 
             if (response == ResponseType.OK)
-                action_func ();
+                if (ok_func != null)
+                    ok_func ();
             else {
-                if (ignore_func != null)
-                    ignore_func ();
+                if (cancel_func != null)
+                    cancel_func ();
             }
         });
 
@@ -63,16 +84,15 @@ private class Boxes.Notificationbar: GLib.Object {
     private void setup_action_notify () {
         info_bar = new InfoBar ();
         info_bar.get_style_context ().add_class ("osd");
-        info_bar.spacing = 120;
         info_bar.margin = 5;
 
-        label = new Label ("");
+        message_label = new Label ("");
         var content_area = info_bar.get_content_area () as Container;
-        content_area.add (label);
+        content_area.add (message_label);
 
-        action_button = new Button ();
-        info_bar.add_action_widget (action_button, ResponseType.OK);
-        action_button.use_stock = true;
+        ok_button = new Button ();
+        info_bar.add_action_widget (ok_button, ResponseType.OK);
+        ok_button.use_stock = true;
 
         var image = new Image.from_icon_name ("window-close-symbolic", IconSize.BUTTON);
         var close_button = new Button ();
@@ -84,7 +104,6 @@ private class Boxes.Notificationbar: GLib.Object {
         var button_box = info_bar.get_action_area () as ButtonBox;
         button_box.orientation = Orientation.HORIZONTAL;
         button_box.set_child_non_homogeneous (close_button, true);
-        info_bar.set_message_type (MessageType.INFO);
 
         info_bar.show_all ();
 
@@ -92,6 +111,7 @@ private class Boxes.Notificationbar: GLib.Object {
         app.stage.add (actor);
         actor.hide ();
         actor.scale_y = 0f;
+        actor.depth = 1f; // Apear above every view
     }
 
     private void show () {



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