[gnome-maps/wip/geoclue-refactor: 6/9] geoclue: Improve check for connected



commit d0c94f76a0e3d4f1b369fb1ecc8722c2d11f1fbc
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Tue Nov 25 18:53:17 2014 +0100

    geoclue: Improve check for connected

 src/geoclue.js |   43 +++++++++++++++++++++++--------------------
 1 files changed, 23 insertions(+), 20 deletions(-)
---
diff --git a/src/geoclue.js b/src/geoclue.js
index 81f0998..97d162a 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -45,6 +45,7 @@ const ClientInterface = '<node> \
     <property name="DesktopId" type="s" access="readwrite"/> \
     <property name="RequestedAccuracyLevel" type="u" access="readwrite"/> \
     <property name="DistanceThreshold" type="u" access="readwrite"/> \
+    <property name="Active" type="b" access="read"/> \
     <method name="Start"/> \
     <method name="Stop"/> \
     <signal name="LocationUpdated"> \
@@ -83,32 +84,23 @@ const Geoclue = new Lang.Class({
         'connected': GObject.ParamSpec.boolean('connected',
                                                'Connected',
                                                'Connected to DBus service',
-                                               GObject.ParamFlags.READABLE,
+                                               GObject.ParamFlags.READABLE |
+                                               GObject.ParamFlags.WRITABLE,
                                                false)
     },
 
-    get connected() {
-        return this._connected;
+    set connected(c) {
+        this._connected = c;
+        this.notify('connected');
     },
 
-    findLocation: function() {
-        if (!this._clientProxy)
-            return;
-
-        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);
-            }
-        });
+    get connected() {
+        return this._connected;
     },
 
     _init: function() {
         this.parent();
-        this._connected = false;
+        this.connected = false;
 
         let lastLocation = Application.settings.get('last-location');
         if (lastLocation.length >= 3) {
@@ -148,8 +140,13 @@ const Geoclue = new Lang.Class({
         this._clientProxy.DesktopId = "org.gnome.Maps";
         this._clientProxy.RequestedAccuracyLevel = AccuracyLevel.EXACT;
 
-        this._connected = true;
-        this.notify('connected');
+        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);
+            }
+        }).bind(this));
     },
 
     _onLocationUpdated: function(proxy, sender, [oldPath, newPath]) {
@@ -160,7 +157,13 @@ const Geoclue = new Lang.Class({
                                               longitude: geoclueLocation.Longitude,
                                               accuracy: geoclueLocation.Accuracy,
                                               description: geoclueLocation.Description });
-        this._updateLocation(location, false);
+
+        this.connected = this._clientProxy.Active;
+        this._clientProxy.connect('g-properties-changed', (function() {
+            this.connected = this._clientProxy.Active;
+        }).bind(this));
+
+        this._updateLocation(location);
     },
 
     _updateLocation: function(location) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]