File indexing completed on 2022-11-23 12:13:06

0001 /********************************************************************
0002  KSld - the KDE Screenlocker Daemon
0003  This file is part of the KDE project.
0004 
0005 Copyright 1999 Martin R. Jones <mjones@kde.org>
0006 Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
0007 
0008 This program is free software; you can redistribute it and/or modify
0009 it under the terms of the GNU General Public License as published by
0010 the Free Software Foundation; either version 2 of the License, or
0011 (at your option) any later version.
0012 
0013 This program is distributed in the hope that it will be useful,
0014 but WITHOUT ANY WARRANTY; without even the implied warranty of
0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016 GNU General Public License for more details.
0017 
0018 You should have received a copy of the GNU General Public License
0019 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0020 *********************************************************************/
0021 #ifndef SCREENLOCKER_INTERFACE_H
0022 #define SCREENLOCKER_INTERFACE_H
0023 
0024 #include <QDBusContext>
0025 #include <QDBusMessage>
0026 #include <QObject>
0027 
0028 class QDBusServiceWatcher;
0029 
0030 namespace ScreenLocker
0031 {
0032 class InhibitRequest
0033 {
0034 public:
0035     QString dbusid;
0036     uint cookie;
0037     uint powerdevilcookie;
0038 };
0039 
0040 class KSldApp;
0041 class Interface : public QObject, protected QDBusContext
0042 {
0043     Q_OBJECT
0044     Q_CLASSINFO("D-Bus Interface", "org.freedesktop.ScreenSaver")
0045 public:
0046     explicit Interface(KSldApp *parent = nullptr);
0047     ~Interface() override;
0048 
0049 public Q_SLOTS:
0050     /**
0051      * Lock the screen.
0052      */
0053     void Lock();
0054 
0055     /**
0056      * Like Lock() but immediately show the switch user dialog
0057      */
0058     void SwitchUser();
0059 
0060     /**
0061      * Simulate user activity
0062      */
0063     void SimulateUserActivity();
0064     /**
0065      * Request a change in the state of the screensaver.
0066      * Set to TRUE to request that the screensaver activate.
0067      * Active means that the screensaver has blanked the
0068      * screen and may run a graphical theme.  This does
0069      * not necessary mean that the screen is locked.
0070      */
0071     bool SetActive(bool state);
0072 
0073     /// Returns the value of the current state of activity (See setActive)
0074     bool GetActive();
0075 
0076     /**
0077      * Returns the number of seconds that the screensaver has
0078      * been active.  Returns zero if the screensaver is not active.
0079      */
0080     uint GetActiveTime();
0081 
0082     /**
0083      * Returns the number of seconds that the session has
0084      * been idle.  Returns zero if the session is not idle.
0085      */
0086     uint GetSessionIdleTime();
0087 
0088     /**
0089      * Request that saving the screen due to system idleness
0090      * be blocked until UnInhibit is called or the
0091      * calling process exits.
0092      * The cookie is a random number used to identify the request
0093      */
0094     uint Inhibit(const QString &application_name, const QString &reason_for_inhibit);
0095     /// Cancel a previous call to Inhibit() identified by the cookie.
0096     void UnInhibit(uint cookie);
0097 
0098     /**
0099      * Request that running themes while the screensaver is active
0100      * be blocked until UnThrottle is called or the
0101      * calling process exits.
0102      * The cookie is a random number used to identify the request
0103      */
0104     uint Throttle(const QString &application_name, const QString &reason_for_inhibit);
0105     /// Cancel a previous call to Throttle() identified by the cookie.
0106     void UnThrottle(uint cookie);
0107 
0108     // org.kde.screensvar
0109     void configure();
0110 
0111 Q_SIGNALS:
0112     // DBus signals
0113     void ActiveChanged(bool state);
0114 
0115     void AboutToLock();
0116 
0117 private Q_SLOTS:
0118     void slotLocked();
0119     void slotUnlocked();
0120     void serviceUnregistered(const QString &name);
0121 
0122 private:
0123     void sendLockReplies();
0124 
0125     KSldApp *m_daemon;
0126     QDBusServiceWatcher *m_serviceWatcher;
0127     QList<InhibitRequest> m_requests;
0128     uint m_next_cookie;
0129     QList<QDBusMessage> m_lockReplies;
0130 };
0131 }
0132 
0133 #endif // SCREENLOCKER_INTERFACE_H