/* * 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 time_t last_gps_time; protected time_t last_gps_time_system_time; protected time_t last_system_time; protected dynamic DBus.Object gps_time; protected uint system_time_timeout; protected time_t last_minute; public Clock() { 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); last_minute = 0; last_gps_time = 0; last_gps_time_system_time = 0; last_system_time = time_t(); gps_time = zavai.registry.sbus.get_object( "org.freesmartphone.ogpsd", "/org/freedesktop/Gypsy", "org.freedesktop.Gypsy.Time"); system_time_timeout = Timeout.add(5000, on_system_time); gps_time.TimeChanged += on_gps_time; update_time(); } public void update_time() { time_t new_last_minute; string type; if (last_gps_time_system_time + 10 > last_system_time) { new_last_minute = last_gps_time / 60; type = "gps"; } else { new_last_minute = last_system_time / 60; type = "sys"; } if (new_last_minute != last_minute) { last_minute = new_last_minute; var t = Time.local(last_minute * 60); l_date.set_text(t.format("%a %d %b")); l_time.set_text("%2d:%02d (%s)".printf(t.hour, t.minute, type)); } } private void on_gps_time(dynamic DBus.Object pos, int t) { if (t == 0) { last_gps_time_system_time = 0; update_time(); } else { last_gps_time = (time_t)t; last_gps_time_system_time = time_t(); update_time(); } } private bool on_system_time() { last_system_time = time_t(); update_time(); return true; } } 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); } } } }