inhibitor.h 2.57 KB
Newer Older
1
/*
Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
2
 * Copyright 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <QObject>

/**
 * The Inhibitor class provides a convenient way to temporarily disable Night Color.
 */
class Inhibitor : public QObject
{
    Q_OBJECT
    /**
     * This property holds a value to indicate the current state of the inhibitor.
     */
    Q_PROPERTY(State state READ state NOTIFY stateChanged)

public:
    explicit Inhibitor(QObject *parent = nullptr);
    ~Inhibitor() override;

    /**
     * This enum type is used to specify the state of the inhibitor.
     */
    enum State {
        Inhibiting,   ///< Night Color is being inhibited.
        Inhibited,    ///< Night Color is inhibited.
        Uninhibiting, ///< Night Color is being uninhibited.
        Uninhibited,  ///< Night Color is uninhibited.
    };
    Q_ENUM(State)

    /**
     * Returns the current state of the inhibitor.
     */
    State state() const;

public Q_SLOTS:
    /**
     * Attempts to temporarily disable Night Color.
     *
     * After calling this method, the inhibitor will enter the Inhibiting state.
     * Eventually, the inhibitor will enter the Inhibited state when the inhibition
     * request has been processed successfully by the Night Color manager.
     *
     * This method does nothing if the inhibitor is in the Inhibited state.
     */
    void inhibit();

    /**
     * Attempts to undo the previous call to inhibit() method.
     *
     * After calling this method, the inhibitor will enter the Uninhibiting state.
     * Eventually, the inhibitor will enter the Uninhibited state when the uninhibition
     * request has been processed by the Night Color manager.
     *
     * This method does nothing if the inhibitor is in the Uninhibited state.
     */
    void uninhibit();

Q_SIGNALS:
    /**
     * Emitted whenever the state of the inhibitor has changed.
     */
    void stateChanged();

private:
    class Private;
    QScopedPointer<Private> d;
};