diff --git a/applets/batterymonitor/package/contents/ui/BrightnessItem.qml b/applets/batterymonitor/package/contents/ui/BrightnessItem.qml index e745ad3da..7783ce9d7 100644 --- a/applets/batterymonitor/package/contents/ui/BrightnessItem.qml +++ b/applets/batterymonitor/package/contents/ui/BrightnessItem.qml @@ -1,63 +1,68 @@ /* * Copyright 2012-2013 Daniel Nicoletti * Copyright 2013, 2015 Kai Uwe Broulik * * 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 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.0 import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as Components +import org.kde.plasma.components 3.0 as Components3 RowLayout { + id: item property alias icon: brightnessIcon.source property alias label: brightnessLabel.text property alias value: brightnessSlider.value - property alias maximumValue: brightnessSlider.maximumValue + property alias maximumValue: brightnessSlider.to + property alias stepSize: brightnessSlider.stepSize + signal moved() spacing: units.gridUnit PlasmaCore.IconItem { id: brightnessIcon Layout.alignment: Qt.AlignTop Layout.preferredWidth: units.iconSizes.medium Layout.preferredHeight: width } Column { id: brightnessColumn Layout.fillWidth: true Layout.alignment: Qt.AlignTop spacing: 0 Components.Label { id: brightnessLabel width: parent.width height: paintedHeight } - Components.Slider { + Components3.Slider { id: brightnessSlider width: parent.width // Don't allow the slider to turn off the screen // Please see https://git.reviewboard.kde.org/r/122505/ for more information - minimumValue: maximumValue > 100 ? 1 : 0 + from: to > 100 ? 1 : 0 stepSize: 1 + onMoved: item.moved() } } } diff --git a/applets/batterymonitor/package/contents/ui/PopupDialog.qml b/applets/batterymonitor/package/contents/ui/PopupDialog.qml index f163009e2..0e846bb1a 100644 --- a/applets/batterymonitor/package/contents/ui/PopupDialog.qml +++ b/applets/batterymonitor/package/contents/ui/PopupDialog.qml @@ -1,138 +1,131 @@ /* * Copyright 2011 Viranch Mehta * Copyright 2013-2016 Kai Uwe Broulik * * 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 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.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as Components import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.kquickcontrolsaddons 2.0 FocusScope { id: dialog focus: true property alias model: batteryList.model property bool pluggedIn property int remainingTime property bool isBrightnessAvailable property bool isKeyboardBrightnessAvailable signal powermanagementChanged(bool checked) - Component.onCompleted: { - // setup handler on slider value manually to avoid change on creation - - brightnessSlider.valueChanged.connect(function() { - batterymonitor.screenBrightness = brightnessSlider.value - }) - - keyboardBrightnessSlider.valueChanged.connect(function() { - batterymonitor.keyboardBrightness = keyboardBrightnessSlider.value - }) - } - Column { id: settingsColumn anchors.horizontalCenter: parent.horizontalCenter width: parent.width - units.gridUnit spacing: Math.round(units.gridUnit / 2) Components.Label { // this is just for metrics, TODO use TextMetrics in 5.4 instead id: percentageMeasurementLabel text: i18nc("Used for measurement", "100%") visible: false } PowerManagementItem { id: pmSwitch width: parent.width onEnabledChanged: powermanagementChanged(enabled) KeyNavigation.tab: batteryList KeyNavigation.backtab: keyboardBrightnessSlider } BrightnessItem { id: brightnessSlider width: parent.width icon: "video-display-brightness" label: i18n("Display Brightness") visible: isBrightnessAvailable value: batterymonitor.screenBrightness maximumValue: batterymonitor.maximumScreenBrightness KeyNavigation.tab: keyboardBrightnessSlider KeyNavigation.backtab: batteryList + stepSize: batterymonitor.maximumScreenBrightness/100 + + onMoved: batterymonitor.screenBrightness = value // Manually dragging the slider around breaks the binding Connections { target: batterymonitor onScreenBrightnessChanged: brightnessSlider.value = batterymonitor.screenBrightness } } BrightnessItem { id: keyboardBrightnessSlider width: parent.width icon: "input-keyboard-brightness" label: i18n("Keyboard Brightness") value: batterymonitor.keyboardBrightness maximumValue: batterymonitor.maximumKeyboardBrightness visible: isKeyboardBrightnessAvailable KeyNavigation.tab: pmSwitch KeyNavigation.backtab: brightnessSlider + onMoved: batterymonitor.keyboardBrightness = value + // Manually dragging the slider around breaks the binding Connections { target: batterymonitor onKeyboardBrightnessChanged: keyboardBrightnessSlider.value = batterymonitor.keyboardBrightness } } } PlasmaExtras.ScrollArea { anchors { horizontalCenter: parent.horizontalCenter top: settingsColumn.bottom topMargin: units.gridUnit // not divided by 2 for unified looks bottom: dialog.bottom } width: parent.width - units.gridUnit ListView { id: batteryList boundsBehavior: Flickable.StopAtBounds spacing: Math.round(units.gridUnit / 2) KeyNavigation.tab: brightnessSlider KeyNavigation.backtab: pmSwitch delegate: BatteryItem { width: parent.width battery: model } } } } diff --git a/applets/batterymonitor/package/contents/ui/batterymonitor.qml b/applets/batterymonitor/package/contents/ui/batterymonitor.qml index 91c2b8285..ac6407528 100644 --- a/applets/batterymonitor/package/contents/ui/batterymonitor.qml +++ b/applets/batterymonitor/package/contents/ui/batterymonitor.qml @@ -1,254 +1,263 @@ /* * Copyright 2011 Sebastian Kügler * Copyright 2011 Viranch Mehta * Copyright 2013-2015 Kai Uwe Broulik * * 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 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.0 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.kcoreaddons 1.0 as KCoreAddons import org.kde.kquickcontrolsaddons 2.0 import "logic.js" as Logic Item { id: batterymonitor Plasmoid.switchWidth: units.gridUnit * 10 Plasmoid.switchHeight: units.gridUnit * 10 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft LayoutMirroring.childrenInherit: true Plasmoid.status: { if (powermanagementDisabled) { return PlasmaCore.Types.ActiveStatus } if (pmSource.data.Battery["Has Cumulative"]) { if (pmSource.data.Battery.State !== "Charging" && pmSource.data.Battery.Percent <= 5) { return PlasmaCore.Types.NeedsAttentionStatus } else if (pmSource.data["Battery"]["State"] !== "FullyCharged") { return PlasmaCore.Types.ActiveStatus } } return PlasmaCore.Types.PassiveStatus } Plasmoid.toolTipMainText: { if (batteries.count === 0) { return i18n("No Batteries Available"); } else if (!pmSource.data["Battery"]["Has Cumulative"]) { // Bug 362924: Distinguish between no batteries and no power supply batteries // just show the generic applet title in the latter case return i18n("Battery and Brightness") } else if (pmSource.data["Battery"]["State"] === "FullyCharged") { return i18n("Fully Charged"); } else if (pmSource.data["AC Adapter"] && pmSource.data["AC Adapter"]["Plugged in"]) { var percent = pmSource.data.Battery.Percent var state = pmSource.data.Battery.State if (state === "Charging") { return i18n("%1% Charging", percent) } else if (state === "NoCharge") { return i18n("%1% Plugged in, not Charging", percent) } else { return i18n("%1% Plugged in", percent) } } else { if (remainingTime > 0) { return i18nc("%1 is remaining time, %2 is percentage", "%1 Remaining (%2%)", KCoreAddons.Format.formatDuration(remainingTime, KCoreAddons.FormatTypes.HideSeconds), pmSource.data["Battery"]["Percent"]) } else { return i18n("%1% Battery Remaining", pmSource.data["Battery"]["Percent"]); } } } Plasmoid.toolTipSubText: powermanagementDisabled ? i18n("Power management is disabled") : "" Plasmoid.icon: "battery" property bool disableBrightnessUpdate: true property int screenBrightness readonly property int maximumScreenBrightness: pmSource.data["PowerDevil"] ? pmSource.data["PowerDevil"]["Maximum Screen Brightness"] || 0 : 0 property int keyboardBrightness readonly property int maximumKeyboardBrightness: pmSource.data["PowerDevil"] ? pmSource.data["PowerDevil"]["Maximum Keyboard Brightness"] || 0 : 0 readonly property int remainingTime: Number(pmSource.data["Battery"]["Remaining msec"]) property bool powermanagementDisabled: false property var inhibitions: [] readonly property var kcms: ["powerdevilprofilesconfig.desktop", "powerdevilactivitiesconfig.desktop", "powerdevilglobalconfig.desktop"] readonly property bool kcmsAuthorized: KCMShell.authorize(batterymonitor.kcms).length > 0 readonly property var kcm_energyinfo: ["kcm_energyinfo.desktop"] readonly property bool kcmEnergyInformationAuthorized: KCMShell.authorize(kcm_energyinfo).length > 0 + property QtObject updateScreenBrightnessJob onScreenBrightnessChanged: { if (disableBrightnessUpdate) { return; } var service = pmSource.serviceForSource("PowerDevil"); var operation = service.operationDescription("setBrightness"); operation.brightness = screenBrightness; // show OSD only when the plasmoid isn't expanded since the moving slider is feedback enough operation.silent = plasmoid.expanded - service.startOperationCall(operation); + updateScreenBrightnessJob = service.startOperationCall(operation); + updateScreenBrightnessJob.finished.connect(function(job) { + Logic.updateBrightness(batterymonitor, pmSource); + }); } + + property QtObject updateKeyboardBrightnessJob onKeyboardBrightnessChanged: { if (disableBrightnessUpdate) { return; } var service = pmSource.serviceForSource("PowerDevil"); var operation = service.operationDescription("setKeyboardBrightness"); operation.brightness = keyboardBrightness; operation.silent = plasmoid.expanded - service.startOperationCall(operation); + updateKeyboardBrightnessJob = service.startOperationCall(operation); + updateKeyboardBrightnessJob.finished.connect(function(job) { + Logic.updateBrightness(batterymonitor, pmSource); + }); } function action_powerdevilkcm() { KCMShell.open(batterymonitor.kcms); } function action_energyinformationkcm() { KCMShell.open(batterymonitor.kcm_energyinfo); } Component.onCompleted: { Logic.updateBrightness(batterymonitor, pmSource); Logic.updateInhibitions(batterymonitor, pmSource) if (batterymonitor.kcmEnergyInformationAuthorized) { plasmoid.setAction("energyinformationkcm", i18n("&Show Energy Information..."), "battery"); } if (batterymonitor.kcmsAuthorized) { plasmoid.setAction("powerdevilkcm", i18n("&Configure Power Saving..."), "preferences-system-power-management"); } } Plasmoid.compactRepresentation: CompactRepresentation { property int wheelDelta: 0 onEntered: wheelDelta = 0 onExited: wheelDelta = 0 onWheel: { var delta = wheel.angleDelta.y || wheel.angleDelta.x var maximumBrightness = batterymonitor.maximumScreenBrightness // Don't allow the UI to turn off the screen // Please see https://git.reviewboard.kde.org/r/122505/ for more information var minimumBrightness = (maximumBrightness > 100 ? 1 : 0) var steps = Math.max(1, Math.round(maximumBrightness / 20)) var deltaSteps = delta / 120; batterymonitor.screenBrightness = Math.max(minimumBrightness, Math.min(maximumBrightness, batterymonitor.screenBrightness + deltaSteps * steps)); } } property QtObject pmSource: PlasmaCore.DataSource { id: pmSource engine: "powermanagement" connectedSources: sources onSourceAdded: { disconnectSource(source); connectSource(source); } onSourceRemoved: { disconnectSource(source); } onDataChanged: { Logic.updateBrightness(batterymonitor, pmSource) Logic.updateInhibitions(batterymonitor, pmSource) } } property QtObject batteries: PlasmaCore.SortFilterModel { id: batteries filterRole: "Is Power Supply" sortOrder: Qt.DescendingOrder sourceModel: PlasmaCore.SortFilterModel { sortRole: "Pretty Name" sortOrder: Qt.AscendingOrder sortCaseSensitivity: Qt.CaseInsensitive sourceModel: PlasmaCore.DataModel { dataSource: pmSource sourceFilter: "Battery[0-9]+" } } } Plasmoid.fullRepresentation: PopupDialog { id: dialogItem Layout.minimumWidth: units.iconSizes.medium * 9 Layout.minimumHeight: units.gridUnit * 15 // TODO Probably needs a sensible preferredHeight too model: plasmoid.expanded ? batteries : null anchors.fill: parent focus: true isBrightnessAvailable: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Screen Brightness Available"] ? true : false isKeyboardBrightnessAvailable: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Keyboard Brightness Available"] ? true : false pluggedIn: pmSource.data["AC Adapter"] !== undefined && pmSource.data["AC Adapter"]["Plugged in"] property int cookie1: -1 property int cookie2: -1 onPowermanagementChanged: { var service = pmSource.serviceForSource("PowerDevil"); if (checked) { var op1 = service.operationDescription("stopSuppressingSleep"); op1.cookie = cookie1; var op2 = service.operationDescription("stopSuppressingScreenPowerManagement"); op2.cookie = cookie2; var job1 = service.startOperationCall(op1); job1.finished.connect(function(job) { cookie1 = -1; }); var job2 = service.startOperationCall(op2); job2.finished.connect(function(job) { cookie2 = -1; }); } else { var reason = i18n("The battery applet has enabled system-wide inhibition"); var op1 = service.operationDescription("beginSuppressingSleep"); op1.reason = reason; var op2 = service.operationDescription("beginSuppressingScreenPowerManagement"); op2.reason = reason; var job1 = service.startOperationCall(op1); job1.finished.connect(function(job) { cookie1 = job.result; }); var job2 = service.startOperationCall(op2); job2.finished.connect(function(job) { cookie2 = job.result; }); } batterymonitor.powermanagementDisabled = !checked } } } diff --git a/applets/batterymonitor/package/contents/ui/logic.js b/applets/batterymonitor/package/contents/ui/logic.js index cfe711e94..39e7f4d1a 100644 --- a/applets/batterymonitor/package/contents/ui/logic.js +++ b/applets/batterymonitor/package/contents/ui/logic.js @@ -1,83 +1,86 @@ /* * Copyright 2011 Sebastian Kügler * Copyright 2012 Viranch Mehta * Copyright 2014-2016 Kai Uwe Broulik * * 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 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. */ function stringForBatteryState(batteryData) { if (batteryData["Plugged in"]) { switch(batteryData["State"]) { case "Discharging": return i18n("Discharging"); case "FullyCharged": return i18n("Fully Charged"); case "Charging": return i18n("Charging"); // when in doubt we're not charging default: return i18n("Not Charging"); } } else { return i18nc("Battery is currently not present in the bay","Not present"); } } function batteryDetails(batteryData, remainingTime) { var data = [] if (remainingTime > 0 && batteryData["Is Power Supply"] && (batteryData["State"] == "Discharging" || batteryData["State"] == "Charging")) { data.push({label: (batteryData["State"] == "Charging" ? i18n("Time To Full:") : i18n("Time To Empty:")) }) data.push({value: KCoreAddons.Format.formatDuration(remainingTime, KCoreAddons.FormatTypes.HideSeconds) }) } if (batteryData["Is Power Supply"] && batteryData["Capacity"] != "" && typeof batteryData["Capacity"] == "number") { data.push({label: i18n("Battery Health:") }) data.push({value: i18nc("Placeholder is battery health percentage", "%1%", batteryData["Capacity"]) }) } return data } function updateBrightness(rootItem, source) { + if (rootItem.updateScreenBrightnessJob || rootItem.updateKeyboardBrightnessJob) + return; + if (!source.data["PowerDevil"]) { return; } // we don't want passive brightness change send setBrightness call rootItem.disableBrightnessUpdate = true; if (typeof source.data["PowerDevil"]["Screen Brightness"] === 'number') { rootItem.screenBrightness = source.data["PowerDevil"]["Screen Brightness"]; } if (typeof source.data["PowerDevil"]["Keyboard Brightness"] === 'number') { rootItem.keyboardBrightness = source.data["PowerDevil"]["Keyboard Brightness"]; } rootItem.disableBrightnessUpdate = false; } function updateInhibitions(rootItem, source) { var inhibitions = []; if (source.data["Inhibitions"]) { for(var key in pmSource.data["Inhibitions"]) { if (key === "plasmashell" || key === "plasmoidviewer") { // ignore our own inhibition continue } inhibitions.push(pmSource.data["Inhibitions"][key]) } } rootItem.inhibitions = inhibitions } diff --git a/dataengines/powermanagement/powermanagementjob.cpp b/dataengines/powermanagement/powermanagementjob.cpp index 0e3618c8a..0cc57f6a8 100644 --- a/dataengines/powermanagement/powermanagementjob.cpp +++ b/dataengines/powermanagement/powermanagementjob.cpp @@ -1,132 +1,142 @@ /* * Copyright 2011 Sebastian Kügler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 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. */ #include #include #include #include #include // kde-workspace/libs #include #include #include "powermanagementjob.h" #include PowerManagementJob::PowerManagementJob(const QString &operation, QMap ¶meters, QObject *parent) : ServiceJob(parent->objectName(), operation, parameters, parent) { } PowerManagementJob::~PowerManagementJob() { } +static void callWhenFinished(const QDBusPendingCall& pending, std::function func, QObject* parent) +{ + QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(pending, parent); + QObject::connect(watcher, &QDBusPendingCallWatcher::finished, + parent, [func](QDBusPendingCallWatcher* watcher) { + watcher->deleteLater(); + func(); + }); +} + void PowerManagementJob::start() { const QString operation = operationName(); //qDebug() << "starting operation ... " << operation; if (operation == QLatin1String("lockScreen")) { if (KAuthorized::authorizeAction(QStringLiteral("lock_screen"))) { const QString interface(QStringLiteral("org.freedesktop.ScreenSaver")); QDBusInterface screensaver(interface, QStringLiteral("/ScreenSaver")); screensaver.asyncCall(QStringLiteral("Lock")); setResult(true); return; } qDebug() << "operation denied " << operation; setResult(false); return; } else if (operation == QLatin1String("suspend") || operation == QLatin1String("suspendToRam")) { Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState, nullptr, nullptr); setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::SuspendState)); return; } else if (operation == QLatin1String("suspendToDisk")) { Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState, nullptr, nullptr); setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::HibernateState)); return; } else if (operation == QLatin1String("suspendHybrid")) { Solid::PowerManagement::requestSleep(Solid::PowerManagement::HybridSuspendState, nullptr, nullptr); setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::HybridSuspendState)); return; } else if (operation == QLatin1String("requestShutDown")) { requestShutDown(); setResult(true); return; } else if (operation == QLatin1String("switchUser")) { // Taken from kickoff/core/itemhandlers.cpp org::kde::krunner::App krunner(QStringLiteral("org.kde.krunner"), QStringLiteral("/App"), QDBusConnection::sessionBus()); krunner.switchUser(); setResult(true); return; } else if (operation == QLatin1String("beginSuppressingSleep")) { setResult(Solid::PowerManagement::beginSuppressingSleep(parameters().value(QStringLiteral("reason")).toString())); return; } else if (operation == QLatin1String("stopSuppressingSleep")) { setResult(Solid::PowerManagement::stopSuppressingSleep(parameters().value(QStringLiteral("cookie")).toInt())); return; } else if (operation == QLatin1String("beginSuppressingScreenPowerManagement")) { setResult(Solid::PowerManagement::beginSuppressingScreenPowerManagement(parameters().value(QStringLiteral("reason")).toString())); return; } else if (operation == QLatin1String("stopSuppressingScreenPowerManagement")) { setResult(Solid::PowerManagement::stopSuppressingScreenPowerManagement(parameters().value(QStringLiteral("cookie")).toInt())); return; } else if (operation == QLatin1String("setBrightness")) { - setScreenBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool()); - setResult(true); + auto pending = setScreenBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool()); + callWhenFinished(pending, [this] { setResult(true); }, this); return; } else if (operation == QLatin1String("setKeyboardBrightness")) { - setKeyboardBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool()); - setResult(true); + auto pending = setKeyboardBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool()); + callWhenFinished(pending, [this] { setResult(true); }, this); return; } qDebug() << "don't know what to do with " << operation; setResult(false); } -void PowerManagementJob::setScreenBrightness(int value, bool silent) +QDBusPendingCall PowerManagementJob::setScreenBrightness(int value, bool silent) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"), QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"), QStringLiteral("org.kde.Solid.PowerManagement.Actions.BrightnessControl"), silent ? "setBrightnessSilent" : "setBrightness"); msg << value; - QDBusConnection::sessionBus().asyncCall(msg); + return QDBusConnection::sessionBus().asyncCall(msg); } -void PowerManagementJob::setKeyboardBrightness(int value, bool silent) +QDBusPendingCall PowerManagementJob::setKeyboardBrightness(int value, bool silent) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"), QStringLiteral("/org/kde/Solid/PowerManagement/Actions/KeyboardBrightnessControl"), QStringLiteral("org.kde.Solid.PowerManagement.Actions.KeyboardBrightnessControl"), silent ? "setKeyboardBrightnessSilent" : "setKeyboardBrightness"); msg << value; - QDBusConnection::sessionBus().asyncCall(msg); + return QDBusConnection::sessionBus().asyncCall(msg); } void PowerManagementJob::requestShutDown() { KWorkSpace::requestShutDown(); } diff --git a/dataengines/powermanagement/powermanagementjob.h b/dataengines/powermanagement/powermanagementjob.h index fbaeb6751..a2cf8308f 100644 --- a/dataengines/powermanagement/powermanagementjob.h +++ b/dataengines/powermanagement/powermanagementjob.h @@ -1,44 +1,45 @@ /* * Copyright 2011 Sebastian Kügler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 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. */ #ifndef POWERMANAGEMENTJOB_H #define POWERMANAGEMENTJOB_H // plasma #include +class QDBusPendingCall; + class PowerManagementJob : public Plasma::ServiceJob { - Q_OBJECT public: PowerManagementJob(const QString &operation, QMap ¶meters, QObject *parent = nullptr); ~PowerManagementJob() override; protected: void start() override; private: void requestShutDown(); - void setScreenBrightness(int value, bool silent); - void setKeyboardBrightness(int value, bool silent); + QDBusPendingCall setScreenBrightness(int value, bool silent); + QDBusPendingCall setKeyboardBrightness(int value, bool silent); }; #endif // POWERMANAGEMENTJOB_H