Verified Commit 860af42f authored by ivan tkachenko's avatar ivan tkachenko
Browse files

applet: Fix enabled states of Wi-Fi and WWAN checkboxes in Edit Mode

We don't have full control over `enabled` property all the time, as it
inherits its state through parent-child chain in QML. Instead of
reusing it for custom logic, just introduce a new property for that.

This patch replaces assignments with bindings, and drops two extra
signal handlers which are not needed anymore because the property they
were updating is now a reliable readonly boolean.

(cherry picked from commit 72f9d9bd)
parent b89ad7ef
Pipeline #243056 passed with stage
in 1 minute and 38 seconds
......@@ -31,21 +31,17 @@ RowLayout {
PlasmaNM.EnabledConnections {
id: enabledConnections
onWirelessEnabledChanged: {
wifiSwitchButton.checked = wifiSwitchButton.enabled && enabled
}
onWirelessHwEnabledChanged: {
wifiSwitchButton.enabled = enabled && availableDevices.wirelessDeviceAvailable && !PlasmaNM.Configuration.airplaneModeEnabled
}
// When user interactively toggles a checkbox, a binding may be
// preserved, but the state gets out of sync until next relevant
// notify signal is dispatched. So, we refresh the bindings here.
onWwanEnabledChanged: {
wwanSwitchButton.checked = wwanSwitchButton.enabled && enabled
}
onWirelessEnabledChanged: wifiSwitchButton.checked = Qt.binding(() =>
wifiSwitchButton.administrativelyEnabled && enabledConnections.wirelessEnabled
);
onWwanHwEnabledChanged: {
wwanSwitchButton.enabled = enabled && availableDevices.modemDeviceAvailable && !PlasmaNM.Configuration.airplaneModeEnabled
}
onWwanEnabledChanged: wwanSwitchButton.checked = Qt.binding(() =>
wwanSwitchButton.administrativelyEnabled && enabledConnections.wwanEnabled
);
}
spacing: PlasmaCore.Units.smallSpacing * 3
......@@ -53,10 +49,16 @@ RowLayout {
PlasmaComponents3.CheckBox {
id: wifiSwitchButton
checked: enabled && enabledConnections.wirelessEnabled
enabled: enabledConnections.wirelessHwEnabled && availableDevices.wirelessDeviceAvailable && !PlasmaNM.Configuration.airplaneModeEnabled
// can't overload Item::enabled, because it's being used for other things, like Edit Mode on a desktop
readonly property bool administrativelyEnabled:
!PlasmaNM.Configuration.airplaneModeEnabled
&& availableDevices.wirelessDeviceAvailable
&& enabledConnections.wirelessHwEnabled
checked: administrativelyEnabled && enabledConnections.wirelessEnabled
enabled: administrativelyEnabled
icon.name: enabled ? "network-wireless-on" : "network-wireless-off"
icon.name: administrativelyEnabled ? "network-wireless-on" : "network-wireless-off"
visible: availableDevices.wirelessDeviceAvailable
KeyNavigation.right: wwanSwitchButton.visible ? wwanSwitchButton : wwanSwitchButton.KeyNavigation.right
......@@ -95,10 +97,16 @@ RowLayout {
PlasmaComponents3.CheckBox {
id: wwanSwitchButton
checked: enabled && enabledConnections.wwanEnabled
enabled: enabledConnections.wwanHwEnabled && availableDevices.modemDeviceAvailable && !PlasmaNM.Configuration.airplaneModeEnabled
// can't overload Item::enabled, because it's being used for other things, like Edit Mode on a desktop
readonly property bool administrativelyEnabled:
!PlasmaNM.Configuration.airplaneModeEnabled
&& availableDevices.modemDeviceAvailable
&& enabledConnections.wwanHwEnabled
checked: administrativelyEnabled && enabledConnections.wwanEnabled
enabled: administrativelyEnabled
icon.name: enabled ? "network-mobile-on" : "network-mobile-off"
icon.name: administrativelyEnabled ? "network-mobile-on" : "network-mobile-off"
visible: availableDevices.modemDeviceAvailable
KeyNavigation.left: wifiSwitchButton
......
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