File indexing completed on 2021-12-21 14:17:30

0001 /********************************************************************
0002  KSld - the KDE Screenlocker Daemon
0003  This file is part of the KDE project.
0004 
0005 Copyright (C) 2014 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007 This program is free software; you can redistribute it and/or modify
0008 it under the terms of the GNU General Public License as published by
0009 the Free Software Foundation; either version 2 of the License, or
0010 (at your option) any later version.
0011 
0012 This program is distributed in the hope that it will be useful,
0013 but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 GNU General Public License for more details.
0016 
0017 You should have received a copy of the GNU General Public License
0018 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019 *********************************************************************/
0020 #ifndef LOGIND_H
0021 #define LOGIND_H
0022 
0023 #include <QDBusConnection>
0024 #include <QDBusPendingCallWatcher>
0025 #include <QDBusUnixFileDescriptor>
0026 #include <QObject>
0027 
0028 class QDBusServiceWatcher;
0029 
0030 class LogindIntegration : public QObject
0031 {
0032     Q_OBJECT
0033 public:
0034     explicit LogindIntegration(QObject *parent = nullptr);
0035     ~LogindIntegration() override;
0036 
0037     bool isConnected() const
0038     {
0039         return m_connected;
0040     }
0041 
0042     void inhibit();
0043     void uninhibit();
0044 
0045     bool isInhibited() const;
0046 
0047     /**
0048      * Notify logind of our current state
0049      */
0050     void setLocked(bool locked);
0051     bool isLocked() const;
0052 
0053 Q_SIGNALS:
0054     /**
0055      * signalled when logind asks us to lock
0056      */
0057     void requestLock();
0058     void requestUnlock();
0059     void connectedChanged();
0060     void prepareForSleep(bool);
0061     void inhibited();
0062 
0063 private:
0064     friend class LogindTest;
0065     /**
0066      * The DBusConnection argument is needed for the unit test. Logind uses the system bus
0067      * on which the unit test's fake logind cannot register to. Thus the unit test need to
0068      * be able to do everything over the session bus. This ctor allows the LogindTest to
0069      * create a LogindIntegration which listens on the session bus.
0070      **/
0071     explicit LogindIntegration(const QDBusConnection &connection, QObject *parent = nullptr);
0072     void logindServiceRegistered();
0073     void consolekitServiceRegistered();
0074     void commonServiceRegistered(QDBusPendingCallWatcher *watcher);
0075     QDBusConnection m_bus;
0076     QDBusServiceWatcher *m_logindServiceWatcher;
0077     bool m_connected;
0078     QDBusUnixFileDescriptor m_inhibitFileDescriptor;
0079     const QString *m_service;
0080     const QString *m_path;
0081     QString m_sessionPath;
0082     const QString *m_managerInterface;
0083     const QString *m_sessionInterface;
0084 };
0085 
0086 #endif