[gnome-maps] Geoclue: Allow overriding location
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Geoclue: Allow overriding location
- Date: Sat, 31 Aug 2013 18:29:50 +0000 (UTC)
commit 201c762c45aa16f22405d4e7372d8e0838a6e221
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Mon Aug 26 03:45:19 2013 +0300
Geoclue: Allow overriding location
Currently this only updates the concept of user location within Maps.
I'm hoping that later we can build something more sophisticed on top of
this: Allowing user to easily submit WiFi/IP information to server to
not only improve geolocation for the user submitting the data but also
other users (when) in the same area. This will be very important since
the open/free geolocation services we (will) use in geoclue don't have
enough coverage/accuracy.
Perhaps geoclue can provide an API for data submission:
https://bugs.freedesktop.org/show_bug.cgi?id=68536
https://bugzilla.gnome.org/show_bug.cgi?id=706726
data/org.gnome.maps.gschema.xml.in | 5 ++
src/geoclue.js | 82 ++++++++++++++++++++++-------------
2 files changed, 56 insertions(+), 31 deletions(-)
---
diff --git a/data/org.gnome.maps.gschema.xml.in b/data/org.gnome.maps.gschema.xml.in
index e7490a8..339d74c 100644
--- a/data/org.gnome.maps.gschema.xml.in
+++ b/data/org.gnome.maps.gschema.xml.in
@@ -30,5 +30,10 @@
<_summary>Maximum number of search results</_summary>
<_description>Maximum number of search results from geocode search.</_description>
</key>
+ <key name="last-location-user-set" type="b">
+ <default>true</default>
+ <_summary>User set last known location</_summary>
+ <_description>Last known location was set manually by user.</_description>
+ </key>
</schema>
</schemalist>
diff --git a/src/geoclue.js b/src/geoclue.js
index 2e27817..2ad5243 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -64,6 +64,20 @@ const LocationProxy = Gio.DBusProxy.makeProxyWrapper(LocationInterface);
const Geoclue = new Lang.Class({
Name: 'Geoclue',
+ overrideLocation: function(location) {
+ if (this._locationUpdatedId > 0) {
+ this._clientProxy.disconnectSignal(this._locationUpdatedId);
+ this._locationUpdatedId = 0;
+ this._clientProxy.StopRemote(function(result, e) {
+ if (e) {
+ log ("Failed to connect to GeoClue2 service: " + e.message);
+ }
+ });
+ }
+
+ this._updateLocation(location, true);
+ },
+
_init: function() {
let lastLocation = Application.settings.get_value('last-location');
if (lastLocation.n_children() >= 3) {
@@ -76,12 +90,9 @@ const Geoclue = new Lang.Class({
accuracy: accuracy.get_double() });
let lastLocationDescription = Application.settings.get_string('last-location-description');
this.location.set_description(lastLocationDescription);
+ this.userSetLocation = Application.settings.get_boolean('last-location-user-set');
}
- this._findLocation();
- },
-
- _findLocation: function() {
this._managerProxy = new ManagerProxy(Gio.DBus.system,
"org.freedesktop.GeoClue2",
"/org/freedesktop/GeoClue2/Manager");
@@ -89,6 +100,18 @@ const Geoclue = new Lang.Class({
this._managerProxy.GetClientRemote(this._onGetClientReady.bind(this));
},
+ _findLocation: function() {
+ this._locationUpdatedId =
+ this._clientProxy.connectSignal("LocationUpdated",
+ this._onLocationUpdated.bind(this));
+
+ this._clientProxy.StartRemote(function(result, e) {
+ if (e) {
+ log ("Failed to connect to GeoClue2 service: " + e.message);
+ }
+ });
+ },
+
_onGetClientReady: function(result, e) {
if (e) {
log ("Failed to connect to GeoClue2 service: " + e.message);
@@ -100,38 +123,35 @@ const Geoclue = new Lang.Class({
this._clientProxy = new ClientProxy(Gio.DBus.system,
"org.freedesktop.GeoClue2",
clientPath);
- this._clientProxy.connectSignal("LocationUpdated",
- this._onLocationUpdated.bind(this));
- this._clientProxy.StartRemote(this._onStartReady.bind(this));
- },
-
- _onStartReady: function(result, e) {
- if (e) {
- log ("Failed to connect to GeoClue2 service: " + e.message);
- }
+ if (!this.userSetLocation)
+ this._findLocation();
},
_onLocationUpdated: function(proxy, sender, [oldPath, newPath]) {
let geoclueLocation = new LocationProxy(Gio.DBus.system,
- "org.freedesktop.GeoClue2",
- newPath);
- this.location = new Geocode.Location({ latitude: geoclueLocation.Latitude,
- longitude: geoclueLocation.Longitude,
- accuracy: geoclueLocation.Accuracy,
- description: geoclueLocation.Description });
- try {
- let variant = GLib.Variant.new('ad', [this.location.latitude,
- this.location.longitude,
- this.location.accuracy]);
- Application.settings.set_value('last-location', variant);
- Application.settings.set_string('last-location-description', this.location.description);
-
- this.emit('location-changed');
- Utils.debug("Found location: " + this.location.description);
- } catch (e) {
- log("Failed to find your location: " + e);
- }
+ "org.freedesktop.GeoClue2",
+ newPath);
+ let location = new Geocode.Location({ latitude: geoclueLocation.Latitude,
+ longitude: geoclueLocation.Longitude,
+ accuracy: geoclueLocation.Accuracy,
+ description: geoclueLocation.Description });
+ this._updateLocation(location, false);
+ },
+
+ _updateLocation: function(location, userSet) {
+ this.location = location;
+
+ let variant = GLib.Variant.new('ad', [location.latitude,
+ location.longitude,
+ location.accuracy]);
+ Application.settings.set_value('last-location', variant);
+ Application.settings.set_string('last-location-description', location.description);
+ Application.settings.set_boolean('last-location-user-set', userSet);
+ this.userSetLocation = userSet;
+
+ this.emit('location-changed');
+ Utils.debug("Updated location: " + location.description);
}
});
Utils.addSignalMethods(Geoclue.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]