| 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 | #include "systeminhibitor.h" |
| 5 | |
| 6 | void SystemInhibitor::classBegin() |
| 7 | { |
| 8 | } |
| 9 | |
| 10 | void SystemInhibitor::componentComplete() |
| 11 | { |
| 12 | m_ready = true; |
| 13 | apply(); |
| 14 | } |
| 15 | |
| 16 | void SystemInhibitor::setEnabled(bool enable) |
| 17 | { |
| 18 | if (m_enabled == enable) { |
| 19 | return; |
| 20 | } |
| 21 | m_enabled = enable; |
| 22 | Q_EMIT enabledChanged(); |
| 23 | |
| 24 | apply(); |
| 25 | } |
| 26 | |
| 27 | void SystemInhibitor::apply() |
| 28 | { |
| 29 | if (!m_ready) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | m_inhibitor.reset(); |
| 34 | if (m_enabled) { |
| 35 | m_inhibitor.emplace(args&: m_reason, args&: m_types, args&: m_window, args: this); |
| 36 | } |
| 37 | } |
| 38 |
