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();
30 QString
name = fakeDevice()->property(QStringLiteral(
"batteryType")).toString();
32 if (name == QLatin1String(
"pda")) {
33 return Solid::Battery::PdaBattery;
34 }
else if (name == QLatin1String(
"ups")) {
35 return Solid::Battery::UpsBattery;
36 }
else if (name == QLatin1String(
"primary")) {
37 return Solid::Battery::PrimaryBattery;
38 }
else if (name == QLatin1String(
"mouse")) {
39 return Solid::Battery::MouseBattery;
40 }
else if (name == QLatin1String(
"keyboard")) {
41 return Solid::Battery::KeyboardBattery;
42 }
else if (name == QLatin1String(
"keyboard_mouse")) {
43 return Solid::Battery::KeyboardMouseBattery;
44 }
else if (name == QLatin1String(
"camera")) {
45 return Solid::Battery::CameraBattery;
46 }
else if (name == QLatin1String(
"gaminginput")) {
47 return Solid::Battery::GamingInputBattery;
48 }
else if (name == QLatin1String(
"bluetooth")) {
49 return Solid::Battery::BluetoothBattery;
50 }
else if (name == QLatin1String(
"tablet")) {
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();
94 if (state == QLatin1String(
"charging")) {
95 return Solid::Battery::Charging;
96 }
else if (state == QLatin1String(
"discharging")) {
97 return Solid::Battery::Discharging;
98 }
else if (state == QLatin1String(
"fullyCharged")) {
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)
int toInt(bool *ok, int base) const const