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
28 public class Waypoint : BigButton
32 set_label("Take waypoint");
33 zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
34 clicked += on_clicked;
35 set_sensitive(zavai.gps.gpx.tracking);
38 protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
40 stderr.printf("Toggled %d\n", (int)new_state);
41 set_sensitive(new_state);
44 protected void on_clicked()
46 stderr.printf("Activate\n");
47 zavai.gps.gpx.waypoint();
52 class GPXAudioTracer(gtk.ToggleAction):
53 states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
55 def __init__(self, registry, **kw):
57 super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
59 self.registry = registry
60 self.recorder = zavai.Recorder(registry)
61 self.set_active(False)
63 self.connect("toggled", self.on_toggle)
67 super(GPXAudioTracer, self).shutdown()
69 def on_toggle(self, *args):
70 self.state = (self.state + 1) % len(self.states)
71 self.set_property("label", self.states[self.state])
78 zavai.info("GPX trace started")
79 gpx = self.registry.resource("gpx")
80 gpx.connect("gpx", self)
81 gpx.add_activity_monitor(self.on_gpx_activity_changed)
84 zavai.info("GPX trace ended")
85 gpx = self.registry.resource("gpx")
86 gpx.disconnect("gpx", self)
88 gpx.del_activity_monitor(self.on_gpx_activity_changed)
90 def on_gpx_activity_changed(self, gpx, state):
92 self.recorder.start(gpx.basename + ".wav")
98 public class GPSRequestLink : Gtk.ToggleButton
100 protected string label_start;
101 protected string label_stop;
102 protected zavai.StatusIcon status_icon;
103 protected int fix_status = 0;
105 public GPSRequestLink()
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";
115 fix_status = zavai.gps.gps.fix_status();
116 zavai.gps.gps.fix_status_changed += on_fix_status_changed;
119 status_icon = new zavai.StatusIcon();
120 status_icon.install();
121 status_icon.clicked += on_status_clicked;
125 protected void update_icon()
128 if (fix_status != libgps.STATUS_NO_FIX)
129 name = zavai.config.icondir + "/" + (get_active() ? "gps_fix_on.png" : "gps_fix_off.png");
131 name = zavai.config.icondir + "/" + (get_active() ? "gps_nofix_on.png" : "gps_nofix_off.png");
132 stderr.printf("load icon from %s\n", name);
133 status_icon.set_from_file(name);
136 private void on_fix_status_changed(int fix_status)
138 this.fix_status = fix_status;
142 private void on_toggled(Gtk.Button src)
144 stderr.printf("TOGGOLED\n");
146 zavai.gps.gps.request("servicerequestlink");
148 zavai.gps.gps.release("servicerequestlink");
149 set_label(get_active() ? label_stop : label_start);
153 private void on_status_clicked(Gtk.Button b)
155 set_active(!get_active());
160 public class GPSStuck : Gtk.Button
162 protected bool happened;
166 label = "The GPS is stuck";
168 clicked += on_clicked;
169 set_size_request(0, zavai.config.min_button_height);
172 public void on_clicked()
174 zavai.gps.gps.power_cycle(happened);
175 happened = !happened;
177 label = "The GPS is stuck AGAIN";
179 label = "The GPS is stuck";
186 registry.register(GPXAudioTracer(registry))
190 // var menu_waypoint = new Waypoint();
191 var menu_gpsrequest = new GPSRequestLink();
194 zavai.menu_gps.add_service_toggle(zavai.gps.gpx, "Start GPX trace", "Stop GPX trace");
195 //zavai.menu_gps.add_applet("ui.gps.monitor");
196 //zavai.menu_gps.add_widget(menu_waypoint);
197 zavai.menu_gps.add_widget(menu_gpsrequest);
198 //zavai.menu_gps.add_widget(new GPSStuck());