/* * app_alarm - zavai alarm system * * Copyright (C) 2010 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using GLib; namespace zavai { namespace ui { namespace alarm { /* // Compute a-b in microseconds static long timediff(Posix.timeval* a, Posix.timeval* b) { return (a->tv_sec - b->tv_sec) * 1000000 + (a->tv_usec - b->tv_usec); } */ public class AlarmNotifier : zavai.Resource, Gtk.Window { protected Gtk.VBox vbox; protected bool shown; protected Gtk.Label message; protected Gtk.Button ack; protected uint cancel_timeout; protected weak clock.AlarmTriggerInfo current = null; public AlarmNotifier() { Object( type: Gtk.WindowType.TOPLEVEL, title: "Alarm" ); shown = false; destroy_with_parent = true; set_transient_for(zavai.app); set_modal(true); set_position(Gtk.WindowPosition.CENTER_ON_PARENT); set_size_request(300, 500); 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; set_skip_pager_hint(true); set_skip_taskbar_hint(true); set_type_hint(Gdk.WindowTypeHint.POPUP_MENU); message = new Gtk.Label("no message"); vbox.pack_start(message, false, true, 0); ack = new Gtk.Button.with_label("Ack"); ack.clicked += on_iface_ack; vbox.pack_start(ack, true, true, 0); //vbox.show_all(); zavai.registry.register(this); clock.alarm_trigger_queue.triggered += on_trigger; clock.alarm_trigger_queue.acked += on_done; clock.alarm_trigger_queue.canceled += on_done; } protected void abort_timeout() { if (cancel_timeout != 0) { Source.remove(cancel_timeout); cancel_timeout = 0; } } protected void on_iface_ack() { if (current == null) return; clock.alarm_trigger_queue.ack(current); } protected bool on_iface_timeout() { if (current == null) return false; clock.alarm_trigger_queue.cancel(current); return false; } public void on_trigger(clock.AlarmTriggerInfo info) { current = info; message.set_text(info.label); ui.power.backlight.request("alarmnotifier"); if (!shown) { show_all(); show(); visible = true; present(); shown = true; } else { // TODO: do more in case it is visible but has no visibility (is covered by others) visible = !visible; if (visible) present(); } abort_timeout(); cancel_timeout = Timeout.add(30 * 1000, on_iface_timeout); } public void on_done(clock.AlarmTriggerInfo info) { if (current == null || current != info) return; visible = false; abort_timeout(); current = null; ui.power.backlight.release("alarmnotifier"); } public void shutdown() { abort_timeout(); } } public AlarmNotifier notifier = null; public void init() { if (clock.alarm_trigger_queue != null) notifier = new AlarmNotifier(); } } } }