Commit 8801aae8 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Battery Monitor] Indicate when a charge limit has been configured

parent 6827254e
......@@ -66,6 +66,14 @@ ColumnLayout {
Layout.leftMargin: units.gridUnit + units.smallSpacing // width of checkbox and spacer
spacing: units.smallSpacing
InhibitionHint {
Layout.fillWidth: true
readonly property var chargeStopThreshold: pmSource.data["Battery"] ? pmSource.data["Battery"]["Charge Stop Threshold"] : undefined
visible: powerManagementHeadingColumn.pluggedIn && typeof chargeStopThreshold === "number" && chargeStopThreshold < 100
iconSource: "kt-speed-limits" // FIXME good icon
text: i18n("Your battery is configured to only charge up to %1%.", chargeStopThreshold || 0)
}
InhibitionHint {
Layout.fillWidth: true
visible: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Is Lid Present"] && !pmSource.data["PowerDevil"]["Triggers Lid Action"] ? true : false
......
......@@ -125,6 +125,14 @@ void PowermanagementEngine::init()
SLOT(batteryRemainingTimeChanged(qulonglong)))) {
qDebug() << "error connecting to remaining time changes";
}
if (!QDBusConnection::sessionBus().connect(SOLID_POWERMANAGEMENT_SERVICE,
QStringLiteral("/org/kde/Solid/PowerManagement"),
SOLID_POWERMANAGEMENT_SERVICE,
QStringLiteral("chargeStopThresholdChanged"), this,
SLOT(chargeStopThresholdChanged(int)))) {
qDebug() << "error connecting to charge stop threshold changes via dbus";
}
}
}
......@@ -206,6 +214,20 @@ bool PowermanagementEngine::sourceRequestEvent(const QString &name)
});
}
QDBusMessage msg = QDBusMessage::createMethodCall(SOLID_POWERMANAGEMENT_SERVICE,
QStringLiteral("/org/kde/Solid/PowerManagement"),
SOLID_POWERMANAGEMENT_SERVICE,
QStringLiteral("chargeStopThreshold"));
QDBusPendingReply<int> reply = QDBusConnection::sessionBus().asyncCall(msg);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<int> reply = *watcher;
if (!reply.isError()) {
chargeStopThresholdChanged(reply.value());
}
watcher->deleteLater();
});
m_sources = basicSourceNames() + batterySources;
} else if (name == QLatin1String("AC Adapter")) {
connect(Solid::PowerManagement::notifier(), &Solid::PowerManagement::Notifier::appShouldConserveResourcesChanged,
......@@ -676,6 +698,11 @@ void PowermanagementEngine::populateApplicationData(const QString &name, QString
}
}
void PowermanagementEngine::chargeStopThresholdChanged(int threshold)
{
setData(QStringLiteral("Battery"), QStringLiteral("Charge Stop Threshold"), threshold);
}
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(powermanagement, PowermanagementEngine, "plasma-dataengine-powermanagement.json")
#include "powermanagementengine.moc"
......@@ -69,6 +69,7 @@ private Q_SLOTS:
void maximumKeyboardBrightnessChanged(int maximumBrightness);
void triggersLidActionChanged(bool triggers);
void inhibitionsChanged(const QList<InhibitionInfo> &added, const QStringList &removed);
void chargeStopThresholdChanged(int threshold);
private:
void populateApplicationData(const QString &name, QString *prettyName, QString *icon);
......
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