2 * app_notify - zavai notification 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 public abstract class Notifier : Gtk.Dialog
29 public string notifier_name { get; construct; }
32 set_transient_for(zavai.app);
34 set_position(Gtk.WindowPosition.CENTER_ON_PARENT);
37 protected virtual bool push_aux_state()
42 protected virtual bool push_vibrator_state()
47 protected virtual bool push_ringtone_state()
54 ui.power.backlight.request(notifier_name);
56 // Setup our attention seeking strategy
57 bool has_aux = zavai.led.aux != null && push_aux_state();
58 bool has_vibrator = zavai.led.vibrator != null && push_vibrator_state();
59 bool has_ringtone = zavai.audio.soundplayer != null && push_ringtone_state();
64 if (has_ringtone) zavai.audio.soundplayer.pop_state(notifier_name);
65 if (has_vibrator) zavai.led.vibrator.pop_state(notifier_name);
66 if (has_aux) zavai.led.aux.pop_state(notifier_name);
68 ui.power.backlight.release(notifier_name);
73 protected class CallNotifierDialog : ui.notify.Notifier
75 protected Gtk.Label message;
76 protected Gtk.Button message_button;
78 public CallNotifierDialog(string title, string text)
81 notifier_name: "call",
85 set_size_request(300, 500);
87 add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK);
88 add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL);
89 set_default_response(Gtk.ResponseType.OK);
91 weak Gtk.VBox vbox = (Gtk.VBox)get_content_area();
93 message = new Gtk.Label(text);
94 message_button = new Gtk.Button();
95 message_button.set_image(message);
96 message_button.clicked += (b) => { response(Gtk.ResponseType.OK); };
97 vbox.pack_start(message_button, true, true, 0);
98 message_button.show();
101 protected override bool push_aux_state()
103 var state = new zavai.led.LedState(notifier_name);
104 state.set_blink(255);
105 zavai.led.aux.push_state(state);
109 protected override bool push_vibrator_state()
111 var state = new zavai.led.LedState(notifier_name);
112 state.set_blink(255);
113 zavai.led.vibrator.push_state(state);
117 protected override bool push_ringtone_state()
119 var state = new zavai.audio.PlayerState(notifier_name, config.ringtone_call, true);
120 zavai.audio.soundplayer.push_state(state);
125 public class CallNotifier : zavai.Resource, ui.notify.Notifier
127 protected int call_index = -1;
128 protected CallNotifierDialog dialog = null;
130 public CallNotifier()
132 zavai.registry.register(this);
134 zavai.gsm.gsm.new_call += trigger;
135 zavai.gsm.gsm.end_call += done;
138 public void trigger(int index)
141 dialog = new CallNotifierDialog("Call", "TODO");
143 if (zavai.led.auxbutton != null)
144 zavai.led.auxbutton.event += on_auxbutton;
146 int res = dialog.run();
149 case Gtk.ResponseType.OK:
150 // TODO clock.alarm_trigger_queue.ack(current);
152 case Gtk.ResponseType.CANCEL:
153 // TODO clock.alarm_trigger_queue.cancel(current);
157 if (zavai.led.auxbutton != null)
158 zavai.led.auxbutton.event -= on_auxbutton;
165 protected bool on_auxbutton(ulong time, bool pressed)
167 if (dialog == null) return false;
168 dialog.response(Gtk.ResponseType.OK);
172 public void done(int index)
174 if (call_index != index || dialog == null) return;
175 dialog.response(Gtk.ResponseType.NONE);
178 public void shutdown()
180 if (dialog == null) return;
181 dialog.response(Gtk.ResponseType.CANCEL);
185 public CallNotifier call = null;
189 var ps = new zavai.audio.PlayerState("gsm", zavai.config.ringtone_sms, false);
190 zavai.audio.soundplayer.push_state(ps);
195 call = new CallNotifier();
197 zavai.gsm.gsm.new_sms += sms;