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
27 // Compute a-b in microseconds
28 static long timediff(Posix.timeval* a, Posix.timeval* b)
30 return (a->tv_sec - b->tv_sec) * 1000000 + (a->tv_usec - b->tv_usec);
33 public class AlarmNotifier : zavai.Resource, Gtk.Window
35 protected Gtk.VBox vbox;
37 protected Gtk.Label message;
38 protected Gtk.Button ack;
39 protected uint cancel_timeout;
41 public AlarmNotifier()
44 type: Gtk.WindowType.TOPLEVEL,
48 destroy_with_parent = true;
49 set_transient_for(zavai.app);
51 set_position(Gtk.WindowPosition.CENTER_ON_PARENT);
52 set_size_request(300, 500);
54 vbox = new Gtk.VBox(false, 0);
59 //destroy += Gtk.main_quit;
60 //set_events(get_events() | Gdk.EventMask.VISIBILITY_NOTIFY_MASK);
61 //visibility_notify_event += on_visibility;
62 set_skip_pager_hint(true);
63 set_skip_taskbar_hint(true);
64 set_type_hint(Gdk.WindowTypeHint.POPUP_MENU);
66 message = new Gtk.Label("no message");
67 vbox.pack_start(message, false, true, 0);
69 ack = new Gtk.Button.with_label("Ack");
70 ack.clicked += on_ack;
71 vbox.pack_start(ack, true, true, 0);
74 zavai.registry.register(this);
77 protected void on_ack()
82 protected bool on_timeout()
88 public void trigger(string text)
90 message.set_text(text);
100 // TODO: do more in case it is visible but has no visibility (is covered by others)
106 if (cancel_timeout != 0)
108 Source.remove(cancel_timeout);
111 cancel_timeout = Timeout.add(2000, on_timeout);
114 public void confirm()
117 if (cancel_timeout != 0)
119 Source.remove(cancel_timeout);
127 if (cancel_timeout != 0)
129 Source.remove(cancel_timeout);
134 public void shutdown() {}
137 public AlarmNotifier notifier;
141 notifier = new AlarmNotifier();