/* * app_main - zavai main status display * * Copyright (C) 2009 Enrico Zini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using GLib; namespace zavai { namespace ui { namespace main { /* public class StatusBar : Gtk.HBox { void StatusBar() { } } */ public class Clock : Gtk.VBox { protected Gtk.Label l_date; 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; public Clock() { last_time = time_t(); last_time_type = zavai.clock.SourceType.SYSTEM; last_deadline = 0; last_deadline_label = ""; l_date = new Gtk.Label("--"); l_date.modify_font(Pango.FontDescription.from_string("Sans 40")); pack_start(l_date, 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")); pack_start(l_deadline, false, false, 0); zavai.clock.clock.minute_changed += on_minute_changed; zavai.clock.clock.schedule_changed += on_schedule_changed; zavai.clock.clock.request("ui.main.clock"); } private void on_schedule_changed() { zavai.clock.Alarm a = zavai.clock.clock.next_alarm(); if (a == null) { last_deadline = 0; last_deadline_label = ""; } else { last_deadline = a.deadline; last_deadline_label = a.label; } on_minute_changed((long)last_time, last_time_type); } private void on_minute_changed(long ts, zavai.clock.SourceType type) { last_time = (time_t)ts; last_time_type = type; string typetag = "unknown"; switch (type) { case zavai.clock.SourceType.GPS: typetag = "gps"; break; case zavai.clock.SourceType.SYSTEM: 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)); if (last_deadline == 0) l_deadline.set_text(""); else { int remaining = (int)(last_time - last_deadline); 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)); } } } public class Status : Applet { public Gtk.HBox status_icons; public Clock clock; public AppletPushLink menu; 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); } } Status status; public void init() { status = new Status("Zavai"); zavai.registry.register_applet("zavai.status", status); } } } }