Some attempt to compile it with new vala, failed
[gregoa/zavai.git] / plugins / 55_gpx_trace.py
index b4c1106134b48d6fd31ac1ff5a5d411e06356ee5..6cc08ace44edaa9bc0f6237d3a1cf4989e570ad8 100644 (file)
@@ -20,12 +20,38 @@ from gettext import gettext as _
 import gtk
 import zavai
 
+class GPSOn(gtk.ToggleAction):
+    states = [_("GPS always on"), _("GPS on when needed")]
+
+    def __init__(self, registry, **kw):
+        self.state = 0
+        super(GPSOn, self).__init__("menu.main.gps.alwayson", self.states[self.state], None, None)
+
+        self.registry = registry
+        self.set_active(False)
+
+        self.connect("toggled", self.on_toggle)
+
+    def on_toggle(self, *args):
+        self.state = (self.state + 1) % len(self.states)
+        self.set_property("label", self.states[self.state])
+        if self.get_active():
+            self.start()
+        else:
+            self.stop()
+
+    def start(self):
+        self.registry.resource("gps").connect("gps", self)
+
+    def stop(self):
+        self.registry.resource("gps").disconnect("gps", self)
+
 class GPXTracer(gtk.ToggleAction):
     states = [_("Start GPX trace"), _("Stop GPX trace")]
 
     def __init__(self, registry, **kw):
         self.state = 0
-        super(GPXTracer, self).__init__("menu.main.gps.toggle", self.states[self.state], None, None)
+        super(GPXTracer, self).__init__("menu.main.gps.gpx", self.states[self.state], None, None)
 
         self.registry = registry
         self.set_active(False)
@@ -42,11 +68,11 @@ class GPXTracer(gtk.ToggleAction):
 
     def start(self):
         zavai.info("GPX trace started")
-        self.registry.resource("gpx").request(self)
+        self.registry.resource("gpx").connect("gpx", self)
 
     def stop(self):
         zavai.info("GPX trace ended")
-        self.registry.resource("gpx").release(self)
+        self.registry.resource("gpx").disconnect("gpx", self)
 
 class GPXWaypoint(gtk.Action):
     def __init__(self, registry, **kw):
@@ -61,7 +87,52 @@ class GPXWaypoint(gtk.Action):
     def on_activate(self, *args):
         self.gpx.waypoint()
 
+class GPXAudioTracer(gtk.ToggleAction):
+    states = [_("Start GPX and audio trace"), _("Stop GPX and audio trace")]
+
+    def __init__(self, registry, **kw):
+        self.state = 0
+        super(GPXAudioTracer, self).__init__("menu.main.gps.gpxaudio", self.states[self.state], None, None)
+
+        self.registry = registry
+        self.recorder = zavai.Recorder(registry)
+        self.set_active(False)
+
+        self.connect("toggled", self.on_toggle)
+
+    def shutdown(self):
+        self.recorder.stop()
+        super(GPXAudioTracer, self).shutdown()
+
+    def on_toggle(self, *args):
+        self.state = (self.state + 1) % len(self.states)
+        self.set_property("label", self.states[self.state])
+        if self.get_active():
+            self.start()
+        else:
+            self.stop()
+
+    def start(self):
+        zavai.info("GPX trace started")
+        gpx = self.registry.resource("gpx")
+        gpx.connect("gpx", self)
+        gpx.add_activity_monitor(self.on_gpx_activity_changed)
+
+    def stop(self):
+        zavai.info("GPX trace ended")
+        gpx = self.registry.resource("gpx")
+        gpx.disconnect("gpx", self)
+        self.recorder.stop()
+        gpx.del_activity_monitor(self.on_gpx_activity_changed)
+
+    def on_gpx_activity_changed(self, gpx, state):
+        if state:
+            self.recorder.start(gpx.basename + ".wav")
+        else:
+            self.recorder.stop()
 
 def init(conf = None, registry = None, **kw):
     registry.register(GPXTracer(registry))
+    registry.register(GPXAudioTracer(registry))
     registry.register(GPXWaypoint(registry))
+    registry.register(GPSOn(registry))