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
This commit is contained in:
Zeeshan Ali (Khattak) 2014-08-06 17:04:00 +01:00
parent 0af4dc0b4c
commit f1957dccb7
2 changed files with 25 additions and 23 deletions

View File

@ -145,7 +145,6 @@
</schema> </schema>
<enum id="org.gnome.shell.geoclue.AccuracyLevel"> <enum id="org.gnome.shell.geoclue.AccuracyLevel">
<value value="0" nick="off"/>
<value value="1" nick="country"/> <value value="1" nick="country"/>
<value value="4" nick="city"/> <value value="4" nick="city"/>
<value value="5" nick="neighborhood"/> <value value="5" nick="neighborhood"/>
@ -155,17 +154,23 @@
<schema id="org.gnome.shell.location" <schema id="org.gnome.shell.location"
path="/org/gnome/shell/location/" path="/org/gnome/shell/location/"
gettext-domain="@GETTEXT_PACKAGE@"> gettext-domain="@GETTEXT_PACKAGE@">
<key type="b" name="enabled">
<default>true</default>
<_summary>Geolocation services are enabled.</_summary>
<_description>
If true, applications are allowed to access location information.
</_description>
</key>
<key name="max-accuracy-level" enum="org.gnome.shell.geoclue.AccuracyLevel"> <key name="max-accuracy-level" enum="org.gnome.shell.geoclue.AccuracyLevel">
<default>'exact'</default> <default>'exact'</default>
<_summary>The maximum accuracy level of location.</_summary> <_summary>The maximum accuracy level of location.</_summary>
<_description> <_description>
Configures the maximum level of location accuracy applications are Configures the maximum level of location accuracy applications are
allowed to see. Valid options are 'off' (disable location tracking), allowed to see. Valid options are 'country', 'city', 'neighborhood',
'country', 'city', 'neighborhood', 'street', and 'exact' (typically 'street', and 'exact' (typically requires GPS receiver). Please keep in
requires GPS receiver). Please keep in mind that this only controls mind that this only controls what GeoClue will allow applications to see
what GeoClue will allow applications to see and they can find user's and they can find user's location on their own using network resources
location on their own using network resources (albeit with street-level (albeit with street-level accuracy at best).
accuracy at best).
</_description> </_description>
</key> </key>
</schema> </schema>

View File

@ -11,6 +11,7 @@ const Shell = imports.gi.Shell;
const LOCATION_SCHEMA = 'org.gnome.shell.location'; const LOCATION_SCHEMA = 'org.gnome.shell.location';
const MAX_ACCURACY_LEVEL = 'max-accuracy-level'; const MAX_ACCURACY_LEVEL = 'max-accuracy-level';
const ENABLED = 'enabled';
var GeoclueIface = '<node> \ var GeoclueIface = '<node> \
<interface name="org.freedesktop.GeoClue2.Manager"> \ <interface name="org.freedesktop.GeoClue2.Manager"> \
@ -44,6 +45,8 @@ const Indicator = new Lang.Class({
this.parent(); this.parent();
this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA }); 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, this._settings.connect('changed::' + MAX_ACCURACY_LEVEL,
Lang.bind(this, this._onMaxAccuracyLevelChanged)); Lang.bind(this, this._onMaxAccuracyLevelChanged));
@ -123,7 +126,6 @@ const Indicator = new Lang.Class({
this._propertiesChangedId = this._proxy.connect('g-properties-changed', this._propertiesChangedId = this._proxy.connect('g-properties-changed',
Lang.bind(this, this._onGeocluePropsChanged)); Lang.bind(this, this._onGeocluePropsChanged));
this._availableAccuracyLevel = this._proxy.AvailableAccuracyLevel;
this._syncIndicator(); this._syncIndicator();
this._proxy.AddAgentRemote('gnome-shell', Lang.bind(this, this._onAgentRegistered)); this._proxy.AddAgentRemote('gnome-shell', Lang.bind(this, this._onAgentRegistered));
@ -148,10 +150,8 @@ const Indicator = new Lang.Class({
}, },
_onOnOffAction: function() { _onOnOffAction: function() {
if (this._getMaxAccuracyLevel() == 0) let enabled = this._settings.get_boolean(ENABLED);
this._settings.set_enum(MAX_ACCURACY_LEVEL, this._availableAccuracyLevel); this._settings.set_boolean(ENABLED, !enabled);
else
this._settings.set_enum(MAX_ACCURACY_LEVEL, 0);
}, },
_onSessionUpdated: function() { _onSessionUpdated: function() {
@ -160,12 +160,12 @@ const Indicator = new Lang.Class({
}, },
_updateMenuLabels: function() { _updateMenuLabels: function() {
if (this._getMaxAccuracyLevel() == 0) { if (this._settings.get_boolean(ENABLED)) {
this._item.status.text = _("Disabled");
this._onOffAction.label.text = _("Enable");
} else {
this._item.status.text = this._indicator.visible ? _("In Use") : _("Enabled"); this._item.status.text = this._indicator.visible ? _("In Use") : _("Enabled");
this._onOffAction.label.text = _("Disable"); 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() { _getMaxAccuracyLevel: function() {
if (this._settings.get_boolean(ENABLED))
return this._settings.get_enum(MAX_ACCURACY_LEVEL); return this._settings.get_enum(MAX_ACCURACY_LEVEL);
else
return 0;
}, },
_notifyMaxAccuracyLevel: function() { _notifyMaxAccuracyLevel: function() {
@ -191,12 +194,6 @@ const Indicator = new Lang.Class({
let unpacked = properties.deep_unpack(); let unpacked = properties.deep_unpack();
if ("InUse" in unpacked) if ("InUse" in unpacked)
this._syncIndicator(); this._syncIndicator();
if ("AvailableAccuracyLevel" in unpacked) {
this._availableAccuracyLevel = this._proxy.AvailableAccuracyLevel;
if (this._getMaxAccuracyLevel() != 0)
this._settings.set_enum(MAX_ACCURACY_LEVEL, this._availableAccuracyLevel);
}
} }
}); });