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(
"isPresent").
toBool();
33 return Solid::Battery::PdaBattery;
34 }
else if (name ==
"ups") {
35 return Solid::Battery::UpsBattery;
36 }
else if (name ==
"primary") {
37 return Solid::Battery::PrimaryBattery;
38 }
else if (name ==
"mouse") {
39 return Solid::Battery::MouseBattery;
40 }
else if (name ==
"keyboard") {
41 return Solid::Battery::KeyboardBattery;
42 }
else if (name ==
"keyboard_mouse") {
43 return Solid::Battery::KeyboardMouseBattery;
44 }
else if (name ==
"camera") {
45 return Solid::Battery::CameraBattery;
46 }
else if (name ==
"gaminginput") {
47 return Solid::Battery::GamingInputBattery;
48 }
else if (name ==
"bluetooth") {
49 return Solid::Battery::BluetoothBattery;
50 }
else if (name ==
"tablet") {
51 return Solid::Battery::TabletBattery;
53 return Solid::Battery::UnknownBattery;
57int FakeBattery::chargePercent()
const
59 int last_full = fakeDevice()->property(
"lastFullLevel").
toInt();
60 int current = fakeDevice()->property(
"currentLevel").
toInt();
64 percent = (100 * current) / last_full;
70int FakeBattery::capacity()
const
72 return fakeDevice()->property(
"capacity").
toInt();
75bool FakeBattery::isRechargeable()
const
77 return fakeDevice()->property(
"isRechargeable").
toBool();
80bool FakeBattery::isPowerSupply()
const
82 return fakeDevice()->property(
"isPowerSupply").
toBool();
89 if (state ==
"charging") {
90 return Solid::Battery::Charging;
91 }
else if (state ==
"discharging") {
92 return Solid::Battery::Discharging;
93 }
else if (state ==
"fullyCharged") {
94 return Solid::Battery::FullyCharged;
96 return Solid::Battery::NoCharge;
100qlonglong FakeBattery::timeToEmpty()
const
102 return fakeDevice()->property(
"timeToEmpty").
toLongLong();
105qlonglong FakeBattery::timeToFull()
const
107 return fakeDevice()->property(
"timeToFull").
toLongLong();
115 case Solid::Battery::Charging:
118 case Solid::Battery::Discharging:
119 name =
"discharging";
121 case Solid::Battery::NoCharge:
124 case Solid::Battery::FullyCharged:
125 name =
"fullyCharged";
129 fakeDevice()->setProperty(
"chargeState", name);
130 Q_EMIT chargeStateChanged(newState, fakeDevice()->udi());
133void FakeBattery::setChargeLevel(
int newLevel)
135 fakeDevice()->setProperty(
"currentLevel", newLevel);
136 Q_EMIT chargePercentChanged(chargePercent(), fakeDevice()->udi());
144double FakeBattery::energy()
const
146 return fakeDevice()->property(
"energy").
toDouble();
149double FakeBattery::energyFull()
const
151 return fakeDevice()->property(
"energyFull").
toDouble();
154double FakeBattery::energyFullDesign()
const
156 return fakeDevice()->property(
"energyFullDesign").
toDouble();
159double FakeBattery::energyRate()
const
161 return fakeDevice()->property(
"energyRate").
toDouble();
164double FakeBattery::voltage()
const
166 return fakeDevice()->property(
"voltage").
toDouble();
169double FakeBattery::temperature()
const
171 return fakeDevice()->property(
"temperature").
toDouble();
174QString FakeBattery::serial()
const
176 return fakeDevice()->property(
"serial").
toString();
179qlonglong FakeBattery::remainingTime()
const
181 return fakeDevice()->property(
"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(StandardShortcut 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