No need to fullscreen: matchbox does it for us
[gregoa/zavai.git] / zavai / gps.py
index 75c25a58971d768265860fccf446d14ef3813c28..47af68fb9f76e6b7970c3cba824be53e12ffa571 100755 (executable)
@@ -118,26 +118,13 @@ class GPSPosition():
 
     def _start_listening(self):
         self.gps.request(self)
-
-        self.bus.add_signal_receiver(
+        self.gps.bus.add_signal_receiver(
             self.on_position_changed, 'PositionChanged', 'org.freedesktop.Gypsy.Position',
             'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
 
-        # TODO: find out how come sometimes these events are not sent
-        self.gps.bus.add_signal_receiver(
-            self.on_satellites_changed, 'SatellitesChanged', 'org.freedesktop.Gypsy.Satellite',
-            'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
-        self.gps.bus.add_signal_receiver(
-            self.on_ubxdebug_packet, 'DebugPacket', 'org.freesmartphone.GPS.UBX',
-            'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
-        self.debug_request()
-
     def _stop_listening(self):
         self.gps.bus.remove_signal_receiver(
-            self.on_satellites_changed, 'SatellitesChanged', 'org.freedesktop.Gypsy.Satellite',
-            'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
-        self.gps.bus.remove_signal_receiver(
-            self.on_ubxdebug_packet, 'DebugPacket', 'org.freesmartphone.GPS.UBX',
+            self.on_position_changed, 'PositionChanged', 'org.freedesktop.Gypsy.Position',
             'org.freesmartphone.ogpsd', '/org/freedesktop/Gypsy')
         self.gps.release(self)
 
@@ -267,7 +254,20 @@ class GPX(zavai.Resource):
             if conf.has_option("gps", "trackdir"):
                 self.trackdir = conf.get("gps", "trackdir")
         if not os.path.isdir(self.trackdir):
+            zavai.info("Creating directory", self.trackdir)
             os.makedirs(self.trackdir)
+        self.activity_monitors = set()
+
+    def add_activity_monitor(self, cb):
+        self.activity_monitors.add(cb)
+        cb(self, self.last_pos is not None)
+
+    def del_activity_monitor(self, cb):
+        self.activity_monitors.discard(cb)
+
+    def notify_activity_monitors(self):
+        for mon in self.activity_monitors:
+            mon(self, self.last_pos is not None)
 
     def request(self, tag):
         "Request the GPX trace to be taken"
@@ -319,6 +319,7 @@ class GPX(zavai.Resource):
     xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">""" % VERSION
 
         self.wpt_seq = 1;
+        self.notify_activity_monitors()
 
     def stop(self):
         if self.trk is not None:
@@ -330,6 +331,7 @@ class GPX(zavai.Resource):
             self.wpt.close()
             self.wpt = None
         self.last_pos = None
+        self.notify_activity_monitors()
 
     def shutdown(self):
         self.stop()