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")
153 registry.register(GPXAudioTracer(registry))
154 registry.register(GPXWaypoint(registry))
157 var useless = new Useless();
158 zavai.registry.register_applet("app.debug.useless", useless);
160 var menu_waypoint = new Waypoint();
161 //label_on = "Stop GPX trace";
162 //label_off = "Start GPX trace";
163 //label_on = "Stop GPS monitor";
164 //label_off = "Start GPS monitor";
165 //label_on = "Stop GPS position tracking";
166 //label_off = "Start GPS position tracking";
167 //label_on = "Stop keeping GPS on";
168 //label_off = "Keep GPS on";
171 var menu_gps = new zavai.Menu("GPS");
172 //menu_gps.add_applet("app.debug.useless");
173 menu_gps.add_service_toggle("gps", "Keep GPS on", "Stop keeping GPS on");
174 menu_gps.add_service_toggle("gps.gpx", "Start GPX trace", "Stop GPX trace");
175 menu_gps.add_widget(menu_waypoint);
177 zavai.registry.register_menu("menu.gps", menu_gps);
178 zavai.registry.getmenu("menu.main").add_applet("menu.gps");