Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Palacios GUI Added
[palacios.git] / linux_usr / gui / palacios / vnc_module / vncclientthread.h
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.
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; 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.
21 **
22 ****************************************************************************/
23
24 #ifndef VNCCLIENTTHREAD_H
25 #define VNCCLIENTTHREAD_H
26
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
36
37 #include "remoteview.h"
38
39 #include <QQueue>
40 #include <QThread>
41 #include <QImage>
42 #include <QMutex>
43
44 extern "C" {
45 #include <rfb/rfbclient.h>
46 }
47
48 class ClientEvent
49 {
50 public:
51     virtual ~ClientEvent();
52
53     virtual void fire(rfbClient*) = 0;
54 };
55
56 class KeyClientEvent : public ClientEvent
57 {
58 public:
59     KeyClientEvent(int key, int pressed)
60             : m_key(key), m_pressed(pressed) {}
61
62     void fire(rfbClient*);
63
64 private:
65     int m_key;
66     int m_pressed;
67 };
68
69 class PointerClientEvent : public ClientEvent
70 {
71 public:
72     PointerClientEvent(int x, int y, int buttonMask)
73             : m_x(x), m_y(y), m_buttonMask(buttonMask) {}
74
75     void fire(rfbClient*);
76
77 private:
78     int m_x;
79     int m_y;
80     int m_buttonMask;
81 };
82
83 class ClientCutEvent : public ClientEvent
84 {
85 public:
86     ClientCutEvent(const QString &text)
87             : text(text) {}
88
89     void fire(rfbClient*);
90
91 private:
92     QString text;
93 };
94
95 class VncClientThread: public QThread
96 {
97     Q_OBJECT
98
99 public:
100     Q_ENUMS(ColorDepth)
101
102     enum ColorDepth {
103         bpp32,
104         bpp16,
105         bpp8
106     };
107
108     explicit VncClientThread(QObject *parent = 0);
109     ~VncClientThread();
110     const QImage image(int x = 0, int y = 0, int w = 0, int h = 0);
111     void setImage(const QImage &img);
112     void emitUpdated(int x, int y, int w, int h);
113     void emitGotCut(const QString &text);
114     void stop();
115     void setHost(const QString &host);
116     void setPort(int port);
117     void setQuality(RemoteView::Quality quality);
118     void setPassword(const QString &password) {
119         m_password = password;
120     }
121     const QString password() const {
122         return m_password;
123     }
124
125     RemoteView::Quality quality() const;
126     ColorDepth colorDepth() const;
127     uint8_t *frameBuffer;
128
129 signals:
130     void imageUpdated(int x, int y, int w, int h);
131     void gotCut(const QString &text);
132     void passwordRequest();
133     void outputErrorMessage(const QString &message);
134
135 public slots:
136     void mouseEvent(int x, int y, int buttonMask);
137     void keyEvent(int key, bool pressed);
138     void clientCut(const QString &text);
139
140 protected:
141     void run();
142
143 private:
144     static void setClientColorDepth(rfbClient *cl, ColorDepth cd);
145     void setColorDepth(ColorDepth colorDepth);
146     //these static methods are callback functions for libvncclient
147     static rfbBool newclient(rfbClient *cl);
148     static void updatefb(rfbClient *cl, int x, int y, int w, int h);
149     static void cuttext(rfbClient *cl, const char *text, int textlen);
150     static char* passwdHandler(rfbClient *cl);
151     static void outputHandler(const char *format, ...);
152
153     QImage m_image;
154     rfbClient *cl;
155     QString m_host;
156     QString m_password;
157     int m_port;
158     QMutex mutex;
159     RemoteView::Quality m_quality;
160     ColorDepth m_colorDepth;
161     QQueue<ClientEvent* > m_eventQueue;
162     //color table for 8bit indexed colors
163     static QVector<QRgb> m_colorTable;
164
165     volatile bool m_stopped;
166     volatile bool m_passwordError;
167
168 private slots:
169     void checkOutputErrorMessage();
170 };
171
172 #endif