]> ToastFreeware Gitweb - gregoa/zavai.git/blob - src/app_gps.vala
Merge branch 'master' into gregoa
[gregoa/zavai.git] / src / app_gps.vala
1 /*
2  * gpx_trace - zavai GPX trace functions
3  *
4  * Copyright (C) 2009  Enrico Zini <enrico@enricozini.org>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 using GLib;
22
23 namespace zavai {
24 namespace ui {
25 namespace gps {
26
27 #if 0
28 public class Waypoint : BigButton
29 {
30     public Waypoint()
31     {
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);
36     }
37
38     protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
39     {
40         stderr.printf("Toggled %d\n", (int)new_state);
41         set_sensitive(new_state);
42     }
43
44     protected void on_clicked()
45     {
46         stderr.printf("Activate\n");
47         zavai.gps.gpx.waypoint();
48     }
49 }
50
51 /*
52 class GPXAudioTracer(gtk.ToggleAction):
53     states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
54
55     def __init__(self, registry, **kw):
56         self.state = 0
57         super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
58
59         self.registry = registry
60         self.recorder = zavai.Recorder(registry)
61         self.set_active(False)
62
63         self.connect("toggled", self.on_toggle)
64
65     def shutdown(self):
66         self.recorder.stop()
67         super(GPXAudioTracer, self).shutdown()
68
69     def on_toggle(self, *args):
70         self.state = (self.state + 1) % len(self.states)
71         self.set_property("label", self.states[self.state])
72         if self.get_active():
73             self.start()
74         else:
75             self.stop()
76
77     def start(self):
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)
82
83     def stop(self):
84         zavai.info("GPX trace ended")
85         gpx = self.registry.resource("gpx")
86         gpx.disconnect("gpx", self)
87         self.recorder.stop()
88         gpx.del_activity_monitor(self.on_gpx_activity_changed)
89
90     def on_gpx_activity_changed(self, gpx, state):
91         if state:
92             self.recorder.start(gpx.basename + ".wav")
93         else:
94             self.recorder.stop()
95 */
96 #endif
97
98 public class GPSRequestLink : Gtk.ToggleButton
99 {
100     protected string label_start;
101     protected string label_stop;
102     protected zavai.StatusIcon status_icon;
103     protected int fix_status = 0;
104
105     public GPSRequestLink()
106     {
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;
111
112         set_label(get_active() ? label_stop : label_start);
113
114         //tooltip = "GPS status";
115         fix_status = zavai.gps.gps.fix_status();
116         zavai.gps.gps.fix_status_changed += on_fix_status_changed;
117
118         // GPS status icon
119         status_icon = new zavai.StatusIcon();
120         status_icon.install();
121         status_icon.clicked += on_status_clicked;
122         update_icon();
123     }
124
125     protected void update_icon()
126     {
127         string name;
128         if (fix_status != libgps.STATUS_NO_FIX)
129             name = zavai.config.icondir + "/" + (get_active() ? "gps_fix_on.png" : "gps_fix_off.png");
130         else
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);
134     }
135
136     private void on_fix_status_changed(int fix_status)
137     {
138         this.fix_status = fix_status;
139         update_icon();
140     }
141
142     private void on_toggled(Gtk.Button src)
143     {
144 stderr.printf("TOGGOLED\n");
145         if (get_active())
146             zavai.gps.gps.request("servicerequestlink");
147         else
148             zavai.gps.gps.release("servicerequestlink");
149         set_label(get_active() ? label_stop : label_start);
150         update_icon();
151     }
152
153     private void on_status_clicked(Gtk.Button b)
154     {
155         set_active(!get_active());
156     }
157 }
158
159 #if 0
160 public class GPSStuck : Gtk.Button
161 {
162     protected bool happened;
163
164     public GPSStuck()
165     {
166         label = "The GPS is stuck";
167         happened = false;
168         clicked += on_clicked;
169         set_size_request(0, zavai.config.min_button_height);
170     }
171
172     public void on_clicked()
173     {
174         zavai.gps.gps.power_cycle(happened);
175         happened = !happened;
176         if (happened)
177             label = "The GPS is stuck AGAIN";
178         else
179             label = "The GPS is stuck";
180     }
181 }
182 #endif
183 public void init()
184 {
185     /*
186     registry.register(GPXAudioTracer(registry))
187     */
188
189     // Apps
190     // var menu_waypoint = new Waypoint();
191     var menu_gpsrequest = new GPSRequestLink();
192
193     // Menus
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());
199 }
200
201 }
202 }
203 }