From 0e207d5da1d7af5ab6c8445e858ee129b6e057c2 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Sat, 6 Mar 2010 17:06:12 +0100 Subject: [PATCH] Timeout the alarm after a bit --- src/app_alarm.vala | 55 ++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/app_alarm.vala b/src/app_alarm.vala index 1760798..3b78752 100644 --- a/src/app_alarm.vala +++ b/src/app_alarm.vala @@ -36,6 +36,7 @@ public class AlarmNotifier : zavai.Resource, Gtk.Window protected bool shown; protected Gtk.Label message; protected Gtk.Button ack; + protected uint cancel_timeout; public AlarmNotifier() { @@ -53,6 +54,8 @@ public class AlarmNotifier : zavai.Resource, Gtk.Window vbox = new Gtk.VBox(false, 0); add(vbox); + cancel_timeout = 0; + //destroy += Gtk.main_quit; //set_events(get_events() | Gdk.EventMask.VISIBILITY_NOTIFY_MASK); //visibility_notify_event += on_visibility; @@ -76,6 +79,12 @@ public class AlarmNotifier : zavai.Resource, Gtk.Window confirm(); } + protected bool on_timeout() + { + cancel(); + return false; + } + public void trigger(string text) { message.set_text(text); @@ -93,16 +102,33 @@ public class AlarmNotifier : zavai.Resource, Gtk.Window if (visible) present(); } + + if (cancel_timeout != 0) + { + Source.remove(cancel_timeout); + cancel_timeout = 0; + } + cancel_timeout = Timeout.add(2000, on_timeout); } public void confirm() { visible = false; + if (cancel_timeout != 0) + { + Source.remove(cancel_timeout); + cancel_timeout = 0; + } } public void cancel() { visible = false; + if (cancel_timeout != 0) + { + Source.remove(cancel_timeout); + cancel_timeout = 0; + } } public void shutdown() {} @@ -113,35 +139,6 @@ public AlarmNotifier notifier; public void init() { notifier = new AlarmNotifier(); - - //zavai.registry.getmenu("menu.main").add_applet("menu.power"); - //tpm = new TogglePowerMenu(); - //zavai.registry.getmenu("menu.main").add_widget(tpm); - - /* - raise_icon = new RaiseIcon(); - raise_icon.set_visible(true); - - close_or_back = new CloseOrBack(); - close_or_back.set_visible(true); - - window_list = new WindowList("Current apps"); - zavai.registry.register_applet("wm.list", window_list); - zavai.registry.getmenu("menu.main").add_applet("wm.list"); - - try { - launcher = new Launcher("Run program"); - } catch (Error e) { - zavai.log.error("Not running launcher: " + e.message); - launcher = null; - } - - if (launcher != null) - { - zavai.registry.register_applet("wm.launcher", launcher); - zavai.registry.getmenu("menu.main").add_applet("wm.launcher"); - } - */ } } -- 2.39.5