Solid

power.h
1/*
2 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef SOLID_POWER_H
8#define SOLID_POWER_H
9
10#include "solid_export.h"
11#include <QObject>
12
13namespace Solid
14{
15class StatesJob;
16class AcPluggedJob;
17class InhibitionJob;
18class RequestStateJob;
19class SOLID_EXPORT Power : public QObject
20{
21 Q_OBJECT
22public:
23 /**
24 * List of states a device can be in
25 *
26 * This list of states can be used to either put the device
27 * running the code into a specific state (for example put a
28 * laptop to sleep) or to avoid (inhibit) that state to happen,
29 * for example to prevent the screen to be dimed automatically
30 *
31 * Since this is quite specific to each platform some backends might
32 * not support all states.
33 *
34 * Some States are more complex or contain sub-states, those are usually
35 * set using a specific job (for example Sleep can be done either using suspend to ram,
36 * suspend to disk or an hybrid approach).
37 *
38 * @see InhibitionTypes
39 */
40 enum InhibitionType {
41 None = 0,
42 Sleep = 1 << 0,
43 Screen = 1 << 1,
44 Shutdown = 1 << 3,
45 };
46 /*
47 * Stores a combination of #InhibitionType values.
48 */
49 Q_DECLARE_FLAGS(InhibitionTypes, InhibitionType)
50 Q_FLAG(InhibitionTypes)
51 /**
52 * Returns an instance of Power
53 *
54 * Having an instance of Power is useful to monitor any changes
55 * in the power management system by connecting to its signals, like
56 * acPluggedChanged().
57 *
58 * If you are interested in Power during the entire life cycle of your
59 * application, then you want to use this singleton. If instead you are
60 * only interested for a short period of time, consider instantiating your own
61 * Solid::Power so you can free the memory at any point.
62 */
63 static Power *self();
64
65 /**
66 * Returns an AcPluggedJob
67 *
68 * The returned AcPluggedJob has to be started, when finished
69 * the Job::result() signal will be emitted.
70 */
71 static AcPluggedJob *isAcPlugged(QObject *parent = nullptr);
72
73 /**
74 * Returns an InhibitionJob
75 *
76 * The returned job is initialized with the given @p states and @p description
77 */
78 static InhibitionJob *inhibit(Power::InhibitionTypes states, const QString &description, QObject *parent = nullptr);
79
80 /**
81 * Query the supported states (like Sleep or Hibernation)
82 * @return a StatesJob
83 */
84 static StatesJob *supportedStates(QObject *parent = nullptr);
85
86 /**
87 * Set the computer in a desired @p state (like Sleep or Hibernation)
88 * @return a RequestStateJob
89 */
90 static RequestStateJob *requestState(Power::InhibitionType state, QObject *parent = nullptr);
91
92 /**
93 * If you are not going to destroy this object for the entire
94 * application life cycle, you might want to use self() singleton.
95 *
96 * The only reason to instantiate your own Power object is for when an
97 * application is only interested in power management during a small
98 * period of time and you want to free the memory after using it.
99 */
100 explicit Power(QObject *parent = nullptr);
101
102Q_SIGNALS:
103 /**
104 * Emitted when the system changes the power source
105 * @param plugged whether the system runs on AC
106 */
107 void acPluggedChanged(bool plugged);
108
109 /**
110 * Emitted when the system is about to suspend/hibernate
111 *
112 * @since 5.6
113 */
114 void aboutToSuspend();
115
116 /**
117 * Emitted when the system has just resumed from being suspended/hibernated
118 */
119 void resumeFromSuspend();
120
121private:
122 class Private;
123 Private *const d;
124};
125
126Q_DECLARE_OPERATORS_FOR_FLAGS(Power::InhibitionTypes)
127
128}
129
130#endif // SOLID_POWER_H
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 Fri May 24 2024 11:56:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.