[gnome-maps/wip/geoclue-refactor: 6/7] geoclue: Change 'connected' property to 'state'
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/geoclue-refactor: 6/7] geoclue: Change 'connected' property to 'state'
- Date: Mon, 1 Dec 2014 13:58:38 +0000 (UTC)
commit ba923cee72c73aaccc6bbb1189d5e15501c517d6
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Tue Nov 25 20:24:10 2014 +0100
geoclue: Change 'connected' property to 'state'
The state property can include information that there
is an error message waiting to be read.
src/geoclue.js | 70 ++++++++++++++++++++++++++++++++++++----------------
src/mainWindow.js | 15 ++++++++---
2 files changed, 59 insertions(+), 26 deletions(-)
---
diff --git a/src/geoclue.js b/src/geoclue.js
index e58674d..380d611 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -56,14 +56,6 @@ const ClientInterface = '<node> \
</node>';
const ClientProxy = Gio.DBusProxy.makeProxyWrapper(ClientInterface);
-const AccuracyLevel = {
- COUNTRY: 1,
- CITY: 4,
- NEIGHBORHOOD: 5,
- STREET: 6,
- EXACT: 8
-};
-
const LocationInterface = '<node> \
<interface name="org.freedesktop.GeoClue2.Location"> \
<property name="Latitude" type="d" access="read"/> \
@@ -74,6 +66,22 @@ const LocationInterface = '<node> \
</node>';
const LocationProxy = Gio.DBusProxy.makeProxyWrapper(LocationInterface);
+const AccuracyLevel = {
+ COUNTRY: 1,
+ CITY: 4,
+ NEIGHBORHOOD: 5,
+ STREET: 6,
+ EXACT: 8
+};
+
+const State = {
+ ENABLED: 0,
+ DISABLED: 1,
+ MESSAGE: 2
+};
+
+const _NOT_AVAILABLE_MSG = _("Location service not available");
+
const Geoclue = new Lang.Class({
Name: 'Geoclue',
Extends: GObject.Object,
@@ -81,21 +89,23 @@ const Geoclue = new Lang.Class({
'location-changed': { }
},
Properties: {
- 'connected': GObject.ParamSpec.boolean('connected',
- 'Connected',
- 'Connected to DBus service',
- GObject.ParamFlags.READABLE |
- GObject.ParamFlags.WRITABLE,
- false)
+ 'state': GObject.ParamSpec.int('state',
+ '',
+ '',
+ GObject.ParamFlags.READABLE |
+ GObject.ParamFlags.WRITABLE,
+ State.ENABLED,
+ State.MESSAGE,
+ State.DISABLED)
},
- set connected(c) {
- this._connected = c;
- this.notify('connected');
+ set state(s) {
+ this._state = s;
+ this.notify('state');
},
- get connected() {
- return this._connected;
+ get state() {
+ return this._state;
},
_init: function() {
@@ -110,13 +120,20 @@ const Geoclue = new Lang.Class({
this._managerProxy.GetClientRemote(this._onGetClientReady.bind(this));
} catch (e) {
Utils.debug("Failed to connect to GeoClue2 service: " + e.message);
- log('Connection with GeoClue failed, we are not able to find your location!');
+ this._message = _NOT_AVAILABLE_MSG;
+ this.state = State.MESSAGE;
}
},
+ readMessage: function() {
+ this.state = State.DISABLED;
+ return this._message;
+ },
+
_onGetClientReady: function(result, e) {
if (e) {
- log ("Failed to connect to GeoClue2 service: " + e.message);
+ this._message = _NOT_AVAILABLE_MSG;
+ this.state = State.MESSAGE;
return;
}
@@ -130,9 +147,18 @@ const Geoclue = new Lang.Class({
this._clientProxy.connectSignal('LocationUpdated',
this._onLocationUpdated.bind(this));
+
+ this._clientProxy.connect('g-properties-changed', (function() {
+ if (this._clientProxy.Active === true)
+ this.state = State.ENABLED;
+ else
+ this.state = State.DISABLED;
+ }).bind(this));
+
this._clientProxy.StartRemote((function(result, e) {
if (e) {
- log ("Failed to connect to GeoClue2 service: " + e.message);
+ this._message = _NOT_AVAILABLE_MSG;
+ this.state = State.MESSAGE;
}
}).bind(this));
},
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d09ffe0..753c762 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -32,6 +32,7 @@ const Application = imports.application;
const Config = imports.config;
const ContextMenu = imports.contextMenu;
const FavoritesPopover = imports.favoritesPopover;
+const Geoclue = imports.geoclue;
const LayersPopover = imports.layersPopover;
const MapView = imports.mapView;
const PlaceEntry = imports.placeEntry;
@@ -199,15 +200,16 @@ const MainWindow = new Lang.Class({
this._favoritesButton.sensitive = favoritesPopover.rows > 0;
}).bind(this));
- Application.geoclue.connect('notify::connected', (function() {
- this._gotoUserLocationButton.sensitive = Application.geoclue.connected;
+ Application.geoclue.connect('notify::state', (function() {
+ let sensitive = Application.geoclue.state !== Geoclue.State.DISABLED;
+ this._gotoUserLocationButton.sensitive = sensitive;
}).bind(this));
this.window.application.connect('notify::connected', (function() {
let app = this.window.application;
this._gotoUserLocationButton.sensitive = (app.connected &&
- Application.geoclue.connected);
+ Application.geoclue.state !== Geoclue.State.Disabled);
this._layersButton.sensitive = app.connected;
this._toggleSidebarButton.sensitive = app.connected;
this._favoritesButton.sensitive = (app.connected &&
@@ -287,7 +289,12 @@ const MainWindow = new Lang.Class({
},
_onGotoUserLocationActivate: function() {
- this.mapView.gotoUserLocation(true);
+ if (Application.geoclue.state === Geoclue.State.MESSAGE) {
+ let message = Application.geoclue.readMessage();
+ Application.notificationManager.showMessage(message);
+ } else {
+ this.mapView.gotoUserLocation(true);
+ }
},
_onMapTypeMenuActivate: function(action) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]