Solid

frontend/battery.h
1/*
2 SPDX-FileCopyrightText: 2006-2007 Kevin Ottens <ervin@kde.org>
3 SPDX-FileCopyrightText: 2012 Lukas Tinkl <ltinkl@redhat.com>
4 SPDX-FileCopyrightText: 2014 Kai Uwe Broulik <kde@privat.broulik.de>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#ifndef SOLID_BATTERY_H
10#define SOLID_BATTERY_H
11
12#include <solid/solid_export.h>
13
14#include <solid/deviceinterface.h>
15
16namespace Solid
17{
18class BatteryPrivate;
19class Device;
20
21/**
22 * This device interface is available on batteries.
23 */
24class SOLID_EXPORT Battery : public DeviceInterface
25{
26 Q_OBJECT
27 Q_PROPERTY(bool present READ isPresent NOTIFY presentStateChanged)
28 Q_PROPERTY(BatteryType type READ type CONSTANT)
29 Q_PROPERTY(int chargePercent READ chargePercent NOTIFY chargePercentChanged)
30 Q_PROPERTY(int capacity READ capacity NOTIFY capacityChanged)
31 Q_PROPERTY(int cycleCount READ cycleCount NOTIFY cycleCountChanged)
32 Q_PROPERTY(bool rechargeable READ isRechargeable CONSTANT)
33 Q_PROPERTY(bool powerSupply READ isPowerSupply NOTIFY powerSupplyStateChanged)
34 Q_PROPERTY(ChargeState chargeState READ chargeState NOTIFY chargeStateChanged)
35 Q_PROPERTY(qlonglong timeToEmpty READ timeToEmpty NOTIFY timeToEmptyChanged)
36 Q_PROPERTY(qlonglong timeToFull READ timeToFull NOTIFY timeToFullChanged)
37 Q_PROPERTY(double energy READ energy NOTIFY energyChanged)
38 Q_PROPERTY(double energyFull READ energyFull NOTIFY energyFullChanged)
39 Q_PROPERTY(double energyFullDesign READ energyFullDesign NOTIFY energyFullDesignChanged)
40 Q_PROPERTY(double energyRate READ energyRate NOTIFY energyRateChanged)
41 Q_PROPERTY(double voltage READ voltage NOTIFY voltageChanged)
42 Q_PROPERTY(double temperature READ temperature NOTIFY temperatureChanged)
43 Q_PROPERTY(Technology technology READ technology CONSTANT)
44 Q_PROPERTY(QString serial READ serial CONSTANT)
45 Q_PROPERTY(qlonglong remainingTime READ remainingTime NOTIFY remainingTimeChanged)
46 Q_DECLARE_PRIVATE(Battery)
47 friend class Device;
48
49public:
50 /**
51 * This enum type defines the type of the device holding the battery
52 *
53 * - PdaBattery : A battery in a Personal Digital Assistant
54 * - UpsBattery : A battery in an Uninterruptible Power Supply
55 * - PrimaryBattery : A primary battery for the system (for example laptop battery)
56 * - MouseBattery : A battery in a mouse
57 * - KeyboardBattery : A battery in a keyboard
58 * - KeyboardMouseBattery : A battery in a combined keyboard and mouse
59 * - CameraBattery : A battery in a camera
60 * - PhoneBattery : A battery in a phone
61 * - MonitorBattery : A battery in a monitor
62 * - GamingInputBattery : A battery in a gaming input device (for example a wireless game pad)
63 * - BluetoothBattery: A generic Bluetooth device battery (if its type isn't known, a Bluetooth
64 * mouse would normally show up as a MouseBattery), @since 5.54
65 * - TabletBattery : A battery in a graphics tablet or pen, @since 5.88
66 * - HeadphoneBattery : A battery in a headphone, @since 6.0
67 * - HeadsetBattery : A battery in a headset, @since 6.0
68 * - TouchpadBattery : A battery in a touchpad. This is how the Dualsense Wireless Controller is categorized @since 6.0
69 * - UnknownBattery : A battery in an unknown device
70 */
72 UnknownBattery,
73 PdaBattery,
74 UpsBattery,
75 PrimaryBattery,
76 MouseBattery,
77 KeyboardBattery,
78 KeyboardMouseBattery,
79 CameraBattery,
80 PhoneBattery,
81 MonitorBattery,
82 GamingInputBattery,
83 BluetoothBattery,
84 TabletBattery,
85 HeadphoneBattery,
86 HeadsetBattery,
87 TouchpadBattery,
88 };
89 Q_ENUM(BatteryType)
90
91 /**
92 * This enum type defines charge state of a battery
93 *
94 * - NoCharge : Battery charge is stable, not charging or discharging or
95 * the state is Unknown
96 * - Charging : Battery is charging
97 * - Discharging : Battery is discharging
98 * - FullyCharged: The battery is fully charged; a battery not necessarily
99 * charges up to 100%
100 */
101 enum ChargeState { NoCharge, Charging, Discharging, FullyCharged };
102 Q_ENUM(ChargeState)
103
104 /**
105 * Technology used in the battery
106 *
107 * 0: Unknown
108 * 1: Lithium ion
109 * 2: Lithium polymer
110 * 3: Lithium iron phosphate
111 * 4: Lead acid
112 * 5: Nickel cadmium
113 * 6: Nickel metal hydride
114 */
116 UnknownTechnology = 0,
117 LithiumIon,
118 LithiumPolymer,
119 LithiumIronPhosphate,
120 LeadAcid,
121 NickelCadmium,
122 NickelMetalHydride,
123 };
124 Q_ENUM(Technology)
125
126private:
127 /**
128 * Creates a new Battery object.
129 * You generally won't need this. It's created when necessary using
130 * Device::as().
131 *
132 * @param backendObject the device interface object provided by the backend
133 * @see Solid::Device::as()
134 */
135 SOLID_NO_EXPORT explicit Battery(QObject *backendObject);
136
137public:
138 /**
139 * Destroys a Battery object.
140 */
141 ~Battery() override;
142
143 /**
144 * Get the Solid::DeviceInterface::Type of the Battery device interface.
145 *
146 * @return the Battery device interface type
147 * @see Solid::DeviceInterface::Type
148 */
150 {
151 return DeviceInterface::Battery;
152 }
153
154 /**
155 * Indicates if this battery is currently present in its bay.
156 *
157 * @return true if the battery is present, false otherwise
158 */
159 bool isPresent() const;
160
161 /**
162 * Retrieves the type of device holding this battery.
163 *
164 * @return the type of device holding this battery
165 * @see Solid::Battery::BatteryType
166 */
167 Solid::Battery::BatteryType type() const;
168
169 /**
170 * Retrieves the current charge level of the battery normalised
171 * to percent.
172 *
173 * @return the current charge level normalised to percent
174 */
175 int chargePercent() const;
176
177 /**
178 * Retrieves the battery capacity normalised to percent,
179 * meaning how much energy can it hold compared to what it is designed to.
180 * The capacity of the battery will reduce with age.
181 * A capacity value less than 75% is usually a sign that you should renew your battery.
182 *
183 * @since 4.11
184 * @return the battery capacity normalised to percent
185 */
186 int capacity() const;
187
188 /**
189 * Retrieves the number of charge cycles this battery has experienced so far,
190 * or -1 if this information is unavailable.
191 *
192 * @since 6.9
193 * @return the number of charge cycles
194 */
195 int cycleCount() const;
196
197 /**
198 * Indicates if the battery is rechargeable.
199 *
200 * @return true if the battery is rechargeable, false otherwise (one time usage)
201 */
202 bool isRechargeable() const;
203
204 /**
205 * Indicates if the battery is powering the machine.
206 *
207 * @return true if the battery is powersupply, false otherwise
208 */
209 bool isPowerSupply() const;
210
211 /**
212 * Retrieves the current charge state of the battery. It can be in a stable
213 * state (no charge), charging or discharging.
214 *
215 * @return the current battery charge state
216 * @see Solid::Battery::ChargeState
217 */
218 Solid::Battery::ChargeState chargeState() const;
219
220 /**
221 * Time (in seconds) until the battery is empty.
222 *
223 * @return time until the battery is empty
224 * @since 5.0
225 */
226 qlonglong timeToEmpty() const;
227
228 /**
229 * Time (in seconds) until the battery is full.
230 *
231 * @return time until the battery is full
232 * @since 5.0
233 */
234 qlonglong timeToFull() const;
235
236 /**
237 * Retrieves the technology used to manufacture the battery.
238 *
239 * @return the battery technology
240 * @see Solid::Battery::Technology
241 */
242 Solid::Battery::Technology technology() const;
243
244 /**
245 * Amount of energy (measured in Wh) currently available in the power source.
246 *
247 * @return amount of battery energy in Wh
248 */
249 double energy() const;
250
251 /**
252 * Amount of energy (measured in Wh) the battery has when it is full.
253 *
254 * @return amount of battery energy when full in Wh
255 * @since 5.7
256 */
257 double energyFull() const;
258
259 /**
260 * Amount of energy (measured in Wh) the battery should have by design hen it is full.
261 *
262 * @return amount of battery energy when full by design in Wh
263 * @since 5.7
264 */
265 double energyFullDesign() const;
266
267 /**
268 * Amount of energy being drained from the source, measured in W.
269 * If positive, the source is being discharged, if negative it's being charged.
270 *
271 * @return battery rate in Watts
272 *
273 */
274 double energyRate() const;
275
276 /**
277 * Voltage in the Cell or being recorded by the meter.
278 *
279 * @return voltage in Volts
280 */
281 double voltage() const;
282
283 /**
284 * The temperature of the battery in degrees Celsius.
285 *
286 * @return the battery temperature in degrees Celsius
287 * @since 5.0
288 */
289 double temperature() const;
290
291 /**
292 * The serial number of the battery
293 *
294 * @return the serial number of the battery
295 * @since 5.0
296 */
297 QString serial() const;
298
299 /**
300 * Retrieves the current estimated remaining time of the system batteries
301 *
302 * @return the current global estimated remaining time in seconds
303 * @since 5.8
304 */
305 qlonglong remainingTime() const;
306
307Q_SIGNALS:
308 /**
309 * This signal is emitted if the battery gets plugged in/out of the
310 * battery bay.
311 *
312 * @param newState the new plugging state of the battery, type is boolean
313 * @param udi the UDI of the battery with thew new plugging state
314 */
315 void presentStateChanged(bool newState, const QString &udi);
316
317 /**
318 * This signal is emitted when the charge percent value of this
319 * battery has changed.
320 *
321 * @param value the new charge percent value of the battery
322 * @param udi the UDI of the battery with the new charge percent
323 */
324 void chargePercentChanged(int value, const QString &udi);
325
326 /**
327 * This signal is emitted when the capacity of this battery has changed.
328 *
329 * @param value the new capacity of the battery
330 * @param udi the UDI of the battery with the new capacity
331 * @since 4.11
332 */
333 void capacityChanged(int value, const QString &udi);
334
335 /**
336 * This signal is emitted when the number of charge cycles of the
337 * battery has changed.
338 *
339 * @param value the new number of charge cycles of the battery
340 * @param udi the UDI of the battery with the new number of charge cycles
341 * @since 6.9
342 */
343 void cycleCountChanged(int value, const QString &udi);
344
345 /**
346 * This signal is emitted when the power supply state of the battery
347 * changes.
348 *
349 * @param newState the new power supply state, type is boolean
350 * @param udi the UDI of the battery with the new power supply state
351 * @since 4.11
352 */
353 void powerSupplyStateChanged(bool newState, const QString &udi);
354
355 /**
356 * This signal is emitted when the charge state of this battery
357 * has changed.
358 *
359 * @param newState the new charge state of the battery, it's one of
360 * the type Solid::Battery::ChargeState
361 * @see Solid::Battery::ChargeState
362 * @param udi the UDI of the battery with the new charge state
363 */
364 void chargeStateChanged(int newState, const QString &udi = QString());
365
366 /**
367 * This signal is emitted when the time until the battery is empty
368 * has changed.
369 *
370 * @param time the new remaining time
371 * @param udi the UDI of the battery with the new remaining time
372 * @since 5.0
373 */
374 void timeToEmptyChanged(qlonglong time, const QString &udi);
375
376 /**
377 * This signal is emitted when the time until the battery is full
378 * has changed.
379 *
380 * @param time the new remaining time
381 * @param udi the UDI of the battery with the new remaining time
382 * @since 5.0
383 */
384 void timeToFullChanged(qlonglong time, const QString &udi);
385
386 /**
387 * This signal is emitted when the energy value of this
388 * battery has changed.
389 *
390 * @param energy the new energy value of the battery
391 * @param udi the UDI of the battery with the new energy value
392 */
393 void energyChanged(double energy, const QString &udi);
394
395 /**
396 * This signal is emitted when the energy full value of this
397 * battery has changed.
398 *
399 * @param energy the new energy full value of the battery
400 * @param udi the UDI of the battery with the new energy full value
401 */
402 void energyFullChanged(double energy, const QString &udi);
403
404 /**
405 * This signal is emitted when the energy full design value of this
406 * battery has changed.
407 *
408 * @param energy the new energy full design value of the battery
409 * @param udi the UDI of the battery with the new energy full design value
410 */
411 void energyFullDesignChanged(double energy, const QString &udi);
412
413 /**
414 * This signal is emitted when the energy rate value of this
415 * battery has changed.
416 *
417 * If positive, the source is being discharged, if negative it's being charged.
418 *
419 * @param energyRate the new energy rate value of the battery
420 * @param udi the UDI of the battery with the new charge percent
421 */
422 void energyRateChanged(double energyRate, const QString &udi);
423
424 /**
425 * This signal is emitted when the voltage in the cell has changed.
426 *
427 * @param voltage the new voltage of the cell
428 * @param udi the UDI of the battery with the new voltage
429 * @since 5.0
430 */
431 void voltageChanged(double voltage, const QString &udi);
432
433 /**
434 * This signal is emitted when the battery temperature has changed.
435 *
436 * @param temperature the new temperature of the battery in degrees Celsius
437 * @param udi the UDI of the battery with the new temperature
438 * @since 5.0
439 */
440 void temperatureChanged(double temperature, const QString &udi);
441
442 /**
443 * This signal is emitted when the estimated battery remaining time changes.
444 *
445 * @param time the new remaining time
446 * @param udi the UDI of the battery with the new remaining time
447 * @since 5.8
448 */
449 void remainingTimeChanged(qlonglong time, const QString &udi);
450};
451}
452
453#endif
This device interface is available on batteries.
void temperatureChanged(double temperature, const QString &udi)
This signal is emitted when the battery temperature has changed.
void energyChanged(double energy, const QString &udi)
This signal is emitted when the energy value of this battery has changed.
void energyRateChanged(double energyRate, const QString &udi)
This signal is emitted when the energy rate value of this battery has changed.
BatteryType
This enum type defines the type of the device holding the battery.
void capacityChanged(int value, const QString &udi)
This signal is emitted when the capacity of this battery has changed.
void energyFullDesignChanged(double energy, const QString &udi)
This signal is emitted when the energy full design value of this battery has changed.
Technology
Technology used in the battery.
void timeToEmptyChanged(qlonglong time, const QString &udi)
This signal is emitted when the time until the battery is empty has changed.
void energyFullChanged(double energy, const QString &udi)
This signal is emitted when the energy full value of this battery has changed.
void cycleCountChanged(int value, const QString &udi)
This signal is emitted when the number of charge cycles of the battery has changed.
void powerSupplyStateChanged(bool newState, const QString &udi)
This signal is emitted when the power supply state of the battery changes.
void presentStateChanged(bool newState, const QString &udi)
This signal is emitted if the battery gets plugged in/out of the battery bay.
void timeToFullChanged(qlonglong time, const QString &udi)
This signal is emitted when the time until the battery is full has changed.
void remainingTimeChanged(qlonglong time, const QString &udi)
This signal is emitted when the estimated battery remaining time changes.
void chargePercentChanged(int value, const QString &udi)
This signal is emitted when the charge percent value of this battery has changed.
void chargeStateChanged(int newState, const QString &udi=QString())
This signal is emitted when the charge state of this battery has changed.
ChargeState
This enum type defines charge state of a battery.
static Type deviceInterfaceType()
Get the Solid::DeviceInterface::Type of the Battery device interface.
void voltageChanged(double voltage, const QString &udi)
This signal is emitted when the voltage in the cell has changed.
Base class of all the device interfaces.
Type
This enum type defines the type of device interface that a Device can have.
This class allows applications to deal with devices available in the underlying system.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:23 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.