[gnome-shell] location: Allow user to disable GPS



commit 5d05b669024b7115fc9b6e128961655c5d105d34
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Feb 17 01:25:13 2014 +0000

    location: Allow user to disable GPS
    
    When exact accuracy (i-e GPS) is available, allow user to disable that.
    When users don't want application to get their precise location, they
    can now opt for network-based geolocation only, which can be
    street-level at best.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723684

 js/ui/status/location.js |   80 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 74 insertions(+), 6 deletions(-)
---
diff --git a/js/ui/status/location.js b/js/ui/status/location.js
index 5661b57..07fa611 100644
--- a/js/ui/status/location.js
+++ b/js/ui/status/location.js
@@ -35,6 +35,14 @@ var AgentIface = '<node> \
   </interface> \
 </node>';
 
+const AccuracyLevel = {
+    NONE: 0,
+    COUNTRY: 1,
+    CITY: 4,
+    STREET: 6,
+    EXACT: 8,
+};
+
 const Indicator = new Lang.Class({
     Name: 'LocationIndicator',
     Extends: PanelMenu.SystemIndicator,
@@ -61,6 +69,18 @@ const Indicator = new Lang.Class({
         this._item.status.text = _("On");
         this._onoffAction = this._item.menu.addAction(_("Turn Off"), Lang.bind(this, this._onOnOffAction));
 
+        this._accurateItem = new PopupMenu.PopupMenuItem(_("Accurate (GPS + Network)"), false);
+        this._accurateItem.connect('activate', Lang.bind(this, this._onAccurateItemActivated));
+        this._item.menu.addMenuItem(this._accurateItem);
+
+        this._powerSavingItem = new PopupMenu.PopupMenuItem(_("Power Saving (Network Only)"), false);
+        this._powerSavingItem.connect('activate', Lang.bind(this, this._onPowerSavingItemActivated));
+        this._item.menu.addMenuItem(this._powerSavingItem);
+
+        this._offItem = new PopupMenu.PopupMenuItem(_("Off"), false);
+        this._offItem.connect('activate', Lang.bind(this, this._onOffItemActivated));
+        this._item.menu.addMenuItem(this._offItem);
+
         this.menu.addMenuItem(this._item);
 
         this._watchId = Gio.bus_watch_name(Gio.BusType.SYSTEM,
@@ -150,16 +170,48 @@ const Indicator = new Lang.Class({
         if (this._getMaxAccuracyLevel() == 0)
             this._settings.set_enum(MAX_ACCURACY_LEVEL, this._availableAccuracyLevel);
         else
-            this._settings.set_enum(MAX_ACCURACY_LEVEL, 0);
+            this._settings.set_enum(MAX_ACCURACY_LEVEL, AccuracyLevel.NONE);
+    },
+
+    _onAccurateItemActivated: function() {
+        this._settings.set_enum(MAX_ACCURACY_LEVEL, AccuracyLevel.EXACT);
+    },
+
+    _onPowerSavingItemActivated: function() {
+        this._settings.set_enum(MAX_ACCURACY_LEVEL, AccuracyLevel.STREET);
+    },
+
+    _onOffItemActivated: function() {
+        this._settings.set_enum(MAX_ACCURACY_LEVEL, AccuracyLevel.NONE);
     },
 
     _onMaxAccuracyLevelChanged: function() {
-        if (this._getMaxAccuracyLevel() == 0) {
-            this._item.status.text = _("Off");
-            this._onoffAction.label.text = "Turn On";
+        let maxAccuracyLevel = this._getMaxAccuracyLevel();
+        if (this._availableAccuracyLevel < AccuracyLevel.EXACT) {
+            if (maxAccuracyLevel == 0) {
+                this._item.status.text = _("Off");
+                this._onoffAction.label.text = "Turn On";
+            } else {
+                this._item.status.text = _("On");
+                this._onoffAction.label.text = "Turn Off";
+            }
         } else {
-            this._item.status.text = _("On");
-            this._onoffAction.label.text = "Turn Off";
+            if (maxAccuracyLevel == 0) {
+                this._item.status.text = _("Off");
+                this._offItem.setOrnament(PopupMenu.Ornament.DOT);
+                this._accurateItem.setOrnament(PopupMenu.Ornament.NONE);
+                this._powerSavingItem.setOrnament(PopupMenu.Ornament.NONE);
+            } else if (maxAccuracyLevel < AccuracyLevel.EXACT) {
+                this._item.status.text = _("Power Saving");
+                this._powerSavingItem.setOrnament(PopupMenu.Ornament.DOT);
+                this._accurateItem.setOrnament(PopupMenu.Ornament.NONE);
+                this._offItem.setOrnament(PopupMenu.Ornament.NONE);
+            } else {
+                this._item.status.text = _("Accurate");
+                this._accurateItem.setOrnament(PopupMenu.Ornament.DOT);
+                this._offItem.setOrnament(PopupMenu.Ornament.NONE);
+                this._powerSavingItem.setOrnament(PopupMenu.Ornament.NONE);
+            }
         }
 
         // Gotta ensure geoclue is up and we are registered as agent to it
@@ -180,6 +232,22 @@ const Indicator = new Lang.Class({
     _updateMenu: function() {
         this._availableAccuracyLevel = this._proxy.AvailableAccuracyLevel;
         this.menu.actor.visible = (this._availableAccuracyLevel != 0);
+        if (this._availableAccuracyLevel == 0)
+            return;
+
+        if (this._availableAccuracyLevel < AccuracyLevel.EXACT) {
+            this._onoffAction.actor.show();
+            this._accurateItem.actor.hide();
+            this._powerSavingItem.actor.hide();
+            this._offItem.actor.hide();
+        } else {
+            this._onoffAction.actor.hide();
+            this._accurateItem.actor.show();
+            this._powerSavingItem.actor.show();
+            this._offItem.actor.show();
+        }
+
+        this._onMaxAccuracyLevelChanged();
     },
 
     _onGeocluePropsChanged: function(proxy, properties) {


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