10#include "powermanagementengine.h"
13#include <solid/device.h>
14#include <solid/deviceinterface.h>
15#include <solid/devicenotifier.h>
24#include <QDBusConnectionInterface>
26#include <QDBusInterface>
27#include <QDBusMetaType>
28#include <QDBusPendingCallWatcher>
32#include "powermanagementservice.h"
33#include <Plasma5Support/DataContainer>
35using namespace Qt::StringLiterals;
37static constexpr QLatin1String SOLID_POWERMANAGEMENT_SERVICE(
"org.kde.Solid.PowerManagement");
38static constexpr QLatin1String FDO_POWERMANAGEMENT_SERVICE(
"org.freedesktop.PowerManagement");
42template<
typename ReplyType>
43void createAsyncDBusMethodCallAndCallback(
QObject *parent,
48 std::function<
void(ReplyType)> &&callback)
56 callback(reply.
value());
63PowermanagementEngine::PowermanagementEngine(
QObject *parent)
65 , m_sources(basicSourceNames())
67 qDBusRegisterMetaType<QList<InhibitionInfo>>();
68 qDBusRegisterMetaType<InhibitionInfo>();
69 qDBusRegisterMetaType<QList<QVariant>>();
70 qDBusRegisterMetaType<QList<QVariantMap>>();
74PowermanagementEngine::~PowermanagementEngine()
78void PowermanagementEngine::init()
85 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/HandleButtonEvents"),
86 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.HandleButtonEvents"),
87 QStringLiteral(
"triggersLidActionChanged"),
89 SLOT(triggersLidActionChanged(
bool)))) {
90 qDebug() <<
"error connecting to lid action trigger changes via dbus";
94 QStringLiteral(
"/org/kde/Solid/PowerManagement/PolicyAgent"),
95 QStringLiteral(
"org.kde.Solid.PowerManagement.PolicyAgent"),
96 QStringLiteral(
"InhibitionsChanged"),
99 qDebug() <<
"error connecting to inhibition changes via dbus";
103 QStringLiteral(
"/org/kde/Solid/PowerManagement"),
104 SOLID_POWERMANAGEMENT_SERVICE,
105 QStringLiteral(
"batteryRemainingTimeChanged"),
107 SLOT(batteryRemainingTimeChanged(qulonglong)))) {
108 qDebug() <<
"error connecting to remaining time changes";
112 QStringLiteral(
"/org/kde/Solid/PowerManagement"),
113 SOLID_POWERMANAGEMENT_SERVICE,
114 QStringLiteral(
"smoothedBatteryRemainingTimeChanged"),
116 SLOT(smoothedBatteryRemainingTimeChanged(qulonglong)))) {
117 qDebug() <<
"error connecting to smoothed remaining time changes";
121 QStringLiteral(
"/org/kde/Solid/PowerManagement"),
122 SOLID_POWERMANAGEMENT_SERVICE,
123 QStringLiteral(
"chargeStopThresholdChanged"),
125 SLOT(chargeStopThresholdChanged(
int)))) {
126 qDebug() <<
"error connecting to charge stop threshold changes via dbus";
130 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/PowerProfile"),
131 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.PowerProfile"),
132 QStringLiteral(
"currentProfileChanged"),
134 SLOT(updatePowerProfileCurrentProfile(
QString)))) {
135 qDebug() <<
"error connecting to current profile changes via dbus";
139 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/PowerProfile"),
140 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.PowerProfile"),
141 QStringLiteral(
"profileChoicesChanged"),
144 qDebug() <<
"error connecting to profile choices changes via dbus";
148 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/PowerProfile"),
149 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.PowerProfile"),
150 QStringLiteral(
"performanceInhibitedReasonChanged"),
152 SLOT(updatePowerProfilePerformanceInhibitedReason(
QString)))) {
153 qDebug() <<
"error connecting to inhibition reason changes via dbus";
157 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/PowerProfile"),
158 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.PowerProfile"),
159 QStringLiteral(
"performanceDegradedReasonChanged"),
161 SLOT(updatePowerProfilePerformanceDegradedReason(
QString)))) {
162 qDebug() <<
"error connecting to degradation reason changes via dbus";
166 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/PowerProfile"),
167 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.PowerProfile"),
168 QStringLiteral(
"profileHoldsChanged"),
171 qDebug() <<
"error connecting to profile hold changes via dbus";
176 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/PowerProfile"),
177 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.PowerProfile"),
178 QStringLiteral(
"configuredProfileChanged"),
180 SLOT(updatePowerProfileConfiguredProfile(
QString)))) {
181 qDebug() <<
"error connecting to configured profile changes via dbus";
186 QStringLiteral(
"/org/freedesktop/PowerManagement"),
187 QStringLiteral(
"org.freedesktop.PowerManagement.Inhibit"),
188 QStringLiteral(
"HasInhibitChanged"),
190 SLOT(hasInhibitionChanged(
bool)))) {
191 qDebug() <<
"error connecting to fdo inhibition changes via dbus";
196QStringList PowermanagementEngine::basicSourceNames()
const
199 sources << QStringLiteral(
"Battery") << QStringLiteral(
"AC Adapter") << QStringLiteral(
"Sleep States") << QStringLiteral(
"PowerDevil")
200 << QStringLiteral(
"Inhibitions") << QStringLiteral(
"Power Profiles") << QStringLiteral(
"PowerManagement");
213 m_batterySources.
clear();
216 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Has Battery"),
false);
217 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Has Cumulative"),
false);
227 const QString source = QStringLiteral(
"Battery%1").
arg(index++);
229 batterySources << source;
230 m_batterySources[deviceBattery.udi()] = source;
238 updateBatteryChargeState(battery->
chargeState(), deviceBattery.udi());
239 updateBatteryChargePercent(battery->
chargePercent(), deviceBattery.udi());
240 updateBatteryEnergy(battery->
energy(), deviceBattery.udi());
241 updateBatteryPresentState(battery->
isPresent(), deviceBattery.udi());
242 updateBatteryPowerSupplyState(battery->
isPowerSupply(), deviceBattery.udi());
244 setData(source, QStringLiteral(
"Vendor"), deviceBattery.vendor());
245 setData(source, QStringLiteral(
"Product"), deviceBattery.product());
247 setData(source, QStringLiteral(
"Type"), batteryTypeToString(battery));
250 updateBatteryNames();
251 updateOverallBattery();
253 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Sources"), batterySources);
254 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Has Battery"), !batterySources.
isEmpty());
255 if (!batterySources.
isEmpty()) {
256 createPowerManagementDBusMethodCallAndNotifyChanged<qulonglong>(
257 QStringLiteral(
"batteryRemainingTime"),
258 std::bind(&PowermanagementEngine::batteryRemainingTimeChanged,
this, std::placeholders::_1));
259 createPowerManagementDBusMethodCallAndNotifyChanged<qulonglong>(
260 QStringLiteral(
"smoothedBatteryRemainingTime"),
261 std::bind(&PowermanagementEngine::smoothedBatteryRemainingTimeChanged,
this, std::placeholders::_1));
264 createPowerManagementDBusMethodCallAndNotifyChanged<int>(QStringLiteral(
"chargeStopThreshold"),
265 std::bind(&PowermanagementEngine::chargeStopThresholdChanged,
this, std::placeholders::_1));
267 m_sources = basicSourceNames() + batterySources;
270 QStringLiteral(
"/org/freedesktop/PowerManagement"),
271 QStringLiteral(
"org.freedesktop.PowerManagement"),
272 QStringLiteral(
"PowerSaveStatusChanged"),
274 SLOT(updateAcPlugState(
bool)));
277 QStringLiteral(
"/org/freedesktop/PowerManagement"),
278 QStringLiteral(
"org.freedesktop.PowerManagement"),
279 QStringLiteral(
"GetPowerSaveStatus"));
281 updateAcPlugState(reply.
isValid() ? reply.value() :
false);
283 createPowerManagementDBusMethodCallAndNotifyChanged<bool>(QStringLiteral(
"isLidPresent"), [
this](
bool replyValue) {
284 setData(QStringLiteral(
"PowerDevil"), QStringLiteral(
"Is Lid Present"), replyValue);
287 createAsyncDBusMethodCallAndCallback<bool>(
this,
288 SOLID_POWERMANAGEMENT_SERVICE,
289 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/HandleButtonEvents"),
290 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.HandleButtonEvents"),
291 QStringLiteral(
"triggersLidAction"),
292 std::bind(&PowermanagementEngine::triggersLidActionChanged,
this, std::placeholders::_1));
294 createAsyncDBusMethodCallAndCallback<bool>(
this,
295 QStringLiteral(
"org.freedesktop.PowerManagement"),
296 QStringLiteral(
"/org/freedesktop/PowerManagement"),
297 QStringLiteral(
"org.freedesktop.PowerManagement.Inhibit"),
298 QStringLiteral(
"HasInhibit"),
299 [
this](
const bool &replyValue) {
300 hasInhibitionChanged(replyValue);
304 createAsyncDBusMethodCallAndCallback<QList<InhibitionInfo>>(
this,
305 SOLID_POWERMANAGEMENT_SERVICE,
306 QStringLiteral(
"/org/kde/Solid/PowerManagement/PolicyAgent"),
307 QStringLiteral(
"org.kde.Solid.PowerManagement.PolicyAgent"),
308 QStringLiteral(
"ListInhibitions"),
317 updatePowerProfileDaemonInstalled(
QDBusConnection::systemBus().interface()->isServiceRegistered(QStringLiteral(
"net.hadess.PowerProfiles")).value());
318 createPowerProfileDBusMethodCallAndNotifyChanged<QString>(
319 QStringLiteral(
"currentProfile"),
320 std::bind(&PowermanagementEngine::updatePowerProfileCurrentProfile,
this, std::placeholders::_1));
321 createPowerProfileDBusMethodCallAndNotifyChanged<QStringList>(
322 QStringLiteral(
"profileChoices"),
323 std::bind(&PowermanagementEngine::updatePowerProfileChoices,
this, std::placeholders::_1));
324 createPowerProfileDBusMethodCallAndNotifyChanged<QString>(
325 QStringLiteral(
"performanceInhibitedReason"),
326 std::bind(&PowermanagementEngine::updatePowerProfilePerformanceInhibitedReason,
this, std::placeholders::_1));
327 createPowerProfileDBusMethodCallAndNotifyChanged<QString>(
328 QStringLiteral(
"performanceDegradedReason"),
329 std::bind(&PowermanagementEngine::updatePowerProfilePerformanceDegradedReason,
this, std::placeholders::_1));
330 createPowerProfileDBusMethodCallAndNotifyChanged<QList<QVariantMap>>(
331 QStringLiteral(
"profileHolds"),
332 std::bind(&PowermanagementEngine::updatePowerProfileHolds,
this, std::placeholders::_1));
333 createPowerProfileDBusMethodCallAndNotifyChanged<QString>(
334 QStringLiteral(
"configuredProfile"),
335 std::bind(&PowermanagementEngine::updatePowerProfileConfiguredProfile,
this, std::placeholders::_1));
337 qDebug() <<
"Data for" << name <<
"not found";
345 switch (battery->
type()) {
346 case Solid::Battery::PrimaryBattery:
347 return QStringLiteral(
"Battery");
348 case Solid::Battery::UpsBattery:
349 return QStringLiteral(
"Ups");
350 case Solid::Battery::MonitorBattery:
351 return QStringLiteral(
"Monitor");
352 case Solid::Battery::MouseBattery:
353 return QStringLiteral(
"Mouse");
354 case Solid::Battery::KeyboardBattery:
355 return QStringLiteral(
"Keyboard");
356 case Solid::Battery::PdaBattery:
357 return QStringLiteral(
"Pda");
358 case Solid::Battery::PhoneBattery:
359 return QStringLiteral(
"Phone");
360 case Solid::Battery::GamingInputBattery:
361 return QStringLiteral(
"GamingInput");
362 case Solid::Battery::BluetoothBattery:
363 return QStringLiteral(
"Bluetooth");
364 case Solid::Battery::TabletBattery:
365 return QStringLiteral(
"Tablet");
366 case Solid::Battery::HeadphoneBattery:
367 return QStringLiteral(
"Headphone");
368 case Solid::Battery::HeadsetBattery:
369 return QStringLiteral(
"Headset");
370 case Solid::Battery::TouchpadBattery:
371 return QStringLiteral(
"Touchpad");
373 return QStringLiteral(
"Unknown");
389 return new PowerManagementService(
this);
395QString PowermanagementEngine::batteryStateToString(
int newState)
const
397 QString state(QStringLiteral(
"Unknown"));
398 if (newState == Solid::Battery::NoCharge) {
400 }
else if (newState == Solid::Battery::Charging) {
402 }
else if (newState == Solid::Battery::Discharging) {
404 }
else if (newState == Solid::Battery::FullyCharged) {
411void PowermanagementEngine::updateBatteryChargeState(
int newState,
const QString &udi)
413 const QString source = m_batterySources[udi];
414 setData(source, QStringLiteral(
"State"), batteryStateToString(newState));
415 updateOverallBattery();
418void PowermanagementEngine::updateBatteryPresentState(
bool newState,
const QString &udi)
420 const QString source = m_batterySources[udi];
421 setData(source, QStringLiteral(
"Plugged in"), newState);
424void PowermanagementEngine::updateBatteryChargePercent(
int newValue,
const QString &udi)
426 const QString source = m_batterySources[udi];
427 setData(source, QStringLiteral(
"Percent"), newValue);
428 updateOverallBattery();
431void PowermanagementEngine::updateBatteryEnergy(
double newValue,
const QString &udi)
433 const QString source = m_batterySources[udi];
434 setData(source, QStringLiteral(
"Energy"), newValue);
437void PowermanagementEngine::updateBatteryPowerSupplyState(
bool newState,
const QString &udi)
439 const QString source = m_batterySources[udi];
440 setData(source, QStringLiteral(
"Is Power Supply"), newState);
443void PowermanagementEngine::updateBatteryNames()
445 uint unnamedBatteries = 0;
446 for (
const QString &source : std::as_const(m_batterySources)) {
448 if (batteryDataContainer) {
449 const QString batteryVendor = batteryDataContainer->
data()[QStringLiteral(
"Vendor")].toString();
450 const QString batteryProduct = batteryDataContainer->
data()[QStringLiteral(
"Product")].toString();
453 const bool showBatteryName = batteryDataContainer->
data()[QStringLiteral(
"Type")].toString() !=
QLatin1String(
"Battery")
454 || !batteryDataContainer->
data()[QStringLiteral(
"Is Power Supply")].toBool();
456 if (!batteryProduct.
isEmpty() && batteryProduct !=
QLatin1String(
"Unknown Battery") && showBatteryName) {
457 if (!batteryVendor.
isEmpty()) {
458 setData(source, QStringLiteral(
"Pretty Name"),
QString(batteryVendor +
' ' + batteryProduct));
460 setData(source, QStringLiteral(
"Pretty Name"), batteryProduct);
464 if (unnamedBatteries > 1) {
465 setData(source, QStringLiteral(
"Pretty Name"),
i18nc(
"Placeholder is the battery number",
"Battery %1", unnamedBatteries));
467 setData(source, QStringLiteral(
"Pretty Name"),
i18n(
"Battery"));
474void PowermanagementEngine::updateOverallBattery()
477 bool hasCumulative =
false;
480 double totalEnergy = 0;
481 bool allFullyCharged =
true;
482 bool charging =
false;
483 bool noCharge =
false;
484 double totalPercentage = 0;
491 hasCumulative =
true;
493 energy += battery->
energy();
496 allFullyCharged = allFullyCharged && (battery->
chargeState() == Solid::Battery::FullyCharged);
497 charging = charging || (battery->
chargeState() == Solid::Battery::Charging);
498 noCharge = noCharge || (battery->
chargeState() == Solid::Battery::NoCharge);
507 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Percent"), qRound(totalPercentage));
508 }
else if (totalEnergy > 0) {
509 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Percent"), qRound(energy / totalEnergy * 100));
510 }
else if (count > 0) {
511 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Percent"), qRound(totalPercentage /
static_cast<qreal
>(count)));
513 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Percent"),
int(0));
517 if (allFullyCharged) {
518 setData(QStringLiteral(
"Battery"), QStringLiteral(
"State"),
"FullyCharged");
519 }
else if (charging) {
520 setData(QStringLiteral(
"Battery"), QStringLiteral(
"State"),
"Charging");
521 }
else if (noCharge) {
522 setData(QStringLiteral(
"Battery"), QStringLiteral(
"State"),
"NoCharge");
524 setData(QStringLiteral(
"Battery"), QStringLiteral(
"State"),
"Discharging");
527 setData(QStringLiteral(
"Battery"), QStringLiteral(
"State"),
"Unknown");
530 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Has Cumulative"), hasCumulative);
533void PowermanagementEngine::updateAcPlugState(
bool onBattery)
535 setData(QStringLiteral(
"AC Adapter"), QStringLiteral(
"Plugged in"), !onBattery);
538void PowermanagementEngine::updatePowerProfileDaemonInstalled(
const bool &installed)
540 setData(QStringLiteral(
"Power Profiles"), QStringLiteral(
"Installed"), installed);
543void PowermanagementEngine::updatePowerProfileCurrentProfile(
const QString &activeProfile)
545 setData(QStringLiteral(
"Power Profiles"), QStringLiteral(
"Current Profile"), activeProfile);
548void PowermanagementEngine::updatePowerProfileChoices(
const QStringList &choices)
550 setData(QStringLiteral(
"Power Profiles"), QStringLiteral(
"Profiles"), choices);
553void PowermanagementEngine::updatePowerProfilePerformanceInhibitedReason(
const QString &reason)
555 setData(QStringLiteral(
"Power Profiles"), QStringLiteral(
"Performance Inhibited Reason"), reason);
558void PowermanagementEngine::updatePowerProfilePerformanceDegradedReason(
const QString &reason)
560 setData(QStringLiteral(
"Power Profiles"), QStringLiteral(
"Performance Degraded Reason"), reason);
566 std::transform(holds.
cbegin(), holds.
cend(), std::back_inserter(out), [
this](
const QVariantMap &hold) {
569 populateApplicationData(hold[QStringLiteral(
"ApplicationId")].toString(), &prettyName, &icon);
571 {QStringLiteral(
"Name"), prettyName},
572 {QStringLiteral(
"Icon"), icon},
573 {QStringLiteral(
"Reason"), hold[QStringLiteral(
"Reason")]},
574 {QStringLiteral(
"Profile"), hold[QStringLiteral(
"Profile")]},
577 setData(QStringLiteral(
"Power Profiles"), QStringLiteral(
"Profile Holds"),
QVariant::fromValue(out));
580void PowermanagementEngine::updatePowerProfileConfiguredProfile(
const QString &activeProfile)
582 setData(QStringLiteral(
"Power Profiles"), QStringLiteral(
"Configured Profile"), activeProfile);
585void PowermanagementEngine::deviceRemoved(
const QString &udi)
587 if (m_batterySources.
contains(udi)) {
594 const QString source = m_batterySources[udi];
595 m_batterySources.
remove(udi);
599 sourceNames.removeAll(source);
600 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Sources"), sourceNames);
601 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Has Battery"), !sourceNames.isEmpty());
603 updateOverallBattery();
607void PowermanagementEngine::deviceAdded(
const QString &udi)
610 if (device.isValid()) {
616 while (sourceNames.contains(QStringLiteral(
"Battery%1").arg(index))) {
620 const QString source = QStringLiteral(
"Battery%1").
arg(index);
621 sourceNames << source;
622 m_batterySources[device.udi()] = source;
631 updateBatteryChargeState(battery->
chargeState(), device.udi());
632 updateBatteryChargePercent(battery->
chargePercent(), device.udi());
633 updateBatteryEnergy(battery->
energy(), device.udi());
634 updateBatteryPresentState(battery->
isPresent(), device.udi());
635 updateBatteryPowerSupplyState(battery->
isPowerSupply(), device.udi());
637 setData(source, QStringLiteral(
"Vendor"), device.vendor());
638 setData(source, QStringLiteral(
"Product"), device.product());
640 setData(source, QStringLiteral(
"Type"), batteryTypeToString(battery));
642 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Sources"), sourceNames);
643 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Has Battery"), !sourceNames.isEmpty());
645 updateBatteryNames();
646 updateOverallBattery();
651void PowermanagementEngine::batteryRemainingTimeChanged(qulonglong time)
654 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Remaining msec"), time);
657void PowermanagementEngine::smoothedBatteryRemainingTimeChanged(qulonglong time)
659 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Smoothed Remaining msec"), time);
662void PowermanagementEngine::triggersLidActionChanged(
bool triggers)
664 setData(QStringLiteral(
"PowerDevil"), QStringLiteral(
"Triggers Lid Action"), triggers);
667void PowermanagementEngine::hasInhibitionChanged(
bool inhibited)
669 setData(QStringLiteral(
"PowerManagement"), QStringLiteral(
"Has Inhibition"), inhibited);
675 removeData(QStringLiteral(
"Inhibitions"), (*it));
682 const QString &reason = (*it).second;
684 populateApplicationData(name, &prettyName, &icon);
686 setData(QStringLiteral(
"Inhibitions"),
688 QVariantMap{{QStringLiteral(
"Name"), prettyName}, {QStringLiteral(
"Icon"), icon}, {QStringLiteral(
"Reason"), reason}});
692template<
typename ReplyType>
693inline void PowermanagementEngine::createPowerManagementDBusMethodCallAndNotifyChanged(
const QString &method, std::function<
void(ReplyType)> &&callback)
695 createAsyncDBusMethodCallAndCallback<ReplyType>(
this,
696 SOLID_POWERMANAGEMENT_SERVICE,
697 QStringLiteral(
"/org/kde/Solid/PowerManagement"),
698 SOLID_POWERMANAGEMENT_SERVICE,
700 std::move(callback));
703template<
typename ReplyType>
704inline void PowermanagementEngine::createPowerProfileDBusMethodCallAndNotifyChanged(
const QString &method, std::function<
void(ReplyType)> &&callback)
706 createAsyncDBusMethodCallAndCallback<ReplyType>(
this,
707 SOLID_POWERMANAGEMENT_SERVICE,
708 QStringLiteral(
"/org/kde/Solid/PowerManagement/Actions/PowerProfile"),
709 QStringLiteral(
"org.kde.Solid.PowerManagement.Actions.PowerProfile"),
711 std::move(callback));
714void PowermanagementEngine::populateApplicationData(
const QString &name,
QString *prettyName,
QString *icon)
716 if (m_applicationInfo.
contains(name)) {
717 const auto &info = m_applicationInfo.
value(name);
718 *prettyName = info.
first;
723 *prettyName = service->name();
724 *icon = service->icon();
726 m_applicationInfo.
insert(name, qMakePair(*prettyName, *icon));
737void PowermanagementEngine::chargeStopThresholdChanged(
int threshold)
739 setData(QStringLiteral(
"Battery"), QStringLiteral(
"Charge Stop Threshold"), threshold);
744#include "powermanagementengine.moc"
static KIdleTime * instance()
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
static Ptr serviceByStorageId(const QString &_storageId)
A set of data exported via a DataEngine.
const DataEngine::Data data() const
Returns the data for this DataContainer.
Data provider for plasmoids (Plasma plugins)
void removeSource(const QString &source)
Removes a data source.
virtual bool updateSourceEvent(const QString &source)
Called by internal updating mechanisms to trigger the engine to refresh the data contained in a given...
void removeData(const QString &source, const QString &key)
Removes a data entry from a source.
void setData(const QString &source, const QVariant &value)
Sets a value for a data source.
Q_INVOKABLE DataContainer * containerForSource(const QString &source)
Retrieves a pointer to the DataContainer for a given source.
void removeAllData(const QString &source)
Removes all the data associated with a data source.
This class provides a generic API for write access to settings or services.
This class provides runtime information about the battery and AC status for use in power management P...
QStringList sources() const override
bool sourceRequestEvent(const QString &name) override
When a source that does not currently exist is requested by the consumer, this method is called to gi...
bool updateSourceEvent(const QString &source) override
Called by internal updating mechanisms to trigger the engine to refresh the data contained in a given...
Plasma5Support::Service * serviceForSource(const QString &source) override
void energyChanged(double energy, const QString &udi)
Solid::Battery::BatteryType type() const
int chargePercent() const
Solid::Battery::ChargeState chargeState() const
double energyFull() const
void powerSupplyStateChanged(bool newState, const QString &udi)
void presentStateChanged(bool newState, const QString &udi)
bool isPowerSupply() const
void chargePercentChanged(int value, const QString &udi)
void chargeStateChanged(int newState, const QString &udi=QString())
void deviceRemoved(const QString &udi)
void deviceAdded(const QString &udi)
static QList< Device > listFromType(const DeviceInterface::Type &type, const QString &parentUdi=QString())
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
QString name(GameStandardAction id)
Namespace for everything in libplasma.
QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout) const const
QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode, int timeout) const const
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
void finished(QDBusPendingCallWatcher *self)
bool isError() const const
typename Select< 0 >::Type value() const const
bool isValid() const const
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
bool remove(const Key &key)
T value(const Key &key) const const
QList< T > values() const const
bool hasThemeIcon(const QString &name)
const_iterator cbegin() const const
const_iterator cend() const const
const_iterator constBegin() const const
const_iterator constEnd() const const
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QString arg(Args &&... args) const const
QString first(qsizetype n) const const
bool isEmpty() const const
QString section(QChar sep, qsizetype start, qsizetype end, SectionFlags flags) const const
QString toLower() const const
QVariant fromValue(T &&value)