File indexing completed on 2024-04-21 05:27:35
0001 /* 0002 SPDX-FileCopyrightText: 1999 Martin R. Jones <mjones@kde.org> 0003 SPDX-FileCopyrightText: 2011 Martin Gräßlin <mgraesslin@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #pragma once 0008 0009 #include <QDBusContext> 0010 #include <QDBusMessage> 0011 #include <QObject> 0012 0013 class QDBusServiceWatcher; 0014 0015 namespace ScreenLocker 0016 { 0017 class InhibitRequest 0018 { 0019 public: 0020 QString dbusid; 0021 uint cookie; 0022 uint powerdevilcookie; 0023 }; 0024 0025 class KSldApp; 0026 class Interface : public QObject, protected QDBusContext 0027 { 0028 Q_OBJECT 0029 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.ScreenSaver") 0030 public: 0031 explicit Interface(KSldApp *parent = nullptr); 0032 ~Interface() override; 0033 0034 public Q_SLOTS: 0035 /** 0036 * Lock the screen. 0037 */ 0038 void Lock(); 0039 0040 /** 0041 * Like Lock() but immediately show the switch user dialog 0042 */ 0043 void SwitchUser(); 0044 0045 /** 0046 * Simulate user activity 0047 */ 0048 void SimulateUserActivity(); 0049 /** 0050 * Request a change in the state of the screensaver. 0051 * Set to TRUE to request that the screensaver activate. 0052 * Active means that the screensaver has blanked the 0053 * screen and may run a graphical theme. This does 0054 * not necessary mean that the screen is locked. 0055 */ 0056 bool SetActive(bool state); 0057 0058 /// Returns the value of the current state of activity (See setActive) 0059 bool GetActive(); 0060 0061 /** 0062 * Returns the number of seconds that the screensaver has 0063 * been active. Returns zero if the screensaver is not active. 0064 */ 0065 uint GetActiveTime(); 0066 0067 /** 0068 * Returns the number of seconds that the session has 0069 * been idle. Returns zero if the session is not idle. 0070 */ 0071 uint GetSessionIdleTime(); 0072 0073 /** 0074 * Request that saving the screen due to system idleness 0075 * be blocked until UnInhibit is called or the 0076 * calling process exits. 0077 * The cookie is a random number used to identify the request 0078 */ 0079 uint Inhibit(const QString &application_name, const QString &reason_for_inhibit); 0080 /// Cancel a previous call to Inhibit() identified by the cookie. 0081 void UnInhibit(uint cookie); 0082 0083 /** 0084 * Request that running themes while the screensaver is active 0085 * be blocked until UnThrottle is called or the 0086 * calling process exits. 0087 * The cookie is a random number used to identify the request 0088 */ 0089 uint Throttle(const QString &application_name, const QString &reason_for_inhibit); 0090 /// Cancel a previous call to Throttle() identified by the cookie. 0091 void UnThrottle(uint cookie); 0092 0093 // org.kde.screensvar 0094 void configure(); 0095 0096 Q_SIGNALS: 0097 // DBus signals 0098 void ActiveChanged(bool state); 0099 0100 void AboutToLock(); 0101 0102 private Q_SLOTS: 0103 void slotLocked(); 0104 void slotUnlocked(); 0105 void serviceUnregistered(const QString &name); 0106 0107 private: 0108 void sendLockReplies(); 0109 0110 KSldApp *m_daemon; 0111 QDBusServiceWatcher *m_serviceWatcher; 0112 QList<InhibitRequest> m_requests; 0113 uint m_next_cookie; 0114 QList<QDBusMessage> m_lockReplies; 0115 }; 0116 }