Ability to build a Qt-only version of the KRDC VNC backend.
[kdenetwork.git] / krdc / vnc / vncclientthread.h
blobf2bb3f233c6a4ef233a80041233ed4a2171407b9
1 /****************************************************************************
2 **
3 ** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
4 **
5 ** This file is part of KDE.
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.
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.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
22 ****************************************************************************/
24 #ifndef VNCCLIENTTHREAD_H
25 #define VNCCLIENTTHREAD_H
27 #ifdef QTONLY
28 #include <QDebug>
29 #define kDebug(n) qDebug()
30 #define kBacktrace() ""
31 #define i18n tr
32 #else
33 #include <KDebug>
34 #include <KLocale>
35 #endif
37 #include "remoteview.h"
39 #include <QQueue>
40 #include <QThread>
41 #include <QImage>
42 #include <QMutex>
44 extern "C" {
45 #include <rfb/rfbclient.h>
48 class ClientEvent
50 public:
51 virtual ~ClientEvent();
53 virtual void fire(rfbClient*) = 0;
56 class KeyClientEvent : public ClientEvent
58 public:
59 KeyClientEvent(int key, int pressed)
60 : m_key(key), m_pressed(pressed) {}
62 void fire(rfbClient*);
64 private:
65 int m_key;
66 int m_pressed;
69 class PointerClientEvent : public ClientEvent
71 public:
72 PointerClientEvent(int x, int y, int buttonMask)
73 : m_x(x), m_y(y), m_buttonMask(buttonMask) {}
75 void fire(rfbClient*);
77 private:
78 int m_x;
79 int m_y;
80 int m_buttonMask;
83 class ClientCutEvent : public ClientEvent
85 public:
86 ClientCutEvent(char *text)
87 : text(text) {}
89 void fire(rfbClient*);
91 private:
92 char *text;
95 class VncClientThread: public QThread
97 Q_OBJECT
99 public:
100 explicit VncClientThread();
101 ~VncClientThread();
102 const QImage image(int x = 0, int y = 0, int w = 0, int h = 0);
103 void setImage(const QImage &img);
104 void emitUpdated(int x, int y, int w, int h);
105 void emitGotCut(const QString &text);
106 void stop();
107 void setHost(const QString &host);
108 void setPort(int port);
109 void setQuality(RemoteView::Quality quality);
110 void setPassword(const QString &password) {
111 m_password = password;
113 const QString password() const {
114 return m_password;
117 RemoteView::Quality quality() const;
119 signals:
120 void imageUpdated(int x, int y, int w, int h);
121 void gotCut(const QString &text);
122 void passwordRequest();
123 void outputErrorMessage(const QString &message);
125 public slots:
126 void mouseEvent(int x, int y, int buttonMask);
127 void keyEvent(int key, bool pressed);
128 void clientCut(const QString &text);
130 protected:
131 void run();
133 private:
134 static char* passwdHandler(rfbClient *cl);
135 static void outputHandler(const char *format, ...);
137 QImage m_image;
138 rfbClient *cl;
139 QString m_host;
140 QString m_password;
141 int m_port;
142 QMutex mutex;
143 RemoteView::Quality m_quality;
144 QQueue<ClientEvent* > m_eventQueue;
146 volatile bool m_stopped;
147 volatile bool m_passwordError;
149 private slots:
150 void checkOutputErrorMessage();
153 #endif