From f1957dccb7f3c91cd4dcc5547505465ad1b39dde Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Wed, 6 Aug 2014 17:04:00 +0100 Subject: [PATCH] location: Separate setting for enabling/disabling Having the on/off setting be backed by a boolean in dconf makes sense anyway but this is mainly to be able to remember the max accuracy set before user disabled geolocation so that when they enable it next time, we have the max accuracy level on same value as before. There hasn't been a real need for this but now we are about to add geolocation settings in control center and it'll be easiser for control-center to simply toggle a boolean property rather than to have to know about and deal with accuracy levels. Later we might also want to add accuracy level settings to privacy panel so keeping the accuracy level setting around still. However we no longer support 'off' accuracy level as the new boolean property covers that. This also implies that we no longer track available accuracy level, which made the code a bit hard to follow/maintain. https://bugzilla.gnome.org/show_bug.cgi?id=734483 --- data/org.gnome.shell.gschema.xml.in.in | 19 ++++++++++------- js/ui/status/location.js | 29 ++++++++++++-------------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/data/org.gnome.shell.gschema.xml.in.in b/data/org.gnome.shell.gschema.xml.in.in index 51900da58..f60772e5c 100644 --- a/data/org.gnome.shell.gschema.xml.in.in +++ b/data/org.gnome.shell.gschema.xml.in.in @@ -145,7 +145,6 @@ - @@ -155,17 +154,23 @@ + + true + <_summary>Geolocation services are enabled. + <_description> + If true, applications are allowed to access location information. + + 'exact' <_summary>The maximum accuracy level of location. <_description> Configures the maximum level of location accuracy applications are - allowed to see. Valid options are 'off' (disable location tracking), - 'country', 'city', 'neighborhood', 'street', and 'exact' (typically - requires GPS receiver). Please keep in mind that this only controls - what GeoClue will allow applications to see and they can find user's - location on their own using network resources (albeit with street-level - accuracy at best). + allowed to see. Valid options are 'country', 'city', 'neighborhood', + 'street', and 'exact' (typically requires GPS receiver). Please keep in + mind that this only controls what GeoClue will allow applications to see + and they can find user's location on their own using network resources + (albeit with street-level accuracy at best). diff --git a/js/ui/status/location.js b/js/ui/status/location.js index 15b5f80cb..7444ee767 100644 --- a/js/ui/status/location.js +++ b/js/ui/status/location.js @@ -11,6 +11,7 @@ const Shell = imports.gi.Shell; const LOCATION_SCHEMA = 'org.gnome.shell.location'; const MAX_ACCURACY_LEVEL = 'max-accuracy-level'; +const ENABLED = 'enabled'; var GeoclueIface = ' \ \ @@ -44,6 +45,8 @@ const Indicator = new Lang.Class({ this.parent(); this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA }); + this._settings.connect('changed::' + ENABLED, + Lang.bind(this, this._onMaxAccuracyLevelChanged)); this._settings.connect('changed::' + MAX_ACCURACY_LEVEL, Lang.bind(this, this._onMaxAccuracyLevelChanged)); @@ -123,7 +126,6 @@ const Indicator = new Lang.Class({ this._propertiesChangedId = this._proxy.connect('g-properties-changed', Lang.bind(this, this._onGeocluePropsChanged)); - this._availableAccuracyLevel = this._proxy.AvailableAccuracyLevel; this._syncIndicator(); this._proxy.AddAgentRemote('gnome-shell', Lang.bind(this, this._onAgentRegistered)); @@ -148,10 +150,8 @@ const Indicator = new Lang.Class({ }, _onOnOffAction: function() { - if (this._getMaxAccuracyLevel() == 0) - this._settings.set_enum(MAX_ACCURACY_LEVEL, this._availableAccuracyLevel); - else - this._settings.set_enum(MAX_ACCURACY_LEVEL, 0); + let enabled = this._settings.get_boolean(ENABLED); + this._settings.set_boolean(ENABLED, !enabled); }, _onSessionUpdated: function() { @@ -160,12 +160,12 @@ const Indicator = new Lang.Class({ }, _updateMenuLabels: function() { - if (this._getMaxAccuracyLevel() == 0) { - this._item.status.text = _("Disabled"); - this._onOffAction.label.text = _("Enable"); - } else { + if (this._settings.get_boolean(ENABLED)) { this._item.status.text = this._indicator.visible ? _("In Use") : _("Enabled"); this._onOffAction.label.text = _("Disable"); + } else { + this._item.status.text = _("Disabled"); + this._onOffAction.label.text = _("Enable"); } }, @@ -179,7 +179,10 @@ const Indicator = new Lang.Class({ }, _getMaxAccuracyLevel: function() { - return this._settings.get_enum(MAX_ACCURACY_LEVEL); + if (this._settings.get_boolean(ENABLED)) + return this._settings.get_enum(MAX_ACCURACY_LEVEL); + else + return 0; }, _notifyMaxAccuracyLevel: function() { @@ -191,12 +194,6 @@ const Indicator = new Lang.Class({ let unpacked = properties.deep_unpack(); if ("InUse" in unpacked) this._syncIndicator(); - if ("AvailableAccuracyLevel" in unpacked) { - this._availableAccuracyLevel = this._proxy.AvailableAccuracyLevel; - - if (this._getMaxAccuracyLevel() != 0) - this._settings.set_enum(MAX_ACCURACY_LEVEL, this._availableAccuracyLevel); - } } });