diff --git a/containments/panel/package/contents/ui/quicksettings/Delegate.qml b/containments/panel/package/contents/ui/quicksettings/Delegate.qml index 76023231..6105e26b 100644 --- a/containments/panel/package/contents/ui/quicksettings/Delegate.qml +++ b/containments/panel/package/contents/ui/quicksettings/Delegate.qml @@ -16,8 +16,6 @@ ColumnLayout { id: delegateRoot spacing: units.smallSpacing - required property var settingsModel - signal closeRequested signal panelClosed @@ -66,7 +64,7 @@ ColumnLayout { if (delegateRoot.toggle) { delegateRoot.toggle(); } else if (delegateRoot.toggleFunction) { - settingsModel[delegateRoot.toggleFunction](); + delegateRoot.toggleFunction(); } else if (delegateRoot.settingsCommand) { NanoShell.StartupFeedback.open( delegateRoot.icon, @@ -89,7 +87,7 @@ ColumnLayout { closeRequested(); plasmoid.nativeInterface.executeCommand(delegateRoot.settingsCommand); } else if (delegateRoot.toggleFunction) { - root[delegateRoot.toggleFunction](); + delegateRoot.toggleFunction(); } } } @@ -136,7 +134,7 @@ ColumnLayout { plasmoid.nativeInterface.executeCommand(delegateRoot.settingsCommand); closeRequested(); } else if (delegateRoot.toggleFunction) { - settingsModel[delegateRoot.toggleFunction](); + delegateRoot.toggleFunction(); } } } diff --git a/containments/panel/package/contents/ui/quicksettings/QuickSetting.qml b/containments/panel/package/contents/ui/quicksettings/QuickSetting.qml new file mode 100644 index 00000000..8f4f60ba --- /dev/null +++ b/containments/panel/package/contents/ui/quicksettings/QuickSetting.qml @@ -0,0 +1,17 @@ +/* +* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.10 + +QtObject +{ + required property string text + required property string icon + property string settingsCommand + property bool enabled: true + + default property var children: [] +} diff --git a/containments/panel/package/contents/ui/quicksettings/QuickSettingsModel.qml b/containments/panel/package/contents/ui/quicksettings/QuickSettingsModel.qml index 1942feff..120f3b3f 100644 --- a/containments/panel/package/contents/ui/quicksettings/QuickSettingsModel.qml +++ b/containments/panel/package/contents/ui/quicksettings/QuickSettingsModel.qml @@ -18,7 +18,7 @@ import org.kde.plasma.private.nanoshell 2.0 as NanoShell import org.kde.plasma.components 3.0 as PC3 Item { - property alias model: settingsModel + id: modelItem property bool screenshotRequested: false signal panelClosed() @@ -30,10 +30,113 @@ Item { } } - ListModel { - id: settingsModel - } - + readonly property list model: [ + QuickSetting { + text: i18n("Settings") + icon: "configure" + enabled: false + settingsCommand: "plasma-settings" + }, + QuickSetting { + text: i18n("Wifi") + icon: "network-wireless-signal" + settingsCommand: "plasma-settings -m kcm_mobile_wifi" + function toggle() { + nmHandler.enableWireless(!enabledConnections.wirelessEnabled) + } + enabled: enabledConnections.wirelessEnabled + }, + QuickSetting { + text: i18n("Bluetooth") + icon: "network-bluetooth" + settingsCommand: "plasma-settings -m kcm_bluetooth" + function toggle() { + var enable = !BluezQt.Manager.bluetoothOperational; + BluezQt.Manager.bluetoothBlocked = !enable; + + for (var i = 0; i < BluezQt.Manager.adapters.length; ++i) { + var adapter = BluezQt.Manager.adapters[i]; + adapter.powered = enable; + } + } + enabled: BluezQt.Manager.bluetoothOperational + }, + QuickSetting { + text: i18n("Mobile Data") + icon: "network-modem" + settingsCommand: "plasma-settings -m kcm_mobile_broadband" + enabled: enabledConnections.wwanEnabled + function toggle() { + nmHandler.enableWwan(!enabledConnections.wwanEnabled) + } + }, + QuickSetting { + text: i18n("Battery") + icon: "battery-full" + enabled: false + settingsCommand: "plasma-settings -m kcm_mobile_power" + }, + QuickSetting { + text: i18n("Sound") + icon: "audio-speakers-symbolic" + enabled: false + settingsCommand: "plasma-settings -m kcm_pulseaudio" + function toggle() { + volumeProvider.showVolumeOverlay() + } + }, + QuickSetting { + text: i18n("Flashlight") + icon: "flashlight-on" + enabled: plasmoid.nativeInterface.torchEnabled + function toggle() { + plasmoid.nativeInterface.toggleTorch() + } + }, + QuickSetting { + text: i18n("Location") + icon: "gps" + enabled: false + }, + QuickSetting { + text: i18n("Screenshot") + icon: "spectacle" + enabled: false + function toggle() { + modelItem.screenshotRequested = true; + root.closeRequested(); + } + }, + QuickSetting { + text: i18n("Auto-rotate") + icon: "rotation-allowed" + enabled: plasmoid.nativeInterface.autoRotateEnabled + function toggle() { + plasmoid.nativeInterface.autoRotateEnabled = !enabled + } + }, + QuickSetting { + text: i18n("Night Color") + icon: "redshift-status-on" + enabled: compositorAdaptor.active + settingsCommand: "plasma-settings -m kcm_nightcolor" + + CC.CompositorAdaptor { + id: compositorAdaptor + } + function toggle() { + if (compositorAdaptor.active) { + compositorAdaptor.activeStaged = false; + } else { + compositorAdaptor.activeStaged = true; + compositorAdaptor.modeStaged = 3; // always on + } + compositorAdaptor.sendConfigurationAll(); + enabled = compositorAdaptor.active; + } + } + ] + PlasmaNM.Handler { id: nmHandler } @@ -41,154 +144,4 @@ Item { PlasmaNM.EnabledConnections { id: enabledConnections } - - // night color - CC.CompositorAdaptor { - id: compositorAdaptor - } - - Connections { - target: BluezQt.Manager - function onBluetoothOperationalChanged() { - settingsModel.get(2).enabled = BluezQt.Manager.bluetoothOperational - } - } - - function toggleAirplane() { - print("toggle airplane mode") - } - - function toggleTorch() { - plasmoid.nativeInterface.toggleTorch() - settingsModel.get(6).enabled = plasmoid.nativeInterface.torchEnabled - } - - function toggleWifi() { - nmHandler.enableWireless(!enabledConnections.wirelessEnabled) - settingsModel.get(1).enabled = !enabledConnections.wirelessEnabled - } - - function toggleWwan() { - nmHandler.enableWwan(!enabledConnections.wwanEnabled) - settingsModel.get(3).enabled = !enabledConnections.wwanEnabled - } - - function toggleRotation() { - const enable = !plasmoid.nativeInterface.autoRotateEnabled - plasmoid.nativeInterface.autoRotateEnabled = enable - settingsModel.get(9).enabled = enable - } - - function toggleBluetooth() { - var enable = !BluezQt.Manager.bluetoothOperational; - BluezQt.Manager.bluetoothBlocked = !enable; - - for (var i = 0; i < BluezQt.Manager.adapters.length; ++i) { - var adapter = BluezQt.Manager.adapters[i]; - adapter.powered = enable; - } - } - - function toggleNightColor() { - if (compositorAdaptor.active) { - compositorAdaptor.activeStaged = false; - } else { - compositorAdaptor.activeStaged = true; - compositorAdaptor.modeStaged = 3; // always on - } - compositorAdaptor.sendConfigurationAll(); - settingsModel.get(10).enabled = compositorAdaptor.active; - } - - // components needed for quick settings - function requestScreenshot() { - screenshotRequested = true; - root.closeRequested(); - } - - function openVolumeOsd() { - volumeProvider.showVolumeOverlay(); - } - - // initialize quick settings - Component.onCompleted: { - //NOTE: add all in javascript as the static decl of listelements can't have scripts - settingsModel.append({ - "text": i18n("Settings"), - "icon": "configure", - "enabled": false, - "settingsCommand": "plasma-settings", - "toggleFunction": "" - }); - settingsModel.append({ - "text": i18n("Wifi"), - "icon": "network-wireless-signal", - "settingsCommand": "plasma-settings -m kcm_mobile_wifi", - "toggleFunction": "toggleWifi", - "enabled": enabledConnections.wirelessEnabled - }); - settingsModel.append({ - "text": i18n("Bluetooth"), - "icon": "network-bluetooth", - "settingsCommand": "plasma-settings -m kcm_bluetooth", - "toggleFunction": "toggleBluetooth", - "delegate": "", - "enabled": BluezQt.Manager.bluetoothOperational - }); - settingsModel.append({ - "text": i18n("Mobile Data"), - "icon": "network-modem", - "settingsCommand": "plasma-settings -m kcm_mobile_broadband", - "toggleFunction": "toggleWwan", - "enabled": enabledConnections.wwanEnabled - }); - settingsModel.append({ - "text": i18n("Battery"), - "icon": "battery-full", - "enabled": false, - "settingsCommand": "plasma-settings -m kcm_mobile_power", - "toggleFunction": "" - }); - settingsModel.append({ - "text": i18n("Sound"), - "icon": "audio-speakers-symbolic", - "enabled": false, - "settingsCommand": "plasma-settings -m kcm_pulseaudio", - "toggleFunction": "openVolumeOsd" - }); - settingsModel.append({ - "text": i18n("Flashlight"), - "icon": "flashlight-on", - "enabled": plasmoid.nativeInterface.torchEnabled, - "settingsCommand": "", - "toggleFunction": "toggleTorch" - }); - settingsModel.append({ - "text": i18n("Location"), - "icon": "gps", - "enabled": false, - "settingsCommand": "" - }); - settingsModel.append({ - "text": i18n("Screenshot"), - "icon": "spectacle", - "enabled": false, - "settingsCommand": "", - "toggleFunction": "requestScreenshot" - }); - settingsModel.append({ - "text": i18n("Auto-rotate"), - "icon": "rotation-allowed", - "enabled": plasmoid.nativeInterface.autoRotateEnabled, - "settingsCommand": "", - "toggleFunction": "toggleRotation" - }); - settingsModel.append({ - "text": i18n("Night Color"), - "icon": "redshift-status-on", - "enabled": compositorAdaptor.active, - "settingsCommand": "", // change once night color kcm is added - "toggleFunction": "toggleNightColor" - }); - } } diff --git a/containments/panel/package/contents/ui/quicksettings/QuickSettingsPanel.qml b/containments/panel/package/contents/ui/quicksettings/QuickSettingsPanel.qml index 791d8875..9446d0ec 100644 --- a/containments/panel/package/contents/ui/quicksettings/QuickSettingsPanel.qml +++ b/containments/panel/package/contents/ui/quicksettings/QuickSettingsPanel.qml @@ -135,7 +135,7 @@ Item { model: quickSettingsModel.model delegate: Delegate { id: delegateItem - settingsModel: quickSettingsModel + required property var modelData width: root.expandedRatio < 0.4 ? Math.max(implicitWidth + PlasmaCore.Units.smallSpacing * 2, flow.width / (flow.columns + 1)) : Math.max(implicitWidth + PlasmaCore.Units.smallSpacing * 2, @@ -143,6 +143,11 @@ Item { labelOpacity: y > 0 ? 1 : root.expandedRatio opacity: y <= 0 ? 1 : root.expandedRatio + text: modelData.text + icon: modelData.icon + enabled: modelData.enabled + settingsCommand: modelData.settingsCommand + toggleFunction: modelData.toggle Connections { target: delegateItem