1 | /******************************************************************** |
2 | KWin - the KDE window manager |
3 | This file is part of the KDE project. |
4 | |
5 | Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org> |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | *********************************************************************/ |
20 | #ifndef KWIN_CLIENT_MACHINE_H |
21 | #define KWIN_CLIENT_MACHINE_H |
22 | |
23 | #include <QObject> |
24 | #include <xcb/xcb.h> |
25 | |
26 | // forward declaration |
27 | struct addrinfo; |
28 | template <typename T> |
29 | class QFutureWatcher; |
30 | |
31 | namespace KWin { |
32 | |
33 | class GetAddrInfo : public QObject |
34 | { |
35 | Q_OBJECT |
36 | public: |
37 | explicit GetAddrInfo(const QByteArray &hostName, QObject *parent = NULL); |
38 | virtual ~GetAddrInfo(); |
39 | |
40 | void resolve(); |
41 | |
42 | Q_SIGNALS: |
43 | void local(); |
44 | |
45 | private Q_SLOTS: |
46 | void slotResolved(); |
47 | void slotOwnAddressResolved(); |
48 | |
49 | private: |
50 | void compare(); |
51 | bool resolved(QFutureWatcher<int> *watcher); |
52 | bool m_resolving; |
53 | bool m_resolved; |
54 | bool m_ownResolved; |
55 | QByteArray m_hostName; |
56 | addrinfo *m_addressHints; |
57 | addrinfo *m_address; |
58 | addrinfo *m_ownAddress; |
59 | QFutureWatcher<int> *m_watcher; |
60 | QFutureWatcher<int> *m_ownAddressWatcher; |
61 | }; |
62 | |
63 | class ClientMachine : public QObject |
64 | { |
65 | Q_OBJECT |
66 | public: |
67 | explicit ClientMachine(QObject *parent = NULL); |
68 | virtual ~ClientMachine(); |
69 | |
70 | void resolve(xcb_window_t window, xcb_window_t clientLeader); |
71 | const QByteArray &hostName() const; |
72 | bool isLocal() const; |
73 | static QByteArray localhost(); |
74 | bool isResolving() const; |
75 | |
76 | Q_SIGNALS: |
77 | void localhostChanged(); |
78 | |
79 | private Q_SLOTS: |
80 | void setLocal(); |
81 | void resolveFinished(); |
82 | |
83 | private: |
84 | void checkForLocalhost(); |
85 | QByteArray m_hostName; |
86 | bool m_localhost; |
87 | bool m_resolved; |
88 | bool m_resolving; |
89 | }; |
90 | |
91 | inline |
92 | bool ClientMachine::isLocal() const |
93 | { |
94 | return m_localhost; |
95 | } |
96 | |
97 | inline |
98 | const QByteArray &ClientMachine::hostName() const |
99 | { |
100 | return m_hostName; |
101 | } |
102 | |
103 | inline |
104 | QByteArray ClientMachine::localhost() |
105 | { |
106 | return "localhost" ; |
107 | } |
108 | |
109 | inline |
110 | bool ClientMachine::isResolving() const |
111 | { |
112 | return m_resolving; |
113 | } |
114 | |
115 | } // namespace |
116 | |
117 | #endif |
118 | |