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 class AlarmNotifierDialog : ui.notify.Notifier
{
- protected Gtk.VBox vbox;
- protected bool shown;
protected Gtk.Label message;
- protected Gtk.Button ack;
- protected uint cancel_timeout;
+ protected Gtk.Button message_button;
- public AlarmNotifier()
+ public AlarmNotifierDialog(string title, string text)
{
Object(
- type: Gtk.WindowType.TOPLEVEL,
- title: "Alarm"
+ notifier_name: "alarm",
+ title: title
);
- 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);
+ set_size_request(300, 500);
- message = new Gtk.Label("no message");
- vbox.pack_start(message, false, true, 0);
+ add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK);
+ add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL);
+ set_default_response(Gtk.ResponseType.OK);
- ack = new Gtk.Button.with_label("Ack");
- ack.clicked += on_ack;
- vbox.pack_start(ack, true, true, 0);
+ weak Gtk.VBox vbox = (Gtk.VBox)get_content_area();
- //vbox.show_all();
- zavai.registry.register(this);
+ message = new Gtk.Label(text);
+ message_button = new Gtk.Button();
+ message_button.set_image(message);
+ message_button.clicked += (b) => { response(Gtk.ResponseType.OK); };
+ vbox.pack_start(message_button, true, true, 0);
+ message_button.show();
}
- protected void on_ack()
+ protected virtual bool push_aux_state()
{
- confirm();
+ var state = new zavai.led.LedState(name);
+ state.set_blink(255);
+ zavai.led.aux.push_state(state);
+ return true;
}
- protected bool on_timeout()
+ protected virtual bool push_vibrator_state()
{
- cancel();
- return false;
+ var state = new zavai.led.LedState(name);
+ state.set_blink(255);
+ zavai.led.aux.push_state(state);
+ return true;
}
- public void trigger(string text)
+ protected virtual bool push_ringtone_state()
{
- message.set_text(text);
+ var state = new zavai.audio.PlayerState(name, config.ringtone_alarm, true);
+ zavai.audio.soundplayer.push_state(state);
+ return true;
+ }
+}
- 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();
- }
+public class AlarmNotifier : zavai.Resource, ui.notify.Notifier
+{
+ protected weak clock.AlarmTriggerInfo current = null;
+ protected AlarmNotifierDialog dialog = null;
- if (cancel_timeout != 0)
- {
- Source.remove(cancel_timeout);
- cancel_timeout = 0;
- }
- cancel_timeout = Timeout.add(2000, on_timeout);
+ public AlarmNotifier()
+ {
+ 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;
}
- public void confirm()
+ public void on_trigger(clock.AlarmTriggerInfo info)
{
- visible = false;
- if (cancel_timeout != 0)
- {
- Source.remove(cancel_timeout);
+ current = info;
+ dialog = new AlarmNotifierDialog("Alarm", info.label);
+
+ uint cancel_timeout = 0;
+ cancel_timeout = Timeout.add(30 * 1000, () => {
+ dialog.response(Gtk.ResponseType.CANCEL);
cancel_timeout = 0;
+ return false;
+ });
+ int res = dialog.run();
+ if (cancel_timeout != 0) Source.remove(cancel_timeout);
+ switch (res)
+ {
+ case Gtk.ResponseType.OK:
+ clock.alarm_trigger_queue.ack(current);
+ break;
+ case Gtk.ResponseType.CANCEL:
+ clock.alarm_trigger_queue.cancel(current);
+ break;
}
+ dialog.destroy();
+ dialog = null;
+ current = null;
}
- public void cancel()
+ public void on_done(clock.AlarmTriggerInfo info)
{
- visible = false;
- if (cancel_timeout != 0)
- {
- Source.remove(cancel_timeout);
- cancel_timeout = 0;
- }
+ if (current == null || dialog == null || current != info) return;
+ dialog.response(Gtk.ResponseType.NONE);
}
- public void shutdown() {}
+ public void shutdown()
+ {
+ if (dialog == null) return;
+ dialog.response(Gtk.ResponseType.CANCEL);
+ }
}
-public AlarmNotifier notifier;
+public AlarmNotifier notifier = null;
public void init()
{
- notifier = new AlarmNotifier();
+ if (clock.alarm_trigger_queue != null)
+ notifier = new AlarmNotifier();
}
}