File indexing completed on 2024-05-05 05:30:25

0001 /*
0002     SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 
0011 class QDBusPendingCallWatcher;
0012 class QDBusInterface;
0013 class OrgFreedesktopDBusPropertiesInterface;
0014 
0015 class Device : public QObject
0016 {
0017     Q_OBJECT
0018 public:
0019     static Device *self();
0020     static void destroy();
0021 
0022     bool isReady() const;
0023     bool isLaptop() const;
0024     bool isLidClosed() const;
0025 
0026 private Q_SLOTS:
0027     void changed();
0028     void isLaptopFetched(QDBusPendingCallWatcher *watcher);
0029     void isLidClosedFetched(QDBusPendingCallWatcher *watcher);
0030 
0031 Q_SIGNALS:
0032     void ready();
0033     void lidClosedChanged(bool closed);
0034     void resumingFromSuspend();
0035     void aboutToSuspend();
0036 
0037 private:
0038     explicit Device(QObject *parent = nullptr);
0039     ~Device() override;
0040 
0041     void setReady();
0042     void fetchIsLaptop();
0043     void fetchLidIsClosed();
0044 
0045     bool m_isReady;
0046     bool m_isLaptop;
0047     bool m_isLidClosed;
0048 
0049     static Device *m_instance;
0050 
0051     OrgFreedesktopDBusPropertiesInterface *m_freedesktop;
0052     QDBusInterface *m_suspendSession;
0053 };