| 1 | // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 2 | // SPDX-FileCopyrightText: 2025 Harald Sitter <sitter@kde.org> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <kguiaddons_export.h> |
| 7 | |
| 8 | #include <QObject> |
| 9 | |
| 10 | class QWindow; |
| 11 | |
| 12 | /*! |
| 13 | \class KSystemInhibitor |
| 14 | \inmodule KGuiAddons |
| 15 | \since 6.23 |
| 16 | |
| 17 | \brief Inhibit system actions such as logout, suspend, etc. |
| 18 | */ |
| 19 | class KGUIADDONS_EXPORT KSystemInhibitor : public QObject |
| 20 | { |
| 21 | Q_OBJECT |
| 22 | public: |
| 23 | /*! |
| 24 | Inhibition types. |
| 25 | |
| 26 | \value Logout Inhibit logout/shutdown |
| 27 | \value UserSwitch Inhibit user switching |
| 28 | \value Suspend Inhibit suspend/hibernate |
| 29 | \value Idle Inhibit idle actions (e.g. screen locking) |
| 30 | */ |
| 31 | enum class Type { |
| 32 | Logout = 1, |
| 33 | UserSwitch = 2, |
| 34 | Suspend = 4, |
| 35 | Idle = 8 |
| 36 | }; |
| 37 | Q_ENUM(Type) |
| 38 | Q_DECLARE_FLAGS(Types, Type) |
| 39 | Q_FLAG(Types) |
| 40 | |
| 41 | /*! |
| 42 | Claim inhibition. |
| 43 | |
| 44 | \a reason is the user-visible reason for the inhibition. |
| 45 | |
| 46 | \a types is a combination of inhibition types. |
| 47 | |
| 48 | \a window is the window for which to apply the inhibition. May be null in which case possible user queries will not be associated with any window. |
| 49 | |
| 50 | \a parent is the parent QObject. |
| 51 | */ |
| 52 | KSystemInhibitor(const QString &reason, Types types, QWindow *window, QObject *parent = nullptr); |
| 53 | |
| 54 | /*! |
| 55 | Release inhibition |
| 56 | */ |
| 57 | ~KSystemInhibitor() override; |
| 58 | |
| 59 | Q_DISABLE_COPY_MOVE(KSystemInhibitor) |
| 60 | |
| 61 | private: |
| 62 | std::unique_ptr<class KSystemInhibitorPrivate> const d; |
| 63 | }; |
| 64 | |