Changeset View
Changeset View
Standalone View
Standalone View
krfb/rfbclient.cpp
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | 16 | | |||
17 | You should have received a copy of the GNU Lesser General Public License | 17 | You should have received a copy of the GNU Lesser General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | #include "rfbclient.h" | 20 | #include "rfbclient.h" | ||
21 | #include "connectiondialog.h" | 21 | #include "connectiondialog.h" | ||
22 | #include "krfbconfig.h" | 22 | #include "krfbconfig.h" | ||
23 | #include "sockethelpers.h" | 23 | #include "sockethelpers.h" | ||
24 | #include "events.h" | 24 | #include "eventsmanager.h" | ||
25 | #include <QSocketNotifier> | 25 | #include <QSocketNotifier> | ||
26 | #include <QDebug> | 26 | #include <QDebug> | ||
27 | #include <poll.h> | 27 | #include <poll.h> | ||
28 | #include <strings.h> //for bzero() | 28 | #include <strings.h> //for bzero() | ||
29 | 29 | | |||
30 | struct RfbClient::Private | 30 | struct RfbClient::Private | ||
31 | { | 31 | { | ||
32 | Private(rfbClientPtr client) : | 32 | Private(rfbClientPtr client) : | ||
33 | controlEnabled(KrfbConfig::allowDesktopControl()), | 33 | controlEnabled(KrfbConfig::allowDesktopControl()), | ||
34 | client(client) | 34 | client(client) | ||
35 | {} | 35 | {} | ||
36 | 36 | | |||
37 | bool controlEnabled; | 37 | bool controlEnabled; | ||
38 | rfbClientPtr client; | 38 | rfbClientPtr client; | ||
39 | QSocketNotifier *notifier; | 39 | QSocketNotifier *notifier; | ||
40 | QSharedPointer<EventHandler> eventHandler; | ||||
40 | QString remoteAddressString; | 41 | QString remoteAddressString; | ||
41 | }; | 42 | }; | ||
42 | 43 | | |||
43 | RfbClient::RfbClient(rfbClientPtr client, QObject* parent) | 44 | RfbClient::RfbClient(rfbClientPtr client, QObject* parent) | ||
44 | : QObject(parent), d(new Private(client)) | 45 | : QObject(parent), d(new Private(client)) | ||
45 | { | 46 | { | ||
46 | d->remoteAddressString = peerAddress(d->client->sock) + QLatin1Char(':') + | 47 | d->remoteAddressString = peerAddress(d->client->sock) + QLatin1Char(':') + | ||
47 | QString::number(peerPort(d->client->sock)); | 48 | QString::number(peerPort(d->client->sock)); | ||
48 | 49 | | |||
49 | d->notifier = new QSocketNotifier(client->sock, QSocketNotifier::Read, this); | 50 | d->notifier = new QSocketNotifier(client->sock, QSocketNotifier::Read, this); | ||
50 | d->notifier->setEnabled(false); | 51 | d->notifier->setEnabled(false); | ||
51 | connect(d->notifier, &QSocketNotifier::activated, this, &RfbClient::onSocketActivated); | 52 | connect(d->notifier, &QSocketNotifier::activated, this, &RfbClient::onSocketActivated); | ||
53 | | ||||
54 | d->eventHandler = EventsManager::instance()->eventHandler(); | ||||
52 | } | 55 | } | ||
53 | 56 | | |||
54 | RfbClient::~RfbClient() | 57 | RfbClient::~RfbClient() | ||
55 | { | 58 | { | ||
56 | //qDebug(); | 59 | //qDebug(); | ||
57 | delete d; | 60 | delete d; | ||
58 | } | 61 | } | ||
59 | 62 | | |||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
105 | rfbClientPtr RfbClient::getRfbClientPtr() | 108 | rfbClientPtr RfbClient::getRfbClientPtr() | ||
106 | { | 109 | { | ||
107 | return d->client; | 110 | return d->client; | ||
108 | } | 111 | } | ||
109 | 112 | | |||
110 | void RfbClient::handleKeyboardEvent(bool down, rfbKeySym keySym) | 113 | void RfbClient::handleKeyboardEvent(bool down, rfbKeySym keySym) | ||
111 | { | 114 | { | ||
112 | if (d->controlEnabled) { | 115 | if (d->controlEnabled) { | ||
113 | EventHandler::handleKeyboard(down, keySym); | 116 | d->eventHandler->handleKeyboard(down, keySym); | ||
114 | } | 117 | } | ||
115 | } | 118 | } | ||
116 | 119 | | |||
117 | void RfbClient::handleMouseEvent(int buttonMask, int x, int y) | 120 | void RfbClient::handleMouseEvent(int buttonMask, int x, int y) | ||
118 | { | 121 | { | ||
119 | if (d->controlEnabled) { | 122 | if (d->controlEnabled) { | ||
120 | EventHandler::handlePointer(buttonMask, x, y); | 123 | d->eventHandler->handlePointer(buttonMask, x, y); | ||
121 | } | 124 | } | ||
122 | } | 125 | } | ||
123 | 126 | | |||
124 | void RfbClient::onSocketActivated() | 127 | void RfbClient::onSocketActivated() | ||
125 | { | 128 | { | ||
126 | //Process not only one, but all pending messages. | 129 | //Process not only one, but all pending messages. | ||
127 | //poll() idea/code copied from vino: | 130 | //poll() idea/code copied from vino: | ||
128 | // Copyright (C) 2003 Sun Microsystems, Inc. | 131 | // Copyright (C) 2003 Sun Microsystems, Inc. | ||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |