File indexing completed on 2024-09-15 12:58:31
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include <QObject> 0012 #include <memory> 0013 #include <xcb/xcb.h> 0014 0015 // forward declaration 0016 struct addrinfo; 0017 template<typename T> 0018 class QFutureWatcher; 0019 0020 namespace KWin 0021 { 0022 0023 class GetAddrInfo : public QObject 0024 { 0025 Q_OBJECT 0026 public: 0027 explicit GetAddrInfo(const QString &hostName, QObject *parent = nullptr); 0028 ~GetAddrInfo() override; 0029 0030 void resolve(); 0031 0032 Q_SIGNALS: 0033 void local(); 0034 0035 private Q_SLOTS: 0036 void slotResolved(); 0037 void slotOwnAddressResolved(); 0038 0039 private: 0040 void compare(); 0041 bool resolved(QFutureWatcher<int> *watcher); 0042 bool m_resolving; 0043 bool m_resolved; 0044 bool m_ownResolved; 0045 QString m_hostName; 0046 std::unique_ptr<addrinfo> m_addressHints; 0047 addrinfo *m_address; 0048 addrinfo *m_ownAddress; 0049 std::unique_ptr<QFutureWatcher<int>> m_watcher; 0050 std::unique_ptr<QFutureWatcher<int>> m_ownAddressWatcher; 0051 }; 0052 0053 class ClientMachine : public QObject 0054 { 0055 Q_OBJECT 0056 public: 0057 explicit ClientMachine(QObject *parent = nullptr); 0058 ~ClientMachine() override; 0059 0060 void resolve(xcb_window_t window, xcb_window_t clientLeader); 0061 const QString &hostName() const; 0062 bool isLocal() const; 0063 static QString localhost(); 0064 bool isResolving() const; 0065 0066 Q_SIGNALS: 0067 void localhostChanged(); 0068 0069 private Q_SLOTS: 0070 void setLocal(); 0071 void resolveFinished(); 0072 0073 private: 0074 void checkForLocalhost(); 0075 QString m_hostName; 0076 bool m_localhost; 0077 bool m_resolved; 0078 bool m_resolving; 0079 }; 0080 0081 inline bool ClientMachine::isLocal() const 0082 { 0083 return m_localhost; 0084 } 0085 0086 inline const QString &ClientMachine::hostName() const 0087 { 0088 return m_hostName; 0089 } 0090 0091 inline QString ClientMachine::localhost() 0092 { 0093 return QStringLiteral("localhost"); 0094 } 0095 0096 inline bool ClientMachine::isResolving() const 0097 { 0098 return m_resolving; 0099 } 0100 0101 } // namespace