Merge lp:~thekorn/zeitgeist-extensions/geolocation-splitup into lp:zeitgeist-extensions

Proposed by Markus Korn
Status: Needs review
Proposed branch: lp:~thekorn/zeitgeist-extensions/geolocation-splitup
Merge into: lp:zeitgeist-extensions
Diff against target: 203 lines (+125/-24)
3 files modified
geolocation/_geolocation.py (+3/-24)
geolocation/geolocation_geoclue.py (+52/-0)
geolocation/geolocation_maemo.py (+70/-0)
To merge this branch: bzr merge lp:~thekorn/zeitgeist-extensions/geolocation-splitup
Reviewer Review Type Date Requested Status
Seif Lotfy Approve
Review via email: mp+35184@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Seif Lotfy (seif) wrote :

Seems to work fine here. Good Job.

review: Approve

Unmerged revisions

54. By Markus Korn

* workaround python-location issue, somehow the 'changed' signal never
  arrives
* small fix

53. By Markus Korn

* modified copyright header
* added few logging statements
* first implementation of the maemo version

52. By Markus Korn

* added missing copyright headers
* changed inheritance order. NOTE: this order is important other wise the
  the hook methods of Extension will overwrite the implementations of the
  extension

51. By Markus Korn

started splitting up the geolocation extension into the logic and an implementation using geoclue as the location provider. Also added the sceleton for the inplementation for maemo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'geolocation/geolocation.py' => 'geolocation/_geolocation.py'
2--- geolocation/geolocation.py 2010-08-02 12:14:59 +0000
3+++ geolocation/_geolocation.py 2010-09-11 08:12:47 +0000
4@@ -4,6 +4,7 @@
5 #
6 # Copyright © 2010 Seif Lotfy <seif@lotfy.com>
7 # Copyright © 2010 Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
8+# Copyright © 2010 Markus Korn <thekorn@gmx.de>
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Lesser General Public License as published by
12@@ -24,13 +25,11 @@
13 import sqlite3
14 import logging
15 import dbus
16-import Geoclue
17
18 from zeitgeist.datamodel import TimeRange, ResultType
19 from _zeitgeist.engine.sql import get_default_cursor
20 from _zeitgeist.engine import constants
21 from _zeitgeist.engine.datamodel import Event
22-from _zeitgeist.engine.extension import Extension
23 from _zeitgeist.engine import constants
24
25 GEOLOCATION_DBUS_OBJECT_PATH = "/org/gnome/zeitgeist/geolocation"
26@@ -51,7 +50,7 @@
27
28 return cursor
29
30-class Geolocation(Extension, dbus.service.Object):
31+class GeolocationBaseClass(dbus.service.Object):
32 """
33 For some workflows it can be practical to identify the location where
34 certain activities were carried out. This Geolocation extension enables
35@@ -67,35 +66,15 @@
36 _position = None
37
38 def __init__ (self, engine):
39- Extension.__init__(self, engine)
40 dbus.service.Object.__init__(self, dbus.SessionBus(),
41 GEOLOCATION_DBUS_OBJECT_PATH)
42
43 self._engine = engine
44 self._cursor = create_db()
45-
46- self._location = Geoclue.DiscoverLocation()
47- self._location.init()
48- self._location.connect(self._position_changed_cb)
49-
50- # Choose a working provider
51- # FIXME: Use the Master provider once it is released
52- for provider in [provider["name"] for provider in self._location.get_available_providers()]:
53- if self._location.set_position_provider(provider) and self._get_position():
54- break
55-
56- def _get_position(self):
57- position = self._location.get_location_info()
58- if "longitude" in position and "latitude" in position and \
59- position["longitude"] != 0 and position["latitude"] != 0:
60- return (position["longitude"], position["latitude"])
61- return None
62-
63- def _position_changed_cb(self):
64- self._position = self._get_position()
65
66 def post_insert_event(self, event, sender):
67 # store location for inserted event
68+ logging.debug("geolocation post_insert %r" %(self._position,))
69 if self._position:
70 try:
71 self._cursor.execute("""
72
73=== added file 'geolocation/geolocation_geoclue.py'
74--- geolocation/geolocation_geoclue.py 1970-01-01 00:00:00 +0000
75+++ geolocation/geolocation_geoclue.py 2010-09-11 08:12:47 +0000
76@@ -0,0 +1,52 @@
77+# -.- coding: utf-8 -.-
78+
79+# Zeitgeist - Geolocation Extension
80+#
81+# Copyright © 2010 Seif Lotfy <seif@lotfy.com>
82+# Copyright © 2010 Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
83+# Copyright © 2010 Markus Korn <thekorn@gmx.de>
84+#
85+# This program is free software: you can redistribute it and/or modify
86+# it under the terms of the GNU Lesser General Public License as published by
87+# the Free Software Foundation, either version 3 of the License, or
88+# (at your option) any later version.
89+#
90+# This program is distributed in the hope that it will be useful,
91+# but WITHOUT ANY WARRANTY; without even the implied warranty of
92+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93+# GNU Lesser General Public License for more details.
94+#
95+# You should have received a copy of the GNU Lesser General Public License
96+# along with this program. If not, see <http://www.gnu.org/licenses/>.
97+
98+import Geoclue
99+import logging
100+
101+from _geolocation import GeolocationBaseClass
102+from _zeitgeist.engine.extension import Extension
103+
104+class GeolocationGeoclue(GeolocationBaseClass, Extension):
105+
106+ def __init__(self, engine):
107+ logging.debug("loading the geoclue implementation of the geolocation extension")
108+ GeolocationBaseClass.__init__(self, engine)
109+
110+ self._location = Geoclue.DiscoverLocation()
111+ self._location.init()
112+ self._location.connect(self._position_changed_cb)
113+
114+ # Choose a working provider
115+ # FIXME: Use the Master provider once it is released
116+ for provider in [provider["name"] for provider in self._location.get_available_providers()]:
117+ if self._location.set_position_provider(provider) and self._get_position():
118+ break
119+
120+ def _get_position(self):
121+ position = self._location.get_location_info()
122+ if "longitude" in position and "latitude" in position and \
123+ position["longitude"] != 0 and position["latitude"] != 0:
124+ return (position["longitude"], position["latitude"])
125+ return None
126+
127+ def _position_changed_cb(self):
128+ self._position = self._get_position()
129
130=== added file 'geolocation/geolocation_maemo.py'
131--- geolocation/geolocation_maemo.py 1970-01-01 00:00:00 +0000
132+++ geolocation/geolocation_maemo.py 2010-09-11 08:12:47 +0000
133@@ -0,0 +1,70 @@
134+# -.- coding: utf-8 -.-
135+
136+# Zeitgeist - Geolocation Extension
137+#
138+# Copyright © 2010 Markus Korn <thekorn@gmx.de>
139+#
140+# This program is free software: you can redistribute it and/or modify
141+# it under the terms of the GNU Lesser General Public License as published by
142+# the Free Software Foundation, either version 3 of the License, or
143+# (at your option) any later version.
144+#
145+# This program is distributed in the hope that it will be useful,
146+# but WITHOUT ANY WARRANTY; without even the implied warranty of
147+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148+# GNU Lesser General Public License for more details.
149+#
150+# You should have received a copy of the GNU Lesser General Public License
151+# along with this program. If not, see <http://www.gnu.org/licenses/>.
152+
153+# see http://wiki.maemo.org/PyMaemo/Using_Location_API
154+
155+import logging
156+import location
157+import gobject
158+
159+from _geolocation import GeolocationBaseClass
160+from _zeitgeist.engine.extension import Extension
161+
162+def on_error(control, error):
163+ print "location error: %d... quitting" % error
164+
165+class GeolocationGeoclue(GeolocationBaseClass, Extension):
166+
167+ def __init__(self, engine):
168+ logging.debug("loading the maemo implementation of the geolocation extension")
169+ GeolocationBaseClass.__init__(self, engine)
170+
171+ control = location.GPSDControl.get_default()
172+ device = location.GPSDevice()
173+ control.set_properties(
174+ preferred_method=location.METHOD_USER_SELECTED,
175+ preferred_interval=location.INTERVAL_1S
176+ )
177+
178+ control.connect("error-verbose", on_error)
179+ device.connect("changed", self.on_changed, control)
180+ #control.connect("gpsd-stopped", on_stop, loop)
181+
182+ def _start(ctrl):
183+ ctrl.start()
184+ return False
185+ gobject.idle_add(_start, control)
186+
187+ # this is an ugly workaround, somehow the 'changed' signal of the
188+ # device never get's catched, poll until we get a fix
189+ def poll_fix(dev):
190+ continue_polling = dev.status != location.GPS_DEVICE_STATUS_FIX
191+ if not continue_polling:
192+ self.on_changed(device, None)
193+ return continue_polling
194+ gobject.timeout_add(1000, poll_fix, device)
195+
196+ def on_changed(self, device, control):
197+ logging.debug("FIX changed %r" %device)
198+ if not device:
199+ return
200+ if device.fix:
201+ if device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
202+ self._position = device.fix[4:6]
203+ logging.info("lat = %f, long = %f" %self._position)

Subscribers

People subscribed via source and target branches

to all changes: