Commit 45dd7bbf authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Make low battery notification critical

This ensures you have to acknowledge it and be aware that the battery is running low.
Otherwise you'll only be notified during a presentation when it's critical.

CCBUG: 420541

Differential Revision: https://phabricator.kde.org/D29309
parent 5602920a
......@@ -228,6 +228,18 @@ void Core::reparseConfiguration()
// Config reloaded
Q_EMIT configurationReloaded();
// Check if critical threshold might have changed and cancel the timer if necessary.
if (m_criticalBatteryTimer->isActive() && currentChargePercent() > PowerDevilSettings::batteryCriticalLevel()) {
m_criticalBatteryTimer->stop();
if (m_criticalBatteryNotification) {
m_criticalBatteryNotification->close();
}
}
if (m_lowBatteryNotification && currentChargePercent() > PowerDevilSettings::batteryLowLevel()) {
m_lowBatteryNotification->close();
}
}
QString Core::currentProfile() const
......@@ -447,6 +459,10 @@ void Core::onDeviceAdded(const QString &udi)
// If a new battery has been added, let's clear some pending suspend actions if the new global batteries percentage is
// higher than the battery critical level. (See bug 329537)
if (m_lowBatteryNotification && currentChargePercent() > PowerDevilSettings::batteryLowLevel()) {
m_lowBatteryNotification->close();
}
if (m_criticalBatteryTimer->isActive() && currentChargePercent() > PowerDevilSettings::batteryCriticalLevel()) {
m_criticalBatteryTimer->stop();
if (m_criticalBatteryNotification) {
......@@ -569,13 +585,26 @@ bool Core::emitBatteryChargePercentNotification(int currentPercent, int previous
return true;
} else if (currentPercent <= PowerDevilSettings::batteryLowLevel() &&
previousPercent > PowerDevilSettings::batteryLowLevel()) {
emitRichNotification(QStringLiteral("lowbattery"), i18n("Battery Low (%1% Remaining)", currentPercent),
i18n("Battery running low - to continue using your computer, plug it in or shut it down and change the battery."));
handleLowBattery(currentPercent);
return true;
}
return false;
}
void Core::handleLowBattery(int percent)
{
if (m_lowBatteryNotification) {
return;
}
m_lowBatteryNotification = new KNotification(QStringLiteral("lowbattery"), KNotification::Persistent, nullptr);
m_lowBatteryNotification->setComponentName(QStringLiteral("powerdevil"));
m_lowBatteryNotification->setTitle(i18n("Battery Low (%1% Remaining)", percent));
m_lowBatteryNotification->setText(i18n("Battery running low - to continue using your computer, plug it in or shut it down and change the battery."));
m_lowBatteryNotification->setUrgency(KNotification::CriticalUrgency);
m_lowBatteryNotification->sendEvent();
}
void Core::handleCriticalBattery(int percent)
{
// no parent, but it won't leak, since it will be closed both in case of timeout or direct action
......@@ -624,6 +653,10 @@ void Core::onAcAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState
if (state == BackendInterface::Plugged) {
// If the AC Adaptor has been plugged in, let's clear some pending suspend actions
if (m_lowBatteryNotification) {
m_lowBatteryNotification->close();
}
if (m_criticalBatteryTimer->isActive()) {
m_criticalBatteryTimer->stop();
if (m_criticalBatteryNotification) {
......
......@@ -97,6 +97,7 @@ Q_SIGNALS:
private:
void registerActionTimeout(Action *action, int timeout);
void unregisterActionTimeouts(Action *action);
void handleLowBattery(int percent);
void handleCriticalBattery(int percent);
/**
......@@ -122,6 +123,7 @@ private:
QHash<QString, int> m_peripheralBatteriesPercent;
QHash<QString, bool> m_batteriesCharged;
QPointer<KNotification> m_lowBatteryNotification;
QTimer *m_criticalBatteryTimer;
QPointer<KNotification> m_criticalBatteryNotification;
......
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