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

When battery drains, show a notification even when AC is plugged in

Only shows the notification if percentage crosses warning/critical
threshold, not on startup, to avoid showing every time on login
in case of e.g. broken battery.
parent bfb57f41
......@@ -551,7 +551,7 @@ void Core::emitRichNotification(const QString &evid, const QString &title, const
nullptr, KNotification::CloseOnTimeout, QStringLiteral("powerdevil"));
}
bool Core::emitBatteryChargePercentNotification(int currentPercent, int previousPercent, const QString &udi)
bool Core::emitBatteryChargePercentNotification(int currentPercent, int previousPercent, const QString &udi, Core::ChargeNotificationFlags flags)
{
using namespace Solid;
Device device(udi);
......@@ -620,7 +620,8 @@ bool Core::emitBatteryChargePercentNotification(int currentPercent, int previous
return false;
}
if (m_backend->acAdapterState() == BackendInterface::Plugged) {
if (m_backend->acAdapterState() == BackendInterface::Plugged
&& !flags.testFlag(ChargeNotificationFlag::NotifyWhenAcPluggedIn)) {
return false;
}
......@@ -743,7 +744,8 @@ void Core::onBatteryChargePercentChanged(int percent, const QString &udi)
m_batteriesPercent[udi] = percent;
if (currentPercent < previousPercent) {
if (emitBatteryChargePercentNotification(currentPercent, previousPercent, udi)) {
// When battery drains while still plugged in, warn nevertheless.
if (emitBatteryChargePercentNotification(currentPercent, previousPercent, udi, ChargeNotificationFlag::NotifyWhenAcPluggedIn)) {
// Only refresh status if a notification has actually been emitted
loadProfile();
}
......
......@@ -78,7 +78,14 @@ public:
void emitNotification(const QString &eventId, const QString &title, const QString &message, const QString &iconName);
bool emitBatteryChargePercentNotification(int currentPercent, int previousPercent, const QString &udi = QString());
enum class ChargeNotificationFlag {
None,
NotifyWhenAcPluggedIn
};
Q_DECLARE_FLAGS(ChargeNotificationFlags, ChargeNotificationFlag)
Q_FLAG(ChargeNotificationFlags)
bool emitBatteryChargePercentNotification(int currentPercent, int previousPercent, const QString &udi = QString(), ChargeNotificationFlags flags = {});
BackendInterface *backend();
......
Supports Markdown
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