diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ include(KDECompilerSettings NO_POLICY_SCOPE) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Widgets DBus X11Extras) -find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Activities Auth IdleTime Config DBusAddons Solid I18n GlobalAccel KIO NotifyConfig Wayland DocTools Crash Notifications) +find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Activities Auth IdleTime Config DBusAddons Solid I18n GlobalAccel KIO NotifyConfig Wayland DocTools Crash Notifications CoreAddons) find_package(KF5Screen CONFIG REQUIRED) find_package(LibKWorkspace CONFIG REQUIRED) diff --git a/daemon/powerdevilcore.h b/daemon/powerdevilcore.h --- a/daemon/powerdevilcore.h +++ b/daemon/powerdevilcore.h @@ -112,6 +112,8 @@ bool m_hasDualGpu; + qulonglong m_batteryRemainingTime; + BackendInterface *m_backend; QDBusServiceWatcher *m_notificationsWatcher; diff --git a/daemon/powerdevilcore.cpp b/daemon/powerdevilcore.cpp --- a/daemon/powerdevilcore.cpp +++ b/daemon/powerdevilcore.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -629,10 +630,28 @@ i18n("AC Adapter Plugged In"), i18n("The computer will no longer go to sleep.")); } else { - emitRichNotification(QStringLiteral("pluggedin"), i18n("Running on AC power"), i18n("The power adapter has been plugged in.")); + QString detail; + if (m_batteryRemainingTime > 0) { + detail = i18n("You need %s to fill the battery", KFormat().formatDuration(m_batteryRemainingTime, KFormat::HideSeconds)); + } else { + int currentPercent = currentChargePercent(); + detail = i18n("Your battery charge level is %s %", currentPercent); + } + + emitRichNotification(QStringLiteral("pluggedin"), i18n("Running on AC power"), detail); } } else if (state == BackendInterface::Unplugged) { - emitRichNotification(QStringLiteral("unplugged"), i18n("Running on Battery Power"), i18n("The power adapter has been unplugged.")); + QString detail; + if (m_batteryRemainingTime > 0) { + detail = i18n("You have %s autonomy left on battery", KFormat().formatDuration(m_batteryRemainingTime, KFormat::HideSeconds)); + } else { + int currentPercent = currentChargePercent(); + detail = i18n("Your battery charge level is %s %", currentPercent); + } + + emitRichNotification(QStringLiteral("unplugged"), + i18n("Running on Battery Power"), + detail); } } @@ -718,6 +737,7 @@ void Core::onBatteryRemainingTimeChanged(qulonglong time) { + m_batteryRemainingTime = time; Q_EMIT batteryRemainingTimeChanged(time); }