2 * app_main - zavai main status display
4 * Copyright (C) 2009 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 public class StatusBar : Gtk.HBox
36 public class Clock : Gtk.VBox
38 protected Gtk.Label l_date;
39 protected Gtk.Button l_date_button;
40 protected Gtk.Label l_time;
41 protected Gtk.Label l_deadline;
42 protected time_t last_time;
43 protected zavai.clock.SourceType last_time_type;
44 protected time_t last_deadline;
45 protected string last_deadline_label;
50 last_time_type = zavai.clock.SourceType.SYSTEM;
52 last_deadline_label = "";
54 l_date = new Gtk.Label("--");
55 l_date.modify_font(Pango.FontDescription.from_string("Sans 40"));
56 l_date_button = new Gtk.Button();
57 l_date_button.set_image(l_date);
58 l_date_button.relief = Gtk.ReliefStyle.NONE;
59 l_date_button.clicked += on_date_clicked;
60 pack_start(l_date_button, false, false, 0);
61 l_time = new Gtk.Label("--:--");
62 l_time.modify_font(Pango.FontDescription.from_string("Sans 60"));
63 pack_start(l_time, false, false, 0);
64 l_deadline = new Gtk.Label("");
65 l_deadline.modify_font(Pango.FontDescription.from_string("Sans 30"));
66 l_deadline.set_justify(Gtk.Justification.CENTER);
67 pack_start(l_deadline, false, false, 0);
69 zavai.clock.clock.minute_changed += on_minute_changed;
70 zavai.clock.clock.schedule_changed += on_schedule_changed;
71 on_schedule_changed(zavai.clock.clock.next_alarm());
73 zavai.clock.clock.request("ui.main.clock");
76 private void on_date_clicked(Gtk.Button b)
78 zavai.app.push_applet(zavai.ui.calendar.calendar);
81 private void on_schedule_changed(zavai.clock.Alarm? next)
86 last_deadline_label = "";
88 last_deadline = next.ev.deadline;
89 last_deadline_label = next.label;
91 on_minute_changed((long)last_time, last_time_type);
94 private void on_minute_changed(long ts, zavai.clock.SourceType type)
96 last_time = (time_t)ts;
97 last_time_type = type;
99 string typetag = "unknown";
102 case zavai.clock.SourceType.GPS:
105 case zavai.clock.SourceType.SYSTEM:
110 var t = Time.local((time_t)ts);
111 l_date.set_text(t.format("%a %d %b"));
112 l_time.set_text("%2d:%02d (%s)".printf(t.hour, t.minute, typetag));
114 if (last_deadline == 0)
115 l_deadline.set_text("");
118 int remaining = (int)(last_deadline - last_time);
119 int hours = remaining / 3600;
120 int minutes = (remaining % 3600) / 60;
121 if (hours == 0 && minutes == 0)
122 l_deadline.set_text(last_deadline_label + "\nanytime now");
124 l_deadline.set_text("%s\nin %02dh %02dm".printf(last_deadline_label, hours, minutes));
129 public class Status : Applet
131 public Gtk.HBox status_icons;
133 public Gtk.Label gsm_status;
134 public Gtk.Label gsm_info;
135 public AppletPushLink menu;
137 public Status(string label)
140 status_icons = new Gtk.HBox(false, 0);
142 gsm_status = new Gtk.Label("");
143 gsm_info = new Gtk.Label("");
144 menu = new AppletPushLink(zavai.menu_main);
146 pack_start(status_icons, false, false, 0);
147 pack_start(clock, false, false, 0);
148 pack_start(gsm_status, false, false, 0);
149 pack_start(gsm_info, false, false, 0);
150 // pack_start(music.player, false, false, 0);
151 pack_end(menu, false, false, 0);
153 zavai.gsm.gsm.status_changed += (msg) => { gsm_status.set_text(msg); };
154 zavai.gsm.gsm.info_changed += () => {
155 stderr.printf("NEW INFO %s %d\n", zavai.gsm.gsm.info_provider, zavai.gsm.gsm.info_signal_strength);
156 if (zavai.gsm.gsm.info_signal_strength != -1)
157 gsm_info.set_text("%s %d%%".printf(zavai.gsm.gsm.info_provider, zavai.gsm.gsm.info_signal_strength));
159 gsm_info.set_text(zavai.gsm.gsm.info_provider);
164 public class IncDec : Gtk.HBox
166 protected Gtk.Button b_decmore;
167 protected Gtk.Button b_dec;
168 protected Gtk.Button b_inc;
169 protected Gtk.Button b_incmore;
170 static const int BH = 50;
171 static const int BW = 50;
173 public signal void tweaked(IncDec id, int amount);
178 b_decmore = new Gtk.Button.with_label("«");
179 b_decmore.set_size_request(BW, BH);
180 b_dec = new Gtk.Button.with_label("<");
181 b_dec.set_size_request(BW, BH);
182 b_inc = new Gtk.Button.with_label(">");
183 b_inc.set_size_request(BW, BH);
184 b_incmore = new Gtk.Button.with_label("»");
185 b_incmore.set_size_request(BW, BH);
186 pack_start(b_decmore, false, true, 0);
187 pack_start(b_dec, false, true, 0);
188 pack_start(b_inc, false, true, 0);
189 pack_start(b_incmore, false, true, 0);
190 b_decmore.clicked += on_clicked;
191 b_dec.clicked += on_clicked;
192 b_inc.clicked += on_clicked;
193 b_incmore.clicked += on_clicked;
196 protected void on_clicked(Gtk.Button b)
204 else if (b == b_incmore)
209 public abstract class AddDeadline : Applet
211 protected Gtk.ComboBoxEntry dl_label;
212 protected Gtk.Button dl_submit;
216 dl_label = new Gtk.ComboBoxEntry.text();
217 dl_label.append_text("Pasta");
218 dl_label.append_text("Talk");
219 dl_label.append_text("Leave");
220 dl_label.changed += on_label_changed;
222 var hbox = new Gtk.HBox(false, 0);
223 hbox.pack_start(new Gtk.Label("Label: "), false, false, 0);
224 hbox.pack_start(dl_label, true, true, 0);
225 pack_start(hbox, false, false, 0);
227 dl_submit = new Gtk.Button.with_label("Activate");
228 dl_submit.set_sensitive(false);
229 dl_submit.clicked += on_submit;
230 button_box.pack_start(dl_submit, true, true, 0);
233 public override void start()
235 ((Gtk.Entry)dl_label.get_child()).set_text("");
239 protected virtual void update()
241 dl_submit.set_sensitive(((Gtk.Entry)dl_label.get_child()).get_text() == "" ? false : true);
244 protected abstract time_t get_deadline();
246 protected void on_label_changed(Gtk.ComboBox e)
251 protected void on_submit(Gtk.Button b)
253 string label = ((Gtk.Entry)dl_label.get_child()).get_text();
254 time_t deadlinets = get_deadline();
255 Time deadline = Time.local(deadlinets);
256 string timespec = deadline.format("%H:%M %m/%d/%Y");
257 zavai.log.info("Scheduling deadline " + label + " at " + timespec);
258 zavai.clock.clock.schedule(timespec, label);
263 public class AddAbsoluteDeadline : AddDeadline
265 protected Gtk.Label dl_day;
266 protected IncDec dl_day_tweak;
267 protected Gtk.Label dl_hour;
268 protected IncDec dl_hour_tweak;
269 protected Gtk.Label dl_min;
270 protected IncDec dl_min_tweak;
271 protected time_t dl_time;
273 public AddAbsoluteDeadline()
275 _label = "Add absolute deadline";
278 dl_day = new Gtk.Label("");
279 dl_day.set_justify(Gtk.Justification.RIGHT);
280 dl_day_tweak = new IncDec();
281 dl_day_tweak.tweaked += on_tweak;
282 var hbox = new Gtk.HBox(false, 0);
283 hbox.pack_start(new Gtk.Label("Day: "), false, false, 0);
284 hbox.pack_start(dl_day, true, true, 0);
285 hbox.pack_start(dl_day_tweak, false, false, 0);
286 pack_start(hbox, false, false, 0);
288 dl_hour = new Gtk.Label("");
289 dl_hour.set_justify(Gtk.Justification.RIGHT);
290 dl_hour_tweak = new IncDec();
291 dl_hour_tweak.tweaked += on_tweak;
292 hbox = new Gtk.HBox(false, 0);
293 hbox.pack_start(new Gtk.Label("Hour: "), false, false, 0);
294 hbox.pack_start(dl_hour, true, true, 0);
295 hbox.pack_start(dl_hour_tweak, false, false, 0);
296 pack_start(hbox, false, false, 0);
298 dl_min = new Gtk.Label("");
299 dl_min.set_justify(Gtk.Justification.RIGHT);
300 dl_min_tweak = new IncDec();
301 dl_min_tweak.tweaked += on_tweak;
302 hbox = new Gtk.HBox(false, 0);
303 hbox.pack_start(new Gtk.Label("Minute: "), false, false, 0);
304 hbox.pack_start(dl_min, true, true, 0);
305 hbox.pack_start(dl_min_tweak, false, false, 0);
306 pack_start(hbox, false, false, 0);
309 public override void start()
315 protected override void update()
317 Time t = Time.local(dl_time);
318 dl_day.set_text(t.format("%a %d %b"));
319 dl_hour.set_text(t.format("%H"));
320 dl_min.set_text(t.format("%M"));
324 protected override time_t get_deadline()
329 protected void on_tweak(IncDec id, int amount)
331 time_t old = dl_time;
332 if (id == dl_day_tweak)
333 dl_time += amount * 3600 * 24;
334 else if (id == dl_hour_tweak)
335 dl_time += amount * 3600;
336 else if (id == dl_min_tweak)
337 dl_time += amount * 60;
338 time_t now = time_t();
345 public class AddRelativeDeadline : AddDeadline
347 protected Gtk.Label dl_hour;
348 protected IncDec dl_hour_tweak;
349 protected Gtk.Label dl_min;
350 protected IncDec dl_min_tweak;
351 protected int dl_time;
353 public AddRelativeDeadline()
355 _label = "Add relative deadline";
358 dl_hour = new Gtk.Label("");
359 dl_hour.set_justify(Gtk.Justification.RIGHT);
360 dl_hour_tweak = new IncDec();
361 dl_hour_tweak.tweaked += on_tweak;
362 var hbox = new Gtk.HBox(false, 0);
363 hbox.pack_start(new Gtk.Label("Hour: "), false, false, 0);
364 hbox.pack_start(dl_hour, true, true, 0);
365 hbox.pack_start(dl_hour_tweak, false, false, 0);
366 pack_start(hbox, false, false, 0);
368 dl_min = new Gtk.Label("");
369 dl_min.set_justify(Gtk.Justification.RIGHT);
370 dl_min_tweak = new IncDec();
371 dl_min_tweak.tweaked += on_tweak;
372 hbox = new Gtk.HBox(false, 0);
373 hbox.pack_start(new Gtk.Label("Minute: "), false, false, 0);
374 hbox.pack_start(dl_min, true, true, 0);
375 hbox.pack_start(dl_min_tweak, false, false, 0);
376 pack_start(hbox, false, false, 0);
379 public override void start()
385 protected override void update()
387 dl_hour.set_text("%2d".printf(dl_time/60));
388 dl_min.set_text("%2d".printf(dl_time%60));
392 protected void on_tweak(IncDec id, int amount)
395 if (id == dl_hour_tweak)
396 dl_time += amount * 60;
397 else if (id == dl_min_tweak)
404 protected override time_t get_deadline()
406 return time_t() + dl_time * 60;
411 public class AddDailyDeadline : Applet
413 public AddDailyDeadline()
415 _label = "Add daily deadline";
420 public Status status;
421 public AddAbsoluteDeadline aad;
422 public AddRelativeDeadline ard;
423 //AddDailyDeadline add;
427 status = new Status("Zavai");
428 aad = new AddAbsoluteDeadline();
429 ard = new AddRelativeDeadline();
431 add = new AddDailyDeadline();
432 zavai.registry.register_applet("clock.adddaily", add);
435 zavai.menu_misc.add_applet(aad);
436 zavai.menu_misc.add_applet(ard);
437 //menu_misc.add_applet("clock.adddaily");