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

@ -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 = '<node> \
<interface name="org.freedesktop.GeoClue2.Manager"> \
@ -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);
}
}
});