Commit fed13d93 authored by Aditya Mehra's avatar Aditya Mehra
Browse files

Add support for power inhibition via powerdevil

parent cb341314
Pipeline #123403 passed with stage
in 1 minute and 4 seconds
/*
SPDX-FileCopyrightText: 2020 Aditya Mehra <aix.m@outlook.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
import QtQuick.Layouts 1.14
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.14
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kcm 1.2 as KCM
import org.kde.mycroft.bigscreen 1.0 as BigScreen
Item {
id: powerManagementItem
property int cookie1: -1
property int cookie2: -1
property bool inhibit
property QtObject pmSource: PlasmaCore.DataSource {
id: pmSource
engine: "powermanagement"
connectedSources: sources
onSourceAdded: {
disconnectSource(source);
connectSource(source);
}
onSourceRemoved: {
disconnectSource(source);
}
}
onInhibitChanged: {
const service = pmSource.serviceForSource("PowerDevil");
if (inhibit) {
const reason = i18n("Bigscreen has enabled system-wide inhibition");
const op1 = service.operationDescription("beginSuppressingSleep");
op1.reason = reason;
const op2 = service.operationDescription("beginSuppressingScreenPowerManagement");
op2.reason = reason;
const job1 = service.startOperationCall(op1);
job1.finished.connect(job => {
cookie1 = job.result;
});
const job2 = service.startOperationCall(op2);
job2.finished.connect(job => {
cookie2 = job.result;
});
console.log("Power Inhibition Activated By Bigscreen");
} else {
const op1 = service.operationDescription("stopSuppressingSleep");
op1.cookie = cookie1;
const op2 = service.operationDescription("stopSuppressingScreenPowerManagement");
op2.cookie = cookie2;
const job1 = service.startOperationCall(op1);
job1.finished.connect(job => {
cookie1 = -1;
});
const job2 = service.startOperationCall(op2);
job2.finished.connect(job => {
cookie2 = -1;
});
console.log("Power Inhibition Deactivated By Bigscreen");
}
}
}
......@@ -40,17 +40,33 @@ Item {
mycroftWindowLoader.item.disconnectclose()
}
}
onEnablePmInhibitionChanged: {
var powerInhibition = plasmoid.nativeInterface.bigLauncherDbusAdapterInterface.pmInhibitionActive()
if(powerInhibition) {
pmInhibitItem.inhibit = true
} else {
pmInhibitItem.inhibit = false
}
}
}
Containment.onAppletAdded: {
addApplet(applet, x, y);
}
PowerManagementItem {
id: pmInhibitItem
//inhibit: plasmoid.nativeInterface.bigLauncherDbusAdapterInterface.pmInhibitionActive()
}
PlasmaCore.ColorScope.colorGroup: PlasmaCore.Theme.ComplementaryColorGroup
Component.onCompleted: {
for (var i in plasmoid.applets) {
root.addApplet(plasmoid.applets[i], -1, -1)
}
console.log("checking for power inhibition")
console.log(plasmoid.nativeInterface.bigLauncherDbusAdapterInterface.pmInhibitionActive())
pmInhibitItem.inhibit = plasmoid.nativeInterface.bigLauncherDbusAdapterInterface.pmInhibitionActive()
}
function addApplet(applet, x, y) {
......
......@@ -49,6 +49,12 @@ void BigLauncherDbusAdapterInterface::enableMycroftIntegration(const bool &mycro
emit enableMycroftIntegrationChanged(mycroftIntegration);
}
void BigLauncherDbusAdapterInterface::enablePmInhibition(const bool &pmInhibition)
{
Configuration::self().setPmInhibitionEnabled(pmInhibition);
emit enablePmInhibitionChanged(pmInhibition);
}
bool BigLauncherDbusAdapterInterface::coloredTilesActive()
{
if(m_useColoredTiles) {
......@@ -72,6 +78,11 @@ bool BigLauncherDbusAdapterInterface::mycroftIntegrationActive()
return Configuration::self().mycroftEnabled();
}
bool BigLauncherDbusAdapterInterface::pmInhibitionActive()
{
return Configuration::self().pmInhibitionEnabled();
}
void BigLauncherDbusAdapterInterface::setColoredTilesActive(const bool &coloredTilesActive)
{
m_useColoredTiles = coloredTilesActive;
......
......@@ -40,6 +40,9 @@ class BigLauncherDbusAdapterInterface : public QDBusAbstractAdaptor
" <signal name=\"enableMycroftIntegrationChanged\">\n"
" <arg direction=\"out\" type=\"b\" name=\"msgEnableMycroftIntegration\"/>\n"
" </signal>\n"
" <signal name=\"enablePmInhibitionChanged\">\n"
" <arg direction=\"out\" type=\"b\" name=\"msgEnablePmInhibition\"/>\n"
" </signal>\n"
" <method name=\"useColoredTiles\">\n"
" <arg direction=\"in\" type=\"b\" name=\"coloredTiles\"/>\n"
" </method>\n"
......@@ -49,6 +52,9 @@ class BigLauncherDbusAdapterInterface : public QDBusAbstractAdaptor
" <method name=\"enableMycroftIntegration\">\n"
" <arg direction=\"in\" type=\"b\" name=\"mycroftIntegration\"/>\n"
" </method>\n"
" <method name=\"enablePmInhibition\">\n"
" <arg direction=\"in\" type=\"b\" name=\"pmInhibition\"/>\n"
" </method>\n"
" <method name=\"coloredTilesActive\">\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
......@@ -58,6 +64,9 @@ class BigLauncherDbusAdapterInterface : public QDBusAbstractAdaptor
" <method name=\"mycroftIntegrationActive\">\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" <method name=\"pmInhibitionActive\">\n"
" <arg direction=\"out\" type=\"b\"/>\n"
" </method>\n"
" </interface>\n"
"")
public:
......@@ -73,6 +82,8 @@ public Q_SLOTS: // METHODS
bool coloredTilesActive();
bool expandableTilesActive();
bool mycroftIntegrationActive();
bool pmInhibitionActive();
void enablePmInhibition(const bool &pmInhibition);
void setColoredTilesActive(const bool &coloredTilesActive);
void setExpandableTilesActive(const bool &expandableTilesActive);
......@@ -81,6 +92,7 @@ Q_SIGNALS: // SIGNALS
void useColoredTilesChanged(const bool &msgUseColoredTiles);
void useExpandableTilesChanged(const bool &msgUseExpandableTiles);
void enableMycroftIntegrationChanged(const bool &msgEnableMycroftIntegration);
void enablePmInhibitionChanged(const bool &msgEnablePmInhibition);
void coloredTilesActiveRequested();
void expandableTilesActiveRequested();
void enableMycroftIntegrationRequested();
......
......@@ -38,3 +38,27 @@ void Configuration::setMycroftEnabled(bool mycroftEnabled)
Q_EMIT mycroftEnabledChanged();
}
}
bool Configuration::pmInhibitionEnabled() const
{
static KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("bigscreen"));
static KConfigGroup grp(config, QLatin1String("General"));
if (grp.isValid()) {
return grp.readEntry(QLatin1String("PowerInhibition"), true);
}
return true;
}
void Configuration::setPmInhibitionEnabled(bool pmInhibitionEnabled)
{
KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("bigscreen"));
KConfigGroup grp(config, QLatin1String("General"));
if (grp.isValid()) {
grp.writeEntry(QLatin1String("PowerInhibition"), pmInhibitionEnabled);
grp.sync();
Q_EMIT pmInhibitionEnabledChanged();
}
}
......@@ -12,15 +12,20 @@ class Q_DECL_EXPORT Configuration : public QObject
{
Q_OBJECT
Q_PROPERTY(bool mycroftEnabled READ mycroftEnabled WRITE setMycroftEnabled NOTIFY mycroftEnabledChanged)
Q_PROPERTY(bool pmInhibitionEnabled READ pmInhibitionEnabled WRITE setPmInhibitionEnabled NOTIFY pmInhibitionEnabledChanged)
public:
bool mycroftEnabled() const;
void setMycroftEnabled(bool mycroftEnabled);
bool pmInhibitionEnabled() const;
void setPmInhibitionEnabled(bool pmInhibitionEnabled);
static Configuration &self();
Q_SIGNALS:
void mycroftEnabledChanged();
void pmInhibitionEnabledChanged();
};
#endif // CONFIGURATION_H
......@@ -112,6 +112,14 @@ bool BigscreenSettings::mycroftIntegrationActive() const
return responseArg.at(0).toBool();
}
bool BigscreenSettings::pmInhibitionActive() const
{
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.biglauncher", "/BigLauncher", "", "pmInhibitionActive");
QDBusMessage response = QDBusConnection::sessionBus().call(msg);
QList<QVariant> responseArg = response.arguments();
return responseArg.at(0).toBool();
}
void BigscreenSettings::setUseColoredTiles(bool useColoredTiles)
{
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.biglauncher", "/BigLauncher", "", "useColoredTiles");
......@@ -133,6 +141,13 @@ void BigscreenSettings::setMycroftIntegrationActive(bool mycroftIntegrationActiv
QDBusConnection::sessionBus().send(msg);
}
void BigscreenSettings::setPmInhibitionActive(bool pmInhibitionActive)
{
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.biglauncher", "/BigLauncher", "", "enablePmInhibition");
msg << pmInhibitionActive;
QDBusConnection::sessionBus().send(msg);
}
void BigscreenSettings::saveTimeZone(const QString &newtimezone)
{
qDebug() << "Saving timezone to config: " << newtimezone;
......
......@@ -52,6 +52,9 @@ public Q_SLOTS:
bool mycroftIntegrationActive() const;
void setMycroftIntegrationActive(bool mycroftIntegrationActive);
bool pmInhibitionActive() const;
void setPmInhibitionActive(bool pmInhibitionActive);
void saveTimeZone(const QString &newtimezone);
bool useNtp() const;
......
......@@ -44,6 +44,9 @@ KCM.SimpleKCM {
if(type == "mycroftIntegration"){
kcm.setMycroftIntegrationActive(result);
}
if(type == "pmInhibition"){
kcm.setPmInhibitionActive(result);
}
}
contentItem: FocusScope {
......@@ -148,6 +151,7 @@ KCM.SimpleKCM {
RowLayout {
id: topContentArea
height: parent.height
Delegates.LocalSettingDelegate {
id: mycroftIntegrationDelegate
......@@ -157,7 +161,25 @@ KCM.SimpleKCM {
name: "Mycroft Integration"
customType: "mycroftIntegration"
KeyNavigation.up: kcmcloseButton
KeyNavigation.right: pmInhibitionDelegate
KeyNavigation.down: desktopThemeView
onActiveFocusChanged: {
if(activeFocus){
contentLayout.currentSection = topContentArea
}
}
}
Delegates.LocalSettingDelegate {
id: pmInhibitionDelegate
implicitWidth: desktopThemeView.view.cellWidth * 2
implicitHeight: desktopThemeView.view.cellHeight
isChecked: kcm.pmInhibitionActive() ? 1 : 0
name: "Power Inhibition"
customType: "pmInhibition"
KeyNavigation.up: kcmcloseButton
KeyNavigation.right: coloredTileDelegate
KeyNavigation.left: mycroftIntegrationDelegate
KeyNavigation.down: desktopThemeView
onActiveFocusChanged: {
if(activeFocus){
......@@ -165,6 +187,7 @@ KCM.SimpleKCM {
}
}
}
Delegates.LocalSettingDelegate {
id: coloredTileDelegate
implicitWidth: desktopThemeView.view.cellWidth * 2
......@@ -173,7 +196,7 @@ KCM.SimpleKCM {
name: "Colored Tiles"
customType: "coloredTile"
KeyNavigation.up: kcmcloseButton
KeyNavigation.left: mycroftIntegrationDelegate
KeyNavigation.left: pmInhibitionDelegate
KeyNavigation.right: expandableTileDelegate
KeyNavigation.down: desktopThemeView
onActiveFocusChanged: {
......@@ -182,6 +205,7 @@ KCM.SimpleKCM {
}
}
}
Delegates.LocalSettingDelegate {
id: expandableTileDelegate
implicitWidth: desktopThemeView.cellWidth * 2
......@@ -199,6 +223,7 @@ KCM.SimpleKCM {
}
}
}
Delegates.TimeDelegate {
id: timeDateSettingsDelegate
implicitWidth: desktopThemeView.cellWidth * 2
......
Markdown is supported
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