1/********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
27struct addrinfo;
28template <typename T>
29class QFutureWatcher;
30
31namespace KWin {
32
33class GetAddrInfo : public QObject
34{
35 Q_OBJECT
36public:
37 explicit GetAddrInfo(const QByteArray &hostName, QObject *parent = NULL);
38 virtual ~GetAddrInfo();
39
40 void resolve();
41
42Q_SIGNALS:
43 void local();
44
45private Q_SLOTS:
46 void slotResolved();
47 void slotOwnAddressResolved();
48
49private:
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
63class ClientMachine : public QObject
64{
65 Q_OBJECT
66public:
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
76Q_SIGNALS:
77 void localhostChanged();
78
79private Q_SLOTS:
80 void setLocal();
81 void resolveFinished();
82
83private:
84 void checkForLocalhost();
85 QByteArray m_hostName;
86 bool m_localhost;
87 bool m_resolved;
88 bool m_resolving;
89};
90
91inline
92bool ClientMachine::isLocal() const
93{
94 return m_localhost;
95}
96
97inline
98const QByteArray &ClientMachine::hostName() const
99{
100 return m_hostName;
101}
102
103inline
104QByteArray ClientMachine::localhost()
105{
106 return "localhost";
107}
108
109inline
110bool ClientMachine::isResolving() const
111{
112 return m_resolving;
113}
114
115} // namespace
116
117#endif
118