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

KDE's Doxygen guidelines are available online.