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
27 public class StatusBar : Gtk.HBox
34 public class Clock : Gtk.VBox
36 protected Gtk.Label l_date;
37 protected Gtk.Label l_time;
39 protected time_t last_gps_time;
40 protected time_t last_gps_time_system_time;
41 protected time_t last_system_time;
42 protected dynamic DBus.Object gps_time;
43 protected uint system_time_timeout;
44 protected time_t last_minute;
48 l_date = new Gtk.Label("--");
49 l_date.modify_font(Pango.FontDescription.from_string("Sans 40"));
50 pack_start(l_date, false, false, 0);
51 l_time = new Gtk.Label("--:--");
52 l_time.modify_font(Pango.FontDescription.from_string("Sans 60"));
53 pack_start(l_time, false, false, 0);
55 stderr.printf("CLOCK\n");
58 last_gps_time_system_time = 0;
59 last_system_time = time_t();
61 gps_time = zavai.registry.sbus.get_object(
62 "org.freesmartphone.ogpsd",
63 "/org/freedesktop/Gypsy",
64 "org.freedesktop.Gypsy.Time");
66 system_time_timeout = Timeout.add(5000, on_system_time);
67 gps_time.TimeChanged += on_gps_time;
71 public void update_time()
73 time_t new_last_minute;
75 if (last_gps_time_system_time + 10 > last_system_time)
77 new_last_minute = last_gps_time / 60;
82 new_last_minute = last_system_time / 60;
85 if (new_last_minute != last_minute)
87 last_minute = new_last_minute;
88 var t = Time.local(last_minute * 60);
89 l_date.set_text(t.format("%a %d %b"));
90 l_time.set_text("%2d:%02d (%s)".printf(t.hour, t.minute, type));
94 private void on_gps_time(dynamic DBus.Object pos, int t)
96 last_gps_time = (time_t)t;
97 last_gps_time_system_time = time_t();
101 private bool on_system_time()
103 last_system_time = time_t();
109 public class Status : Applet
112 public AppletPushLink menu;
114 public Status(string label)
118 menu = new AppletPushLink("menu.main");
120 pack_start(clock, false, false, 0);
121 pack_end(menu, false, false, 0);
129 status = new Status("Zavai");
130 zavai.registry.register_applet("zavai.status", status);