diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ I18n CoreAddons # KFormat Notifications - KDELibs4Support #Solid::Power + Solid # Solid::Power ) find_package(packagekitqt5 REQUIRED) diff --git a/src/declarative/CMakeLists.txt b/src/declarative/CMakeLists.txt --- a/src/declarative/CMakeLists.txt +++ b/src/declarative/CMakeLists.txt @@ -16,7 +16,7 @@ KF5::CoreAddons KF5::Notifications KF5::ConfigCore - KF5::KDELibs4Support + KF5::Solid PK::packagekitqt5 ) @@ -37,7 +37,7 @@ KF5::I18n KF5::CoreAddons KF5::ConfigCore - KF5::KDELibs4Support + KF5::Solid KF5::Notifications PK::packagekitqt5 ) diff --git a/src/declarative/pkupdates.h b/src/declarative/pkupdates.h --- a/src/declarative/pkupdates.h +++ b/src/declarative/pkupdates.h @@ -237,6 +237,7 @@ Activity m_activity = Idle; bool m_lastCheckSuccessful = false; bool m_checkUpdatesWhenNetworkOnline = false; + bool m_isOnBattery; }; #endif // PLASMA_PK_UPDATES_H diff --git a/src/declarative/pkupdates.cpp b/src/declarative/pkupdates.cpp --- a/src/declarative/pkupdates.cpp +++ b/src/declarative/pkupdates.cpp @@ -27,7 +27,8 @@ #include #include #include -#include +#include +#include #include #include @@ -42,18 +43,32 @@ } // namespace { PkUpdates::PkUpdates(QObject *parent) : - QObject(parent) + QObject(parent), + m_isOnBattery(true) { setStatusMessage(i18n("Idle")); connect(PackageKit::Daemon::global(), &PackageKit::Daemon::changed, this, &PkUpdates::onChanged); connect(PackageKit::Daemon::global(), &PackageKit::Daemon::updatesChanged, this, &PkUpdates::onUpdatesChanged); connect(PackageKit::Daemon::global(), &PackageKit::Daemon::networkStateChanged, this, &PkUpdates::networkStateChanged); - connect(Solid::PowerManagement::notifier(), &Solid::PowerManagement::Notifier::resumingFromSuspend, this, + connect(Solid::Power::self(), &Solid::Power::resumeFromSuspend, this, [this] {PackageKit::Daemon::stateHasChanged(QStringLiteral("resume"));}); - connect(Solid::PowerManagement::notifier(), &Solid::PowerManagement::Notifier::appShouldConserveResourcesChanged, - this, &PkUpdates::isOnBatteryChanged); + connect(Solid::Power::self(), &Solid::Power::acPluggedChanged, this, [this] (bool acPlugged) { + qCDebug(PLASMA_PK_UPDATES) << "acPluggedChanged onBattery:" << m_isOnBattery << "->" << !acPlugged; + if (!acPlugged != m_isOnBattery) { + m_isOnBattery = !acPlugged; + emit PkUpdates::isOnBatteryChanged(); + } + }); + auto acPluggedJob = Solid::Power::self()->isAcPlugged(this); + connect(acPluggedJob , &Solid::Job::result, this, [this] (Solid::Job* job) { + bool acPlugged = static_cast(job)->isPlugged(); + qCDebug(PLASMA_PK_UPDATES) << "acPlugged initial state" << acPlugged; + m_isOnBattery = !acPlugged; + emit PkUpdates::isOnBatteryChanged(); + }); + acPluggedJob->start(); connect(PackageKit::Daemon::global(), &PackageKit::Daemon::networkStateChanged, this, &PkUpdates::doDelayedCheckUpdates); connect(this, &PkUpdates::isActiveChanged, this, &PkUpdates::messageChanged); @@ -189,8 +204,8 @@ bool PkUpdates::isOnBattery() const { - qCDebug(PLASMA_PK_UPDATES) << "Is on battery:" << Solid::PowerManagement::appShouldConserveResources(); - return Solid::PowerManagement::appShouldConserveResources(); + qCDebug(PLASMA_PK_UPDATES) << "Is on battery:" << m_isOnBattery; + return m_isOnBattery; } void PkUpdates::getUpdateDetails(const QString &pkgID)