2 * app_alarm - zavai alarm system
4 * Copyright (C) 2010 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 // Compute a-b in microseconds
29 static long timediff(Posix.timeval* a, Posix.timeval* b)
31 return (a->tv_sec - b->tv_sec) * 1000000 + (a->tv_usec - b->tv_usec);
35 public class AlarmNotifier : zavai.Resource, Gtk.Window
37 protected Gtk.VBox vbox;
39 protected Gtk.Label message;
40 protected Gtk.Button ack;
41 protected uint cancel_timeout;
42 protected weak clock.AlarmTriggerInfo current = null;
44 public AlarmNotifier()
47 type: Gtk.WindowType.TOPLEVEL,
51 destroy_with_parent = true;
52 set_transient_for(zavai.app);
54 set_position(Gtk.WindowPosition.CENTER_ON_PARENT);
55 set_size_request(300, 500);
57 vbox = new Gtk.VBox(false, 0);
62 //destroy += Gtk.main_quit;
63 //set_events(get_events() | Gdk.EventMask.VISIBILITY_NOTIFY_MASK);
64 //visibility_notify_event += on_visibility;
65 set_skip_pager_hint(true);
66 set_skip_taskbar_hint(true);
67 set_type_hint(Gdk.WindowTypeHint.POPUP_MENU);
69 message = new Gtk.Label("no message");
70 vbox.pack_start(message, false, true, 0);
72 ack = new Gtk.Button.with_label("Ack");
73 ack.clicked += on_iface_ack;
74 vbox.pack_start(ack, true, true, 0);
77 zavai.registry.register(this);
79 clock.alarm_trigger_queue.triggered += on_trigger;
80 clock.alarm_trigger_queue.acked += on_done;
81 clock.alarm_trigger_queue.canceled += on_done;
84 protected void abort_timeout()
86 if (cancel_timeout != 0)
88 Source.remove(cancel_timeout);
93 protected void on_iface_ack()
95 if (current == null) return;
96 clock.alarm_trigger_queue.ack(current);
99 protected bool on_iface_timeout()
101 if (current == null) return false;
102 clock.alarm_trigger_queue.cancel(current);
106 public void on_trigger(clock.AlarmTriggerInfo info)
109 message.set_text(info.label);
111 ui.power.backlight.request("alarmnotifier");
121 // TODO: do more in case it is visible but has no visibility (is covered by others)
128 cancel_timeout = Timeout.add(30 * 1000, on_iface_timeout);
131 public void on_done(clock.AlarmTriggerInfo info)
133 if (current == null || current != info) return;
137 ui.power.backlight.release("alarmnotifier");
140 public void shutdown()
146 public AlarmNotifier notifier = null;
150 if (clock.alarm_trigger_queue != null)
151 notifier = new AlarmNotifier();