Changeset View
Standalone View
daemon/powerdevilcore.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | 81 | { | |||
---|---|---|---|---|---|
83 | // Unload all actions before exiting, and clear the cache | 83 | // Unload all actions before exiting, and clear the cache | ||
84 | ActionPool::instance()->unloadAllActiveActions(); | 84 | ActionPool::instance()->unloadAllActiveActions(); | ||
85 | ActionPool::instance()->clearCache(); | 85 | ActionPool::instance()->clearCache(); | ||
86 | } | 86 | } | ||
87 | 87 | | |||
88 | void Core::loadCore(BackendInterface* backend) | 88 | void Core::loadCore(BackendInterface* backend) | ||
89 | { | 89 | { | ||
90 | if (!backend) { | 90 | if (!backend) { | ||
91 | onBackendError(i18n("No valid Power Management backend plugins are available. " | 91 | onBackendError(i18n("No valid Power Management backend plugins available. " | ||
92 | "A new installation might solve this problem.")); | 92 | "A new installation might solve this problem.")); | ||
93 | return; | 93 | return; | ||
94 | } | 94 | } | ||
95 | 95 | | |||
96 | m_backend = backend; | 96 | m_backend = backend; | ||
97 | 97 | | |||
98 | // Async backend init - so that KDED gets a bit of a speed up | 98 | // Async backend init - so that KDED gets a bit of a speed up | ||
99 | qCDebug(POWERDEVIL) << "Core loaded, initializing backend"; | 99 | qCDebug(POWERDEVIL) << "Core loaded, initializing backend"; | ||
100 | connect(m_backend, SIGNAL(backendReady()), this, SLOT(onBackendReady())); | 100 | connect(m_backend, SIGNAL(backendReady()), this, SLOT(onBackendReady())); | ||
101 | connect(m_backend, SIGNAL(backendError(QString)), this, SLOT(onBackendError(QString))); | 101 | connect(m_backend, SIGNAL(backendError(QString)), this, SLOT(onBackendError(QString))); | ||
102 | m_backend->init(); | 102 | m_backend->init(); | ||
103 | } | 103 | } | ||
104 | 104 | | |||
105 | void Core::onBackendReady() | 105 | void Core::onBackendReady() | ||
106 | { | 106 | { | ||
107 | qCDebug(POWERDEVIL) << "Backend is ready, KDE Power Management system initialized"; | 107 | qCDebug(POWERDEVIL) << "Backend ready, KDE Power Management system initialized"; | ||
108 | 108 | | |||
109 | m_profilesConfig = KSharedConfig::openConfig(QStringLiteral("powermanagementprofilesrc"), KConfig::CascadeConfig); | 109 | m_profilesConfig = KSharedConfig::openConfig(QStringLiteral("powermanagementprofilesrc"), KConfig::CascadeConfig); | ||
110 | 110 | | |||
111 | QStringList groups = m_profilesConfig->groupList(); | 111 | QStringList groups = m_profilesConfig->groupList(); | ||
112 | // the "migration" key is for shortcuts migration in added by migratePre512KeyboardShortcuts | 112 | // the "migration" key is for shortcuts migration in added by migratePre512KeyboardShortcuts | ||
113 | // and as such our configuration would never be considered empty, ignore it! | 113 | // and as such our configuration would never be considered empty, ignore it! | ||
114 | groups.removeOne(QStringLiteral("migration")); | 114 | groups.removeOne(QStringLiteral("migration")); | ||
115 | 115 | | |||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 247 | if (PolicyAgent::instance()->requirePolicyCheck(PolicyAgent::ChangeProfile) != PolicyAgent::None) { | |||
248 | qCDebug(POWERDEVIL) << "Policy Agent prevention: on"; | 248 | qCDebug(POWERDEVIL) << "Policy Agent prevention: on"; | ||
249 | return; | 249 | return; | ||
250 | } | 250 | } | ||
251 | 251 | | |||
252 | KConfigGroup config; | 252 | KConfigGroup config; | ||
253 | 253 | | |||
254 | // Check the activity in which we are in | 254 | // Check the activity in which we are in | ||
255 | QString activity = m_activityConsumer->currentActivity(); | 255 | QString activity = m_activityConsumer->currentActivity(); | ||
256 | qCDebug(POWERDEVIL) << "We are now into activity " << activity; | 256 | qCDebug(POWERDEVIL) << "We are now in activity " << activity; // into? direction? | ||
ngraham: I'd say "using activity <whatever>" | |||||
257 | KConfigGroup activitiesConfig(m_profilesConfig, "Activities"); | 257 | KConfigGroup activitiesConfig(m_profilesConfig, "Activities"); | ||
258 | qCDebug(POWERDEVIL) << activitiesConfig.groupList() << activitiesConfig.keyList(); | 258 | qCDebug(POWERDEVIL) << activitiesConfig.groupList() << activitiesConfig.keyList(); | ||
259 | 259 | | |||
260 | // Are we mirroring an activity? | 260 | // Are we mirroring an activity? | ||
261 | if (activitiesConfig.group(activity).readEntry("mode", "None") == QStringLiteral("ActLike") && | 261 | if (activitiesConfig.group(activity).readEntry("mode", "None") == QStringLiteral("ActLike") && | ||
262 | activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("AC") && | 262 | activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("AC") && | ||
263 | activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("Battery") && | 263 | activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("Battery") && | ||
264 | activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("LowBattery")) { | 264 | activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("LowBattery")) { | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 314 | { | |||
321 | i = m_screenActivityInhibit.begin(); | 321 | i = m_screenActivityInhibit.begin(); | ||
322 | while (i != m_screenActivityInhibit.end()) { | 322 | while (i != m_screenActivityInhibit.end()) { | ||
323 | PolicyAgent::instance()->ReleaseInhibition(i.value()); | 323 | PolicyAgent::instance()->ReleaseInhibition(i.value()); | ||
324 | i = m_screenActivityInhibit.erase(i); | 324 | i = m_screenActivityInhibit.erase(i); | ||
325 | } | 325 | } | ||
326 | } | 326 | } | ||
327 | 327 | | |||
328 | if (!config.isValid()) { | 328 | if (!config.isValid()) { | ||
329 | emitNotification(QStringLiteral("powerdevilerror"), i18n("The profile \"%1\" has been selected, " | 329 | emitNotification(QStringLiteral("powerdevilerror"), i18n("Profile \"%1\" has been selected " | ||
330 | "but it does not exist.\nPlease check your PowerDevil configuration.", | 330 | "but does not exist.\nPlease check your PowerDevil configuration.", | ||
ngraham: Remove "the profile" | |||||
rooty: Hmm sure | |||||
Actually you're right, without "the profile" and "it" it sounds fancier haha rooty: Actually you're right, without "the profile" and "it" it sounds fancier haha | |||||
331 | profileId)); | 331 | profileId)); | ||
332 | return; | 332 | return; | ||
333 | } | 333 | } | ||
334 | 334 | | |||
335 | // Check: do we need to change profile at all? | 335 | // Check: do we need to change profile at all? | ||
336 | if (m_currentProfile == profileId && !force) { | 336 | if (m_currentProfile == profileId && !force) { | ||
337 | // No, let's leave things as they are | 337 | // No, let's leave things as they are | ||
338 | qCDebug(POWERDEVIL) << "Skipping action reload routine as profile has not changed"; | 338 | qCDebug(POWERDEVIL) << "Skipping action reload routine as profile has not changed"; | ||
Show All 20 Lines | 358 | Q_FOREACH (const QString &actionName, config.groupList()) { | |||
359 | Action *action = ActionPool::instance()->loadAction(actionName, config.group(actionName), this); | 359 | Action *action = ActionPool::instance()->loadAction(actionName, config.group(actionName), this); | ||
360 | if (action) { | 360 | if (action) { | ||
361 | action->onProfileLoad(); | 361 | action->onProfileLoad(); | ||
362 | } else { | 362 | } else { | ||
363 | // Ouch, error. But let's just warn and move on anyway | 363 | // Ouch, error. But let's just warn and move on anyway | ||
364 | //TODO Maybe Remove from the configuration if unsupported | 364 | //TODO Maybe Remove from the configuration if unsupported | ||
365 | qCWarning(POWERDEVIL) << "The profile " << profileId << "tried to activate" | 365 | qCWarning(POWERDEVIL) << "The profile " << profileId << "tried to activate" | ||
366 | << actionName << "a non-existent action. This is usually due to an installation problem," | 366 | << actionName << "a non-existent action. This is usually due to an installation problem," | ||
367 | " or to a configuration problem, or simply the action is not supported"; | 367 | " a configuration problem, or the action not being supported"; | ||
ngraham: "or the action is not supported" -> "or the action not being supported" | |||||
"or because the action is not supported", "This is due to the action not being supported" sounds too elaborate for my taste and I'd rather have a disconnected clause here rooty: "or because the action is not supported", "This is due to the action not being supported"… | |||||
That was actually going to be my first suggestion. :) Go ahead and do that if you think it sounds better. ngraham: That was actually going to be my first suggestion. :) Go ahead and do that if you think it… | |||||
368 | } | 368 | } | ||
369 | } | 369 | } | ||
370 | 370 | | |||
371 | // We are now on a different profile | 371 | // We are now on a different profile | ||
372 | m_currentProfile = profileId; | 372 | m_currentProfile = profileId; | ||
373 | Q_EMIT profileChanged(m_currentProfile); | 373 | Q_EMIT profileChanged(m_currentProfile); | ||
374 | } | 374 | } | ||
375 | 375 | | |||
376 | // Now... any special behaviors we'd like to consider? | 376 | // Now... any special behaviors we'd like to consider? | ||
377 | if (activityConfig.readEntry("mode", "None") == QStringLiteral("SpecialBehavior")) { | 377 | if (activityConfig.readEntry("mode", "None") == QStringLiteral("SpecialBehavior")) { | ||
378 | qCDebug(POWERDEVIL) << "Activity has special behaviors"; | 378 | qCDebug(POWERDEVIL) << "Activity has special behaviors"; | ||
379 | KConfigGroup behaviorGroup = activityConfig.group("SpecialBehavior"); | 379 | KConfigGroup behaviorGroup = activityConfig.group("SpecialBehavior"); | ||
380 | if (behaviorGroup.readEntry("performAction", false)) { | 380 | if (behaviorGroup.readEntry("performAction", false)) { | ||
381 | // Let's override the configuration for this action at all times | 381 | // Let's override the configuration for this action at all times | ||
382 | ActionPool::instance()->loadAction(QStringLiteral("SuspendSession"), behaviorGroup.group("ActionConfig"), this); | 382 | ActionPool::instance()->loadAction(QStringLiteral("SuspendSession"), behaviorGroup.group("ActionConfig"), this); | ||
383 | qCDebug(POWERDEVIL) << "Activity overrides suspend session action"; | 383 | qCDebug(POWERDEVIL) << "Activity overrides suspend session action"; // debug hence not sleep | ||
384 | } | 384 | } | ||
385 | 385 | | |||
386 | if (behaviorGroup.readEntry("noSuspend", false)) { | 386 | if (behaviorGroup.readEntry("noSuspend", false)) { | ||
387 | qCDebug(POWERDEVIL) << "Activity triggers a suspend inhibition"; | 387 | qCDebug(POWERDEVIL) << "Activity triggers a suspend inhibition"; // debug hence not sleep | ||
388 | // Trigger a special inhibition - if we don't have one yet | 388 | // Trigger a special inhibition - if we don't have one yet | ||
389 | if (!m_sessionActivityInhibit.contains(activity)) { | 389 | if (!m_sessionActivityInhibit.contains(activity)) { | ||
390 | int cookie = | 390 | int cookie = | ||
391 | PolicyAgent::instance()->AddInhibition(PolicyAgent::InterruptSession, i18n("Activity Manager"), | 391 | PolicyAgent::instance()->AddInhibition(PolicyAgent::InterruptSession, i18n("Activity Manager"), | ||
392 | i18n("This activity's policies prevent the system from suspending")); | 392 | i18n("This activity's policies prevent the system from going to sleep")); | ||
393 | 393 | | |||
394 | m_sessionActivityInhibit.insert(activity, cookie); | 394 | m_sessionActivityInhibit.insert(activity, cookie); | ||
395 | } | 395 | } | ||
396 | } | 396 | } | ||
397 | 397 | | |||
398 | if (behaviorGroup.readEntry("noScreenManagement", false)) { | 398 | if (behaviorGroup.readEntry("noScreenManagement", false)) { | ||
399 | qCDebug(POWERDEVIL) << "Activity triggers a screen management inhibition"; | 399 | qCDebug(POWERDEVIL) << "Activity triggers a screen management inhibition"; | ||
400 | // Trigger a special inhibition - if we don't have one yet | 400 | // Trigger a special inhibition - if we don't have one yet | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 420 | { | |||
457 | // higher than the battery critical level. (See bug 329537) | 457 | // higher than the battery critical level. (See bug 329537) | ||
458 | if (m_criticalBatteryTimer->isActive() && currentChargePercent() > PowerDevilSettings::batteryCriticalLevel()) { | 458 | if (m_criticalBatteryTimer->isActive() && currentChargePercent() > PowerDevilSettings::batteryCriticalLevel()) { | ||
459 | m_criticalBatteryTimer->stop(); | 459 | m_criticalBatteryTimer->stop(); | ||
460 | if (m_criticalBatteryNotification) { | 460 | if (m_criticalBatteryNotification) { | ||
461 | m_criticalBatteryNotification->close(); | 461 | m_criticalBatteryNotification->close(); | ||
462 | } | 462 | } | ||
463 | emitRichNotification(QStringLiteral("pluggedin"), | 463 | emitRichNotification(QStringLiteral("pluggedin"), | ||
464 | i18n("Extra Battery Added"), | 464 | i18n("Extra Battery Added"), | ||
465 | i18n("All pending suspend actions have been canceled.")); // FIXME This wording is too technical | 465 | i18n("The computer will no longer go to sleep.")); | ||
466 | } | 466 | } | ||
467 | } | 467 | } | ||
468 | 468 | | |||
469 | void Core::onDeviceRemoved(const QString &udi) | 469 | void Core::onDeviceRemoved(const QString &udi) | ||
470 | { | 470 | { | ||
471 | if (!m_batteriesPercent.contains(udi) && !m_peripheralBatteriesPercent.contains(udi)) { | 471 | if (!m_batteriesPercent.contains(udi) && !m_peripheralBatteriesPercent.contains(udi)) { | ||
472 | // We don't know about this device | 472 | // We don't know about this device | ||
473 | return; | 473 | return; | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 525 | if (currentPercent <= PowerDevilSettings::peripheralBatteryLowLevel() && | |||
533 | QString title; | 533 | QString title; | ||
534 | QString msg; | 534 | QString msg; | ||
535 | QString icon; | 535 | QString icon; | ||
536 | 536 | | |||
537 | switch(b->type()) { | 537 | switch(b->type()) { | ||
538 | case Battery::MouseBattery: | 538 | case Battery::MouseBattery: | ||
539 | title = i18n("Mouse Battery Low (%1% Remaining)", currentPercent); | 539 | title = i18n("Mouse Battery Low (%1% Remaining)", currentPercent); | ||
540 | msg = i18nc("Placeholder is device name", | 540 | msg = i18nc("Placeholder is device name", | ||
541 | "The battery in your mouse (\"%1\") is low, and the device may turn itself off at any time. " | 541 | "The battery in (\"%1\") is running low, and the device may turn off at any time. " | ||
542 | "Please replace or charge the battery as soon as possible.", name); | 542 | "Please recharge or replace the battery.", name); | ||
Are we 100% sure that name will always be a good enough string that the user will recognize it as their mouse? (not a rhetorical question, I really am wondering :) ) Same for other instances below too. ngraham: Are we 100% sure that `name` will always be a good enough string that the user will recognize… | |||||
I thought about that, then realized that the heading says "Mouse" (Mouse Battery Low) "Keyboard" etc. so it seems redundant too (to repeat it in the body text) rooty: I thought about that, then realized that the heading says "Mouse" (Mouse Battery Low)… | |||||
ngraham: Ah, you're right! | |||||
Since you removed the separation between the three cases you might as well unify the codebase into one. Now you have three separate identical strings. Also, "The battery in (some device) is running low" with the parenthesis is a bit awkward since now it's the sentence's subject. broulik: Since you removed the separation between the three cases you might as well unify the codebase… | |||||
543 | icon = QStringLiteral("input-mouse"); | 543 | icon = QStringLiteral("input-mouse"); | ||
544 | break; | 544 | break; | ||
545 | case Battery::KeyboardBattery: | 545 | case Battery::KeyboardBattery: | ||
546 | title = i18n("Keyboard Battery Low (%1% Remaining)", currentPercent); | 546 | title = i18n("Keyboard Battery Low (%1% Remaining)", currentPercent); | ||
547 | msg = i18nc("Placeholder is device name", | 547 | msg = i18nc("Placeholder is device name", | ||
548 | "The battery in your keyboard (\"%1\") is low, and the device may turn itself off at any time. " | 548 | "The battery in (\"%1\") is running low, and the device may turn off at any time. " | ||
549 | "Please replace or charge the battery as soon as possible.", name); | 549 | "Please recharge or replace the battery.", name); | ||
550 | icon = QStringLiteral("input-keyboard"); | 550 | icon = QStringLiteral("input-keyboard"); | ||
551 | break; | 551 | break; | ||
552 | default: | 552 | default: | ||
553 | title = i18nc("The battery in an external device", "Device Battery Low (%1% Remaining)", currentPercent); | 553 | title = i18nc("The battery in an external device", "Device Battery Low (%1% Remaining)", currentPercent); | ||
554 | msg = i18nc("Placeholder is device name", | 554 | msg = i18nc("Placeholder is device name", | ||
555 | "The battery in a connected device (\"%1\") is low, and the device may turn itself off at any time. " | 555 | "The battery in (\"%1\") is running low, and the device may turn off at any time. " | ||
556 | "Please replace or charge the battery as soon as possible.", name); | 556 | "Please recharge or replace the battery.", name); | ||
557 | icon = QStringLiteral("battery-caution"); | 557 | icon = QStringLiteral("battery-caution"); | ||
558 | break; | 558 | break; | ||
559 | } | 559 | } | ||
560 | 560 | | |||
561 | emitNotification(QStringLiteral("lowperipheralbattery"), title, msg, icon); | 561 | emitNotification(QStringLiteral("lowperipheralbattery"), title, msg, icon); | ||
562 | 562 | | |||
563 | return true; | 563 | return true; | ||
564 | } | 564 | } | ||
565 | 565 | | |||
566 | return false; | 566 | return false; | ||
567 | } | 567 | } | ||
568 | 568 | | |||
569 | if (m_backend->acAdapterState() == BackendInterface::Plugged) { | 569 | if (m_backend->acAdapterState() == BackendInterface::Plugged) { | ||
570 | return false; | 570 | return false; | ||
571 | } | 571 | } | ||
572 | 572 | | |||
573 | if (currentPercent <= PowerDevilSettings::batteryCriticalLevel() && | 573 | if (currentPercent <= PowerDevilSettings::batteryCriticalLevel() && | ||
574 | previousPercent > PowerDevilSettings::batteryCriticalLevel()) { | 574 | previousPercent > PowerDevilSettings::batteryCriticalLevel()) { | ||
575 | handleCriticalBattery(currentPercent); | 575 | handleCriticalBattery(currentPercent); | ||
576 | return true; | 576 | return true; | ||
577 | } else if (currentPercent <= PowerDevilSettings::batteryLowLevel() && | 577 | } else if (currentPercent <= PowerDevilSettings::batteryLowLevel() && | ||
578 | previousPercent > PowerDevilSettings::batteryLowLevel()) { | 578 | previousPercent > PowerDevilSettings::batteryLowLevel()) { | ||
579 | emitRichNotification(QStringLiteral("lowbattery"), i18n("Battery Low (%1% Remaining)", currentPercent), | 579 | emitRichNotification(QStringLiteral("lowbattery"), i18n("Battery Low (%1% Remaining)", currentPercent), | ||
580 | i18n("Your battery is low. If you need to continue using your computer, either plug in your computer, or shut it down and then change the battery.")); | 580 | i18n("Battery running low - to continue using your computer, plug it in or shut it down and change the battery.")); | ||
not a fan of that hyphen. It is in the heading, so just change the main text to "To continue using your computer..." broulik: not a fan of that hyphen. It is in the heading, so just change the main text to "To continue… | |||||
581 | return true; | 581 | return true; | ||
582 | } | 582 | } | ||
583 | return false; | 583 | return false; | ||
584 | } | 584 | } | ||
585 | 585 | | |||
586 | void Core::handleCriticalBattery(int percent) | 586 | void Core::handleCriticalBattery(int percent) | ||
587 | { | 587 | { | ||
588 | // no parent, but it won't leak, since it will be closed both in case of timeout or direct action | 588 | // no parent, but it won't leak, since it will be closed both in case of timeout or direct action | ||
589 | m_criticalBatteryNotification = new KNotification(QStringLiteral("criticalbattery"), KNotification::Persistent, nullptr); | 589 | m_criticalBatteryNotification = new KNotification(QStringLiteral("criticalbattery"), KNotification::Persistent, nullptr); | ||
590 | m_criticalBatteryNotification->setComponentName(QStringLiteral("powerdevil")); | 590 | m_criticalBatteryNotification->setComponentName(QStringLiteral("powerdevil")); | ||
591 | m_criticalBatteryNotification->setTitle(i18n("Battery Critical (%1% Remaining)", percent)); | 591 | m_criticalBatteryNotification->setTitle(i18n("Battery Critical (%1% Remaining)", percent)); | ||
592 | 592 | | |||
593 | const QStringList actions = {i18nc("Cancel timeout that will automatically suspend system because of low battery", "Cancel")}; | 593 | const QStringList actions = {i18nc("Cancel timeout that will automatically put system to sleep because of low battery", "Cancel")}; | ||
594 | 594 | | |||
595 | connect(m_criticalBatteryNotification.data(), &KNotification::action1Activated, this, [this] { | 595 | connect(m_criticalBatteryNotification.data(), &KNotification::action1Activated, this, [this] { | ||
596 | m_criticalBatteryTimer->stop(); | 596 | m_criticalBatteryTimer->stop(); | ||
597 | m_criticalBatteryNotification->close(); | 597 | m_criticalBatteryNotification->close(); | ||
598 | }); | 598 | }); | ||
599 | 599 | | |||
600 | switch (PowerDevilSettings::batteryCriticalAction()) { | 600 | switch (PowerDevilSettings::batteryCriticalAction()) { | ||
601 | case PowerDevil::BundledActions::SuspendSession::ShutdownMode: | 601 | case PowerDevil::BundledActions::SuspendSession::ShutdownMode: | ||
602 | m_criticalBatteryNotification->setText(i18n("Your battery level is critical, the computer will be halted in 60 seconds.")); | 602 | m_criticalBatteryNotification->setText(i18n("Battery level critical. Your computer will shut down in 60 seconds.")); | ||
603 | m_criticalBatteryNotification->setActions(actions); | 603 | m_criticalBatteryNotification->setActions(actions); | ||
604 | m_criticalBatteryTimer->start(); | 604 | m_criticalBatteryTimer->start(); | ||
605 | break; | 605 | break; | ||
606 | case PowerDevil::BundledActions::SuspendSession::ToDiskMode: | 606 | case PowerDevil::BundledActions::SuspendSession::ToDiskMode: | ||
607 | m_criticalBatteryNotification->setText(i18n("Your battery level is critical, the computer will be hibernated in 60 seconds.")); | 607 | m_criticalBatteryNotification->setText(i18n("Battery level critical. Your computer will enter hibernation mode in 60 seconds.")); | ||
ngraham: "go into" -> "enter" ? | |||||
rooty: Better, yes. We could use just "enter hibernation" without mode too | |||||
608 | m_criticalBatteryNotification->setActions(actions); | 608 | m_criticalBatteryNotification->setActions(actions); | ||
609 | m_criticalBatteryTimer->start(); | 609 | m_criticalBatteryTimer->start(); | ||
610 | break; | 610 | break; | ||
611 | case PowerDevil::BundledActions::SuspendSession::ToRamMode: | 611 | case PowerDevil::BundledActions::SuspendSession::ToRamMode: | ||
612 | m_criticalBatteryNotification->setText(i18n("Your battery level is critical, the computer will be suspended in 60 seconds.")); | 612 | m_criticalBatteryNotification->setText(i18n("Battery level critical. Your computer will go to sleep in 60 seconds.")); // go into sleep mode? | ||
ngraham: "go to sleep" is just fine here | |||||
rooty: Not very fancy tho 🤣 | |||||
613 | m_criticalBatteryNotification->setActions(actions); | 613 | m_criticalBatteryNotification->setActions(actions); | ||
614 | m_criticalBatteryTimer->start(); | 614 | m_criticalBatteryTimer->start(); | ||
615 | break; | 615 | break; | ||
616 | default: | 616 | default: | ||
617 | m_criticalBatteryNotification->setText(i18n("Your battery level is critical, save your work as soon as possible.")); | 617 | m_criticalBatteryNotification->setText(i18n("Battery level critical. Please save your work.")); | ||
618 | // no timer, no actions | 618 | // no timer, no actions | ||
619 | break; | 619 | break; | ||
620 | } | 620 | } | ||
621 | 621 | | |||
622 | m_criticalBatteryNotification->sendEvent(); | 622 | m_criticalBatteryNotification->sendEvent(); | ||
623 | } | 623 | } | ||
624 | 624 | | |||
625 | void Core::onAcAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState state) | 625 | void Core::onAcAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState state) | ||
626 | { | 626 | { | ||
627 | qCDebug(POWERDEVIL); | 627 | qCDebug(POWERDEVIL); | ||
628 | // Post request for faking an activity event - usually adapters don't plug themselves out :) | 628 | // Post request for faking an activity event - usually adapters don't plug themselves out :) | ||
629 | m_pendingWakeupEvent = true; | 629 | m_pendingWakeupEvent = true; | ||
630 | loadProfile(); | 630 | loadProfile(); | ||
631 | 631 | | |||
632 | if (state == BackendInterface::Plugged) { | 632 | if (state == BackendInterface::Plugged) { | ||
633 | // If the AC Adaptor has been plugged in, let's clear some pending suspend actions | 633 | // If the AC Adaptor has been plugged in, let's clear some pending suspend actions | ||
634 | if (m_criticalBatteryTimer->isActive()) { | 634 | if (m_criticalBatteryTimer->isActive()) { | ||
635 | m_criticalBatteryTimer->stop(); | 635 | m_criticalBatteryTimer->stop(); | ||
636 | if (m_criticalBatteryNotification) { | 636 | if (m_criticalBatteryNotification) { | ||
637 | m_criticalBatteryNotification->close(); | 637 | m_criticalBatteryNotification->close(); | ||
638 | } | 638 | } | ||
639 | emitRichNotification(QStringLiteral("pluggedin"), | 639 | emitRichNotification(QStringLiteral("pluggedin"), | ||
640 | i18n("AC Adapter Plugged In"), | 640 | i18n("AC Adapter Plugged In"), | ||
641 | i18n("All pending suspend actions have been canceled.")); | 641 | i18n("The computer will no longer go to sleep.")); | ||
broulik: Sounds like from now on it will never suspend anymore. | |||||
642 | } else { | 642 | } else { | ||
643 | emitRichNotification(QStringLiteral("pluggedin"), i18n("Running on AC power"), i18n("The power adaptor has been plugged in.")); | 643 | emitRichNotification(QStringLiteral("pluggedin"), i18n("Running on AC power"), i18n("The power adapter has been plugged in.")); | ||
ngraham: Not sure this comment is really necessary :) | |||||
rooty: :) | |||||
644 | } | 644 | } | ||
645 | } else if (state == BackendInterface::Unplugged) { | 645 | } else if (state == BackendInterface::Unplugged) { | ||
646 | emitRichNotification(QStringLiteral("unplugged"), i18n("Running on Battery Power"), i18n("The power adaptor has been unplugged.")); | 646 | emitRichNotification(QStringLiteral("unplugged"), i18n("Running on Battery Power"), i18n("The power adapter has been unplugged.")); | ||
647 | } | 647 | } | ||
648 | } | 648 | } | ||
649 | 649 | | |||
650 | void Core::onBackendError(const QString& error) | 650 | void Core::onBackendError(const QString& error) | ||
651 | { | 651 | { | ||
652 | emitNotification(QStringLiteral("powerdevilerror"), i18n("KDE Power Management System could not be initialized. " | 652 | emitNotification(QStringLiteral("powerdevilerror"), i18n("The KDE Power Management System could not be initialized. " | ||
653 | "The backend reported the following error: %1\n" | 653 | "The backend reported the following error: %1\n" | ||
654 | "Please check your system configuration", error)); | 654 | "Please check your system configuration", error)); | ||
655 | } | 655 | } | ||
656 | 656 | | |||
657 | void Core::onBatteryChargePercentChanged(int percent, const QString &udi) | 657 | void Core::onBatteryChargePercentChanged(int percent, const QString &udi) | ||
658 | { | 658 | { | ||
659 | if (m_peripheralBatteriesPercent.contains(udi)) { | 659 | if (m_peripheralBatteriesPercent.contains(udi)) { | ||
660 | const int previousPercent = m_peripheralBatteriesPercent.value(udi); | 660 | const int previousPercent = m_peripheralBatteriesPercent.value(udi); | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 685 | { | |||
705 | for (auto i = m_batteriesCharged.constBegin(); i != m_batteriesCharged.constEnd(); ++i) { | 705 | for (auto i = m_batteriesCharged.constBegin(); i != m_batteriesCharged.constEnd(); ++i) { | ||
706 | if (!i.value()) { | 706 | if (!i.value()) { | ||
707 | currentCharged = false; | 707 | currentCharged = false; | ||
708 | break; | 708 | break; | ||
709 | } | 709 | } | ||
710 | } | 710 | } | ||
711 | 711 | | |||
712 | if (!previousCharged && currentCharged) { | 712 | if (!previousCharged && currentCharged) { | ||
713 | emitRichNotification(QStringLiteral("fullbattery"), i18n("Charge Complete"), i18n("Your battery is now fully charged.")); | 713 | emitRichNotification(QStringLiteral("fullbattery"), i18n("Charging Complete"), i18n("Battery now fully charged.")); | ||
714 | loadProfile(); | 714 | loadProfile(); | ||
715 | } | 715 | } | ||
716 | } | 716 | } | ||
717 | 717 | | |||
718 | void Core::onCriticalBatteryTimerExpired() | 718 | void Core::onCriticalBatteryTimerExpired() | ||
719 | { | 719 | { | ||
720 | if (m_criticalBatteryNotification) { | 720 | if (m_criticalBatteryNotification) { | ||
721 | m_criticalBatteryNotification->close(); | 721 | m_criticalBatteryNotification->close(); | ||
Show All 39 Lines | |||||
761 | void Core::onLidClosedChanged(bool closed) | 761 | void Core::onLidClosedChanged(bool closed) | ||
762 | { | 762 | { | ||
763 | Q_EMIT lidClosedChanged(closed); | 763 | Q_EMIT lidClosedChanged(closed); | ||
764 | } | 764 | } | ||
765 | 765 | | |||
766 | void Core::onAboutToSuspend() | 766 | void Core::onAboutToSuspend() | ||
767 | { | 767 | { | ||
768 | if (PowerDevilSettings::pausePlayersOnSuspend()) { | 768 | if (PowerDevilSettings::pausePlayersOnSuspend()) { | ||
769 | qCDebug(POWERDEVIL) << "Pausing all media players before suspending"; | 769 | qCDebug(POWERDEVIL) << "Pausing all media players before sleep"; | ||
770 | 770 | | |||
771 | QDBusPendingCall listNamesCall = QDBusConnection::sessionBus().interface()->asyncCall(QStringLiteral("ListNames")); | 771 | QDBusPendingCall listNamesCall = QDBusConnection::sessionBus().interface()->asyncCall(QStringLiteral("ListNames")); | ||
772 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(listNamesCall, this); | 772 | QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(listNamesCall, this); | ||
773 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { | 773 | connect(callWatcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { | ||
774 | QDBusPendingReply<QStringList> reply = *watcher; | 774 | QDBusPendingReply<QStringList> reply = *watcher; | ||
775 | watcher->deleteLater(); | 775 | watcher->deleteLater(); | ||
776 | 776 | | |||
777 | if (reply.isError()) { | 777 | if (reply.isError()) { | ||
778 | qCWarning(POWERDEVIL) << "Failed to fetch list of DBus service names for pausing players on suspend" << reply.error().message(); | 778 | qCWarning(POWERDEVIL) << "Failed to fetch list of DBus service names for pausing players on entering sleep" << reply.error().message(); | ||
779 | return; | 779 | return; | ||
780 | } | 780 | } | ||
781 | 781 | | |||
782 | const QStringList &services = reply.value(); | 782 | const QStringList &services = reply.value(); | ||
783 | for (const QString &serviceName : services) { | 783 | for (const QString &serviceName : services) { | ||
784 | if (!serviceName.startsWith(QLatin1String("org.mpris.MediaPlayer2."))) { | 784 | if (!serviceName.startsWith(QLatin1String("org.mpris.MediaPlayer2."))) { | ||
785 | continue; | 785 | continue; | ||
786 | } | 786 | } | ||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |
I'd say "using activity <whatever>"