mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
solid: generalize USB batteries and add enum for fully charged battery
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
74944b18f7
commit
649dcbd2a0
6 changed files with 32 additions and 60 deletions
|
@ -41,33 +41,17 @@ Solid::Battery::BatteryType FakeBattery::type() const
|
|||
{
|
||||
QString name = fakeDevice()->property("batteryType").toString();
|
||||
|
||||
if (name == "pda")
|
||||
if (name == "primary")
|
||||
{
|
||||
return Solid::Battery::PdaBattery;
|
||||
return Solid::Battery::PrimaryBattery;
|
||||
}
|
||||
else if (name == "ups")
|
||||
{
|
||||
return Solid::Battery::UpsBattery;
|
||||
}
|
||||
else if (name == "primary")
|
||||
else if (name == "usb")
|
||||
{
|
||||
return Solid::Battery::PrimaryBattery;
|
||||
}
|
||||
else if (name == "mouse")
|
||||
{
|
||||
return Solid::Battery::MouseBattery;
|
||||
}
|
||||
else if (name == "keyboard")
|
||||
{
|
||||
return Solid::Battery::KeyboardBattery;
|
||||
}
|
||||
else if (name == "keyboard_mouse")
|
||||
{
|
||||
return Solid::Battery::KeyboardMouseBattery;
|
||||
}
|
||||
else if (name == "camera")
|
||||
{
|
||||
return Solid::Battery::CameraBattery;
|
||||
return Solid::Battery::UsbBattery;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -117,9 +101,13 @@ Solid::Battery::ChargeState FakeBattery::chargeState() const
|
|||
{
|
||||
return Solid::Battery::Discharging;
|
||||
}
|
||||
else if (state == "full")
|
||||
{
|
||||
return Solid::Battery::FullCharge;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Solid::Battery::NoCharge;
|
||||
return Solid::Battery::UnknownCharge;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,8 +123,11 @@ void FakeBattery::setChargeState(Solid::Battery::ChargeState newState)
|
|||
case Solid::Battery::Discharging:
|
||||
name = "discharging";
|
||||
break;
|
||||
case Solid::Battery::NoCharge:
|
||||
name = "noCharge";
|
||||
case Solid::Battery::FullCharge:
|
||||
name = "full";
|
||||
break;
|
||||
case Solid::Battery::UnknownCharge:
|
||||
name = "unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<property key="interfaces">Battery</property>
|
||||
<property key="parent">/org/kde/solid/fakehw/computer</property>
|
||||
<property key="isPluged">false</property>
|
||||
<property key="batteryType">mouse</property>
|
||||
<property key="batteryType">usb</property>
|
||||
<!-- Battery properties beyond charge percentage are only reported by UPower
|
||||
for primary batteries, not for other batteries like this mouse -->
|
||||
<property key="isRechargeable">true</property>
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
using namespace Solid::Backends::UDev;
|
||||
|
||||
// for reference:
|
||||
// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power
|
||||
// linux/drivers/power/supply/power_supply_sysfs.c
|
||||
// include/linux/power_supply.h
|
||||
|
||||
|
@ -33,7 +34,7 @@ Battery::Battery(UDevDevice *device)
|
|||
m_client(new UdevQt::Client(powersupplysubsystems)),
|
||||
m_chargepercent(0),
|
||||
m_capacity(0),
|
||||
m_chargestate(Solid::Battery::NoCharge),
|
||||
m_chargestate(Solid::Battery::UnknownCharge),
|
||||
m_ispowersupply(false),
|
||||
m_isplugged(false)
|
||||
{
|
||||
|
@ -65,25 +66,15 @@ Solid::Battery::BatteryType Battery::type() const
|
|||
return Solid::Battery::PrimaryBattery;
|
||||
} else if (powersupplytype == QLatin1String("ups")) {
|
||||
return Solid::Battery::UpsBattery;
|
||||
} else if (powersupplytype == QLatin1String("usb_aca")) {
|
||||
// one of:
|
||||
// Solid::Battery::MouseBattery
|
||||
// Solid::Battery::KeyboardBattery
|
||||
// Solid::Battery::KeyboardMouseBattery
|
||||
// Solid::Battery::CameraBattery
|
||||
return Solid::Battery::KeyboardMouseBattery;
|
||||
} else if (powersupplytype == QLatin1String("usb_pd")) {
|
||||
return Solid::Battery::MonitorBattery;
|
||||
} else if (powersupplytype == QLatin1String("usb_pd_drp")) {
|
||||
// one of:
|
||||
// Solid::Battery::PdaBattery
|
||||
return Solid::Battery::PhoneBattery;
|
||||
} else if (powersupplytype.contains(QLatin1String("usb"))) {
|
||||
return Solid::Battery::UsbBattery;
|
||||
}
|
||||
return Solid::Battery::UnknownBattery;
|
||||
}
|
||||
|
||||
int Battery::chargePercent() const
|
||||
{
|
||||
// yes, it is POWER_SUPPLY_CAPACITY
|
||||
return m_device->deviceProperty("POWER_SUPPLY_CAPACITY").toInt();
|
||||
}
|
||||
|
||||
|
@ -122,9 +113,11 @@ Solid::Battery::ChargeState Battery::chargeState() const
|
|||
return Solid::Battery::Charging;
|
||||
} else if (powersupplystatus == QLatin1String("discharging")) {
|
||||
return Solid::Battery::Discharging;
|
||||
} else if (powersupplystatus == QLatin1String("full")) {
|
||||
return Solid::Battery::FullCharge;
|
||||
}
|
||||
|
||||
return Solid::Battery::NoCharge; // stable or unknown
|
||||
return Solid::Battery::UnknownCharge;
|
||||
}
|
||||
|
||||
void Battery::slotEmitSignals(const UdevQt::Device &device)
|
||||
|
|
|
@ -87,7 +87,7 @@ bool Solid::Battery::isRechargeable() const
|
|||
Solid::Battery::ChargeState Solid::Battery::chargeState() const
|
||||
{
|
||||
Q_D(const Battery);
|
||||
return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), NoCharge, chargeState());
|
||||
return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), UnknownCharge, chargeState());
|
||||
}
|
||||
|
||||
#include "moc_battery.cpp"
|
||||
|
|
|
@ -51,31 +51,23 @@ namespace Solid
|
|||
/**
|
||||
* This enum type defines the type of the device holding the battery
|
||||
*
|
||||
* - PdaBattery : A battery in a Personal Digital Assistant
|
||||
* - UpsBattery : A battery in an Uninterruptible Power Supply
|
||||
* - PrimaryBattery : A primary battery for the system (for example laptop battery)
|
||||
* - MouseBattery : A battery in a mouse
|
||||
* - KeyboardBattery : A battery in a keyboard
|
||||
* - KeyboardMouseBattery : A battery in a combined keyboard and mouse
|
||||
* - CameraBattery : A battery in a camera
|
||||
* - PhoneBattery : A battery in a phone
|
||||
* - MonitorBattery : A battery in a monitor
|
||||
* - UnknownBattery : A battery in an unknown device
|
||||
* - PrimaryBattery : A primary battery for the system (for example laptop battery)
|
||||
* - UpsBattery : A battery in an Uninterruptible Power Supply
|
||||
* - UsbBattery : A battery in a is of USB device (for example mouse battery)
|
||||
*/
|
||||
enum BatteryType { UnknownBattery, PdaBattery, UpsBattery,
|
||||
PrimaryBattery, MouseBattery, KeyboardBattery,
|
||||
KeyboardMouseBattery, CameraBattery,
|
||||
PhoneBattery, MonitorBattery };
|
||||
enum BatteryType { UnknownBattery, PrimaryBattery, UpsBattery,
|
||||
UsbBattery };
|
||||
|
||||
/**
|
||||
* This enum type defines charge state of a battery
|
||||
*
|
||||
* - NoCharge : Battery charge is stable, not charging or discharging or
|
||||
* the state is Unknown
|
||||
* - UnknownCharge : Battery state is Unknown
|
||||
* - Charging : Battery is charging
|
||||
* - Discharging : Battery is discharging
|
||||
* - FullCharge : Battery is fully charged
|
||||
*/
|
||||
enum ChargeState { NoCharge, Charging, Discharging };
|
||||
enum ChargeState { UnknownCharge, Charging, Discharging, FullCharge };
|
||||
|
||||
|
||||
private:
|
||||
|
@ -127,8 +119,6 @@ namespace Solid
|
|||
*/
|
||||
BatteryType type() const;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the current charge level of the battery normalised
|
||||
* to percent.
|
||||
|
|
|
@ -56,8 +56,6 @@ namespace Ifaces
|
|||
*/
|
||||
virtual Solid::Battery::BatteryType type() const = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the current charge level of the battery normalised
|
||||
* to percent.
|
||||
|
|
Loading…
Add table
Reference in a new issue