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;
51 last_time_type = zavai.clock.SourceType.SYSTEM;
53 last_deadline_label = "";
55 l_date = new Gtk.Label("--");
56 l_date.modify_font(Pango.FontDescription.from_string("Sans 40"));
57 l_date_button = new Gtk.Button();
58 l_date_button.set_image(l_date);
59 l_date_button.relief = Gtk.ReliefStyle.NONE;
60 l_date_button.clicked += on_date_clicked;
61 pack_start(l_date_button, false, false, 0);
62 l_time = new Gtk.Label("--:--");
63 l_time.modify_font(Pango.FontDescription.from_string("Sans 60"));
64 pack_start(l_time, false, false, 0);
65 l_deadline = new Gtk.Label("");
66 l_deadline.modify_font(Pango.FontDescription.from_string("Sans 30"));
67 l_deadline.set_justify(Gtk.Justification.CENTER);
68 pack_start(l_deadline, false, false, 0);
71 pack_start(log, false, false, 0);
73 zavai.clock.clock.minute_changed += on_minute_changed;
74 zavai.clock.clock.schedule_changed += on_schedule_changed;
75 on_schedule_changed(zavai.clock.clock.next_alarm());
77 zavai.clock.clock.request("ui.main.clock");
80 private void on_date_clicked(Gtk.Button b)
82 zavai.app.push_applet(zavai.ui.calendar.calendar);
85 private void on_schedule_changed(zavai.clock.Alarm? next)
90 last_deadline_label = "";
92 last_deadline = next.ev.deadline;
93 last_deadline_label = next.label;
95 on_minute_changed((long)last_time, last_time_type);
98 private void on_minute_changed(long ts, zavai.clock.SourceType type)
100 last_time = (time_t)ts;
101 last_time_type = type;
103 string typetag = "unknown";
106 case zavai.clock.SourceType.GPS:
109 case zavai.clock.SourceType.SYSTEM:
114 var t = Time.local((time_t)ts);
115 l_date.set_text(t.format("%a %d %b"));
116 l_time.set_text("%2d:%02d (%s)".printf(t.hour, t.minute, typetag));
118 if (last_deadline == 0)
119 l_deadline.set_text("");
122 int remaining = (int)(last_deadline - last_time);
123 int hours = remaining / 3600;
124 int minutes = (remaining % 3600) / 60;
125 if (hours == 0 && minutes == 0)
126 l_deadline.set_text(last_deadline_label + "\nanytime now");
128 l_deadline.set_text("%s\nin %02dh %02dm".printf(last_deadline_label, hours, minutes));
133 public class Status : Applet
135 public Gtk.HBox status_icons;
137 public Gtk.Label gsm_status;
138 public Gtk.Label gsm_info;
139 public AppletPushLink menu;
141 public Status(string label)
144 status_icons = new Gtk.HBox(false, 0);
146 gsm_status = new Gtk.Label("");
147 gsm_info = new Gtk.Label("");
148 menu = new AppletPushLink(zavai.menu_main);
150 pack_start(status_icons, false, false, 0);
151 pack_start(clock, false, false, 0);
152 pack_start(gsm_status, false, false, 0);
153 pack_start(gsm_info, false, false, 0);
154 // pack_start(music.player, false, false, 0);
155 pack_end(menu, false, false, 0);
157 zavai.gsm.gsm.status_changed += (msg) => { gsm_status.set_text(msg); };
158 zavai.gsm.gsm.info_changed += () => {
159 stderr.printf("NEW INFO %s %s %d\n", zavai.gsm.gsm.info_provider, zavai.gsm.gsm.info_registration, zavai.gsm.gsm.info_signal_strength);
160 string text = "%s (%s)".printf(zavai.gsm.gsm.info_provider, zavai.gsm.gsm.info_registration);
161 if (zavai.gsm.gsm.info_signal_strength != -1)
162 text = "%s %d%%".printf(text, zavai.gsm.gsm.info_signal_strength);
163 gsm_info.set_text(text);
168 public class IncDec : Gtk.HBox
170 protected Gtk.Button b_decmore;
171 protected Gtk.Button b_dec;
172 protected Gtk.Button b_inc;
173 protected Gtk.Button b_incmore;
174 static const int BH = 50;
175 static const int BW = 50;
177 public signal void tweaked(IncDec id, int amount);
182 b_decmore = new Gtk.Button.with_label("«");
183 b_decmore.set_size_request(BW, BH);
184 b_dec = new Gtk.Button.with_label("<");
185 b_dec.set_size_request(BW, BH);
186 b_inc = new Gtk.Button.with_label(">");
187 b_inc.set_size_request(BW, BH);
188 b_incmore = new Gtk.Button.with_label("»");
189 b_incmore.set_size_request(BW, BH);
190 pack_start(b_decmore, false, true, 0);
191 pack_start(b_dec, false, true, 0);
192 pack_start(b_inc, false, true, 0);
193 pack_start(b_incmore, false, true, 0);
194 b_decmore.clicked += on_clicked;
195 b_dec.clicked += on_clicked;
196 b_inc.clicked += on_clicked;
197 b_incmore.clicked += on_clicked;
200 protected void on_clicked(Gtk.Button b)
208 else if (b == b_incmore)
213 public abstract class AddDeadline : Applet
215 protected Gtk.ComboBoxEntry dl_label;
216 protected Gtk.Button dl_submit;
220 dl_label = new Gtk.ComboBoxEntry.text();
221 dl_label.append_text("Pasta");
222 dl_label.append_text("Talk");
223 dl_label.append_text("Leave");
224 dl_label.changed += on_label_changed;
226 var hbox = new Gtk.HBox(false, 0);
227 hbox.pack_start(new Gtk.Label("Label: "), false, false, 0);
228 hbox.pack_start(dl_label, true, true, 0);
229 pack_start(hbox, false, false, 0);
231 dl_submit = new Gtk.Button.with_label("Activate");
232 dl_submit.set_sensitive(false);
233 dl_submit.clicked += on_submit;
234 button_box.pack_start(dl_submit, true, true, 0);
237 public override void start()
239 ((Gtk.Entry)dl_label.get_child()).set_text("");
243 protected virtual void update()
245 dl_submit.set_sensitive(((Gtk.Entry)dl_label.get_child()).get_text() == "" ? false : true);
248 protected abstract time_t get_deadline();
250 protected void on_label_changed(Gtk.ComboBox e)
255 protected void on_submit(Gtk.Button b)
257 string label = ((Gtk.Entry)dl_label.get_child()).get_text();
258 time_t deadlinets = get_deadline();
259 Time deadline = Time.local(deadlinets);
260 string timespec = deadline.format("%H:%M %m/%d/%Y");
261 zavai.log.info("Scheduling deadline " + label + " at " + timespec);
262 zavai.clock.clock.schedule(timespec, label);
267 public class AddAbsoluteDeadline : AddDeadline
269 protected Gtk.Label dl_day;
270 protected IncDec dl_day_tweak;
271 protected Gtk.Label dl_hour;
272 protected IncDec dl_hour_tweak;
273 protected Gtk.Label dl_min;
274 protected IncDec dl_min_tweak;
275 protected time_t dl_time;
277 public AddAbsoluteDeadline()
279 _label = "Add absolute deadline";
282 dl_day = new Gtk.Label("");
283 dl_day.set_justify(Gtk.Justification.RIGHT);
284 dl_day_tweak = new IncDec();
285 dl_day_tweak.tweaked += on_tweak;
286 var hbox = new Gtk.HBox(false, 0);
287 hbox.pack_start(new Gtk.Label("Day: "), false, false, 0);
288 hbox.pack_start(dl_day, true, true, 0);
289 hbox.pack_start(dl_day_tweak, false, false, 0);
290 pack_start(hbox, false, false, 0);
292 dl_hour = new Gtk.Label("");
293 dl_hour.set_justify(Gtk.Justification.RIGHT);
294 dl_hour_tweak = new IncDec();
295 dl_hour_tweak.tweaked += on_tweak;
296 hbox = new Gtk.HBox(false, 0);
297 hbox.pack_start(new Gtk.Label("Hour: "), false, false, 0);
298 hbox.pack_start(dl_hour, true, true, 0);
299 hbox.pack_start(dl_hour_tweak, false, false, 0);
300 pack_start(hbox, false, false, 0);
302 dl_min = new Gtk.Label("");
303 dl_min.set_justify(Gtk.Justification.RIGHT);
304 dl_min_tweak = new IncDec();
305 dl_min_tweak.tweaked += on_tweak;
306 hbox = new Gtk.HBox(false, 0);
307 hbox.pack_start(new Gtk.Label("Minute: "), false, false, 0);
308 hbox.pack_start(dl_min, true, true, 0);
309 hbox.pack_start(dl_min_tweak, false, false, 0);
310 pack_start(hbox, false, false, 0);
313 public override void start()
319 protected override void update()
321 Time t = Time.local(dl_time);
322 dl_day.set_text(t.format("%a %d %b"));
323 dl_hour.set_text(t.format("%H"));
324 dl_min.set_text(t.format("%M"));
328 protected override time_t get_deadline()
333 protected void on_tweak(IncDec id, int amount)
335 time_t old = dl_time;
336 if (id == dl_day_tweak)
337 dl_time += amount * 3600 * 24;
338 else if (id == dl_hour_tweak)
339 dl_time += amount * 3600;
340 else if (id == dl_min_tweak)
341 dl_time += amount * 60;
342 time_t now = time_t();
349 public class AddRelativeDeadline : AddDeadline
351 protected Gtk.Label dl_hour;
352 protected IncDec dl_hour_tweak;
353 protected Gtk.Label dl_min;
354 protected IncDec dl_min_tweak;
355 protected int dl_time;
357 public AddRelativeDeadline()
359 _label = "Add relative deadline";
362 dl_hour = new Gtk.Label("");
363 dl_hour.set_justify(Gtk.Justification.RIGHT);
364 dl_hour_tweak = new IncDec();
365 dl_hour_tweak.tweaked += on_tweak;
366 var hbox = new Gtk.HBox(false, 0);
367 hbox.pack_start(new Gtk.Label("Hour: "), false, false, 0);
368 hbox.pack_start(dl_hour, true, true, 0);
369 hbox.pack_start(dl_hour_tweak, false, false, 0);
370 pack_start(hbox, false, false, 0);
372 dl_min = new Gtk.Label("");
373 dl_min.set_justify(Gtk.Justification.RIGHT);
374 dl_min_tweak = new IncDec();
375 dl_min_tweak.tweaked += on_tweak;
376 hbox = new Gtk.HBox(false, 0);
377 hbox.pack_start(new Gtk.Label("Minute: "), false, false, 0);
378 hbox.pack_start(dl_min, true, true, 0);
379 hbox.pack_start(dl_min_tweak, false, false, 0);
380 pack_start(hbox, false, false, 0);
383 public override void start()
389 protected override void update()
391 dl_hour.set_text("%2d".printf(dl_time/60));
392 dl_min.set_text("%2d".printf(dl_time%60));
396 protected void on_tweak(IncDec id, int amount)
399 if (id == dl_hour_tweak)
400 dl_time += amount * 60;
401 else if (id == dl_min_tweak)
408 protected override time_t get_deadline()
410 return time_t() + dl_time * 60;
414 public class Log : Gtk.VBox
416 protected Gtk.Label l_info;
417 protected Gtk.Button l_info_button;
421 l_info = new Gtk.Label("");
422 // l_info.modify_font(Pango.FontDescription.from_string("Sans 60"));
423 pack_start(l_info, false, false, 0);
425 l_info_button = new Gtk.Button();
426 l_info_button.set_image(l_info);
427 l_info_button.relief = Gtk.ReliefStyle.NONE;
428 l_info_button.clicked += (b) => {
429 zavai.app.push_applet(zavai.ui.logview.log);
431 pack_start(l_info_button, false, false, 0);
433 zavai.log.log.entries_changed += refresh;
438 public void refresh()
441 zavai.log.log.list_entries((d, f) => {
445 l_info.set_text("%d log entries".printf(count));
446 l_info_button.set_sensitive(count != 0);
447 //zavai.log.Log l = zavai.log.log.load(args[2]);
452 public class AddDailyDeadline : Applet
454 public AddDailyDeadline()
456 _label = "Add daily deadline";
461 public Status status;
462 public AddAbsoluteDeadline aad;
463 public AddRelativeDeadline ard;
464 //AddDailyDeadline add;
468 status = new Status("Zavai");
469 aad = new AddAbsoluteDeadline();
470 ard = new AddRelativeDeadline();
472 add = new AddDailyDeadline();
473 zavai.registry.register_applet("clock.adddaily", add);
476 zavai.menu_misc.add_applet(aad);
477 zavai.menu_misc.add_applet(ard);
478 //menu_misc.add_applet("clock.adddaily");