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



commit 22ab5d8e5df3f6925c5d67d12acd2d5e3a1205bb
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Wed Nov 26 02:39:48 2014 -0500

    wip

 src/geoclue.js                    |  110 +++++++++++++++++++++++++++---------
 src/gnome-maps.data.gresource.xml |    1 +
 src/mainWindow.js                 |    8 +-
 3 files changed, 87 insertions(+), 32 deletions(-)
---
diff --git a/src/geoclue.js b/src/geoclue.js
index 7e37e00..b4222a2 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -21,11 +21,14 @@
  */
 
 const GObject = imports.gi.GObject;
+const Gdk = imports.gi.Gdk;
 const Geocode = imports.gi.GeocodeGlib;
 const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 
 const Application = imports.application;
+const Notification = imports.notification;
+const Settings = imports.settings;
 const Utils = imports.utils;
 
 const _ = imports.gettext.gettext;
@@ -77,10 +80,35 @@ const AccuracyLevel = {
 const State = {
     ENABLED: 0,
     DISABLED: 1,
-    MESSAGE: 2
+    NOTIFICATION: 2
 };
 
 const _NOT_AVAILABLE_MSG = _("Location service not available");
+const _NOT_AVAILABLE_NOTIFICATION = new Notification.Plain(_NOT_AVAILABLE_MSG);
+
+const LocationServiceNotification = new Lang.Class({
+    Name: 'LocationServiceNotification',
+    Extends: Notification.Notification,
+    
+    _init: function() {
+        this.parent();
+
+        let ui = Utils.getUIObject('location-service-notification',
+                                   [ 'button', 'grid' ]);
+        ui.button.connect('clicked', (function() {
+
+            let privacyInfo = Gio.DesktopAppInfo.new('gnome-privacy-panel.desktop');
+            try {
+                let display = Gdk.Display.get_default();
+                privacyInfo.launch([], display.get_app_launch_context());
+            } catch(e) {
+                Utils.debug('launching privacy panel failed: ' + e);
+            }
+        }).bind(this));
+
+        this._ui.body.add(ui.grid);
+    }
+});
 
 const Geoclue = new Lang.Class({
     Name: 'Geoclue',
@@ -95,7 +123,7 @@ const Geoclue = new Lang.Class({
                                        GObject.ParamFlags.READABLE |
                                        GObject.ParamFlags.WRITABLE,
                                        State.ENABLED,
-                                       State.MESSAGE,
+                                       State.NOTIFICATION,
                                        State.DISABLED)
     },
 
@@ -108,10 +136,18 @@ const Geoclue = new Lang.Class({
         return this._state;
     },
 
+    get serviceNotification() {
+        if (!this._serviceNotification)
+            this._serviceNotification = new LocationServiceNotification();
+
+        return this._serviceNotification;
+    },
+
+
     _init: function() {
         this.parent();
-        this.connected = false;
-
+        this._state = State.DISABLED;
+        
         let lastLocation = Application.settings.get('last-location');
         if (lastLocation.length >= 3) {
             let [lat, lng, accuracy] = lastLocation;
@@ -125,6 +161,34 @@ const Geoclue = new Lang.Class({
                                              name: _("Current location") });
         }
 
+        this._locationSettings = new Settings.Settings('org.gnome.system.location');
+        if (this._locationSettings) {
+            this._locationSettings.connect('changed::enabled',
+                                           this._updateFromSettings.bind(this));
+            this._updateFromSettings();
+        } else {
+            this._initLocationService();
+        }
+    },
+
+    readNotification: function() {
+        this.state = State.DISABLED;
+        return this._notification;
+    },
+
+    _updateFromSettings: function() {
+        if (this._locationSettings.get('enabled')) {
+            if (this._state !== State.ENABLED)
+                this._initLocationService();
+        } else {
+            if (this._state !== State.NOTIFICATION) {
+                this._notification = this.serviceNotification;
+                this.state = State.NOTIFICATION;
+            }
+        }
+    },
+
+    _initLocationService: function() {
         try {
             this._managerProxy = new ManagerProxy(Gio.DBus.system,
                                                   "org.freedesktop.GeoClue2",
@@ -132,20 +196,15 @@ const Geoclue = new Lang.Class({
             this._managerProxy.GetClientRemote(this._onGetClientReady.bind(this));
         } catch (e) {
             Utils.debug("Failed to connect to GeoClue2 service: " + e.message);
-            this._message = _NOT_AVAILABLE_MSG;
-            this.state = State.MESSAGE;
+            this._notification = _NOT_AVAILABLE_NOTIFICAITON;
+            this.state = State.NOTIFICATION;
         }
     },
 
-    readMessage: function() {
-        this.state = State.DISABLED;
-        return this._message;
-    },
-
     _onGetClientReady: function(result, e) {
         if (e) {
-            this._message = _NOT_AVAILABLE_MSG;
-            this.state = State.MESSAGE;
+            this._notification = _NOT_AVAILABLE_NOTIFICAITON;
+            this.state = State.NOTIFICATION;
             return;
         }
 
@@ -157,20 +216,12 @@ const Geoclue = new Lang.Class({
         this._clientProxy.DesktopId = "org.gnome.Maps";
         this._clientProxy.RequestedAccuracyLevel = AccuracyLevel.EXACT;
 
-        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._updatedId = this._clientProxy.connectSignal('LocationUpdated',
+                                                          this._onLocationUpdated.bind(this));
         this._clientProxy.StartRemote((function(result, e) {
             if (e) {
-                this._message = _NOT_AVAILABLE_MSG;
-                this.state = State.MESSAGE;
+                this._notification = _NOT_AVAILABLE_MSG;
+                this.state = State.NOTIFICATION;
             }
         }).bind(this));
     },
@@ -186,9 +237,12 @@ const Geoclue = new Lang.Class({
 
         this._updateLocation(location);
 
-        this.connected = this._clientProxy.Active;
-        this._clientProxy.connect('g-properties-changed', (function() {
-            this.connected = this._clientProxy.Active;
+        this.state = this._clientProxy.Active ? State.ENABLED : State.DISABLED;
+        this._changedId = this._clientProxy.connect('g-properties-changed', (function() {
+            if (this._clientProxy.Active === true)
+                this.state = State.ENABLED;
+            else
+                this.state = State.DISABLED;
         }).bind(this));
     },
 
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index 0512a79..ede6c6d 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -12,6 +12,7 @@
     <file preprocess="xml-stripblanks">context-menu.ui</file>
     <file preprocess="xml-stripblanks">layers-popover.ui</file>
     <file preprocess="xml-stripblanks">notification.ui</file>
+    <file preprocess="xml-stripblanks">location-service-notification.ui</file>
     <file preprocess="xml-stripblanks">route-via-row.ui</file>
     <file preprocess="xml-stripblanks">map-bubble.ui</file>
     <file preprocess="xml-stripblanks">search-result-bubble.ui</file>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 753c762..ed0d8a2 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -209,7 +209,7 @@ const MainWindow = new Lang.Class({
             let app = this.window.application;
 
             this._gotoUserLocationButton.sensitive = (app.connected &&
-                                                      Application.geoclue.state !== Geoclue.State.Disabled);
+                                                      Application.geoclue.state !== Geoclue.State.DISABLED);
             this._layersButton.sensitive = app.connected;
             this._toggleSidebarButton.sensitive = app.connected;
             this._favoritesButton.sensitive = (app.connected &&
@@ -289,9 +289,9 @@ const MainWindow = new Lang.Class({
     },
 
     _onGotoUserLocationActivate: function() {
-        if (Application.geoclue.state === Geoclue.State.MESSAGE) {
-            let message = Application.geoclue.readMessage();
-            Application.notificationManager.showMessage(message);
+        if (Application.geoclue.state === Geoclue.State.NOTIFICATION) {
+            let notification = Application.geoclue.readNotification();
+            Application.notificationManager.showNotification(notification);
         } else {
             this.mapView.gotoUserLocation(true);
         }


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