Commit 8028a0b9 authored by Nicolas Fella's avatar Nicolas Fella Committed by Nate Graham
Browse files

Make the configuration the canonical source for airplaneModeEnabled

Always access the config file when reading/writing airplane mode.

Remove extra logic when reading airplane mode (that made the getter non-const)

Simplifies QML code
parent 80eddd69
......@@ -46,7 +46,7 @@ ColumnLayout {
}
onWirelessHwEnabledChanged: {
wifiSwitchButton.enabled = enabled && availableDevices.wirelessDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled
wifiSwitchButton.enabled = enabled && availableDevices.wirelessDeviceAvailable && !PlasmaNM.Configuration.airplaneModeEnabled
}
onWwanEnabledChanged: {
......@@ -54,7 +54,7 @@ ColumnLayout {
}
onWwanHwEnabledChanged: {
wwanSwitchButton.enabled = enabled && availableDevices.modemDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled
wwanSwitchButton.enabled = enabled && availableDevices.modemDeviceAvailable && !PlasmaNM.Configuration.airplaneModeEnabled
}
}
......@@ -65,7 +65,7 @@ ColumnLayout {
id: wifiSwitchButton
checked: enabled && enabledConnections.wirelessEnabled
enabled: enabledConnections.wirelessHwEnabled && availableDevices.wirelessDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled
enabled: enabledConnections.wirelessHwEnabled && availableDevices.wirelessDeviceAvailable && !PlasmaNM.Configuration.airplaneModeEnabled
icon.name: enabled ? "network-wireless-on" : "network-wireless-off"
visible: availableDevices.wirelessDeviceAvailable
......@@ -81,7 +81,7 @@ ColumnLayout {
id: wwanSwitchButton
checked: enabled && enabledConnections.wwanEnabled
enabled: enabledConnections.wwanHwEnabled && availableDevices.modemDeviceAvailable && !planeModeSwitchButton.airplaneModeEnabled
enabled: enabledConnections.wwanHwEnabled && availableDevices.modemDeviceAvailable && !PlasmaNM.Configuration.airplaneModeEnabled
icon.name: enabled ? "network-mobile-on" : "network-mobile-off"
visible: availableDevices.modemDeviceAvailable
......@@ -97,29 +97,16 @@ ColumnLayout {
id: planeModeSwitchButton
property bool initialized: false
property bool airplaneModeEnabled: false
checked: airplaneModeEnabled
checked: PlasmaNM.Configuration.airplaneModeEnabled
icon.name: airplaneModeEnabled ? "network-flightmode-on" : "network-flightmode-off"
icon.name: PlasmaNM.Configuration.airplaneModeEnabled ? "network-flightmode-on" : "network-flightmode-off"
visible: availableDevices.modemDeviceAvailable || availableDevices.wirelessDeviceAvailable
onToggled: {
handler.enableAirplaneMode(checked);
airplaneModeEnabled = !airplaneModeEnabled;
}
Binding {
target: PlasmaNM.Configuration
property: "airplaneModeEnabled"
value: planeModeSwitchButton.airplaneModeEnabled
when: planeModeSwitchButton.initialized
}
Component.onCompleted: {
airplaneModeEnabled = PlasmaNM.Configuration.airplaneModeEnabled
initialized = true
PlasmaNM.Configuration.airplaneModeEnabled = checked;
}
PlasmaComponents3.ToolTip {
......
......@@ -86,28 +86,11 @@ void Configuration::setManageVirtualConnections(bool manage)
}
}
bool Configuration::airplaneModeEnabled()
bool Configuration::airplaneModeEnabled() const
{
// Check whether other devices are disabled to assume airplane mode is enabled
// after suspend
const bool isWifiDisabled = !NetworkManager::isWirelessEnabled() || !NetworkManager::isWirelessHardwareEnabled();
const bool isWwanDisabled = !NetworkManager::isWwanEnabled() || !NetworkManager::isWwanHardwareEnabled();
KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("plasma-nm"));
KConfigGroup grp(config, QLatin1String("General"));
if (grp.isValid()) {
if (grp.readEntry(QLatin1String("AirplaneModeEnabled"), false)) {
// We can assume that airplane mode is still activated after resume
if (isWifiDisabled && isWwanDisabled)
return true;
else {
setAirplaneModeEnabled(false);
}
}
}
return false;
static KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("plasma-nm"));
static KConfigGroup grp(config, QLatin1String("General"));
return grp.readEntry(QLatin1String("AirplaneModeEnabled"), false);
}
void Configuration::setAirplaneModeEnabled(bool enabled)
......@@ -117,6 +100,7 @@ void Configuration::setAirplaneModeEnabled(bool enabled)
if (grp.isValid()) {
grp.writeEntry(QLatin1String("AirplaneModeEnabled"), enabled);
grp.sync();
Q_EMIT airplaneModeEnabledChanged();
}
}
......
......@@ -44,7 +44,7 @@ public:
bool manageVirtualConnections();
void setManageVirtualConnections(bool manage);
bool airplaneModeEnabled();
bool airplaneModeEnabled() const;
void setAirplaneModeEnabled(bool enabled);
Q_SIGNAL void airplaneModeEnabledChanged();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment