1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 from datetime import datetime
22
23 from common import gajim
24 from common import pep
25 from common import dbus_support
26 if dbus_support.supported:
27 import dbus
28 import dbus.glib
31 _instance = None
32 @classmethod
37
40
58
59
61 bus = dbus.SessionBus()
62 cli.AddressStart()
63
64 name, description, service, path = cli.GetAddressProvider()
65 if path:
66 provider = bus.get_object(service, path)
67 timestamp, address, accuracy = provider.GetAddress()
68 self._on_geoclue_address_changed(timestamp, address, accuracy)
69
71 bus = dbus.SessionBus()
72 cli.PositionStart()
73
74 name, description, service, path = cli.GetPositionProvider()
75 if path:
76 provider = bus.get_object(service, path)
77 fields, timestamp, lat, lon, alt, accuracy = provider.GetPosition()
78 self._on_geoclue_position_changed(fields, timestamp, lat, lon, alt,
79 accuracy)
80
90
93
96
97 for field in ['country', 'countrycode', 'locality', 'postalcode',
98 'region', 'street']:
99 self._data[field] = address.get(field, None)
100 if timestamp:
101 self._data['timestamp'] = self._timestamp_to_utc(timestamp)
102 if accuracy:
103
104 self._data['accuracy'] = accuracy[1]
105 self._send_location()
106
109
110 _dict = {'lat': lat, 'lon': lon, 'alt': alt}
111 for field in _dict:
112 if _dict[field] is not None:
113 self._data[field] = _dict[field]
114 if timestamp:
115 self._data['timestamp'] = self._timestamp_to_utc(timestamp)
116 if accuracy:
117
118 self._data['accuracy'] = accuracy[1]
119 self._send_location()
120
122 accounts = gajim.connections.keys()
123 for acct in accounts:
124 if not gajim.account_is_connected(acct):
125 continue
126 if not gajim.config.get_per('accounts', acct, 'publish_location'):
127 continue
128 if self.location_info == self._data:
129 continue
130 if 'timestamp' in self.location_info and 'timestamp' in self._data:
131 last_data = self.location_info.copy()
132 del last_data['timestamp']
133 new_data = self._data.copy()
134 del new_data['timestamp']
135 if last_data == new_data:
136 continue
137 gajim.connections[acct].send_location(self._data)
138 self.location_info = self._data.copy()
139
141 time = datetime.utcfromtimestamp(timestamp)
142 return time.strftime('%Y-%m-%dT%H:%MZ')
143
147
151