[gnome-maps] geoclue: Check for DBus ACCESS_DENIED
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] geoclue: Check for DBus ACCESS_DENIED
- Date: Wed, 2 Mar 2016 08:43:11 +0000 (UTC)
commit 785cba12b512c7829d86b60866b3245a9210f9ac
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Tue Mar 1 19:15:03 2016 +0100
geoclue: Check for DBus ACCESS_DENIED
https://bugzilla.gnome.org/show_bug.cgi?id=762594
src/geoclue.js | 88 ++++++++++++++++++++++++-----------------------------
src/mainWindow.js | 34 ++++++++++++--------
2 files changed, 61 insertions(+), 61 deletions(-)
---
diff --git a/src/geoclue.js b/src/geoclue.js
index e935ffe..c0408cf 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -21,6 +21,7 @@
const GObject = imports.gi.GObject;
const GClue = imports.gi.Geoclue;
+const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
@@ -32,12 +33,10 @@ const Utils = imports.utils;
const State = {
INITIAL: 0,
ON: 1,
- OFF: 2,
+ DENIED: 2,
FAILED: 3
};
-const _LOCATION_SETTINGS = 'org.gnome.system.location';
-
const Geoclue = new Lang.Class({
Name: 'Geoclue',
Extends: GObject.Object,
@@ -69,57 +68,50 @@ const Geoclue = new Lang.Class({
this.place = null;
this._state = State.INITIAL;
- // Check the system Location settings
- this._locationSettings = Settings.getSettings(_LOCATION_SETTINGS);
- if (this._locationSettings) {
- this._locationSettings.connect('changed::enabled',
- this._updateFromSettings.bind(this));
- this._updateFromSettings();
- } else {
- this._initLocationService();
- }
- },
-
- _updateFromSettings: function() {
- if (this._locationSettings.get('enabled')) {
- if (this._state !== State.ON)
- Mainloop.idle_add(this._initLocationService.bind(this));
- } else {
- this.state = State.OFF;
- }
+ this.start(null);
},
- _initLocationService: function() {
- GClue.Simple.new("org.gnome.Maps",
- GClue.AccuracyLevel.EXACT,
- null,
- this._onSimpleReady.bind(this));
- },
-
- _onSimpleReady: function(object, result) {
- try {
- this._simple = GClue.Simple.new_finish(result);
- }
- catch (e) {
- Utils.debug("Failed to connect to GeoClue2 service: " + e.message);
- this.state = State.FAILED;
- return;
- }
-
- this._notifyId = this._simple.connect('notify::location',
- this._onLocationNotify.bind(this));
- this.state = State.ON;
-
- this._onLocationNotify(this._simple);
+ start: function(callback) {
+ let id = 'org.gnome.Maps';
+ let level = GClue.AccuracyLevel.EXACT;
+
+ GClue.Simple.new(id, level, null, (function(object, result) {
+ try {
+ this._simple = GClue.Simple.new_finish(result);
+ }
+ catch (e) {
+ Utils.debug("GeoClue2 service: " + e.message);
+ if (e.matches(Gio.DBusError, Gio.DBusError.ACCESS_DENIED))
+ this.state = State.DENIED;
+ else
+ this.state = State.FAILED;
+ if (callback)
+ callback(false);
+ return;
+ }
+
+ this._simple.connect('notify::location',
+ this._onLocationNotify.bind(this));
+ this._simple.client.connect('notify::active', (function() {
+ this.state = this._simple.client.active ? State.ON : State.DENIED;
+ }).bind(this));
+
+ this.state = State.ON;
+ this._onLocationNotify(this._simple);
+ if (callback)
+ callback(true);
+ }).bind(this));
},
_onLocationNotify: function(simple) {
let geoclueLocation = simple.get_location();
- let location = new Location.Location({ latitude: geoclueLocation.latitude,
- longitude: geoclueLocation.longitude,
- accuracy: geoclueLocation.accuracy,
- heading: geoclueLocation.heading,
- description: geoclueLocation.description });
+ let location = new Location.Location({
+ latitude: geoclueLocation.latitude,
+ longitude: geoclueLocation.longitude,
+ accuracy: geoclueLocation.accuracy,
+ heading: geoclueLocation.heading,
+ description: geoclueLocation.description
+ });
this._updateLocation(location);
},
diff --git a/src/mainWindow.js b/src/mainWindow.js
index c3fe80a..84f4c80 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -353,21 +353,29 @@ const MainWindow = new Lang.Class({
_onGotoUserLocationActivate: function() {
let message;
- switch(Application.geoclue.state) {
- case Geoclue.State.FAILED:
- message = _("Failed to connect to location service");
- Application.notificationManager.showMessage(message);
- break;
-
- case Geoclue.State.OFF:
- let notification = this._getLocationServiceNotification();
- Application.notificationManager.showNotification(notification);
- break;
-
- default:
+
+ if (Application.geoclue.state === Geoclue.State.ON) {
this._mapView.gotoUserLocation(true);
- break;
+ return;
}
+
+ Application.geoclue.start((function() {
+ switch(Application.geoclue.state) {
+ case Geoclue.State.FAILED:
+ message = _("Failed to connect to location service");
+ Application.notificationManager.showMessage(message);
+ break;
+
+ case Geoclue.State.DENIED:
+ let notification = this._getLocationServiceNotification();
+ Application.notificationManager.showNotification(notification);
+ break;
+
+ default:
+ this._mapView.gotoUserLocation(true);
+ break;
+ }
+ }).bind(this));
},
_printRouteActivate: function() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]