2 * gpx_trace - zavai GPX trace functions
4 * Copyright (C) 2009--2010 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.toggled += on_gpx_toggled;
33 clicked += on_clicked;
34 set_sensitive(zavai.gps.gpx.started);
37 protected void on_gpx_toggled(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 label_start;
99 protected string label_stop;
100 protected zavai.StatusIcon status_icon;
101 protected int fix_status = 0;
103 public GPSRequestLink()
105 label_start = "Keep GPS on";
106 label_stop = "Stop keeping GPS on";
107 set_size_request(0, zavai.config.min_button_height);
108 set_active(zavai.gps.gps.started);
109 toggled += on_toggled;
111 set_label(get_active() ? label_stop : label_start);
113 //tooltip = "GPS status";
114 fix_status = zavai.gps.gps.fix_status();
115 zavai.gps.gps.fix_status_changed += on_fix_status_changed;
118 status_icon = new zavai.StatusIcon();
119 status_icon.install();
120 status_icon.clicked += on_status_clicked;
124 protected void update_icon()
127 if (fix_status != libgps.STATUS_NO_FIX)
128 name = zavai.config.icondir + "/" + (get_active() ? "gps_fix_on.png" : "gps_fix_off.png");
130 name = zavai.config.icondir + "/" + (get_active() ? "gps_nofix_on.png" : "gps_nofix_off.png");
131 stderr.printf("load icon from %s\n", name);
132 status_icon.set_from_file(name);
135 private void on_fix_status_changed(int fix_status)
137 this.fix_status = fix_status;
141 private void on_toggled(Gtk.Button src)
144 zavai.gps.gps.request("servicerequestlink");
146 zavai.gps.gps.release("servicerequestlink");
147 set_label(get_active() ? label_stop : label_start);
151 private void on_status_clicked(Gtk.Button b)
153 set_active(!get_active());
160 registry.register(GPXAudioTracer(registry))
164 var menu_waypoint = new Waypoint();
165 var menu_gpsrequest = new GPSRequestLink();
168 zavai.menu_gps.add_service_toggle(zavai.gps.gpx, "Start GPX trace", "Stop GPX trace");
169 //zavai.menu_gps.add_applet("ui.gps.monitor");
170 zavai.menu_gps.add_widget(menu_waypoint);
171 zavai.menu_gps.add_widget(menu_gpsrequest);
172 //zavai.menu_gps.add_widget(new GPSStuck());