9#include "fakebattery.h"
12using namespace Solid::Backends::Fake;
14FakeBattery::FakeBattery(FakeDevice *device)
15 : FakeDeviceInterface(device)
19FakeBattery::~FakeBattery()
23bool FakeBattery::isPresent()
const
25 return fakeDevice()->property(QStringLiteral(
"isPresent")).
toBool();
33 return Solid::Battery::PdaBattery;
35 return Solid::Battery::UpsBattery;
37 return Solid::Battery::PrimaryBattery;
39 return Solid::Battery::MouseBattery;
41 return Solid::Battery::KeyboardBattery;
43 return Solid::Battery::KeyboardMouseBattery;
45 return Solid::Battery::CameraBattery;
47 return Solid::Battery::GamingInputBattery;
49 return Solid::Battery::BluetoothBattery;
51 return Solid::Battery::TabletBattery;
53 return Solid::Battery::UnknownBattery;
57int FakeBattery::chargePercent()
const
59 int last_full = fakeDevice()->property(QStringLiteral(
"lastFullLevel")).
toInt();
60 int current = fakeDevice()->property(QStringLiteral(
"currentLevel")).
toInt();
64 percent = (100 * current) / last_full;
70int FakeBattery::capacity()
const
72 return fakeDevice()->property(QStringLiteral(
"capacity")).
toInt();
75bool FakeBattery::isRechargeable()
const
77 return fakeDevice()->property(QStringLiteral(
"isRechargeable")).
toBool();
80bool FakeBattery::isPowerSupply()
const
82 return fakeDevice()->property(QStringLiteral(
"isPowerSupply")).
toBool();
87 QString state = fakeDevice()->property(QStringLiteral(
"chargeState")).
toString();
90 return Solid::Battery::Charging;
92 return Solid::Battery::Discharging;
94 return Solid::Battery::FullyCharged;
96 return Solid::Battery::NoCharge;
100qlonglong FakeBattery::timeToEmpty()
const
102 return fakeDevice()->property(QStringLiteral(
"timeToEmpty")).
toLongLong();
105qlonglong FakeBattery::timeToFull()
const
107 return fakeDevice()->property(QStringLiteral(
"timeToFull")).
toLongLong();
115 case Solid::Battery::Charging:
116 name = QStringLiteral(
"charging");
118 case Solid::Battery::Discharging:
119 name = QStringLiteral(
"discharging");
121 case Solid::Battery::NoCharge:
122 name = QStringLiteral(
"noCharge");
124 case Solid::Battery::FullyCharged:
125 name = QStringLiteral(
"fullyCharged");
129 fakeDevice()->setProperty(QStringLiteral(
"chargeState"), name);
130 Q_EMIT chargeStateChanged(newState, fakeDevice()->udi());
133void FakeBattery::setChargeLevel(
int newLevel)
135 fakeDevice()->setProperty(QStringLiteral(
"currentLevel"), newLevel);
136 Q_EMIT chargePercentChanged(chargePercent(), fakeDevice()->udi());
144double FakeBattery::energy()
const
146 return fakeDevice()->property(QStringLiteral(
"energy")).
toDouble();
149double FakeBattery::energyFull()
const
151 return fakeDevice()->property(QStringLiteral(
"energyFull")).
toDouble();
154double FakeBattery::energyFullDesign()
const
156 return fakeDevice()->property(QStringLiteral(
"energyFullDesign")).
toDouble();
159double FakeBattery::energyRate()
const
161 return fakeDevice()->property(QStringLiteral(
"energyRate")).
toDouble();
164double FakeBattery::voltage()
const
166 return fakeDevice()->property(QStringLiteral(
"voltage")).
toDouble();
169double FakeBattery::temperature()
const
171 return fakeDevice()->property(QStringLiteral(
"temperature")).
toDouble();
174QString FakeBattery::serial()
const
176 return fakeDevice()->property(QStringLiteral(
"serial")).
toString();
179qlonglong FakeBattery::remainingTime()
const
181 return fakeDevice()->property(QStringLiteral(
"remainingTime")).
toLongLong();
184#include "moc_fakebattery.cpp"
BatteryType
This enum type defines the type of the device holding the battery.
Technology
Technology used in the battery.
ChargeState
This enum type defines charge state of a battery.
QString name(StandardAction id)
bool toBool() const const
double toDouble(bool *ok) const const
int toInt(bool *ok) const const
qlonglong toLongLong(bool *ok) const const
QString toString() const const