2017-09-14 19:03:56 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2015 Marco Martin <notmart@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Library General Public License for more details
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import QtQuick 2.1
|
|
|
|
|
import QtQuick.Layouts 1.1
|
|
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
|
|
|
|
import org.kde.plasma.components 2.0 as PlasmaComponents
|
2020-03-02 13:25:11 +00:00
|
|
|
import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
|
2020-10-22 14:01:16 +00:00
|
|
|
import org.kde.bluezqt 1.0 as BluezQt
|
2020-11-19 02:57:27 +00:00
|
|
|
import org.kde.colorcorrect 0.1 as CC
|
2017-09-14 19:03:56 +00:00
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: root
|
|
|
|
|
|
2019-10-04 14:02:26 +00:00
|
|
|
implicitWidth: flow.implicitWidth + units.smallSpacing * 6
|
|
|
|
|
implicitHeight: flow.implicitHeight + units.smallSpacing * 6
|
|
|
|
|
|
2020-02-04 19:44:58 +00:00
|
|
|
signal closeRequested
|
2020-02-04 20:26:26 +00:00
|
|
|
signal closed
|
2020-02-04 19:44:58 +00:00
|
|
|
|
2020-02-06 17:17:47 +00:00
|
|
|
property bool screenshotRequested: false
|
|
|
|
|
|
2020-03-02 13:25:11 +00:00
|
|
|
PlasmaNM.Handler {
|
2020-04-12 14:14:19 +00:00
|
|
|
id: nmHandler
|
2020-03-02 13:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlasmaNM.EnabledConnections {
|
2020-04-12 14:14:19 +00:00
|
|
|
id: enabledConnections
|
2020-03-02 13:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
2020-10-22 14:01:16 +00:00
|
|
|
Connections {
|
|
|
|
|
target: BluezQt.Manager
|
|
|
|
|
|
|
|
|
|
function onBluetoothOperationalChanged() {
|
|
|
|
|
settingsModel.get(2).enabled = BluezQt.Manager.bluetoothOperational
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 19:03:56 +00:00
|
|
|
function toggleAirplane() {
|
|
|
|
|
print("toggle airplane mode")
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 04:02:46 +00:00
|
|
|
function toggleTorch() {
|
|
|
|
|
plasmoid.nativeInterface.toggleTorch()
|
2020-11-19 11:31:28 +00:00
|
|
|
settingsModel.get(6).enabled = plasmoid.nativeInterface.torchEnabled
|
2018-11-12 04:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-02 13:25:11 +00:00
|
|
|
function toggleWifi() {
|
2020-04-12 14:14:19 +00:00
|
|
|
nmHandler.enableWireless(!enabledConnections.wirelessEnabled)
|
|
|
|
|
settingsModel.get(1).enabled = !enabledConnections.wirelessEnabled
|
2020-03-02 13:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-12 11:59:19 +00:00
|
|
|
function toggleWwan() {
|
|
|
|
|
nmHandler.enableWwan(!enabledConnections.wwanEnabled)
|
2020-10-22 14:01:16 +00:00
|
|
|
settingsModel.get(3).enabled = !enabledConnections.wwanEnabled
|
2020-03-12 11:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-12 14:14:51 +00:00
|
|
|
function toggleRotation() {
|
|
|
|
|
const enable = !plasmoid.nativeInterface.autoRotateEnabled
|
|
|
|
|
plasmoid.nativeInterface.autoRotateEnabled = enable
|
2020-10-22 14:01:16 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2020-04-12 14:14:51 +00:00
|
|
|
}
|
2020-11-19 02:57:27 +00:00
|
|
|
|
|
|
|
|
function toggleNightColor() {
|
|
|
|
|
if (compositorAdaptor.active) {
|
|
|
|
|
compositorAdaptor.activeStaged = false;
|
|
|
|
|
} else {
|
|
|
|
|
compositorAdaptor.activeStaged = true;
|
|
|
|
|
compositorAdaptor.modeStaged = 3; // always on
|
|
|
|
|
}
|
|
|
|
|
compositorAdaptor.sendConfigurationAll();
|
2020-11-19 11:31:28 +00:00
|
|
|
settingsModel.get(10).enabled = compositorAdaptor.active;
|
2020-11-19 02:57:27 +00:00
|
|
|
}
|
2020-04-12 14:14:51 +00:00
|
|
|
|
2019-02-06 17:01:12 +00:00
|
|
|
function requestShutdown() {
|
|
|
|
|
print("Shutdown requested, depends on ksmserver running");
|
|
|
|
|
var service = pmSource.serviceForSource("PowerDevil");
|
|
|
|
|
//note the strange camelCasing is intentional
|
|
|
|
|
var operation = service.operationDescription("requestShutDown");
|
|
|
|
|
return service.startOperationCall(operation);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 10:59:26 +00:00
|
|
|
signal plasmoidTriggered(var applet, var id)
|
2017-09-14 19:03:56 +00:00
|
|
|
Layout.minimumHeight: flow.implicitHeight + units.largeSpacing*2
|
|
|
|
|
|
2018-11-11 14:23:13 +00:00
|
|
|
property int screenBrightness
|
2019-02-07 16:23:04 +00:00
|
|
|
property bool disableBrightnessUpdate: true
|
2018-11-11 14:23:13 +00:00
|
|
|
readonly property int maximumScreenBrightness: pmSource.data["PowerDevil"] ? pmSource.data["PowerDevil"]["Maximum Screen Brightness"] || 0 : 0
|
|
|
|
|
|
|
|
|
|
onScreenBrightnessChanged: {
|
2019-02-07 16:23:04 +00:00
|
|
|
if(!disableBrightnessUpdate) {
|
|
|
|
|
var service = pmSource.serviceForSource("PowerDevil");
|
|
|
|
|
var operation = service.operationDescription("setBrightness");
|
|
|
|
|
operation.brightness = screenBrightness;
|
|
|
|
|
operation.silent = true
|
|
|
|
|
service.startOperationCall(operation);
|
|
|
|
|
}
|
2018-11-11 14:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-06 17:17:47 +00:00
|
|
|
function requestScreenshot() {
|
|
|
|
|
screenshotRequested = true;
|
|
|
|
|
root.closeRequested();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onClosed: {
|
|
|
|
|
if (screenshotRequested) {
|
|
|
|
|
plasmoid.nativeInterface.takeScreenshot();
|
|
|
|
|
screenshotRequested = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 14:23:13 +00:00
|
|
|
PlasmaCore.DataSource {
|
|
|
|
|
id: pmSource
|
|
|
|
|
engine: "powermanagement"
|
|
|
|
|
connectedSources: ["PowerDevil"]
|
|
|
|
|
onSourceAdded: {
|
|
|
|
|
if (source === "PowerDevil") {
|
|
|
|
|
disconnectSource(source);
|
|
|
|
|
connectSource(source);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onDataChanged: {
|
2019-02-07 16:23:04 +00:00
|
|
|
disableBrightnessUpdate = true;
|
2018-11-11 14:23:13 +00:00
|
|
|
root.screenBrightness = pmSource.data["PowerDevil"]["Screen Brightness"];
|
2019-02-07 16:23:04 +00:00
|
|
|
disableBrightnessUpdate = false;
|
2018-11-11 14:23:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-19 02:57:27 +00:00
|
|
|
|
|
|
|
|
// night color
|
|
|
|
|
CC.CompositorAdaptor {
|
|
|
|
|
id: compositorAdaptor
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 10:59:26 +00:00
|
|
|
//HACK: make the list know about the applet delegate which is a qtobject
|
|
|
|
|
QtObject {
|
|
|
|
|
id: nullApplet
|
|
|
|
|
}
|
|
|
|
|
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": "",
|
2018-11-09 06:44:36 +00:00
|
|
|
"applet": null
|
2017-10-27 10:59:26 +00:00
|
|
|
});
|
2019-02-08 16:47:03 +00:00
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Wifi"),
|
|
|
|
|
"icon": "network-wireless-signal",
|
2020-08-20 11:07:53 +00:00
|
|
|
"settingsCommand": "plasma-settings -m kcm_mobile_wifi",
|
2020-03-02 13:25:11 +00:00
|
|
|
"toggleFunction": "toggleWifi",
|
|
|
|
|
"enabled": enabledConnections.wirelessEnabled,
|
2019-02-08 16:47:03 +00:00
|
|
|
"applet": null
|
|
|
|
|
});
|
2020-10-22 14:01:16 +00:00
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Bluetooth"),
|
|
|
|
|
"icon": "network-bluetooth",
|
|
|
|
|
"settingsCommand": "plasma-settings -m kcm_bluetooth",
|
|
|
|
|
"toggleFunction": "toggleBluetooth",
|
|
|
|
|
"delegate": "",
|
|
|
|
|
"enabled": BluezQt.Manager.bluetoothOperational,
|
|
|
|
|
"applet": null
|
|
|
|
|
});
|
2019-02-08 16:47:03 +00:00
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Mobile Data"),
|
|
|
|
|
"icon": "network-modem",
|
2020-08-20 11:07:53 +00:00
|
|
|
"settingsCommand": "plasma-settings -m kcm_mobile_broadband",
|
2020-03-12 11:59:19 +00:00
|
|
|
"toggleFunction": "toggleWwan",
|
|
|
|
|
"enabled": enabledConnections.wwanEnabled,
|
2019-02-08 16:47:03 +00:00
|
|
|
"applet": null
|
|
|
|
|
});
|
|
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Battery"),
|
2019-10-21 09:32:15 +00:00
|
|
|
"icon": "battery-full",
|
2019-02-08 16:47:03 +00:00
|
|
|
"enabled": false,
|
|
|
|
|
"settingsCommand": "plasma-settings -m kcm_mobile_power",
|
|
|
|
|
"toggleFunction": "",
|
|
|
|
|
"applet": null
|
|
|
|
|
});
|
|
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Sound"),
|
|
|
|
|
"icon": "audio-speakers-symbolic",
|
|
|
|
|
"enabled": false,
|
|
|
|
|
"settingsCommand": "plasma-settings -m kcm_pulseaudio",
|
|
|
|
|
"toggleFunction": "",
|
|
|
|
|
"applet": null
|
|
|
|
|
});
|
2017-10-27 10:59:26 +00:00
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Flashlight"),
|
2019-02-08 16:47:03 +00:00
|
|
|
"icon": "flashlight-on",
|
2020-11-16 06:20:40 +00:00
|
|
|
"enabled": plasmoid.nativeInterface.torchEnabled,
|
2017-10-27 10:59:26 +00:00
|
|
|
"settingsCommand": "",
|
2018-11-12 04:02:46 +00:00
|
|
|
"toggleFunction": "toggleTorch",
|
2017-10-27 10:59:26 +00:00
|
|
|
"applet": null
|
|
|
|
|
});
|
|
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Location"),
|
2020-05-11 11:56:20 +00:00
|
|
|
"icon": "gps",
|
2017-10-27 10:59:26 +00:00
|
|
|
"enabled": false,
|
|
|
|
|
"settingsCommand": "",
|
|
|
|
|
"applet": null
|
|
|
|
|
});
|
2020-02-06 17:17:47 +00:00
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Screenshot"),
|
|
|
|
|
"icon": "spectacle",
|
|
|
|
|
"enabled": false,
|
|
|
|
|
"settingsCommand": "",
|
|
|
|
|
"toggleFunction": "requestScreenshot",
|
|
|
|
|
"applet": null
|
|
|
|
|
});
|
2020-04-12 14:14:51 +00:00
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Auto-rotate"),
|
|
|
|
|
"icon": "rotation-allowed",
|
|
|
|
|
"enabled": plasmoid.nativeInterface.autoRotateEnabled,
|
|
|
|
|
"settingsCommand": "",
|
|
|
|
|
"toggleFunction": "toggleRotation",
|
|
|
|
|
"applet": null
|
|
|
|
|
});
|
2020-11-19 02:57:27 +00:00
|
|
|
settingsModel.append({
|
|
|
|
|
"text": i18n("Night Color"),
|
|
|
|
|
"icon": "redshift-status-on",
|
|
|
|
|
"enabled": compositorAdaptor.active,
|
|
|
|
|
"settingsCommand": "", // change once night color kcm is added
|
|
|
|
|
"toggleFunction": "toggleNightColor",
|
|
|
|
|
"applet": null
|
|
|
|
|
});
|
2019-02-06 17:01:12 +00:00
|
|
|
|
2019-02-07 11:58:08 +00:00
|
|
|
brightnessSlider.moved.connect(function() {
|
2018-11-11 14:23:13 +00:00
|
|
|
root.screenBrightness = brightnessSlider.value;
|
|
|
|
|
});
|
2019-02-07 16:23:04 +00:00
|
|
|
disableBrightnessUpdate = false;
|
2017-10-27 10:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
2017-09-14 19:03:56 +00:00
|
|
|
ListModel {
|
|
|
|
|
id: settingsModel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Flow {
|
|
|
|
|
id: flow
|
|
|
|
|
anchors {
|
|
|
|
|
fill: parent
|
2020-02-14 12:39:49 +00:00
|
|
|
margins: units.smallSpacing
|
2017-09-14 19:03:56 +00:00
|
|
|
}
|
2020-02-14 13:04:18 +00:00
|
|
|
readonly property real cellSizeHint: units.iconSizes.large + units.smallSpacing * 6
|
2019-10-14 15:51:44 +00:00
|
|
|
readonly property real columnWidth: Math.floor(width / Math.floor(width / cellSizeHint))
|
|
|
|
|
spacing: 0
|
2017-09-14 19:03:56 +00:00
|
|
|
Repeater {
|
|
|
|
|
model: settingsModel
|
2020-10-23 08:55:18 +00:00
|
|
|
delegate: Delegate {
|
|
|
|
|
id: delegateItem
|
|
|
|
|
|
2019-02-06 15:23:01 +00:00
|
|
|
//FIXME: why this is needed?
|
2019-10-14 15:51:44 +00:00
|
|
|
width: flow.columnWidth
|
2017-09-14 19:03:56 +00:00
|
|
|
height: item ? item.implicitHeight : 0
|
2020-10-23 08:55:18 +00:00
|
|
|
|
2020-02-04 19:44:58 +00:00
|
|
|
Connections {
|
2020-10-23 08:55:18 +00:00
|
|
|
target: delegateItem
|
2020-02-04 20:26:26 +00:00
|
|
|
onCloseRequested: root.closeRequested();
|
|
|
|
|
}
|
|
|
|
|
Connections {
|
|
|
|
|
target: root
|
2020-10-23 08:55:18 +00:00
|
|
|
onClosed: delegateItem.panelClosed();
|
2020-02-04 19:44:58 +00:00
|
|
|
}
|
2017-09-14 19:03:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-11 14:23:13 +00:00
|
|
|
|
|
|
|
|
BrightnessItem {
|
|
|
|
|
id: brightnessSlider
|
|
|
|
|
width: flow.width
|
|
|
|
|
icon: "video-display-brightness"
|
|
|
|
|
label: i18n("Display Brightness")
|
|
|
|
|
value: root.screenBrightness
|
|
|
|
|
maximumValue: root.maximumScreenBrightness
|
|
|
|
|
Connections {
|
|
|
|
|
target: root
|
|
|
|
|
onScreenBrightnessChanged: brightnessSlider.value = root.screenBrightness
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-14 19:03:56 +00:00
|
|
|
}
|
|
|
|
|
}
|