edc2526913e9dc1517a2b91bbc151579d060ece3
[gregoa/zavai.git] / vala / 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 namespace zavai {
22 namespace ui {
23 namespace gps {
24
25 /*
26 class GPSOn(gtk.ToggleAction):
27     states = [_("GPS always on"), _("GPS on when needed")]
28
29     def __init__(self, registry, **kw):
30         self.state = 0
31         super(GPSOn, self).__init__("menu.main.gps.alwayson", self.states[self.state], None, None)
32
33         self.registry = registry
34         self.set_active(False)
35
36         self.connect("toggled", self.on_toggle)
37
38     def on_toggle(self, *args):
39         self.state = (self.state + 1) % len(self.states)
40         self.set_property("label", self.states[self.state])
41         if self.get_active():
42             self.start()
43         else:
44             self.stop()
45
46     def start(self):
47         self.registry.resource("gps").connect("gps", self)
48
49     def stop(self):
50         self.registry.resource("gps").disconnect("gps", self)
51
52 class GPXTracer(gtk.ToggleAction):
53     states = [_("Start GPX trace"), _("Stop GPX trace")]
54
55     def __init__(self, registry, **kw):
56         self.state = 0
57         super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
58
59         self.registry = registry
60         self.set_active(False)
61
62         self.connect("toggled", self.on_toggle)
63
64     def on_toggle(self, *args):
65         self.state = (self.state + 1) % len(self.states)
66         self.set_property("label", self.states[self.state])
67         if self.get_active():
68             self.start()
69         else:
70             self.stop()
71
72     def start(self):
73         zavai.info("GPX trace started")
74         self.registry.resource("gpx").connect("gpx", self)
75
76     def stop(self):
77         zavai.info("GPX trace ended")
78         self.registry.resource("gpx").disconnect("gpx", self)
79 */
80
81 public class Waypoint : BigButton
82 {
83     public Waypoint()
84     {
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);
89     }
90
91     protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
92     {
93 stderr.printf("Toggled %d\n", (int)new_state);
94         set_sensitive(new_state);
95     }
96
97     protected void on_clicked()
98     {
99 stderr.printf("Activate\n");
100         zavai.gps.gpx.waypoint();
101     }
102 }
103
104 /*
105 class GPXAudioTracer(gtk.ToggleAction):
106     states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
107
108     def __init__(self, registry, **kw):
109         self.state = 0
110         super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
111
112         self.registry = registry
113         self.recorder = zavai.Recorder(registry)
114         self.set_active(False)
115
116         self.connect("toggled", self.on_toggle)
117
118     def shutdown(self):
119         self.recorder.stop()
120         super(GPXAudioTracer, self).shutdown()
121
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():
126             self.start()
127         else:
128             self.stop()
129
130     def start(self):
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)
135
136     def stop(self):
137         zavai.info("GPX trace ended")
138         gpx = self.registry.resource("gpx")
139         gpx.disconnect("gpx", self)
140         self.recorder.stop()
141         gpx.del_activity_monitor(self.on_gpx_activity_changed)
142
143     def on_gpx_activity_changed(self, gpx, state):
144         if state:
145             self.recorder.start(gpx.basename + ".wav")
146         else:
147             self.recorder.stop()
148 */
149
150 public void init()
151 {
152     /*
153     registry.register(GPXAudioTracer(registry))
154     registry.register(GPXWaypoint(registry))
155
156     // Apps
157     var useless = new Useless();
158     zavai.registry.register_applet("app.debug.useless", useless);
159     */
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";
169
170     // Menus
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);
176
177     zavai.registry.register_menu("menu.gps", menu_gps);
178     zavai.registry.getmenu("menu.main").add_applet("menu.gps");
179 }
180
181 }
182 }
183 }