1
/***************************************************************************
2
* Copyright (C) 2010 by Dario Freddi <drf@kde.org> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18
***************************************************************************/
21
#ifndef POWERDEVIL_BACKENDINTERFACE_H
22
#define POWERDEVIL_BACKENDINTERFACE_H
24
#include <QtCore/QObject>
25
#include <QtCore/QHash>
27
#include <kdemacros.h>
31
namespace PowerDevil {
33
class KDE_EXPORT BackendInterface : public QObject
36
Q_DISABLE_COPY(BackendInterface)
39
explicit BackendInterface(QObject* parent = 0);
40
virtual ~BackendInterface();
43
* This enum type defines the different states of the system battery.
45
* - NoBatteryState: No battery available
46
* - Normal: The battery is at its normal charge level
47
* - Warning: The battery is at its warning charge level
48
* - Low: The battery is at its low charge level
49
* - Critical: The battery is at its critical charge level
51
enum BatteryState{ NoBatteryState, Normal, Warning, Low, Critical };
54
* This enum type defines the different states of the AC adapter.
56
* - UnknownAcAdapterState: The AC adapter has an unknown state
57
* - Plugged: The AC adapter is plugged
58
* - Unplugged: The AC adapter is unplugged
60
enum AcAdapterState{ UnknownAcAdapterState, Plugged, Unplugged };
63
* This enum type defines the types of system button events.
65
* - UnknownButtonType: An unknown button
66
* - PowerButton: A power button pressed event, generally used to turn on or off the system
67
* - SleepButton: A sleep button pressed event, generally used to make the system asleep
68
* - LidOpen: A laptop lid open event
69
* - LidClose: A laptop lid close event
71
enum ButtonType{ UnknownButtonType, PowerButton, SleepButton, LidOpen, LidClose };
74
* This enum type defines the different suspend methods.
76
* - UnknownSuspendMethod: The name says it all
77
* - Standby: Processes are stopped, some hardware is deactivated (ACPI S1)
78
* - ToRam: Most devices are deactivated, only RAM is powered (ACPI S3)
79
* - ToDisk: State of the machine is saved to disk, and it's powered down (ACPI S4)
81
enum SuspendMethod{ UnknownSuspendMethod = 0, Standby = 1, ToRam = 2, ToDisk = 4, HybridSuspend = 8 };
84
* This type stores an OR combination of SuspendMethod values.
86
Q_DECLARE_FLAGS(SuspendMethods, SuspendMethod)
89
* This enum defines the different types of brightness controls.
91
* - UnknownBrightnessControl: Unknown
92
* - Screen: Brightness control for a monitor or laptop panel
93
* - Keyboard: Brightness control for a keyboard backlight
95
enum BrightnessControlType{ UnknownBrightnessControl = 0, Screen = 1, Keyboard = 2 };
97
typedef QHash<QString, BrightnessControlType> BrightnessControlsList;
100
* This enum defines the different types brightness keys.
102
* - Increase: Key to increase brightness (Qt::Key_MonBrightnessUp)
103
* - Decrease: Key to decrease brightness (Qt::Key_MonBrightnessDown)
105
enum BrightnessKeyType{ Increase, Decrease };
108
* This enum defines capabilities of the backend
110
* - SignalResumeFromSuspend: The backend is able to stream the @c resumeFromSuspend signal accurately
112
enum Capability { NoCapabilities = 0, SignalResumeFromSuspend = 1 };
114
Q_DECLARE_FLAGS(Capabilities, Capability)
117
* This struct contains information for a recall notice from the vendor
119
struct RecallNotice {
120
/** The battery uuid */
122
/** The vendor's name */
124
/** The vendor's website */
129
* Initializes the backend. This function @b MUST be called before the backend is usable. Using
130
* any method in BackendInterface without initializing it might lead to undefined behavior. The signal
131
* @c backendReady or @c backendError will be streamed upon completion.
133
* @note Backend implementations @b MUST reimplement this function
135
virtual void init() = 0;
138
* @returns the capabilities of the backend
139
* @see PowerDevil::BackendInterface::Capability
141
Capabilities capabilities() const;
144
* Retrieves the current state of the system battery.
146
* @return the current battery state
147
* @see PowerDevil::BackendInterface::BatteryState
149
BatteryState batteryState() const;
152
* Retrieves the current estimated remaining time of the system batteries
154
* @return the current global estimated remaining time in milliseconds
156
qulonglong batteryRemainingTime() const;
159
* Retrieves the current state of the system AC adapter.
161
* @return the current AC adapter state
162
* @see PowerDevil::BackendInterface::AcAdapterState
164
AcAdapterState acAdapterState() const;
168
* Retrieves the set of suspend methods supported by the system.
170
* @return the suspend methods supported by this system
171
* @see PowerDevil::BackendInterface::SuspendMethod
172
* @see PowerDevil::BackendInterface::SuspendMethods
174
SuspendMethods supportedSuspendMethods() const;
177
* Requests a suspend of the system.
179
* @param method the suspend method to use
180
* @return the job handling the operation
182
virtual KJob *suspend(SuspendMethod method) = 0;
185
* Checks if brightness controls are enabled on this system.
187
* @return a list of the devices available to control
189
BrightnessControlsList brightnessControlsAvailable() const;
192
* Gets the screen brightness.
194
* @param device the name of the device that you would like to control
195
* @return the brightness of the device, as a percentage
197
virtual float brightness(BrightnessControlType type = Screen) const;
200
* @returns whether the lid is closed or not.
202
bool isLidClosed() const;
205
* Sets the screen brightness.
207
* @param brightness the desired screen brightness, as a percentage
208
* @param device the name of the device that you would like to control
209
* @return true if the brightness change succeeded, false otherwise
211
virtual bool setBrightness(float brightness, BrightnessControlType type = Screen) = 0;
214
* Should be called when the user presses a brightness key.
216
* @param type the type of the brightness key press
217
* @see PowerDevil::BackendInterface::BrightnessKeyType
219
virtual void brightnessKeyPressed(BrightnessKeyType type) = 0;
222
* Retrieves the capacities of the installed batteries in percentage.
224
* @returns A dictionary with the battery's capacity percentage mapped to the battery uuid.
226
QHash< QString, uint > capacities() const;
229
* Returns a list of recall notices, if available
231
* @return a list of recall notices
232
* @see PowerDevil::BackendInterface::RecallNotice
234
QList< RecallNotice > recallNotices() const;
238
* This signal is emitted when the AC adapter is plugged or unplugged.
240
* @param newState the new state of the AC adapter, it's one of the
241
* type @see PowerDevil::BackendInterface::AcAdapterState
243
void acAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState newState);
246
* This signal is emitted when the system battery state changed.
248
* @param newState the new state of the system battery, it's one of the
249
* type @see PowerDevil::BackendInterface::BatteryState
251
void batteryStateChanged(PowerDevil::BackendInterface::BatteryState newState);
254
* This signal is emitted when a button has been pressed.
256
* @param buttonType the pressed button type, it's one of the
257
* type @see PowerDevil::BackendInterface::ButtonType
259
void buttonPressed(PowerDevil::BackendInterface::ButtonType buttonType);
262
* This signal is emitted when the brightness changes.
264
* @param brightness the new brightness level
266
void brightnessChanged(float brightness, PowerDevil::BackendInterface::BrightnessControlType type);
269
* This signal is emitted when the estimated battery remaining time changes.
271
* @param time the new remaining time
273
void batteryRemainingTimeChanged(qulonglong time);
276
* This signal is emitted when the backend is ready to be used
283
* This signal is emitted if the backend could not be initialized
285
* @param error Details about the error occurred
288
void backendError(const QString &error);
291
* This signal is emitted when the PC is resuming from suspension
293
void resumeFromSuspend();
296
void setCapabilities(Capabilities capabilities);
298
void onBrightnessChanged(BrightnessControlType device, float brightness);
299
void setBatteryRemainingTime(qulonglong time);
300
void setButtonPressed(PowerDevil::BackendInterface::ButtonType type);
301
void setBatteryState(PowerDevil::BackendInterface::BatteryState state);
302
void setAcAdapterState(PowerDevil::BackendInterface::AcAdapterState state);
304
void setCapacityForBattery(const QString &batteryId, uint percent);
305
void setRecallNotices(const QList< RecallNotice > ¬ices);
307
void setBackendIsReady(BrightnessControlsList availableBrightnessControls, SuspendMethods supportedSuspendMethods);
308
void setBackendHasError(const QString &errorDetails);
311
// This function is actually here due to HAL
312
void setResumeFromSuspend();
323
Q_DECLARE_OPERATORS_FOR_FLAGS(PowerDevil::BackendInterface::Capabilities)
324
Q_DECLARE_OPERATORS_FOR_FLAGS(PowerDevil::BackendInterface::SuspendMethods)
326
#endif // POWERDEVIL_BACKENDINTERFACE_H