Changeset View
Changeset View
Standalone 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 available. " | | |||
92 | "A new installation might solve this problem.")); | | |||
93 | return; | 91 | return; | ||
94 | } | 92 | } | ||
95 | 93 | | |||
96 | m_backend = backend; | 94 | m_backend = backend; | ||
97 | 95 | | |||
98 | // Async backend init - so that KDED gets a bit of a speed up | 96 | // Async backend init - so that KDED gets a bit of a speed up | ||
99 | qCDebug(POWERDEVIL) << "Core loaded, initializing backend"; | 97 | qCDebug(POWERDEVIL) << "Core loaded, initializing backend"; | ||
100 | connect(m_backend, SIGNAL(backendReady()), this, SLOT(onBackendReady())); | 98 | connect(m_backend, SIGNAL(backendReady()), this, SLOT(onBackendReady())); | ||
101 | connect(m_backend, SIGNAL(backendError(QString)), this, SLOT(onBackendError(QString))); | | |||
102 | m_backend->init(); | 99 | m_backend->init(); | ||
103 | } | 100 | } | ||
104 | 101 | | |||
105 | void Core::onBackendReady() | 102 | void Core::onBackendReady() | ||
106 | { | 103 | { | ||
107 | qCDebug(POWERDEVIL) << "Backend ready, KDE Power Management system initialized"; | 104 | qCDebug(POWERDEVIL) << "Backend ready, KDE Power Management system initialized"; | ||
108 | 105 | | |||
109 | m_profilesConfig = KSharedConfig::openConfig(QStringLiteral("powermanagementprofilesrc"), KConfig::CascadeConfig); | 106 | m_profilesConfig = KSharedConfig::openConfig(QStringLiteral("powermanagementprofilesrc"), KConfig::CascadeConfig); | ||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Line(s) | 311 | { | |||
321 | i = m_screenActivityInhibit.begin(); | 318 | i = m_screenActivityInhibit.begin(); | ||
322 | while (i != m_screenActivityInhibit.end()) { | 319 | while (i != m_screenActivityInhibit.end()) { | ||
323 | PolicyAgent::instance()->ReleaseInhibition(i.value()); | 320 | PolicyAgent::instance()->ReleaseInhibition(i.value()); | ||
324 | i = m_screenActivityInhibit.erase(i); | 321 | i = m_screenActivityInhibit.erase(i); | ||
325 | } | 322 | } | ||
326 | } | 323 | } | ||
327 | 324 | | |||
328 | if (!config.isValid()) { | 325 | if (!config.isValid()) { | ||
329 | emitNotification(QStringLiteral("powerdevilerror"), i18n("Profile \"%1\" has been selected " | 326 | qCWarning(POWERDEVIL) << "Profile " << profileId << "has been selected but does not exist."; | ||
330 | "but does not exist.\nPlease check your PowerDevil configuration.", | | |||
331 | profileId)); | | |||
332 | return; | 327 | return; | ||
333 | } | 328 | } | ||
334 | 329 | | |||
335 | // Check: do we need to change profile at all? | 330 | // Check: do we need to change profile at all? | ||
336 | if (m_currentProfile == profileId && !force) { | 331 | if (m_currentProfile == profileId && !force) { | ||
337 | // No, let's leave things as they are | 332 | // No, let's leave things as they are | ||
338 | qCDebug(POWERDEVIL) << "Skipping action reload routine as profile has not changed"; | 333 | qCDebug(POWERDEVIL) << "Skipping action reload routine as profile has not changed"; | ||
339 | 334 | | |||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 415 | { | |||
426 | using namespace Solid; | 421 | using namespace Solid; | ||
427 | Device device(udi); | 422 | Device device(udi); | ||
428 | Battery *b = qobject_cast<Battery *>(device.asDeviceInterface(DeviceInterface::Battery)); | 423 | Battery *b = qobject_cast<Battery *>(device.asDeviceInterface(DeviceInterface::Battery)); | ||
429 | 424 | | |||
430 | if (!b) { | 425 | if (!b) { | ||
431 | return; | 426 | return; | ||
432 | } | 427 | } | ||
433 | 428 | | |||
434 | if (!connect(b, &Battery::chargePercentChanged, this, &Core::onBatteryChargePercentChanged) || | | |||
435 | !connect(b, &Battery::chargeStateChanged, this, &Core::onBatteryChargeStateChanged)) { | | |||
436 | emitNotification(QStringLiteral("powerdevilerror"), i18n("Could not connect to battery interface.\n" | | |||
437 | "Please check your system configuration")); | | |||
438 | } | | |||
439 | | ||||
440 | qCDebug(POWERDEVIL) << "Battery with UDI" << udi << "was detected"; | 429 | qCDebug(POWERDEVIL) << "Battery with UDI" << udi << "was detected"; | ||
441 | 430 | | |||
442 | if (b->isPowerSupply()) { | 431 | if (b->isPowerSupply()) { | ||
443 | m_batteriesPercent[udi] = b->chargePercent(); | 432 | m_batteriesPercent[udi] = b->chargePercent(); | ||
444 | m_batteriesCharged[udi] = (b->chargeState() == Solid::Battery::FullyCharged); | 433 | m_batteriesCharged[udi] = (b->chargeState() == Solid::Battery::FullyCharged); | ||
445 | } else { // non-power supply batteries are treated separately | 434 | } else { // non-power supply batteries are treated separately | ||
446 | m_peripheralBatteriesPercent[udi] = b->chargePercent(); | 435 | m_peripheralBatteriesPercent[udi] = b->chargePercent(); | ||
447 | 436 | | |||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Line(s) | 621 | if (state == BackendInterface::Plugged) { | |||
642 | } else { | 631 | } else { | ||
643 | emitRichNotification(QStringLiteral("pluggedin"), i18n("Running on AC power"), i18n("The power adapter has been plugged in.")); | 632 | emitRichNotification(QStringLiteral("pluggedin"), i18n("Running on AC power"), i18n("The power adapter has been plugged in.")); | ||
644 | } | 633 | } | ||
645 | } else if (state == BackendInterface::Unplugged) { | 634 | } else if (state == BackendInterface::Unplugged) { | ||
646 | emitRichNotification(QStringLiteral("unplugged"), i18n("Running on Battery Power"), i18n("The power adapter has been unplugged.")); | 635 | emitRichNotification(QStringLiteral("unplugged"), i18n("Running on Battery Power"), i18n("The power adapter has been unplugged.")); | ||
647 | } | 636 | } | ||
648 | } | 637 | } | ||
649 | 638 | | |||
650 | void Core::onBackendError(const QString& error) | | |||
651 | { | | |||
652 | emitNotification(QStringLiteral("powerdevilerror"), i18n("The KDE Power Management System could not be initialized. " | | |||
653 | "The backend reported the following error: %1\n" | | |||
654 | "Please check your system configuration", error)); | | |||
655 | } | | |||
656 | | ||||
657 | void Core::onBatteryChargePercentChanged(int percent, const QString &udi) | 639 | void Core::onBatteryChargePercentChanged(int percent, const QString &udi) | ||
658 | { | 640 | { | ||
659 | if (m_peripheralBatteriesPercent.contains(udi)) { | 641 | if (m_peripheralBatteriesPercent.contains(udi)) { | ||
660 | const int previousPercent = m_peripheralBatteriesPercent.value(udi); | 642 | const int previousPercent = m_peripheralBatteriesPercent.value(udi); | ||
661 | m_peripheralBatteriesPercent[udi] = percent; | 643 | m_peripheralBatteriesPercent[udi] = percent; | ||
662 | 644 | | |||
663 | if (percent < previousPercent) { | 645 | if (percent < previousPercent) { | ||
664 | emitBatteryChargePercentNotification(percent, previousPercent, udi); | 646 | emitBatteryChargePercentNotification(percent, previousPercent, udi); | ||
▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines |