[gnome-boxes] Use notification widget from libgd
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Use notification widget from libgd
- Date: Tue, 30 Oct 2012 07:31:13 +0000 (UTC)
commit bee1432b847fcf461465ebf9c08a6f45fb193490
Author: Alexander Larsson <alexl redhat com>
Date: Mon Oct 29 16:32:39 2012 +0100
Use notification widget from libgd
This one has shadows and looks like the gnome-documents
and the contacts one. Additionally, its fully gtk, so
we can later use it in the display page (which does
not use clutter).
https://bugzilla.gnome.org/show_bug.cgi?id=679106
src/notificationbar.vala | 150 ++++++++++++++++------------------------------
1 files changed, 51 insertions(+), 99 deletions(-)
---
diff --git a/src/notificationbar.vala b/src/notificationbar.vala
index 97719b9..1398da4 100644
--- a/src/notificationbar.vala
+++ b/src/notificationbar.vala
@@ -2,22 +2,29 @@
using Gtk;
private class Boxes.Notificationbar: GLib.Object {
- public Clutter.Actor actor { get { return revealer; } }
+ public Clutter.Actor actor { get { return gtk_actor; } }
public delegate void OKFunc ();
public delegate void CancelFunc ();
private GtkClutter.Actor gtk_actor;
- private Revealer revealer;
- private InfoBar info_bar;
- private Label message_label;
- private Button ok_button;
+ private Gtk.Grid top_grid;
- private uint timeout_id;
- private ulong response_id;
+ GLib.List<Widget> active_notifications;
public Notificationbar () {
- setup_action_notify ();
+ active_notifications = new GLib.List<Widget> ();
+
+ top_grid = new Gtk.Grid ();
+ top_grid.show ();
+
+ gtk_actor = new GtkClutter.Actor.with_contents (top_grid);
+ gtk_actor.name = "notificationbar";
+ gtk_actor.x_align = Clutter.ActorAlign.CENTER;
+ gtk_actor.y_align = Clutter.ActorAlign.START;
+ Gdk.RGBA transparent = { 0, 0, 0, 0};
+ gtk_actor.get_widget ().override_background_color (0, transparent);
+
}
public void display_for_action (string message,
@@ -32,7 +39,13 @@ private class Boxes.Notificationbar: GLib.Object {
}
public void cancel () {
- info_bar.response (ResponseType.CANCEL);
+ // We destroy all active notifications, which will cause them to be dismissed
+ while (active_notifications != null)
+ active_notifications.data.destroy ();
+ }
+
+ private void add_notification (Widget w) {
+ top_grid.attach (w, 0, 0, 1, 1);
}
private void display (string message,
@@ -40,105 +53,44 @@ private class Boxes.Notificationbar: GLib.Object {
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;
+ var notification = new Gd.Notification ();
+ notification.valign = Gtk.Align.START;
+ notification.timeout = 6;
- // Replace running notification, if any
- if (timeout_id != 0) {
- Source.remove (timeout_id);
- info_bar.disconnect (response_id);
- }
+ active_notifications.prepend (notification);
- add_timeout ();
+ 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);
- response_id = info_bar.response.connect ((response) => {
- hide ();
+ var message_label = new Label (message);
+ grid.add (message_label);
- Source.remove (timeout_id);
- info_bar.disconnect (response_id);
- timeout_id = 0;
- response_id = 0;
+ if (ok_label != null) {
+ var ok_button = new Button.from_stock (ok_label);
+ ok_button.halign = Gtk.Align.END;
+ grid.add (ok_button);
- if (response == ResponseType.OK) {
+ ok_button.pressed.connect ( () => {
+ ok_pressed = true;
if (ok_func != null)
ok_func ();
- } else {
- if (cancel_func != null)
- cancel_func ();
- }
- });
-
- show ();
- }
-
- private void add_timeout () {
- if (!App.app.window.is_active) {
- // Don't timeout before user gets a chance to see's the notification
- ulong active_id = 0;
- active_id = App.app.window.notify["is-active"].connect (() => {
- add_timeout ();
- App.app.window.disconnect (active_id);
+ notification.dismiss ();
});
-
- return;
}
- timeout_id = Timeout.add_seconds (6, () => {
- info_bar.response (ResponseType.CANCEL);
-
- return false;
- });
- }
-
- private void setup_action_notify () {
- revealer = new Revealer (true);
- revealer.unreveal ();
- revealer.name = "notificationbar-revealer";
-
- info_bar = new InfoBar ();
-
- message_label = new Label ("");
- var content_area = info_bar.get_content_area () as Container;
- content_area.add (message_label);
-
- 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 ();
- close_button.image = image;
- info_bar.add_action_widget (close_button, ResponseType.CANCEL);
- close_button.relief = ReliefStyle.NONE;
- close_button.halign = Align.START;
-
- 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.show_all ();
-
- gtk_actor = new GtkClutter.Actor.with_contents (info_bar);
- gtk_actor.get_widget ().get_style_context ().add_class ("notificationbar");
- gtk_actor.name = "notificationbar";
- revealer.add (gtk_actor);
- revealer.x_align = Clutter.ActorAlign.CENTER;
- revealer.y_align = Clutter.ActorAlign.START;
- }
-
- private void show () {
- revealer.reveal ();
- }
-
- private void hide () {
- revealer.unreveal ();
+ add_notification (notification);
+ notification.show_all ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]