]>
Commit | Line | Data |
---|---|---|
f5bb7afb AM |
1 | diff --git a/solid/solid/backends/fakehw/fakebattery.cpp b/solid/solid/backends/fakehw/fakebattery.cpp |
2 | index 0afe765..147cea0 100644 | |
3901abf5 AM |
3 | --- a/solid/solid/backends/fakehw/fakebattery.cpp |
4 | +++ b/solid/solid/backends/fakehw/fakebattery.cpp | |
f5bb7afb AM |
5 | @@ -85,11 +85,26 @@ int FakeBattery::chargePercent() const |
6 | return percent; | |
7 | } | |
8 | ||
9 | +int FakeBattery::capacity() const | |
10 | +{ | |
11 | + int last_full = fakeDevice()->property("lastFullLevel").toInt(); | |
12 | + int max = fakeDevice()->property("maxLevel").toInt(); | |
13 | + | |
14 | + int percent = (100 * last_full) / max; | |
15 | + | |
16 | + return percent; | |
17 | +} | |
18 | + | |
19 | bool FakeBattery::isRechargeable() const | |
20 | { | |
3901abf5 AM |
21 | return fakeDevice()->property("isRechargeable").toBool(); |
22 | } | |
23 | ||
24 | +bool FakeBattery::isPowerSupply() const | |
25 | +{ | |
26 | + return fakeDevice()->property("isPowerSupply").toBool(); | |
27 | +} | |
28 | + | |
29 | Solid::Battery::ChargeState FakeBattery::chargeState() const | |
30 | { | |
31 | QString state = fakeDevice()->property("chargeState").toString(); | |
f5bb7afb AM |
32 | diff --git a/solid/solid/backends/fakehw/fakebattery.h b/solid/solid/backends/fakehw/fakebattery.h |
33 | index c7e2791..f832a1a 100644 | |
3901abf5 AM |
34 | --- a/solid/solid/backends/fakehw/fakebattery.h |
35 | +++ b/solid/solid/backends/fakehw/fakebattery.h | |
f5bb7afb AM |
36 | @@ -44,8 +44,10 @@ public Q_SLOTS: |
37 | virtual Solid::Battery::BatteryType type() const; | |
38 | ||
3901abf5 | 39 | virtual int chargePercent() const; |
f5bb7afb | 40 | + virtual int capacity() const; |
3901abf5 AM |
41 | |
42 | virtual bool isRechargeable() const; | |
43 | + virtual bool isPowerSupply() const; | |
44 | virtual Solid::Battery::ChargeState chargeState() const; | |
45 | ||
46 | void setChargeState(Solid::Battery::ChargeState newState); | |
f5bb7afb AM |
47 | diff --git a/solid/solid/backends/fakehw/fakecomputer.xml b/solid/solid/backends/fakehw/fakecomputer.xml |
48 | index fe7e323..f33a32b 100644 | |
3901abf5 AM |
49 | --- a/solid/solid/backends/fakehw/fakecomputer.xml |
50 | +++ b/solid/solid/backends/fakehw/fakecomputer.xml | |
51 | @@ -32,9 +32,22 @@ | |
52 | <property key="voltageUnit">mV</property> | |
53 | <property key="voltage">11999</property> | |
54 | <property key="isRechargeable">true</property> | |
55 | + <property key="isPowerSupply">true</property> | |
f5bb7afb AM |
56 | + <property key="chargeState">discharging</property> |
57 | + </device> | |
3901abf5 AM |
58 | + <device udi="/org/kde/solid/fakehw/acpi_BAT1"> |
59 | + <property key="name">Miraculous Mouse</property> | |
60 | + <property key="vendor">Orange Inc.</property> | |
61 | + <property key="interfaces">Battery</property> | |
62 | + <property key="parent">/org/kde/solid/fakehw/computer</property> | |
63 | + <property key="isPluged">false</property> | |
64 | + <property key="batteryType">mouse</property> | |
65 | + <!-- Battery properties beyond charge percentage are only reported by UPower | |
66 | + for primary batteries, not for other batteries like this mouse --> | |
67 | + <property key="isRechargeable">true</property> | |
68 | + <property key="isPowerSupply">true</property> | |
f5bb7afb AM |
69 | <property key="chargeState">discharging</property> |
70 | </device> | |
71 | - | |
3901abf5 AM |
72 | |
73 | ||
74 | <!-- So that it looks like a laptop, | |
f5bb7afb AM |
75 | diff --git a/solid/solid/backends/hal/halbattery.cpp b/solid/solid/backends/hal/halbattery.cpp |
76 | index 4c530da..14de035 100644 | |
3901abf5 AM |
77 | --- a/solid/solid/backends/hal/halbattery.cpp |
78 | +++ b/solid/solid/backends/hal/halbattery.cpp | |
f5bb7afb AM |
79 | @@ -83,11 +83,30 @@ int Battery::chargePercent() const |
80 | return m_device->prop("battery.charge_level.percentage").toInt(); | |
81 | } | |
82 | ||
83 | +int Battery::capacity() const | |
84 | +{ | |
85 | + const qreal lastFull = m_device->prop("battery.charge_level.last_full").toDouble(); | |
86 | + const qreal designFull = m_device->prop("battery.charge_level.design").toDouble(); | |
87 | + | |
88 | + return lastFull / designFull; | |
89 | +} | |
90 | + | |
91 | bool Battery::isRechargeable() const | |
92 | { | |
3901abf5 AM |
93 | return m_device->prop("battery.is_rechargeable").toBool(); |
94 | } | |
95 | ||
96 | +bool Battery::isPowerSupply() const | |
97 | +{ | |
98 | + // NOTE Hal doesn't support the is power supply property, so we're assuming that primary | |
99 | + // and UPS batteries are power supply and all the others are not | |
100 | + if (type() == Solid::Battery::PrimaryBattery || type() == Solid::Battery::UpsBattery) { | |
101 | + return true; | |
102 | + } | |
103 | + | |
104 | + return false; | |
105 | +} | |
106 | + | |
107 | Solid::Battery::ChargeState Battery::chargeState() const | |
108 | { | |
109 | bool charging = m_device->prop("battery.rechargeable.is_charging").toBool(); | |
f5bb7afb AM |
110 | @@ -114,6 +133,12 @@ void Battery::slotPropertyChanged(const QMap<QString,int> &changes) |
111 | emit chargePercentChanged(chargePercent(), m_device->udi()); | |
112 | } | |
113 | ||
114 | + if (changes.contains("battery.charge_level.last_full") | |
115 | + || changes.contains("battery.charge_level.design")) | |
116 | + { | |
117 | + emit capacityChanged(capacity(), m_device->udi()); | |
118 | + } | |
119 | + | |
120 | if (changes.contains("battery.rechargeable.is_charging") | |
121 | || changes.contains("battery.rechargeable.is_discharging")) | |
122 | { | |
123 | diff --git a/solid/solid/backends/hal/halbattery.h b/solid/solid/backends/hal/halbattery.h | |
124 | index e2f38a0..7160e3a 100644 | |
3901abf5 AM |
125 | --- a/solid/solid/backends/hal/halbattery.h |
126 | +++ b/solid/solid/backends/hal/halbattery.h | |
f5bb7afb AM |
127 | @@ -43,14 +43,18 @@ public: |
128 | virtual Solid::Battery::BatteryType type() const; | |
129 | ||
3901abf5 | 130 | virtual int chargePercent() const; |
f5bb7afb | 131 | + virtual int capacity() const; |
3901abf5 AM |
132 | |
133 | virtual bool isRechargeable() const; | |
134 | + virtual bool isPowerSupply() const; | |
135 | virtual Solid::Battery::ChargeState chargeState() const; | |
136 | ||
137 | Q_SIGNALS: | |
138 | void chargePercentChanged(int value, const QString &udi); | |
f5bb7afb | 139 | + void capacityChanged(int value, const QString &udi); |
3901abf5 AM |
140 | void chargeStateChanged(int newState, const QString &udi); |
141 | void plugStateChanged(bool newState, const QString &udi); | |
142 | + void powerSupplyStateChanged(bool newState, const QString &udi); // dummy | |
143 | ||
144 | private Q_SLOTS: | |
145 | void slotPropertyChanged(const QMap<QString,int> &changes); | |
f5bb7afb AM |
146 | diff --git a/solid/solid/backends/upower/upowerbattery.cpp b/solid/solid/backends/upower/upowerbattery.cpp |
147 | index 1a40a2a..7b5bdc4 100644 | |
3901abf5 AM |
148 | --- a/solid/solid/backends/upower/upowerbattery.cpp |
149 | +++ b/solid/solid/backends/upower/upowerbattery.cpp | |
f5bb7afb AM |
150 | @@ -78,11 +78,21 @@ int Battery::chargePercent() const |
151 | return qRound(m_device.data()->prop("Percentage").toDouble()); | |
152 | } | |
153 | ||
154 | +int Battery::capacity() const | |
155 | +{ | |
156 | + return m_device.data()->prop("Capacity").toDouble(); | |
157 | +} | |
158 | + | |
159 | bool Battery::isRechargeable() const | |
160 | { | |
3901abf5 AM |
161 | return m_device.data()->prop("IsRechargeable").toBool(); |
162 | } | |
163 | ||
164 | +bool Battery::isPowerSupply() const | |
165 | +{ | |
166 | + return m_device.data()->prop("PowerSupply").toBool(); | |
167 | +} | |
168 | + | |
169 | Solid::Battery::ChargeState Battery::chargeState() const | |
170 | { | |
171 | Solid::Battery::ChargeState result = Solid::Battery::NoCharge; | |
f5bb7afb AM |
172 | @@ -113,9 +123,11 @@ Solid::Battery::ChargeState Battery::chargeState() const |
173 | void Battery::slotChanged() | |
174 | { | |
175 | if (m_device) { | |
176 | - const bool old_isPlugged = m_isPlugged; | |
3901abf5 | 177 | const int old_chargePercent = m_chargePercent; |
f5bb7afb | 178 | + const int old_capacity = m_capacity; |
3901abf5 | 179 | const Solid::Battery::ChargeState old_chargeState = m_chargeState; |
f5bb7afb | 180 | + const bool old_isPlugged = m_isPlugged; |
3901abf5 AM |
181 | + const bool old_isPowerSupply = m_isPowerSupply; |
182 | updateCache(); | |
183 | ||
184 | if (old_chargePercent != m_chargePercent) | |
f5bb7afb AM |
185 | @@ -123,6 +135,10 @@ void Battery::slotChanged() |
186 | emit chargePercentChanged(m_chargePercent, m_device.data()->udi()); | |
187 | } | |
188 | ||
189 | + if (old_capacity != m_capacity) { | |
190 | + emit capacityChanged(m_capacity, m_device.data()->udi()); | |
191 | + } | |
192 | + | |
193 | if (old_chargeState != m_chargeState) | |
194 | { | |
195 | emit chargeStateChanged(m_chargeState, m_device.data()->udi()); | |
196 | @@ -132,6 +148,11 @@ void Battery::slotChanged() | |
3901abf5 AM |
197 | { |
198 | emit plugStateChanged(m_isPlugged, m_device.data()->udi()); | |
199 | } | |
200 | + | |
201 | + if (old_isPowerSupply != m_isPowerSupply) | |
202 | + { | |
203 | + emit powerSupplyStateChanged(m_isPowerSupply, m_device.data()->udi()); | |
204 | + } | |
205 | } | |
206 | } | |
207 | ||
f5bb7afb AM |
208 | @@ -139,7 +160,9 @@ void Battery::updateCache() |
209 | { | |
3901abf5 AM |
210 | m_isPlugged = isPlugged(); |
211 | m_chargePercent = chargePercent(); | |
f5bb7afb | 212 | + m_capacity = capacity(); |
3901abf5 AM |
213 | m_chargeState = chargeState(); |
214 | + m_isPowerSupply = isPowerSupply(); | |
215 | } | |
216 | ||
217 | #include "backends/upower/upowerbattery.moc" | |
f5bb7afb AM |
218 | diff --git a/solid/solid/backends/upower/upowerbattery.h b/solid/solid/backends/upower/upowerbattery.h |
219 | index 9d52f7b..3f589ce 100644 | |
3901abf5 AM |
220 | --- a/solid/solid/backends/upower/upowerbattery.h |
221 | +++ b/solid/solid/backends/upower/upowerbattery.h | |
f5bb7afb AM |
222 | @@ -44,16 +44,21 @@ public: |
223 | virtual Solid::Battery::BatteryType type() const; | |
224 | ||
3901abf5 | 225 | virtual int chargePercent() const; |
f5bb7afb | 226 | + virtual int capacity() const; |
3901abf5 AM |
227 | |
228 | virtual bool isRechargeable() const; | |
229 | + virtual bool isPowerSupply() const; | |
f5bb7afb | 230 | + |
3901abf5 AM |
231 | virtual Solid::Battery::ChargeState chargeState() const; |
232 | ||
f5bb7afb AM |
233 | - // TODO report stuff like capacity, technology, time-to-full, time-to-empty, energy rates, vendor, etc. |
234 | + // TODO report stuff like technology, time-to-full, time-to-empty, energy rates, vendor, etc. | |
235 | ||
236 | Q_SIGNALS: | |
3901abf5 | 237 | void chargePercentChanged(int value, const QString &udi); |
f5bb7afb | 238 | + void capacityChanged(int value, const QString &udi); |
3901abf5 AM |
239 | void chargeStateChanged(int newState, const QString &udi); |
240 | void plugStateChanged(bool newState, const QString &udi); | |
241 | + void powerSupplyStateChanged(bool newState, const QString &udi); | |
242 | ||
243 | private Q_SLOTS: | |
244 | void slotChanged(); | |
f5bb7afb AM |
245 | @@ -63,7 +68,9 @@ private: |
246 | ||
3901abf5 AM |
247 | bool m_isPlugged; |
248 | int m_chargePercent; | |
f5bb7afb | 249 | + int m_capacity; |
3901abf5 AM |
250 | Solid::Battery::ChargeState m_chargeState; |
251 | + bool m_isPowerSupply; | |
252 | }; | |
253 | } | |
254 | } | |
f5bb7afb AM |
255 | diff --git a/solid/solid/backends/upower/upowerdevice.cpp b/solid/solid/backends/upower/upowerdevice.cpp |
256 | index 4930053..43e7060 100644 | |
3901abf5 AM |
257 | --- a/solid/solid/backends/upower/upowerdevice.cpp |
258 | +++ b/solid/solid/backends/upower/upowerdevice.cpp | |
f5bb7afb | 259 | @@ -83,7 +83,7 @@ bool UPowerDevice::queryDeviceInterface(const Solid::DeviceInterface::Type& type |
3901abf5 AM |
260 | case Solid::DeviceInterface::GenericInterface: |
261 | return true; | |
262 | case Solid::DeviceInterface::Battery: | |
263 | - return (uptype == 2 || uptype == 3 || uptype == 5 || uptype == 6); | |
264 | + return (uptype == 2 || uptype == 3 || uptype == 5 || uptype == 6 || uptype == 7 || uptype == 8); | |
265 | case Solid::DeviceInterface::AcAdapter: | |
266 | return (uptype == 1); | |
267 | default: | |
f5bb7afb AM |
268 | diff --git a/solid/solid/battery.cpp b/solid/solid/battery.cpp |
269 | index 37d7321..f8e2048 100644 | |
3901abf5 AM |
270 | --- a/solid/solid/battery.cpp |
271 | +++ b/solid/solid/battery.cpp | |
f5bb7afb AM |
272 | @@ -30,11 +30,17 @@ Solid::Battery::Battery(QObject *backendObject) |
273 | connect(backendObject, SIGNAL(chargePercentChanged(int,QString)), | |
274 | this, SIGNAL(chargePercentChanged(int,QString))); | |
3901abf5 | 275 | |
f5bb7afb AM |
276 | + connect(backendObject, SIGNAL(capacityChanged(int,QString)), |
277 | + this, SIGNAL(capacityChanged(int,QString))); | |
3901abf5 | 278 | + |
f5bb7afb AM |
279 | connect(backendObject, SIGNAL(chargeStateChanged(int,QString)), |
280 | this, SIGNAL(chargeStateChanged(int,QString))); | |
85ed91f4 AM |
281 | |
282 | connect(backendObject, SIGNAL(plugStateChanged(bool,QString)), | |
283 | this, SIGNAL(plugStateChanged(bool,QString))); | |
284 | + | |
285 | + connect(backendObject, SIGNAL(powerSupplyStateChanged(bool,QString)), | |
286 | + this, SIGNAL(powerSupplyStateChanged(bool,QString))); | |
287 | } | |
288 | ||
289 | Solid::Battery::~Battery() | |
f5bb7afb AM |
290 | @@ -48,6 +54,12 @@ bool Solid::Battery::isPlugged() const |
291 | return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), false, isPlugged()); | |
85ed91f4 AM |
292 | } |
293 | ||
f5bb7afb | 294 | +bool Solid::Battery::isPowerSupply() const |
85ed91f4 | 295 | +{ |
f5bb7afb AM |
296 | + Q_D(const Battery); |
297 | + return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), true, isPowerSupply()); | |
85ed91f4 AM |
298 | +} |
299 | + | |
f5bb7afb | 300 | Solid::Battery::BatteryType Solid::Battery::type() const |
85ed91f4 | 301 | { |
f5bb7afb AM |
302 | Q_D(const Battery); |
303 | @@ -60,6 +72,12 @@ int Solid::Battery::chargePercent() const | |
85ed91f4 AM |
304 | return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), 0, chargePercent()); |
305 | } | |
306 | ||
307 | +int Solid::Battery::capacity() const | |
308 | +{ | |
309 | + Q_D(const Battery); | |
310 | + return_SOLID_CALL(Ifaces::Battery *, d->backendObject(), 100, capacity()); | |
311 | +} | |
312 | + | |
313 | bool Solid::Battery::isRechargeable() const | |
314 | { | |
315 | Q_D(const Battery); | |
f5bb7afb AM |
316 | diff --git a/solid/solid/battery.h b/solid/solid/battery.h |
317 | index 3afac6f..4ee7f69 100644 | |
85ed91f4 AM |
318 | --- a/solid/solid/battery.h |
319 | +++ b/solid/solid/battery.h | |
f5bb7afb AM |
320 | @@ -38,8 +38,10 @@ namespace Solid |
321 | Q_OBJECT | |
322 | Q_ENUMS(BatteryType ChargeState) | |
323 | Q_PROPERTY(bool plugged READ isPlugged) | |
324 | + Q_PROPERTY(bool powerSupply READ isPowerSupply) | |
85ed91f4 AM |
325 | Q_PROPERTY(BatteryType type READ type) |
326 | Q_PROPERTY(int chargePercent READ chargePercent) | |
327 | + Q_PROPERTY(int capacity READ capacity) | |
328 | Q_PROPERTY(bool rechargeable READ isRechargeable) | |
329 | Q_PROPERTY(ChargeState chargeState READ chargeState) | |
330 | Q_DECLARE_PRIVATE(Battery) | |
f5bb7afb AM |
331 | @@ -110,6 +112,14 @@ namespace Solid |
332 | bool isPlugged() const; | |
333 | ||
334 | /** | |
335 | + * Indicates if this battery is powering the machine or from an attached deviced. | |
336 | + * | |
337 | + * @since 4.11 | |
338 | + * @return true the battery is a powersupply, false otherwise | |
339 | + */ | |
340 | + bool isPowerSupply() const; | |
341 | + | |
342 | + /** | |
343 | * Retrieves the type of device holding this battery. | |
344 | * | |
345 | * @return the type of device holding this battery | |
346 | @@ -127,6 +137,14 @@ namespace Solid | |
85ed91f4 AM |
347 | */ |
348 | int chargePercent() const; | |
349 | ||
350 | + /** | |
351 | + * Retrieves the battery capacity normalised to percent, | |
352 | + * meaning how much energy can it hold compared to what it is designed to. | |
353 | + * | |
354 | + * @since 4.11 | |
355 | + * @return the battery capacity normalised to percent | |
356 | + */ | |
357 | + int capacity() const; | |
358 | ||
359 | ||
360 | /** | |
f5bb7afb AM |
361 | diff --git a/solid/solid/ifaces/battery.h b/solid/solid/ifaces/battery.h |
362 | index 9987d18..3158478 100644 | |
85ed91f4 AM |
363 | --- a/solid/solid/ifaces/battery.h |
364 | +++ b/solid/solid/ifaces/battery.h | |
f5bb7afb | 365 | @@ -66,6 +66,15 @@ namespace Ifaces |
85ed91f4 AM |
366 | */ |
367 | virtual int chargePercent() const = 0; | |
368 | ||
369 | + /** | |
370 | + * Retrieves the battery capacity normalised to percent, | |
371 | + * meaning how much energy can it hold compared to what it is designed to. | |
372 | + * | |
373 | + * @since 4.11 | |
374 | + * @return the battery capacity normalised to percent | |
375 | + */ | |
376 | + virtual int capacity() const = 0; | |
377 | + | |
378 | ||
379 | /** | |
380 | * Indicates if the battery is rechargeable. | |
f5bb7afb AM |
381 | @@ -75,6 +84,13 @@ namespace Ifaces |
382 | virtual bool isRechargeable() const = 0; | |
383 | ||
384 | /** | |
385 | + * Indicates if the battery is powering the machine. | |
386 | + * | |
387 | + * @return true if the battery is powersupply, false otherwise | |
388 | + */ | |
389 | + virtual bool isPowerSupply() const = 0; | |
390 | + | |
391 | + /** | |
392 | * Retrieves the current charge state of the battery. It can be in a stable | |
393 | * state (no charge), charging or discharging. | |
394 | * |