summarylogtreecommitdiffstats
path: root/Port-to-geoclue-2.0.patch
blob: 82823de015f421cfaca35699260d3938ab1ccf16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
From: Chow Loong Jin <hyperair@debian.org>
Date: Sun, 15 Jan 2017 23:45:17 +0800
Subject: Port to geoclue-2.0

geoclue has been removed from Debian.
---
 qreator/qrcodes/QRCodeLocationGtk.py | 46 ++++++++++--------------------------
 1 file changed, 12 insertions(+), 34 deletions(-)

diff --git a/qreator/qrcodes/QRCodeLocationGtk.py b/qreator/qrcodes/QRCodeLocationGtk.py
index 9adb634..c6b144f 100644
--- a/qreator/qrcodes/QRCodeLocationGtk.py
+++ b/qreator/qrcodes/QRCodeLocationGtk.py
@@ -14,6 +14,7 @@
 # with this program.  If not, see <http://www.gnu.org/licenses/>.
 ### END LICENSE
 
+import gi
 from gi.repository import Gtk, GtkChamplain, Clutter, Champlain
 from qreator_lib.helpers import get_data_file
 from gi.repository import GtkClutter
@@ -83,37 +84,14 @@ class QRCodeLocationGtk(object):
 
 
 def get_current_location():
-    '''Gets the current location from geolocation via IP (only method
-       currently supported)'''
-    #import Geoclue
-    #POS_PROVIDER = 'Ubuntu GeoIP'
-    #location = Geoclue.DiscoverLocation()
-    #location.init()
-    #location.set_position_provider(POS_PROVIDER)
-    #position = location.get_location_info()
-
-    import dbus
-    bus = dbus.SessionBus()
-
-    # For now we default to the UbuntuGeoIP provider and we fall back to
-    # Hostip. We should probably be cleverer about provider detection, but
-    # this solution works for now and does not rely solely on UbuntuGeoIP,
-    # which means qreator can run on other distros
-    try:
-        geoclue = bus.get_object(
-            'org.freedesktop.Geoclue.Providers.UbuntuGeoIP',
-            '/org/freedesktop/Geoclue/Providers/UbuntuGeoIP')
-    except dbus.exceptions.DBusException:
-        geoclue = bus.get_object(
-            'org.freedesktop.Geoclue.Providers.Hostip',
-            '/org/freedesktop/Geoclue/Providers/Hostip')
-    position_info = geoclue.GetPosition(
-        dbus_interface='org.freedesktop.Geoclue.Position')
-
-    position = {}
-    position['timestamp'] = position_info[1]
-    position['latitude'] = position_info[2]
-    position['longitude'] = position_info[3]
-    position['altitude'] = position_info[4]
-
-    return position['latitude'], position['longitude']
+    '''Gets the current location from geolocation via using Geoclue-2.0'''
+
+    gi.require_version('Geoclue', '2.0')
+    from gi.repository import Geoclue
+
+    geoclue_simple = Geoclue.Simple.new_sync(
+        'qreator', Geoclue.AccuracyLevel.EXACT)
+    location = geoclue_simple.get_location()
+
+    return (location.get_property('latitude'),
+            location.get_property('longitude'))