2 * app_keyboard - zavai keyboard show/hide 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 Keyboard : Service
36 private void on_child_quit(Pid pid, int status)
38 Process.close_pid(pid);
43 protected override void start()
45 string[] args = { "/usr/bin/matchbox-keyboard", null };
49 Gdk.Screen.get_default(),
53 SpawnFlags.SEARCH_PATH | SpawnFlags.STDOUT_TO_DEV_NULL | SpawnFlags.STDERR_TO_DEV_NULL,
57 ChildWatch.add(pid, on_child_quit);
60 log.error("Running matchbox-keyboard: " + e.message);
65 protected override void stop()
69 Posix.kill((int)pid, 15);
77 class GPSOn(gtk.ToggleAction):
78 states = [_("GPS always on"), _("GPS on when needed")]
80 def __init__(self, registry, **kw):
82 super(GPSOn, self).__init__("menu.main.gps.alwayson", self.states[self.state], None, None)
84 self.registry = registry
85 self.set_active(False)
87 self.connect("toggled", self.on_toggle)
89 def on_toggle(self, *args):
90 self.state = (self.state + 1) % len(self.states)
91 self.set_property("label", self.states[self.state])
98 self.registry.resource("gps").connect("gps", self)
101 self.registry.resource("gps").disconnect("gps", self)
103 class GPXTracer(gtk.ToggleAction):
104 states = [_("Start GPX trace"), _("Stop GPX trace")]
106 def __init__(self, registry, **kw):
108 super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
110 self.registry = registry
111 self.set_active(False)
113 self.connect("toggled", self.on_toggle)
115 def on_toggle(self, *args):
116 self.state = (self.state + 1) % len(self.states)
117 self.set_property("label", self.states[self.state])
118 if self.get_active():
124 zavai.info("GPX trace started")
125 self.registry.resource("gpx").connect("gpx", self)
128 zavai.info("GPX trace ended")
129 self.registry.resource("gpx").disconnect("gpx", self)
131 public class Waypoint : BigButton
135 set_label("Take waypoint");
136 zavai.gps.gpx.tracking_changed += on_gpx_tracking_changed;
137 clicked += on_clicked;
138 set_sensitive(zavai.gps.gpx.tracking);
141 protected void on_gpx_tracking_changed(zavai.gps.GPX gpx, bool new_state)
143 stderr.printf("Toggled %d\n", (int)new_state);
144 set_sensitive(new_state);
147 protected void on_clicked()
149 stderr.printf("Activate\n");
150 zavai.gps.gpx.waypoint();
154 class GPXAudioTracer(gtk.ToggleAction):
155 states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
157 def __init__(self, registry, **kw):
159 super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
161 self.registry = registry
162 self.recorder = zavai.Recorder(registry)
163 self.set_active(False)
165 self.connect("toggled", self.on_toggle)
169 super(GPXAudioTracer, self).shutdown()
171 def on_toggle(self, *args):
172 self.state = (self.state + 1) % len(self.states)
173 self.set_property("label", self.states[self.state])
174 if self.get_active():
180 zavai.info("GPX trace started")
181 gpx = self.registry.resource("gpx")
182 gpx.connect("gpx", self)
183 gpx.add_activity_monitor(self.on_gpx_activity_changed)
186 zavai.info("GPX trace ended")
187 gpx = self.registry.resource("gpx")
188 gpx.disconnect("gpx", self)
190 gpx.del_activity_monitor(self.on_gpx_activity_changed)
192 def on_gpx_activity_changed(self, gpx, state):
194 self.recorder.start(gpx.basename + ".wav")
199 public class KeyboardIcon : Gtk.StatusIcon
201 bool requested = false;
203 public KeyboardIcon()
205 activate += on_activate;
209 private void on_activate()
211 requested = !requested;
214 keyboard.request("keyboardicon");
216 keyboard.release("keyboardicon");
219 protected void update_icon()
221 string name = zavai.config.icondir + "/" + (requested ? "kbd_on.png" : "kbd_off.png");
222 stderr.printf("load icon from %s\n", name);
228 public class GPSRequestLink : Gtk.ToggleButton
230 public GPSRequestLink()
233 status_icon = new Gtk.StatusIcon();
234 status_icon.set_visible(true);
235 status_icon.activate += on_status_activate;
239 private void on_fix_status_changed(dynamic DBus.Object pos, int fix_status)
241 this.fix_status = fix_status;
245 private void on_toggled(Gtk.Button src)
247 Service s = zavai.registry.gets(service_name);
249 s.request("servicerequestlink");
251 s.release("servicerequestlink");
252 set_label(get_active() ? label_stop : label_start);
256 private void on_status_activate()
258 set_active(!get_active());
268 stderr.printf("INIT KBD\n");
269 keyboard = new Keyboard();
270 zavai.registry.register_service(keyboard);
271 icon = new KeyboardIcon();
272 icon.set_visible(true);