[gnome-maps/wip/geoclue-refactor: 3/3] wip



commit 6ad486d21648299b4407ea012f4c11901d70361a
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Tue Nov 25 05:57:30 2014 -0500

    wip

 src/geoclue.js    |   48 +++++++++++++++++++++++++++---------------------
 src/mainWindow.js |   22 +++++++---------------
 src/mapView.js    |    3 +++
 src/mapWalker.js  |    2 +-
 4 files changed, 38 insertions(+), 37 deletions(-)
---
diff --git a/src/geoclue.js b/src/geoclue.js
index 81f0998..054a060 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -32,6 +32,7 @@ const _ = imports.gettext.gettext;
 
 const ManagerInterface = '<node> \
 <interface name="org.freedesktop.GeoClue2.Manager"> \
+    <property name="AvailableAccuracyLevel" type="u" access="read"/> \
     <method name="GetClient"> \
         <arg name="client" type="o" direction="out"/> \
     </method> \
@@ -45,6 +46,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 +85,22 @@ const Geoclue = new Lang.Class({
         'connected': GObject.ParamSpec.boolean('connected',
                                                'Connected',
                                                'Connected to DBus service',
-                                               GObject.ParamFlags.READABLE,
-                                               false)
+                                               GObject.ParamFlags.READABLE |
+                                               GObject.ParamFlags.WRITABLE)
     },
 
-    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,19 +140,33 @@ 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]) {
         let geoclueLocation = new LocationProxy(Gio.DBus.system,
                                                 "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);
+
+        this.connected = this._clientProxy.Active;
+        if (!this._propsChangedId) {
+            this._propsChangedId = this._clientProxy.connect('g-properties-changed', (function() {
+                this.connected = this._clientProxy.Active;
+            }).bind(this));
+        }
+
+        this._updateLocation(location);
     },
 
     _updateLocation: function(location) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 30455ae..d09ffe0 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -169,11 +169,6 @@ const MainWindow = new Lang.Class({
                 onActivate: this._placeEntry.grab_focus.bind(this._placeEntry)
             }
         });
-
-        let action = this.window.lookup_action('goto-user-location');
-        Application.geoclue.bind_property('connected',
-                                          action, 'enabled',
-                                          GObject.BindingFlags.SYNC_CREATE);
     },
 
     _initSignals: function() {
@@ -204,10 +199,15 @@ 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;
+        }).bind(this));
+
         this.window.application.connect('notify::connected', (function() {
             let app = this.window.application;
 
-            this._gotoUserLocationButton.sensitive = app.connected;
+            this._gotoUserLocationButton.sensitive = (app.connected &&
+                                                      Application.geoclue.connected);
             this._layersButton.sensitive = app.connected;
             this._toggleSidebarButton.sensitive = app.connected;
             this._favoritesButton.sensitive = (app.connected &&
@@ -287,15 +287,7 @@ const MainWindow = new Lang.Class({
     },
 
     _onGotoUserLocationActivate: function() {
-        if (Application.geoclue.userSetLocation) {
-            Utils.once(Application.geoclue,
-                       'location-changed',
-                       (function() {
-                this.mapView.gotoUserLocation(true);
-            }).bind(this));
-            Application.geoclue.findLocation();
-        } else
-            this.mapView.gotoUserLocation(true);
+        this.mapView.gotoUserLocation(true);
     },
 
     _onMapTypeMenuActivate: function(action) {
diff --git a/src/mapView.js b/src/mapView.js
index bc40b95..dd3e0a6 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -146,6 +146,9 @@ const MapView = new Lang.Class({
     },
 
     gotoUserLocation: function(animate) {
+        if (!this._userLocation)
+            return;
+
         this.emit('going-to-user-location');
         Utils.once(this._userLocation, "gone-to", (function() {
             this.emit('gone-to-user-location');
diff --git a/src/mapWalker.js b/src/mapWalker.js
index c9f6e86..8386525 100644
--- a/src/mapWalker.js
+++ b/src/mapWalker.js
@@ -96,7 +96,7 @@ const MapWalker = new Lang.Class({
     },
 
     goTo: function(animate) {
-        Utils.debug('Going to ' + this.place.location.description);
+        Utils.debug('Going to ' + this.place.name);
         this._mapView.emit('going-to');
 
         if (!animate) {


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