Changeset View
Changeset View
Standalone View
Standalone View
daemon/powerdevilcore.cpp
Show First 20 Lines • Show All 222 Lines • ▼ Show 20 Line(s) | |||||
223 | 223 | | |||
224 | void Core::reparseConfiguration() | 224 | void Core::reparseConfiguration() | ||
225 | { | 225 | { | ||
226 | PowerDevilSettings::self()->load(); | 226 | PowerDevilSettings::self()->load(); | ||
227 | m_profilesConfig->reparseConfiguration(); | 227 | m_profilesConfig->reparseConfiguration(); | ||
228 | 228 | | |||
229 | // Config reloaded | 229 | // Config reloaded | ||
230 | Q_EMIT configurationReloaded(); | 230 | Q_EMIT configurationReloaded(); | ||
231 | | ||||
232 | // Check if critical threshold might have changed and cancel the timer if necessary. | ||||
233 | if (m_criticalBatteryTimer->isActive() && currentChargePercent() > PowerDevilSettings::batteryCriticalLevel()) { | ||||
234 | m_criticalBatteryTimer->stop(); | ||||
235 | if (m_criticalBatteryNotification) { | ||||
236 | m_criticalBatteryNotification->close(); | ||||
237 | } | ||||
238 | } | ||||
239 | | ||||
240 | if (m_lowBatteryNotification && currentChargePercent() > PowerDevilSettings::batteryLowLevel()) { | ||||
241 | m_lowBatteryNotification->close(); | ||||
242 | } | ||||
231 | } | 243 | } | ||
232 | 244 | | |||
233 | QString Core::currentProfile() const | 245 | QString Core::currentProfile() const | ||
234 | { | 246 | { | ||
235 | return m_currentProfile; | 247 | return m_currentProfile; | ||
236 | } | 248 | } | ||
237 | 249 | | |||
238 | void Core::loadProfile(bool force) | 250 | void Core::loadProfile(bool force) | ||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Line(s) | 449 | } else { // non-power supply batteries are treated separately | |||
442 | // also we'll notify about all devices when notifications are ready anyway | 454 | // also we'll notify about all devices when notifications are ready anyway | ||
443 | if (m_notificationsReady) { | 455 | if (m_notificationsReady) { | ||
444 | emitBatteryChargePercentNotification(b->chargePercent(), 1000 /* so current is always lower than previous */, udi); | 456 | emitBatteryChargePercentNotification(b->chargePercent(), 1000 /* so current is always lower than previous */, udi); | ||
445 | } | 457 | } | ||
446 | } | 458 | } | ||
447 | 459 | | |||
448 | // If a new battery has been added, let's clear some pending suspend actions if the new global batteries percentage is | 460 | // If a new battery has been added, let's clear some pending suspend actions if the new global batteries percentage is | ||
449 | // higher than the battery critical level. (See bug 329537) | 461 | // higher than the battery critical level. (See bug 329537) | ||
462 | if (m_lowBatteryNotification && currentChargePercent() > PowerDevilSettings::batteryLowLevel()) { | ||||
463 | m_lowBatteryNotification->close(); | ||||
464 | } | ||||
465 | | ||||
450 | if (m_criticalBatteryTimer->isActive() && currentChargePercent() > PowerDevilSettings::batteryCriticalLevel()) { | 466 | if (m_criticalBatteryTimer->isActive() && currentChargePercent() > PowerDevilSettings::batteryCriticalLevel()) { | ||
451 | m_criticalBatteryTimer->stop(); | 467 | m_criticalBatteryTimer->stop(); | ||
452 | if (m_criticalBatteryNotification) { | 468 | if (m_criticalBatteryNotification) { | ||
453 | m_criticalBatteryNotification->close(); | 469 | m_criticalBatteryNotification->close(); | ||
454 | } | 470 | } | ||
455 | emitRichNotification(QStringLiteral("pluggedin"), | 471 | emitRichNotification(QStringLiteral("pluggedin"), | ||
456 | i18n("Extra Battery Added"), | 472 | i18n("Extra Battery Added"), | ||
457 | i18n("The computer will no longer go to sleep.")); | 473 | i18n("The computer will no longer go to sleep.")); | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 510 | { | |||
564 | } | 580 | } | ||
565 | 581 | | |||
566 | if (currentPercent <= PowerDevilSettings::batteryCriticalLevel() && | 582 | if (currentPercent <= PowerDevilSettings::batteryCriticalLevel() && | ||
567 | previousPercent > PowerDevilSettings::batteryCriticalLevel()) { | 583 | previousPercent > PowerDevilSettings::batteryCriticalLevel()) { | ||
568 | handleCriticalBattery(currentPercent); | 584 | handleCriticalBattery(currentPercent); | ||
569 | return true; | 585 | return true; | ||
570 | } else if (currentPercent <= PowerDevilSettings::batteryLowLevel() && | 586 | } else if (currentPercent <= PowerDevilSettings::batteryLowLevel() && | ||
571 | previousPercent > PowerDevilSettings::batteryLowLevel()) { | 587 | previousPercent > PowerDevilSettings::batteryLowLevel()) { | ||
572 | emitRichNotification(QStringLiteral("lowbattery"), i18n("Battery Low (%1% Remaining)", currentPercent), | 588 | handleLowBattery(currentPercent); | ||
573 | i18n("Battery running low - to continue using your computer, plug it in or shut it down and change the battery.")); | | |||
574 | return true; | 589 | return true; | ||
575 | } | 590 | } | ||
576 | return false; | 591 | return false; | ||
577 | } | 592 | } | ||
578 | 593 | | |||
594 | void Core::handleLowBattery(int percent) | ||||
595 | { | ||||
596 | m_lowBatteryNotification = new KNotification(QStringLiteral("lowbattery"), KNotification::Persistent, nullptr); | ||||
597 | m_lowBatteryNotification->setComponentName(QStringLiteral("powerdevil")); | ||||
598 | m_lowBatteryNotification->setTitle(i18n("Battery Low (%1% Remaining)", percent)); | ||||
599 | m_lowBatteryNotification->setText(i18n("Battery running low - to continue using your computer, plug it in or shut it down and change the battery.")); | ||||
600 | m_lowBatteryNotification->setUrgency(KNotification::CriticalUrgency); | ||||
601 | m_lowBatteryNotification->sendEvent(); | ||||
602 | } | ||||
603 | | ||||
579 | void Core::handleCriticalBattery(int percent) | 604 | void Core::handleCriticalBattery(int percent) | ||
580 | { | 605 | { | ||
581 | // no parent, but it won't leak, since it will be closed both in case of timeout or direct action | 606 | // no parent, but it won't leak, since it will be closed both in case of timeout or direct action | ||
582 | m_criticalBatteryNotification = new KNotification(QStringLiteral("criticalbattery"), KNotification::Persistent, nullptr); | 607 | m_criticalBatteryNotification = new KNotification(QStringLiteral("criticalbattery"), KNotification::Persistent, nullptr); | ||
583 | m_criticalBatteryNotification->setComponentName(QStringLiteral("powerdevil")); | 608 | m_criticalBatteryNotification->setComponentName(QStringLiteral("powerdevil")); | ||
584 | m_criticalBatteryNotification->setTitle(i18n("Battery Critical (%1% Remaining)", percent)); | 609 | m_criticalBatteryNotification->setTitle(i18n("Battery Critical (%1% Remaining)", percent)); | ||
585 | 610 | | |||
586 | const QStringList actions = {i18nc("Cancel timeout that will automatically put system to sleep because of low battery", "Cancel")}; | 611 | const QStringList actions = {i18nc("Cancel timeout that will automatically put system to sleep because of low battery", "Cancel")}; | ||
Show All 32 Lines | |||||
619 | { | 644 | { | ||
620 | qCDebug(POWERDEVIL); | 645 | qCDebug(POWERDEVIL); | ||
621 | // Post request for faking an activity event - usually adapters don't plug themselves out :) | 646 | // Post request for faking an activity event - usually adapters don't plug themselves out :) | ||
622 | m_pendingWakeupEvent = true; | 647 | m_pendingWakeupEvent = true; | ||
623 | loadProfile(); | 648 | loadProfile(); | ||
624 | 649 | | |||
625 | if (state == BackendInterface::Plugged) { | 650 | if (state == BackendInterface::Plugged) { | ||
626 | // If the AC Adaptor has been plugged in, let's clear some pending suspend actions | 651 | // If the AC Adaptor has been plugged in, let's clear some pending suspend actions | ||
652 | if (m_lowBatteryNotification) { | ||||
653 | m_lowBatteryNotification->close(); | ||||
654 | } | ||||
655 | | ||||
627 | if (m_criticalBatteryTimer->isActive()) { | 656 | if (m_criticalBatteryTimer->isActive()) { | ||
628 | m_criticalBatteryTimer->stop(); | 657 | m_criticalBatteryTimer->stop(); | ||
629 | if (m_criticalBatteryNotification) { | 658 | if (m_criticalBatteryNotification) { | ||
630 | m_criticalBatteryNotification->close(); | 659 | m_criticalBatteryNotification->close(); | ||
631 | } | 660 | } | ||
632 | emitRichNotification(QStringLiteral("pluggedin"), | 661 | emitRichNotification(QStringLiteral("pluggedin"), | ||
633 | i18n("AC Adapter Plugged In"), | 662 | i18n("AC Adapter Plugged In"), | ||
634 | i18n("The computer will no longer go to sleep.")); | 663 | i18n("The computer will no longer go to sleep.")); | ||
▲ Show 20 Lines • Show All 267 Lines • Show Last 20 Lines |