solid: coding battery methods for expectations

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-04-22 20:00:45 +03:00
parent a1a16743c3
commit 932aab37be
2 changed files with 7 additions and 3 deletions

View file

@ -55,7 +55,7 @@ Battery::~Battery()
bool Battery::isPlugged() const
{
return (m_device->deviceProperty("POWER_SUPPLY_ONLINE").toInt() == 1);
return (m_device->deviceProperty("POWER_SUPPLY_PRESENT").toInt() == 1);
}
Solid::Battery::BatteryType Battery::type() const
@ -103,6 +103,10 @@ bool Battery::isRechargeable() const
bool Battery::isPowerSupply() const
{
const QString powersupplyscope(m_device->deviceProperty("POWER_SUPPLY_SCOPE").toLower());
if (powersupplyscope == QLatin1String("device")) {
return false;
}
return (chargeState() == Solid::Battery::Discharging);
}
@ -116,7 +120,6 @@ Solid::Battery::ChargeState Battery::chargeState() const
} else if (powersupplystatus == QLatin1String("full")) {
return Solid::Battery::FullyCharged;
}
return Solid::Battery::UnknownCharge;
}

View file

@ -97,7 +97,8 @@ namespace Solid
static Type deviceInterfaceType() { return DeviceInterface::Battery; }
/**
* Indicates if this battery is plugged.
* Indicates if this battery is plugged. If true is returned from this
* method the device status will be shown by applets for example.
*
* @return true if the battery is plugged, false otherwise
*/