]> ToastFreeware Gitweb - gregoa/zavai.git/blobdiff - src/app_main.vala
Added log viewer
[gregoa/zavai.git] / src / app_main.vala
index d0f704133793e778a09530ca2fa4b0dcef185bef..0faa7274ba4bb6c9080dc64caea93693db686940 100644 (file)
@@ -36,14 +36,16 @@ public class StatusBar : Gtk.HBox
 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;
@@ -52,7 +54,11 @@ public class Clock : Gtk.VBox
 
         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);
@@ -61,24 +67,30 @@ public class Clock : Gtk.VBox
         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);
     }
@@ -98,7 +110,7 @@ public class Clock : Gtk.VBox
                 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));
@@ -113,7 +125,7 @@ public class Clock : Gtk.VBox
             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));
         }
     }
 }
@@ -122,19 +134,35 @@ public class Status : Applet
 {
     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");
-
-               pack_start(status_icons, false, false, 0);
-               pack_start(clock, false, false, 0);
-               pack_end(menu, false, false, 0);
-       }
+        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
@@ -152,13 +180,13 @@ public class IncDec : Gtk.HBox
     {
         homogeneous = true;
         b_decmore = new Gtk.Button.with_label("«");
-               b_decmore.set_size_request(BW, BH);
+        b_decmore.set_size_request(BW, BH);
         b_dec = new Gtk.Button.with_label("<");
-               b_dec.set_size_request(BW, BH);
+        b_dec.set_size_request(BW, BH);
         b_inc = new Gtk.Button.with_label(">");
-               b_inc.set_size_request(BW, BH);
+        b_inc.set_size_request(BW, BH);
         b_incmore = new Gtk.Button.with_label("»");
-               b_incmore.set_size_request(BW, BH);
+        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);
@@ -182,16 +210,62 @@ public class IncDec : Gtk.HBox
     }
 }
 
-public class LabelEntry : Gtk.Entry
+public abstract class AddDeadline : Applet
 {
-    public LabelEntry()
+    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();
+    }
+
+    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();
     }
 }
 
-public class AddAbsoluteDeadline : Applet
+public class AddAbsoluteDeadline : AddDeadline
 {
-    protected LabelEntry dl_label;
     protected Gtk.Label dl_day;
     protected IncDec dl_day_tweak;
     protected Gtk.Label dl_hour;
@@ -199,30 +273,24 @@ public class AddAbsoluteDeadline : Applet
     protected Gtk.Label dl_min;
     protected IncDec dl_min_tweak;
     protected time_t dl_time;
-    protected Gtk.Button dl_submit;
 
     public AddAbsoluteDeadline()
     {
         _label = "Add absolute deadline";
         dl_time = 0;
 
-        dl_label = new LabelEntry();
-        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_day = new Gtk.Label("");
+        dl_day.set_justify(Gtk.Justification.RIGHT);
         dl_day_tweak = new IncDec();
         dl_day_tweak.tweaked += on_tweak;
-        hbox = new Gtk.HBox(false, 0);
+        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);
@@ -232,6 +300,7 @@ public class AddAbsoluteDeadline : Applet
         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);
@@ -239,27 +308,26 @@ public class AddAbsoluteDeadline : Applet
         hbox.pack_start(dl_min, true, true, 0);
         hbox.pack_start(dl_min_tweak, false, false, 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()
+    public override void start()
     {
         dl_time = time_t();
-        dl_label.set_text("");
-        update();
+        base.start();
     }
 
-    protected void update()
+    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"));
-        dl_submit.set_sensitive(dl_label.text == "" ? false : true);
+        base.update();
+    }
+
+    protected override time_t get_deadline()
+    {
+        return dl_time;
     }
 
     protected void on_tweak(IncDec id, int amount)
@@ -276,51 +344,33 @@ public class AddAbsoluteDeadline : Applet
             dl_time = old;
         update();
     }
-
-    protected void on_submit(Gtk.Button b)
-    {
-        zavai.clock.clock.schedule(new zavai.clock.Alarm(dl_time, dl_label.text));
-        back();
-    }
-
-    protected void on_label_changed(LabelEntry e)
-    {
-        update();
-    }
 }
 
-public class AddRelativeDeadline : Applet
+public class AddRelativeDeadline : AddDeadline
 {
-    protected LabelEntry dl_label;
     protected Gtk.Label dl_hour;
     protected IncDec dl_hour_tweak;
     protected Gtk.Label dl_min;
     protected IncDec dl_min_tweak;
     protected int dl_time;
-    protected Gtk.Button dl_submit;
 
     public AddRelativeDeadline()
     {
         _label = "Add relative deadline";
         dl_time = 0;
 
-        dl_label = new LabelEntry();
-        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_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);
+        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);
@@ -328,25 +378,19 @@ public class AddRelativeDeadline : Applet
         hbox.pack_start(dl_min, true, true, 0);
         hbox.pack_start(dl_min_tweak, false, false, 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()
+    public override void start()
     {
         dl_time = 0;
-        dl_label.set_text("");
-        update();
+        base.start();
     }
 
-    protected void update()
+    protected override void update()
     {
         dl_hour.set_text("%2d".printf(dl_time/60));
         dl_min.set_text("%2d".printf(dl_time%60));
-        dl_submit.set_sensitive(dl_label.text == "" ? false : true);
+        base.update();
     }
 
     protected void on_tweak(IncDec id, int amount)
@@ -361,18 +405,50 @@ public class AddRelativeDeadline : Applet
         update();
     }
 
-    protected void on_submit(Gtk.Button b)
+    protected override time_t get_deadline()
     {
-        zavai.clock.clock.schedule(new zavai.clock.Alarm(time_t() + dl_time * 60, dl_label.text));
-        back();
+        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 += (b) => {
+            zavai.app.push_applet(zavai.ui.logview.log);
+        };
+        pack_start(l_info_button, false, false, 0);
+
+        zavai.log.log.entries_changed += refresh;
+
+        refresh();
     }
 
-    protected void on_label_changed(LabelEntry e)
+    public void refresh()
     {
-        update();
+        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()
@@ -380,28 +456,26 @@ public class AddDailyDeadline : Applet
         _label = "Add daily deadline";
     }
 }
+*/
 
-Status status;
-AddAbsoluteDeadline aad;
-AddRelativeDeadline ard;
-AddDailyDeadline add;
+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();
-    zavai.registry.register_applet("clock.addabsolute", aad);
     ard = new AddRelativeDeadline();
-    zavai.registry.register_applet("clock.addrelative", ard);
+    /*
     add = new AddDailyDeadline();
     zavai.registry.register_applet("clock.adddaily", add);
+    */
 
-    var menu_misc = zavai.registry.getmenu("menu.misc");
-       menu_misc.add_applet("clock.addabsolute");
-       menu_misc.add_applet("clock.addrelative");
-       menu_misc.add_applet("clock.adddaily");
+    zavai.menu_misc.add_applet(aad);
+    zavai.menu_misc.add_applet(ard);
+    //menu_misc.add_applet("clock.adddaily");
 }
 
 }