File indexing completed on 2025-02-09 04:31:51
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alejandro Fiestas Olivares <afiestas@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef SOLID_INHIBITION_H 0008 #define SOLID_INHIBITION_H 0009 0010 #include <QObject> 0011 0012 #include "solid_export.h" 0013 0014 namespace Solid 0015 { 0016 class InhibitionPrivate; 0017 class AbstractInhibition; 0018 /** 0019 * Holds an inhibition 0020 * 0021 * This object is returned by Power::InhibitionJob::inhibition and it 0022 * holds a reference to the inhibition that has been performed. 0023 * 0024 * When this object is deleted the inhibition will be released 0025 */ 0026 class SOLID_EXPORT Inhibition : public QObject 0027 { 0028 Q_OBJECT 0029 Q_PROPERTY(State state READ state NOTIFY stateChanged) 0030 public: 0031 enum State { 0032 Stopped = 0, 0033 Started = 1, 0034 }; 0035 Q_ENUM(State) 0036 0037 /** 0038 * This is meant to be instantiated by backends only 0039 * 0040 * AbstractInhibition is not part of Solid public API so this 0041 * constructor is meant to be used only by backends. 0042 */ 0043 explicit Inhibition(AbstractInhibition *backend, QObject *parent = nullptr); 0044 virtual ~Inhibition(); 0045 0046 /** 0047 * Returns the current state of the object 0048 * 0049 * The initial value is Started since that is how InhibitionJob will 0050 * return it. The state can be modified by calling stop() and start(). 0051 * Also stateChanged() signal is available. 0052 */ 0053 State state() const; 0054 0055 public Q_SLOTS: 0056 /** 0057 * Stops the inhibition 0058 * 0059 * In case the state() is Started, it will stop the inhibition. 0060 * This happens asynchronously so connect to stateChanged() signal to know 0061 * when stop() has changed the state. 0062 */ 0063 void stop(); 0064 0065 /** 0066 * Starts the inhibition 0067 * 0068 * In case state() is Stopped, it will resume the inhibition. 0069 * This happens asynchronously so connect to stateChanged() signal to 0070 * know when start() has changed the state. 0071 */ 0072 void start(); 0073 0074 protected: 0075 InhibitionPrivate *const d_ptr; 0076 0077 Q_SIGNALS: 0078 void stateChanged(Inhibition::State newState); 0079 }; 0080 } 0081 0082 #endif // SOLID_INHIBITION_H