Markus Korn has proposed merging 
lp:~thekorn/zeitgeist-extensions/geolocation-splitup into 
lp:zeitgeist-extensions.

Requested reviews:
  Zeitgeist Extensions (zeitgeist-extensions)


This branch splits the geolocation extension into two parts, the logic which 
defines the interface and the db structure, and the actual implementations of 
this extension. Right now there are two implementations, one using Geoclue and 
the other one using maemo's liblocation.

In order to run this extension copy geolocation/_geolocation.py and the actual 
extension (geolocation_geoclue.py or geolocation_maemo.py) to the extension dir.
-- 
https://code.launchpad.net/~thekorn/zeitgeist-extensions/geolocation-splitup/+merge/35184
Your team Zeitgeist Extensions is requested to review the proposed merge of 
lp:~thekorn/zeitgeist-extensions/geolocation-splitup into 
lp:zeitgeist-extensions.
=== renamed file 'geolocation/geolocation.py' => 'geolocation/_geolocation.py'
--- geolocation/geolocation.py	2010-08-02 12:14:59 +0000
+++ geolocation/_geolocation.py	2010-09-11 08:12:47 +0000
@@ -4,6 +4,7 @@
 #
 # Copyright © 2010 Seif Lotfy <s...@lotfy.com>
 # Copyright © 2010 Siegfried-Angel Gevatter Pujals <siegfr...@gevatter.com>
+# Copyright © 2010 Markus Korn <thek...@gmx.de>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Lesser General Public License as published by
@@ -24,13 +25,11 @@
 import sqlite3
 import logging
 import dbus
-import Geoclue
 
 from zeitgeist.datamodel import TimeRange, ResultType
 from _zeitgeist.engine.sql import get_default_cursor
 from _zeitgeist.engine import constants
 from _zeitgeist.engine.datamodel import Event
-from _zeitgeist.engine.extension import Extension
 from _zeitgeist.engine import constants
 
 GEOLOCATION_DBUS_OBJECT_PATH = "/org/gnome/zeitgeist/geolocation"
@@ -51,7 +50,7 @@
     
     return cursor
 
-class Geolocation(Extension, dbus.service.Object):
+class GeolocationBaseClass(dbus.service.Object):
     """
     For some workflows it can be practical to identify the location where
     certain activities were carried out. This Geolocation extension enables
@@ -67,35 +66,15 @@
     _position = None
 
     def __init__ (self, engine):
-        Extension.__init__(self, engine)
         dbus.service.Object.__init__(self, dbus.SessionBus(),
             GEOLOCATION_DBUS_OBJECT_PATH)
         
         self._engine = engine
         self._cursor = create_db()
-
-        self._location = Geoclue.DiscoverLocation()
-        self._location.init()
-        self._location.connect(self._position_changed_cb)
-        
-        # Choose a working provider
-        # FIXME: Use the Master provider once it is released
-        for provider in [provider["name"] for provider in self._location.get_available_providers()]:
-            if self._location.set_position_provider(provider) and self._get_position():
-                break
-    
-    def _get_position(self):
-        position = self._location.get_location_info()
-        if "longitude" in position and "latitude" in position and \
-        position["longitude"] != 0 and position["latitude"] != 0:
-            return (position["longitude"], position["latitude"])
-        return None
-    
-    def _position_changed_cb(self):
-        self._position = self._get_position()
     
     def post_insert_event(self, event, sender):
         # store location for inserted event
+        logging.debug("geolocation post_insert %r" %(self._position,))
         if self._position:
             try:
                 self._cursor.execute("""

=== added file 'geolocation/geolocation_geoclue.py'
--- geolocation/geolocation_geoclue.py	1970-01-01 00:00:00 +0000
+++ geolocation/geolocation_geoclue.py	2010-09-11 08:12:47 +0000
@@ -0,0 +1,52 @@
+# -.- coding: utf-8 -.-
+
+# Zeitgeist - Geolocation Extension
+#
+# Copyright © 2010 Seif Lotfy <s...@lotfy.com>
+# Copyright © 2010 Siegfried-Angel Gevatter Pujals <siegfr...@gevatter.com>
+# Copyright © 2010 Markus Korn <thek...@gmx.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import Geoclue
+import logging
+
+from _geolocation import GeolocationBaseClass
+from _zeitgeist.engine.extension import Extension
+
+class GeolocationGeoclue(GeolocationBaseClass, Extension):
+    
+    def __init__(self, engine):
+        logging.debug("loading the geoclue implementation of the geolocation extension")
+        GeolocationBaseClass.__init__(self, engine)
+        
+        self._location = Geoclue.DiscoverLocation()
+        self._location.init()
+        self._location.connect(self._position_changed_cb)
+        
+        # Choose a working provider
+        # FIXME: Use the Master provider once it is released
+        for provider in [provider["name"] for provider in self._location.get_available_providers()]:
+            if self._location.set_position_provider(provider) and self._get_position():
+                break
+    
+    def _get_position(self):
+        position = self._location.get_location_info()
+        if "longitude" in position and "latitude" in position and \
+        position["longitude"] != 0 and position["latitude"] != 0:
+            return (position["longitude"], position["latitude"])
+        return None
+    
+    def _position_changed_cb(self):
+        self._position = self._get_position()

=== added file 'geolocation/geolocation_maemo.py'
--- geolocation/geolocation_maemo.py	1970-01-01 00:00:00 +0000
+++ geolocation/geolocation_maemo.py	2010-09-11 08:12:47 +0000
@@ -0,0 +1,70 @@
+# -.- coding: utf-8 -.-
+
+# Zeitgeist - Geolocation Extension
+#
+# Copyright © 2010 Markus Korn <thek...@gmx.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# see http://wiki.maemo.org/PyMaemo/Using_Location_API
+
+import logging
+import location
+import gobject
+
+from _geolocation import GeolocationBaseClass
+from _zeitgeist.engine.extension import Extension
+
+def on_error(control, error):
+    print "location error: %d... quitting" % error
+
+class GeolocationGeoclue(GeolocationBaseClass, Extension):
+    
+    def __init__(self, engine):
+        logging.debug("loading the maemo implementation of the geolocation extension")
+        GeolocationBaseClass.__init__(self, engine)
+        
+        control = location.GPSDControl.get_default()
+        device = location.GPSDevice()
+        control.set_properties(	
+            preferred_method=location.METHOD_USER_SELECTED,
+            preferred_interval=location.INTERVAL_1S
+        )
+                                
+        control.connect("error-verbose", on_error)
+        device.connect("changed", self.on_changed, control)
+        #control.connect("gpsd-stopped", on_stop, loop)
+                                 
+        def _start(ctrl):
+            ctrl.start()
+            return False
+        gobject.idle_add(_start, control)
+        
+        # this is an ugly workaround, somehow the 'changed' signal of the
+        # device never get's catched, poll until we get a fix
+        def poll_fix(dev):
+            continue_polling = dev.status != location.GPS_DEVICE_STATUS_FIX
+            if not continue_polling:
+                self.on_changed(device, None)
+            return continue_polling
+        gobject.timeout_add(1000, poll_fix, device)
+        
+    def on_changed(self, device, control):
+        logging.debug("FIX changed %r" %device)
+        if not device:
+            return
+        if device.fix:
+            if device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
+                self._position = device.fix[4:6]
+                logging.info("lat = %f, long = %f" %self._position)

_______________________________________________
Mailing list: https://launchpad.net/~zeitgeist
Post to     : zeitgeist@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zeitgeist
More help   : https://help.launchpad.net/ListHelp

Reply via email to