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();
75int FakeBattery::cycleCount()
const
77 return fakeDevice()->property(QStringLiteral(
"cycleCount")).
toInt();
80bool FakeBattery::isRechargeable()
const
82 return fakeDevice()->property(QStringLiteral(
"isRechargeable")).
toBool();
85bool FakeBattery::isPowerSupply()
const
87 return fakeDevice()->property(QStringLiteral(
"isPowerSupply")).
toBool();
92 QString state = fakeDevice()->property(QStringLiteral(
"chargeState")).
toString();
95 return Solid::Battery::Charging;
97 return Solid::Battery::Discharging;
99 return Solid::Battery::FullyCharged;
101 return Solid::Battery::NoCharge;
105qlonglong FakeBattery::timeToEmpty()
const
107 return fakeDevice()->property(QStringLiteral(
"timeToEmpty")).
toLongLong();
110qlonglong FakeBattery::timeToFull()
const
112 return fakeDevice()->property(QStringLiteral(
"timeToFull")).
toLongLong();
120 case Solid::Battery::Charging:
121 name = QStringLiteral(
"charging");
123 case Solid::Battery::Discharging:
124 name = QStringLiteral(
"discharging");
126 case Solid::Battery::NoCharge:
127 name = QStringLiteral(
"noCharge");
129 case Solid::Battery::FullyCharged:
130 name = QStringLiteral(
"fullyCharged");
134 fakeDevice()->setProperty(QStringLiteral(
"chargeState"), name);
135 Q_EMIT chargeStateChanged(newState, fakeDevice()->udi());
138void FakeBattery::setChargeLevel(
int newLevel)
140 fakeDevice()->setProperty(QStringLiteral(
"currentLevel"), newLevel);
141 Q_EMIT chargePercentChanged(chargePercent(), fakeDevice()->udi());
149double FakeBattery::energy()
const
151 return fakeDevice()->property(QStringLiteral(
"energy")).
toDouble();
154double FakeBattery::energyFull()
const
156 return fakeDevice()->property(QStringLiteral(
"energyFull")).
toDouble();
159double FakeBattery::energyFullDesign()
const
161 return fakeDevice()->property(QStringLiteral(
"energyFullDesign")).
toDouble();
164double FakeBattery::energyRate()
const
166 return fakeDevice()->property(QStringLiteral(
"energyRate")).
toDouble();
169double FakeBattery::voltage()
const
171 return fakeDevice()->property(QStringLiteral(
"voltage")).
toDouble();
174double FakeBattery::temperature()
const
176 return fakeDevice()->property(QStringLiteral(
"temperature")).
toDouble();
179QString FakeBattery::serial()
const
181 return fakeDevice()->property(QStringLiteral(
"serial")).
toString();
184qlonglong FakeBattery::remainingTime()
const
186 return fakeDevice()->property(QStringLiteral(
"remainingTime")).
toLongLong();
189#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