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
27 public class Waypoint : BigButton
31 set_label("Take waypoint");
32 zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
33 clicked += on_clicked;
34 set_sensitive(zavai.gps.gpx.tracking);
37 protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
39 stderr.printf("Toggled %d\n", (int)new_state);
40 set_sensitive(new_state);
43 protected void on_clicked()
45 stderr.printf("Activate\n");
46 zavai.gps.gpx.waypoint();
51 class GPXAudioTracer(gtk.ToggleAction):
52 states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
54 def __init__(self, registry, **kw):
56 super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
58 self.registry = registry
59 self.recorder = zavai.Recorder(registry)
60 self.set_active(False)
62 self.connect("toggled", self.on_toggle)
66 super(GPXAudioTracer, self).shutdown()
68 def on_toggle(self, *args):
69 self.state = (self.state + 1) % len(self.states)
70 self.set_property("label", self.states[self.state])
77 zavai.info("GPX trace started")
78 gpx = self.registry.resource("gpx")
79 gpx.connect("gpx", self)
80 gpx.add_activity_monitor(self.on_gpx_activity_changed)
83 zavai.info("GPX trace ended")
84 gpx = self.registry.resource("gpx")
85 gpx.disconnect("gpx", self)
87 gpx.del_activity_monitor(self.on_gpx_activity_changed)
89 def on_gpx_activity_changed(self, gpx, state):
91 self.recorder.start(gpx.basename + ".wav")
96 public class GPSRequestLink : Gtk.ToggleButton
98 protected string service_name;
99 protected string label_start;
100 protected string label_stop;
101 protected zavai.StatusIcon status_icon;
102 protected int fix_status = 0;
104 public GPSRequestLink()
106 service_name = "gps";
107 label_start = "Keep GPS on";
108 label_stop = "Stop keeping GPS on";
109 set_size_request(0, zavai.config.min_button_height);
110 toggled += on_toggled;
112 set_label(get_active() ? label_stop : label_start);
114 //tooltip = "GPS status";
116 fix_status = zavai.gps.gps.device.GetFixStatus();
120 zavai.gps.gps.device.FixStatusChanged += on_fix_status_changed;
123 status_icon = new zavai.StatusIcon();
124 status_icon.install();
125 status_icon.clicked += on_status_clicked;
129 protected void update_icon()
132 if (fix_status == 2 || fix_status == 3)
133 name = zavai.config.icondir + "/" + (get_active() ? "gps_fix_on.png" : "gps_fix_off.png");
135 name = zavai.config.icondir + "/" + (get_active() ? "gps_nofix_on.png" : "gps_nofix_off.png");
136 stderr.printf("load icon from %s\n", name);
137 status_icon.set_from_file(name);
140 private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
142 this.fix_status = fix_status;
146 private void on_toggled(Gtk.Button src)
148 Service s = zavai.registry.gets(service_name);
150 s.request("servicerequestlink");
152 s.release("servicerequestlink");
153 set_label(get_active() ? label_stop : label_start);
157 private void on_status_clicked(Gtk.Button b)
159 set_active(!get_active());
166 registry.register(GPXAudioTracer(registry))
170 var window_list = new SatelliteMonitor();
171 zavai.registry.register_applet("ui.gps.monitor", window_list);
173 var menu_waypoint = new Waypoint();
174 var menu_gpsrequest = new GPSRequestLink();
177 var menu_gps = new zavai.Menu("GPS");
178 //menu_gps.add_applet("app.debug.useless");
179 menu_gps.add_service_toggle("gps.gpx", "Start GPX trace", "Stop GPX trace");
180 menu_gps.add_applet("ui.gps.monitor");
181 menu_gps.add_widget(menu_waypoint);
182 menu_gps.add_widget(menu_gpsrequest);
184 zavai.registry.register_menu("menu.gps", menu_gps);
185 zavai.registry.getmenu("menu.main").add_applet("menu.gps");