public class Clock : Gtk.VBox
{
protected Gtk.Label l_date;
+ protected Gtk.Button l_date_button;
protected Gtk.Label l_time;
protected Gtk.Label l_deadline;
protected time_t last_time;
protected zavai.clock.SourceType last_time_type;
protected time_t last_deadline;
protected string last_deadline_label;
+ protected Log log;
- public Clock()
+ construct
{
last_time = time_t();
last_time_type = zavai.clock.SourceType.SYSTEM;
l_date = new Gtk.Label("--");
l_date.modify_font(Pango.FontDescription.from_string("Sans 40"));
- pack_start(l_date, false, false, 0);
+ l_date_button = new Gtk.Button();
+ l_date_button.set_image(l_date);
+ l_date_button.relief = Gtk.ReliefStyle.NONE;
+ l_date_button.clicked += on_date_clicked;
+ pack_start(l_date_button, false, false, 0);
l_time = new Gtk.Label("--:--");
l_time.modify_font(Pango.FontDescription.from_string("Sans 60"));
pack_start(l_time, false, false, 0);
l_deadline = new Gtk.Label("");
l_deadline.modify_font(Pango.FontDescription.from_string("Sans 30"));
+ l_deadline.set_justify(Gtk.Justification.CENTER);
pack_start(l_deadline, false, false, 0);
+ log = new Log();
+ pack_start(log, false, false, 0);
+
zavai.clock.clock.minute_changed += on_minute_changed;
zavai.clock.clock.schedule_changed += on_schedule_changed;
+ on_schedule_changed(zavai.clock.clock.next_alarm());
zavai.clock.clock.request("ui.main.clock");
}
- private void on_schedule_changed()
+ private void on_date_clicked(Gtk.Button b)
+ {
+ zavai.app.push_applet(zavai.ui.calendar.calendar);
+ }
+
+ private void on_schedule_changed(zavai.clock.Alarm? next)
{
- zavai.clock.Alarm a = zavai.clock.clock.next_alarm();
- if (a == null)
+ if (next == null)
{
last_deadline = 0;
last_deadline_label = "";
- }
- else
- {
- last_deadline = a.deadline;
- last_deadline_label = a.label;
+ } else {
+ last_deadline = next.ev.deadline;
+ last_deadline_label = next.label;
}
on_minute_changed((long)last_time, last_time_type);
}
typetag = "sys";
break;
}
-
+
var t = Time.local((time_t)ts);
l_date.set_text(t.format("%a %d %b"));
l_time.set_text("%2d:%02d (%s)".printf(t.hour, t.minute, typetag));
l_deadline.set_text("");
else
{
- int remaining = (int)(last_time - last_deadline);
+ int remaining = (int)(last_deadline - last_time);
int hours = remaining / 3600;
int minutes = (remaining % 3600) / 60;
if (hours == 0 && minutes == 0)
l_deadline.set_text(last_deadline_label + "\nanytime now");
else
- l_deadline.set_text("%s\non %02dh %02dm".printf(last_deadline_label, hours, minutes));
+ l_deadline.set_text("%s\nin %02dh %02dm".printf(last_deadline_label, hours, minutes));
}
}
}
{
public Gtk.HBox status_icons;
public Clock clock;
+ public Gtk.Label gsm_status;
+ public Gtk.Label gsm_info;
public AppletPushLink menu;
- public Status(string label)
- {
- _label = label;
+ public Status(string label)
+ {
+ _label = label;
status_icons = new Gtk.HBox(false, 0);
clock = new Clock();
- menu = new AppletPushLink("menu.main");
+ gsm_status = new Gtk.Label("");
+ gsm_info = new Gtk.Label("");
+ menu = new AppletPushLink(zavai.menu_main);
+
+ pack_start(status_icons, false, false, 0);
+ pack_start(clock, false, false, 0);
+ pack_start(gsm_status, false, false, 0);
+ pack_start(gsm_info, false, false, 0);
+ // pack_start(music.player, false, false, 0);
+ pack_end(menu, false, false, 0);
+
+ zavai.gsm.gsm.status_changed += (msg) => { gsm_status.set_text(msg); };
+ zavai.gsm.gsm.info_changed += () => {
+stderr.printf("NEW INFO %s %s %d\n", zavai.gsm.gsm.info_provider, zavai.gsm.gsm.info_registration, zavai.gsm.gsm.info_signal_strength);
+ string text = "%s (%s)".printf(zavai.gsm.gsm.info_provider, zavai.gsm.gsm.info_registration);
+ if (zavai.gsm.gsm.info_signal_strength != -1)
+ text = "%s %d%%".printf(text, zavai.gsm.gsm.info_signal_strength);
+ gsm_info.set_text(text);
+ };
+ }
+}
+
+public class IncDec : Gtk.HBox
+{
+ protected Gtk.Button b_decmore;
+ protected Gtk.Button b_dec;
+ protected Gtk.Button b_inc;
+ protected Gtk.Button b_incmore;
+ static const int BH = 50;
+ static const int BW = 50;
+
+ public signal void tweaked(IncDec id, int amount);
+
+ public IncDec()
+ {
+ homogeneous = true;
+ b_decmore = new Gtk.Button.with_label("«");
+ b_decmore.set_size_request(BW, BH);
+ b_dec = new Gtk.Button.with_label("<");
+ b_dec.set_size_request(BW, BH);
+ b_inc = new Gtk.Button.with_label(">");
+ b_inc.set_size_request(BW, BH);
+ b_incmore = new Gtk.Button.with_label("»");
+ b_incmore.set_size_request(BW, BH);
+ pack_start(b_decmore, false, true, 0);
+ pack_start(b_dec, false, true, 0);
+ pack_start(b_inc, false, true, 0);
+ pack_start(b_incmore, false, true, 0);
+ b_decmore.clicked += on_clicked;
+ b_dec.clicked += on_clicked;
+ b_inc.clicked += on_clicked;
+ b_incmore.clicked += on_clicked;
+ }
+
+ protected void on_clicked(Gtk.Button b)
+ {
+ if (b == b_decmore)
+ tweaked(this, -10);
+ else if (b == b_dec)
+ tweaked(this, -1);
+ else if (b == b_inc)
+ tweaked(this, 1);
+ else if (b == b_incmore)
+ tweaked(this, 10);
+ }
+}
+
+public abstract class AddDeadline : Applet
+{
+ protected Gtk.ComboBoxEntry dl_label;
+ protected Gtk.Button dl_submit;
+
+ public AddDeadline()
+ {
+ dl_label = new Gtk.ComboBoxEntry.text();
+ dl_label.append_text("Pasta");
+ dl_label.append_text("Talk");
+ dl_label.append_text("Leave");
+ dl_label.changed += on_label_changed;
+
+ var hbox = new Gtk.HBox(false, 0);
+ hbox.pack_start(new Gtk.Label("Label: "), false, false, 0);
+ hbox.pack_start(dl_label, true, true, 0);
+ pack_start(hbox, false, false, 0);
+
+ dl_submit = new Gtk.Button.with_label("Activate");
+ dl_submit.set_sensitive(false);
+ dl_submit.clicked += on_submit;
+ button_box.pack_start(dl_submit, true, true, 0);
+ }
+
+ public override void start()
+ {
+ ((Gtk.Entry)dl_label.get_child()).set_text("");
+ update();
+ }
+
+ protected virtual void update()
+ {
+ dl_submit.set_sensitive(((Gtk.Entry)dl_label.get_child()).get_text() == "" ? false : true);
+ }
+
+ protected abstract time_t get_deadline();
+
+ protected void on_label_changed(Gtk.ComboBox e)
+ {
+ update();
+ }
- pack_start(status_icons, false, false, 0);
- pack_start(clock, false, false, 0);
- pack_end(menu, false, false, 0);
- }
+ protected void on_submit(Gtk.Button b)
+ {
+ string label = ((Gtk.Entry)dl_label.get_child()).get_text();
+ time_t deadlinets = get_deadline();
+ Time deadline = Time.local(deadlinets);
+ string timespec = deadline.format("%H:%M %m/%d/%Y");
+ zavai.log.info("Scheduling deadline " + label + " at " + timespec);
+ zavai.clock.clock.schedule(timespec, label);
+ back();
+ }
}
-Status status;
+public class AddAbsoluteDeadline : AddDeadline
+{
+ protected Gtk.Label dl_day;
+ protected IncDec dl_day_tweak;
+ protected Gtk.Label dl_hour;
+ protected IncDec dl_hour_tweak;
+ protected Gtk.Label dl_min;
+ protected IncDec dl_min_tweak;
+ protected time_t dl_time;
+
+ public AddAbsoluteDeadline()
+ {
+ _label = "Add absolute deadline";
+ dl_time = 0;
+
+ dl_day = new Gtk.Label("");
+ dl_day.set_justify(Gtk.Justification.RIGHT);
+ dl_day_tweak = new IncDec();
+ dl_day_tweak.tweaked += on_tweak;
+ var hbox = new Gtk.HBox(false, 0);
+ hbox.pack_start(new Gtk.Label("Day: "), false, false, 0);
+ hbox.pack_start(dl_day, true, true, 0);
+ hbox.pack_start(dl_day_tweak, false, false, 0);
+ pack_start(hbox, false, false, 0);
+
+ dl_hour = new Gtk.Label("");
+ dl_hour.set_justify(Gtk.Justification.RIGHT);
+ dl_hour_tweak = new IncDec();
+ dl_hour_tweak.tweaked += on_tweak;
+ hbox = new Gtk.HBox(false, 0);
+ hbox.pack_start(new Gtk.Label("Hour: "), false, false, 0);
+ hbox.pack_start(dl_hour, true, true, 0);
+ hbox.pack_start(dl_hour_tweak, false, false, 0);
+ pack_start(hbox, false, false, 0);
+
+ dl_min = new Gtk.Label("");
+ dl_min.set_justify(Gtk.Justification.RIGHT);
+ dl_min_tweak = new IncDec();
+ dl_min_tweak.tweaked += on_tweak;
+ hbox = new Gtk.HBox(false, 0);
+ hbox.pack_start(new Gtk.Label("Minute: "), false, false, 0);
+ hbox.pack_start(dl_min, true, true, 0);
+ hbox.pack_start(dl_min_tweak, false, false, 0);
+ pack_start(hbox, false, false, 0);
+ }
+
+ public override void start()
+ {
+ dl_time = time_t();
+ base.start();
+ }
+
+ protected override void update()
+ {
+ Time t = Time.local(dl_time);
+ dl_day.set_text(t.format("%a %d %b"));
+ dl_hour.set_text(t.format("%H"));
+ dl_min.set_text(t.format("%M"));
+ base.update();
+ }
+
+ protected override time_t get_deadline()
+ {
+ return dl_time;
+ }
+
+ protected void on_tweak(IncDec id, int amount)
+ {
+ time_t old = dl_time;
+ if (id == dl_day_tweak)
+ dl_time += amount * 3600 * 24;
+ else if (id == dl_hour_tweak)
+ dl_time += amount * 3600;
+ else if (id == dl_min_tweak)
+ dl_time += amount * 60;
+ time_t now = time_t();
+ if (dl_time < now)
+ dl_time = old;
+ update();
+ }
+}
+
+public class AddRelativeDeadline : AddDeadline
+{
+ protected Gtk.Label dl_hour;
+ protected IncDec dl_hour_tweak;
+ protected Gtk.Label dl_min;
+ protected IncDec dl_min_tweak;
+ protected int dl_time;
+
+ public AddRelativeDeadline()
+ {
+ _label = "Add relative deadline";
+ dl_time = 0;
+
+ dl_hour = new Gtk.Label("");
+ dl_hour.set_justify(Gtk.Justification.RIGHT);
+ dl_hour_tweak = new IncDec();
+ dl_hour_tweak.tweaked += on_tweak;
+ var hbox = new Gtk.HBox(false, 0);
+ hbox.pack_start(new Gtk.Label("Hour: "), false, false, 0);
+ hbox.pack_start(dl_hour, true, true, 0);
+ hbox.pack_start(dl_hour_tweak, false, false, 0);
+ pack_start(hbox, false, false, 0);
+
+ dl_min = new Gtk.Label("");
+ dl_min.set_justify(Gtk.Justification.RIGHT);
+ dl_min_tweak = new IncDec();
+ dl_min_tweak.tweaked += on_tweak;
+ hbox = new Gtk.HBox(false, 0);
+ hbox.pack_start(new Gtk.Label("Minute: "), false, false, 0);
+ hbox.pack_start(dl_min, true, true, 0);
+ hbox.pack_start(dl_min_tweak, false, false, 0);
+ pack_start(hbox, false, false, 0);
+ }
+
+ public override void start()
+ {
+ dl_time = 0;
+ base.start();
+ }
+
+ protected override void update()
+ {
+ dl_hour.set_text("%2d".printf(dl_time/60));
+ dl_min.set_text("%2d".printf(dl_time%60));
+ base.update();
+ }
+
+ protected void on_tweak(IncDec id, int amount)
+ {
+ int old = dl_time;
+ if (id == dl_hour_tweak)
+ dl_time += amount * 60;
+ else if (id == dl_min_tweak)
+ dl_time += amount;
+ if (dl_time < 0)
+ dl_time = old;
+ update();
+ }
+
+ protected override time_t get_deadline()
+ {
+ return time_t() + dl_time * 60;
+ }
+}
+
+public class Log : Gtk.VBox
+{
+ protected Gtk.Label l_info;
+ protected Gtk.Button l_info_button;
+
+ construct
+ {
+ l_info = new Gtk.Label("");
+ // l_info.modify_font(Pango.FontDescription.from_string("Sans 60"));
+ pack_start(l_info, false, false, 0);
+
+ l_info_button = new Gtk.Button();
+ l_info_button.set_image(l_info);
+ l_info_button.relief = Gtk.ReliefStyle.NONE;
+ // l_info_button.clicked += on_date_clicked;
+ pack_start(l_info_button, false, false, 0);
+
+ //zavai.clock.clock.minute_changed += on_minute_changed;
+ //zavai.clock.clock.schedule_changed += on_schedule_changed;
+ //on_schedule_changed(zavai.clock.clock.next_alarm());
+
+ //zavai.clock.clock.request("ui.main.clock");
+ refresh();
+ }
+
+ public void refresh()
+ {
+ int count = 0;
+ zavai.log.log.list_entries((d, f) => {
+ ++count;
+ return true;
+ });
+ l_info.set_text("%d log entries".printf(count));
+ l_info_button.set_sensitive(count != 0);
+ //zavai.log.Log l = zavai.log.log.load(args[2]);
+ }
+}
+
+/*
+public class AddDailyDeadline : Applet
+{
+ public AddDailyDeadline()
+ {
+ _label = "Add daily deadline";
+ }
+}
+*/
+
+public Status status;
+public AddAbsoluteDeadline aad;
+public AddRelativeDeadline ard;
+//AddDailyDeadline add;
public void init()
{
status = new Status("Zavai");
- zavai.registry.register_applet("zavai.status", status);
+ aad = new AddAbsoluteDeadline();
+ ard = new AddRelativeDeadline();
+ /*
+ add = new AddDailyDeadline();
+ zavai.registry.register_applet("clock.adddaily", add);
+ */
+
+ zavai.menu_misc.add_applet(aad);
+ zavai.menu_misc.add_applet(ard);
+ //menu_misc.add_applet("clock.adddaily");
}
}