2 * gpx_trace - zavai GPX trace functions
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
26 class GPSOn(gtk.ToggleAction):
27 states = [_("GPS always on"), _("GPS on when needed")]
29 def __init__(self, registry, **kw):
31 super(GPSOn, self).__init__("menu.main.gps.alwayson", self.states[self.state], None, None)
33 self.registry = registry
34 self.set_active(False)
36 self.connect("toggled", self.on_toggle)
38 def on_toggle(self, *args):
39 self.state = (self.state + 1) % len(self.states)
40 self.set_property("label", self.states[self.state])
47 self.registry.resource("gps").connect("gps", self)
50 self.registry.resource("gps").disconnect("gps", self)
52 class GPXTracer(gtk.ToggleAction):
53 states = [_("Start GPX trace"), _("Stop GPX trace")]
55 def __init__(self, registry, **kw):
57 super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
59 self.registry = registry
60 self.set_active(False)
62 self.connect("toggled", self.on_toggle)
64 def on_toggle(self, *args):
65 self.state = (self.state + 1) % len(self.states)
66 self.set_property("label", self.states[self.state])
73 zavai.info("GPX trace started")
74 self.registry.resource("gpx").connect("gpx", self)
77 zavai.info("GPX trace ended")
78 self.registry.resource("gpx").disconnect("gpx", self)
81 public class Waypoint : BigButton
85 set_label("Take waypoint");
86 zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
87 clicked += on_clicked;
88 set_sensitive(zavai.gps.gpx.tracking);
91 protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
93 stderr.printf("Toggled %d\n", (int)new_state);
94 set_sensitive(new_state);
97 protected void on_clicked()
99 stderr.printf("Activate\n");
100 zavai.gps.gpx.waypoint();
105 class GPXAudioTracer(gtk.ToggleAction):
106 states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
108 def __init__(self, registry, **kw):
110 super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
112 self.registry = registry
113 self.recorder = zavai.Recorder(registry)
114 self.set_active(False)
116 self.connect("toggled", self.on_toggle)
120 super(GPXAudioTracer, self).shutdown()
122 def on_toggle(self, *args):
123 self.state = (self.state + 1) % len(self.states)
124 self.set_property("label", self.states[self.state])
125 if self.get_active():
131 zavai.info("GPX trace started")
132 gpx = self.registry.resource("gpx")
133 gpx.connect("gpx", self)
134 gpx.add_activity_monitor(self.on_gpx_activity_changed)
137 zavai.info("GPX trace ended")
138 gpx = self.registry.resource("gpx")
139 gpx.disconnect("gpx", self)
141 gpx.del_activity_monitor(self.on_gpx_activity_changed)
143 def on_gpx_activity_changed(self, gpx, state):
145 self.recorder.start(gpx.basename + ".wav")
150 public class GPSRequestLink : Gtk.ToggleButton
152 protected string service_name;
153 protected string label_start;
154 protected string label_stop;
155 protected Gtk.StatusIcon status_icon;
156 protected int fix_status = 0;
158 public GPSRequestLink()
160 service_name = "gps";
161 label_start = "Keep GPS on";
162 label_stop = "Stop keeping GPS on";
163 set_size_request(0, zavai.config.min_button_height);
164 toggled += on_toggled;
166 set_label(get_active() ? label_stop : label_start);
168 //tooltip = "GPS status";
170 fix_status = zavai.gps.gps.device.GetFixStatus();
174 zavai.gps.gps.device.FixStatusChanged += on_fix_status_changed;
177 status_icon = new Gtk.StatusIcon();
178 status_icon.set_visible(true);
179 status_icon.activate += on_status_activate;
183 protected void update_icon()
186 if (fix_status == 2 || fix_status == 3)
187 name = zavai.config.icondir + "/" + (get_active() ? "gps_fix_on.png" : "gps_fix_off.png");
189 name = zavai.config.icondir + "/" + (get_active() ? "gps_nofix_on.png" : "gps_nofix_off.png");
190 stderr.printf("load icon from %s\n", name);
191 status_icon.set_from_file(name);
194 private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
196 this.fix_status = fix_status;
200 private void on_toggled(Gtk.Button src)
202 Service s = zavai.registry.gets(service_name);
204 s.request("servicerequestlink");
206 s.release("servicerequestlink");
207 set_label(get_active() ? label_stop : label_start);
211 private void on_status_activate()
213 set_active(!get_active());
220 registry.register(GPXAudioTracer(registry))
221 registry.register(GPXWaypoint(registry))
224 var useless = new Useless();
225 zavai.registry.register_applet("app.debug.useless", useless);
227 var menu_waypoint = new Waypoint();
228 var menu_gpsrequest = new GPSRequestLink();
229 //label_on = "Stop GPX trace";
230 //label_off = "Start GPX trace";
231 //label_on = "Stop GPS monitor";
232 //label_off = "Start GPS monitor";
233 //label_on = "Stop GPS position tracking";
234 //label_off = "Start GPS position tracking";
235 //label_on = "Stop keeping GPS on";
236 //label_off = "Keep GPS on";
239 var menu_gps = new zavai.Menu("GPS");
240 //menu_gps.add_applet("app.debug.useless");
241 menu_gps.add_service_toggle("gps.gpx", "Start GPX trace", "Stop GPX trace");
242 menu_gps.add_widget(menu_waypoint);
243 menu_gps.add_widget(menu_gpsrequest);
245 zavai.registry.register_menu("menu.gps", menu_gps);
246 zavai.registry.getmenu("menu.main").add_applet("menu.gps");