summaryrefslogtreecommitdiff
authorwimpie <wimpie>2004-04-07 01:11:12 (UTC)
committer wimpie <wimpie>2004-04-07 01:11:12 (UTC)
commit843ac5d18f43e7f79ea6144c93bde0bd0e3e2f40 (patch) (unidiff)
tree5ea4a70406b4f8428493d050eeaf16580db5293d
parent453109d9dafc25fdaf82197ef8a3f4e34c9272af (diff)
downloadopie-843ac5d18f43e7f79ea6144c93bde0bd0e3e2f40.zip
opie-843ac5d18f43e7f79ea6144c93bde0bd0e3e2f40.tar.gz
opie-843ac5d18f43e7f79ea6144c93bde0bd0e3e2f40.tar.bz2
COnversion too quick to odebug
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/comm/keypebble/krfbdecoder.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp
index 69457e2..d61433f 100644
--- a/noncore/comm/keypebble/krfbdecoder.cpp
+++ b/noncore/comm/keypebble/krfbdecoder.cpp
@@ -1,789 +1,789 @@
1#include "krfbconnection.h" 1#include "krfbconnection.h"
2#include "krfbserverinfo.h" 2#include "krfbserverinfo.h"
3#include "krfbdecoder.h" 3#include "krfbdecoder.h"
4#include "krfbbuffer.h" 4#include "krfbbuffer.h"
5 5
6/* OPIE */ 6/* OPIE */
7#include <opie2/odebug.h> 7#include <opie2/odebug.h>
8using namespace Opie::Core; 8using namespace Opie::Core;
9 9
10/* QT */ 10/* QT */
11#include <qpixmap.h> 11#include <qpixmap.h>
12 12
13/* STD */ 13/* STD */
14#include <assert.h> 14#include <assert.h>
15 15
16// 16//
17// Endian stuff 17// Endian stuff
18// 18//
19#ifndef OPIE_NO_DEBUG 19//#ifndef OPIE_NO_DEBUG
20const int endianTest = 1; 20const int endianTest = 1;
21#endif 21//#endif
22 22
23#define Swap16IfLE(s) \ 23#define Swap16IfLE(s) \
24 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) 24 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
25 25
26#define Swap32IfLE(l) \ 26#define Swap32IfLE(l) \
27 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ 27 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
28 (((l) & 0x00ff0000) >> 8) | \ 28 (((l) & 0x00ff0000) >> 8) | \
29 (((l) & 0x0000ff00) << 8) | \ 29 (((l) & 0x0000ff00) << 8) | \
30 (((l) & 0x000000ff) << 24)) : (l)) 30 (((l) & 0x000000ff) << 24)) : (l))
31 31
32// 32//
33// The lengths of the messages we need to wait for 33// The lengths of the messages we need to wait for
34// 34//
35const int ServerInitLength = 24; 35const int ServerInitLength = 24;
36const int UpdateHeaderLength = 4; 36const int UpdateHeaderLength = 4;
37const int RectHeaderLength = 12; 37const int RectHeaderLength = 12;
38const int RectChunkSize = 4; 38const int RectChunkSize = 4;
39const int CopyRectPosLength = 4; 39const int CopyRectPosLength = 4;
40const int ServerCutLenLength = 7; 40const int ServerCutLenLength = 7;
41 41
42// 42//
43// Client -> Server Message Identifiers 43// Client -> Server Message Identifiers
44// 44//
45static CARD8 SetPixelFormatId = 0; 45static CARD8 SetPixelFormatId = 0;
46//static CARD8 FixColourMapEntriesId = 1; // Not used 46//static CARD8 FixColourMapEntriesId = 1; // Not used
47static CARD8 SetEncodingsId = 2; 47static CARD8 SetEncodingsId = 2;
48static CARD8 UpdateRequestId = 3; 48static CARD8 UpdateRequestId = 3;
49static CARD8 KeyEventId = 4; 49static CARD8 KeyEventId = 4;
50static CARD8 PointerEventId = 5; 50static CARD8 PointerEventId = 5;
51static CARD8 ClientCutTextId = 6; 51static CARD8 ClientCutTextId = 6;
52 52
53// 53//
54// Server -> Client Message Identifiers 54// Server -> Client Message Identifiers
55// 55//
56static CARD8 UpdateId = 0; 56static CARD8 UpdateId = 0;
57static CARD8 BellId = 2; 57static CARD8 BellId = 2;
58static CARD8 ServerCutId = 3; 58static CARD8 ServerCutId = 3;
59 59
60// 60//
61// Encoding identifiers 61// Encoding identifiers
62// 62//
63static CARD32 RawEncoding = Swap32IfLE( 0 ); 63static CARD32 RawEncoding = Swap32IfLE( 0 );
64static CARD32 CopyRectEncoding = Swap32IfLE(1 ); 64static CARD32 CopyRectEncoding = Swap32IfLE(1 );
65static CARD32 RreEncoding = Swap32IfLE( 2 ); 65static CARD32 RreEncoding = Swap32IfLE( 2 );
66static CARD32 CorreEncoding = Swap32IfLE( 4 ); 66static CARD32 CorreEncoding = Swap32IfLE( 4 );
67static CARD32 HexTileEncoding = Swap32IfLE( 5 ); 67static CARD32 HexTileEncoding = Swap32IfLE( 5 );
68 68
69static struct { 69static struct {
70 int keysym; 70 int keysym;
71 int keycode; 71 int keycode;
72} keyMap[] = { 72} keyMap[] = {
73 { 0xff08, Qt::Key_Backspace }, 73 { 0xff08, Qt::Key_Backspace },
74 { 0xff09, Qt::Key_Tab }, 74 { 0xff09, Qt::Key_Tab },
75 { 0xff0d, Qt::Key_Return }, 75 { 0xff0d, Qt::Key_Return },
76 { 0xff1b, Qt::Key_Escape }, 76 { 0xff1b, Qt::Key_Escape },
77 { 0xff63, Qt::Key_Insert }, 77 { 0xff63, Qt::Key_Insert },
78 { 0xffff, Qt::Key_Delete }, 78 { 0xffff, Qt::Key_Delete },
79 { 0xff50, Qt::Key_Home }, 79 { 0xff50, Qt::Key_Home },
80 { 0xff57, Qt::Key_End }, 80 { 0xff57, Qt::Key_End },
81 { 0xff55, Qt::Key_Prior }, 81 { 0xff55, Qt::Key_Prior },
82 { 0xff56, Qt::Key_Next }, 82 { 0xff56, Qt::Key_Next },
83 { 0xff51, Qt::Key_Left }, 83 { 0xff51, Qt::Key_Left },
84 { 0xff52, Qt::Key_Up }, 84 { 0xff52, Qt::Key_Up },
85 { 0xff53, Qt::Key_Right }, 85 { 0xff53, Qt::Key_Right },
86 { 0xff54, Qt::Key_Down }, 86 { 0xff54, Qt::Key_Down },
87 { 0xffbe, Qt::Key_F1 }, 87 { 0xffbe, Qt::Key_F1 },
88 { 0xffbf, Qt::Key_F2 }, 88 { 0xffbf, Qt::Key_F2 },
89 { 0xffc0, Qt::Key_F3 }, 89 { 0xffc0, Qt::Key_F3 },
90 { 0xffc1, Qt::Key_F4 }, 90 { 0xffc1, Qt::Key_F4 },
91 { 0xffc2, Qt::Key_F5 }, 91 { 0xffc2, Qt::Key_F5 },
92 { 0xffc3, Qt::Key_F6 }, 92 { 0xffc3, Qt::Key_F6 },
93 { 0xffc4, Qt::Key_F7 }, 93 { 0xffc4, Qt::Key_F7 },
94 { 0xffc5, Qt::Key_F8 }, 94 { 0xffc5, Qt::Key_F8 },
95 { 0xffc6, Qt::Key_F9 }, 95 { 0xffc6, Qt::Key_F9 },
96 { 0xffc7, Qt::Key_F10 }, 96 { 0xffc7, Qt::Key_F10 },
97 { 0xffc8, Qt::Key_F11 }, 97 { 0xffc8, Qt::Key_F11 },
98 { 0xffc9, Qt::Key_F12 }, 98 { 0xffc9, Qt::Key_F12 },
99 { 0xffe1, Qt::Key_Shift }, 99 { 0xffe1, Qt::Key_Shift },
100 { 0xffe2, Qt::Key_Shift }, 100 { 0xffe2, Qt::Key_Shift },
101 { 0xffe3, Qt::Key_Control }, 101 { 0xffe3, Qt::Key_Control },
102 { 0xffe4, Qt::Key_Control }, 102 { 0xffe4, Qt::Key_Control },
103 { 0xffe7, Qt::Key_Meta }, 103 { 0xffe7, Qt::Key_Meta },
104 { 0xffe8, Qt::Key_Meta }, 104 { 0xffe8, Qt::Key_Meta },
105 { 0xffe9, Qt::Key_Alt }, 105 { 0xffe9, Qt::Key_Alt },
106 { 0xffea, Qt::Key_Alt }, 106 { 0xffea, Qt::Key_Alt },
107 { 0, 0 } 107 { 0, 0 }
108}; 108};
109 109
110 110
111KRFBDecoder::KRFBDecoder( KRFBConnection *con ) 111KRFBDecoder::KRFBDecoder( KRFBConnection *con )
112 : QObject( con, "RFB Decoder" ) 112 : QObject( con, "RFB Decoder" )
113{ 113{
114 assert( con ); 114 assert( con );
115 assert( con->state() == KRFBConnection::Connected ); 115 assert( con->state() == KRFBConnection::Connected );
116 116
117 this->con = con; 117 this->con = con;
118 this->buf = 0; 118 this->buf = 0;
119 this->info = 0; 119 this->info = 0;
120 this->format = 0; 120 this->format = 0;
121 this->buttonMask = 0; 121 this->buttonMask = 0;
122 currentState = Idle; 122 currentState = Idle;
123} 123}
124 124
125KRFBDecoder::~KRFBDecoder() 125KRFBDecoder::~KRFBDecoder()
126{ 126{
127 if ( info ) 127 if ( info )
128 delete info; 128 delete info;
129 if ( format ) 129 if ( format )
130 delete format; 130 delete format;
131} 131}
132 132
133void KRFBDecoder::start() 133void KRFBDecoder::start()
134{ 134{
135 sendClientInit(); 135 sendClientInit();
136} 136}
137 137
138void KRFBDecoder::sendClientInit() 138void KRFBDecoder::sendClientInit()
139{ 139{
140 con->write( &( con->options()->shared ), 1 ); 140 con->write( &( con->options()->shared ), 1 );
141 141
142 // Wait for server init 142 // Wait for server init
143 owarn << "Waiting for server init" << oendl; 143 owarn << "Waiting for server init" << oendl;
144 144
145 static QString statusMsg = tr( "Waiting for server initialization..." ); 145 static QString statusMsg = tr( "Waiting for server initialization..." );
146 emit status( statusMsg ); 146 emit status( statusMsg );
147 147
148 currentState = AwaitingServerInit; 148 currentState = AwaitingServerInit;
149 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); 149 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) );
150 con->waitForData( ServerInitLength ); 150 con->waitForData( ServerInitLength );
151} 151}
152 152
153void KRFBDecoder::gotServerInit() 153void KRFBDecoder::gotServerInit()
154{ 154{
155 owarn << "Got server init" << oendl; 155 owarn << "Got server init" << oendl;
156 disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); 156 disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) );
157 157
158 if ( info ) 158 if ( info )
159 delete info; 159 delete info;
160 info = new KRFBServerInfo; 160 info = new KRFBServerInfo;
161 CHECK_PTR( info ); 161 CHECK_PTR( info );
162 162
163 con->read( &(info->width), 2 ); 163 con->read( &(info->width), 2 );
164 info->width = Swap16IfLE( info->width ); 164 info->width = Swap16IfLE( info->width );
165 con->read( &info->height, 2 ); 165 con->read( &info->height, 2 );
166 info->height = Swap16IfLE( info->height ); 166 info->height = Swap16IfLE( info->height );
167 167
168 con->read( &(info->bpp), 1 ); 168 con->read( &(info->bpp), 1 );
169 con->read( &(info->depth), 1 ); 169 con->read( &(info->depth), 1 );
170 con->read( &(info->bigEndian), 1 ); 170 con->read( &(info->bigEndian), 1 );
171 con->read( &(info->trueColor), 1 ); 171 con->read( &(info->trueColor), 1 );
172 172
173 con->read( &(info->redMax), 2 ); 173 con->read( &(info->redMax), 2 );
174 info->redMax = Swap16IfLE( info->redMax ); 174 info->redMax = Swap16IfLE( info->redMax );
175 con->read( &(info->greenMax), 2 ); 175 con->read( &(info->greenMax), 2 );
176 info->greenMax = Swap16IfLE( info->greenMax ); 176 info->greenMax = Swap16IfLE( info->greenMax );
177 con->read( &(info->blueMax), 2 ); 177 con->read( &(info->blueMax), 2 );
178 info->blueMax = Swap16IfLE( info->blueMax ); 178 info->blueMax = Swap16IfLE( info->blueMax );
179 179
180 con->read( &(info->redShift), 1 ); 180 con->read( &(info->redShift), 1 );
181 con->read( &(info->greenShift), 1 ); 181 con->read( &(info->greenShift), 1 );
182 con->read( &(info->blueShift), 1 ); 182 con->read( &(info->blueShift), 1 );
183 183
184 con->read( info->padding, 3 ); 184 con->read( info->padding, 3 );
185 185
186 con->read( &(info->nameLength), 4 ); 186 con->read( &(info->nameLength), 4 );
187 info->nameLength = Swap32IfLE( info->nameLength ); 187 info->nameLength = Swap32IfLE( info->nameLength );
188 188
189 owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; 189 owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl;
190 qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", 190 qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d",
191 info->bpp, info->depth, info->bigEndian, info->trueColor ); 191 info->bpp, info->depth, info->bigEndian, info->trueColor );
192 qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", 192 qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d",
193 info->redMax, info->greenMax, info->blueMax ); 193 info->redMax, info->greenMax, info->blueMax );
194 qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", 194 qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d",
195 info->redShift, info->greenShift,info-> blueShift ); 195 info->redShift, info->greenShift,info-> blueShift );
196 196
197 buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); 197 buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor);
198 198
199 // Wait for desktop name 199 // Wait for desktop name
200 owarn << "Waiting for desktop name" << oendl; 200 owarn << "Waiting for desktop name" << oendl;
201 201
202 static QString statusMsg = tr( "Waiting for desktop name..." ); 202 static QString statusMsg = tr( "Waiting for desktop name..." );
203 emit status( statusMsg ); 203 emit status( statusMsg );
204 204
205 currentState = AwaitingDesktopName; 205 currentState = AwaitingDesktopName;
206 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); 206 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) );
207 con->waitForData( info->nameLength ); 207 con->waitForData( info->nameLength );
208} 208}
209 209
210void KRFBDecoder::gotDesktopName() 210void KRFBDecoder::gotDesktopName()
211{ 211{
212 assert( info ); 212 assert( info );
213 assert( currentState == AwaitingDesktopName ); 213 assert( currentState == AwaitingDesktopName );
214 214
215 owarn << "Got desktop name" << oendl; 215 owarn << "Got desktop name" << oendl;
216 216
217 disconnect( con, SIGNAL( gotEnoughData() ), 217 disconnect( con, SIGNAL( gotEnoughData() ),
218 this, SLOT( gotDesktopName() ) ); 218 this, SLOT( gotDesktopName() ) );
219 219
220 char *buf = new char[ info->nameLength + 1 ]; 220 char *buf = new char[ info->nameLength + 1 ];
221 CHECK_PTR( buf ); 221 CHECK_PTR( buf );
222 222
223 con->read( buf, info->nameLength ); 223 con->read( buf, info->nameLength );
224 buf[ info->nameLength ] = '\0'; 224 buf[ info->nameLength ] = '\0';
225 info->name = buf; 225 info->name = buf;
226 226
227 owarn << "Desktop: " << info->name.latin1() << "" << oendl; 227 owarn << "Desktop: " << info->name.latin1() << "" << oendl;
228 228
229 delete buf; 229 delete buf;
230 230
231 // Get the format we'll really use and tell the server 231 // Get the format we'll really use and tell the server
232 decidePixelFormat(); 232 decidePixelFormat();
233 sendPixelFormat(); 233 sendPixelFormat();
234 sendAllowedEncodings(); 234 sendAllowedEncodings();
235 currentState = Idle; 235 currentState = Idle;
236 236
237 QString msg; 237 QString msg;
238 msg = tr( "Connected to %1" ); 238 msg = tr( "Connected to %1" );
239 msg = msg.arg( info->name ); 239 msg = msg.arg( info->name );
240 emit status( msg ); 240 emit status( msg );
241 241
242 sendUpdateRequest( false ); 242 sendUpdateRequest( false );
243} 243}
244 244
245void KRFBDecoder::decidePixelFormat() 245void KRFBDecoder::decidePixelFormat()
246{ 246{
247 assert( info ); 247 assert( info );
248 248
249 if ( format ) 249 if ( format )
250 delete format; 250 delete format;
251 format = new KRFBPixelFormat; 251 format = new KRFBPixelFormat;
252 CHECK_PTR( format ); 252 CHECK_PTR( format );
253 253
254 // What depth do we want? 254 // What depth do we want?
255 // 255 //
256 // We'll use the minimum of the remote and local depths, UNLESS an 256 // We'll use the minimum of the remote and local depths, UNLESS an
257 // eight bit session has been specifically requested by the user. 257 // eight bit session has been specifically requested by the user.
258 int screenDepth = QPixmap::defaultDepth(); 258 int screenDepth = QPixmap::defaultDepth();
259 int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; 259 int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth;
260 int chosenDepth; 260 int chosenDepth;
261 261
262 if ( con->options()->colors256 ) 262 if ( con->options()->colors256 )
263 chosenDepth = 8; 263 chosenDepth = 8;
264 else 264 else
265 chosenDepth = bestDepth; 265 chosenDepth = bestDepth;
266 266
267 qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ 267 qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \
268 "eight bit %d, chosenDepth=%d", 268 "eight bit %d, chosenDepth=%d",
269 screenDepth, 269 screenDepth,
270 info->depth, 270 info->depth,
271 bestDepth, 271 bestDepth,
272 con->options()->colors256, chosenDepth ); 272 con->options()->colors256, chosenDepth );
273 273
274 format->depth = chosenDepth; 274 format->depth = chosenDepth;
275 275
276 // If we're using the servers native depth 276 // If we're using the servers native depth
277 if ( chosenDepth == info->depth ) { 277 if ( chosenDepth == info->depth ) {
278 // Use the servers native format 278 // Use the servers native format
279 format->bpp = info->bpp; 279 format->bpp = info->bpp;
280 // format->bigEndian = info->bigEndian; 280 // format->bigEndian = info->bigEndian;
281 format->bigEndian = true; 281 format->bigEndian = true;
282 format->trueColor = info->trueColor; 282 format->trueColor = info->trueColor;
283 format->redMax = info->redMax; 283 format->redMax = info->redMax;
284 format->greenMax = info->greenMax; 284 format->greenMax = info->greenMax;
285 format->blueMax = info->blueMax; 285 format->blueMax = info->blueMax;
286 format->redShift = info->redShift; 286 format->redShift = info->redShift;
287 format->greenShift = info->greenShift; 287 format->greenShift = info->greenShift;
288 format->blueShift = info->blueShift; 288 format->blueShift = info->blueShift;
289 } 289 }
290 else { 290 else {
291 if ( chosenDepth == 8 ) { 291 if ( chosenDepth == 8 ) {
292 format->bpp = 8; 292 format->bpp = 8;
293 format->bigEndian = true; 293 format->bigEndian = true;
294 format->trueColor = true; 294 format->trueColor = true;
295 format->redMax = 7; 295 format->redMax = 7;
296 format->greenMax = 7; 296 format->greenMax = 7;
297 format->blueMax = 3; 297 format->blueMax = 3;
298 format->redShift = 0; 298 format->redShift = 0;
299 format->greenShift = 3; 299 format->greenShift = 3;
300 format->blueShift = 6; 300 format->blueShift = 6;
301 } 301 }
302 } 302 }
303 303
304 format->redMax = Swap16IfLE( format->redMax ); 304 format->redMax = Swap16IfLE( format->redMax );
305 format->greenMax = Swap16IfLE( format->greenMax ); 305 format->greenMax = Swap16IfLE( format->greenMax );
306 format->blueMax = Swap16IfLE( format->blueMax ); 306 format->blueMax = Swap16IfLE( format->blueMax );
307} 307}
308 308
309void KRFBDecoder::sendPixelFormat() 309void KRFBDecoder::sendPixelFormat()
310{ 310{
311 static char padding[3]; 311 static char padding[3];
312 con->write( &SetPixelFormatId, 1 ); 312 con->write( &SetPixelFormatId, 1 );
313 con->write( padding, 3 ); 313 con->write( padding, 3 );
314 314
315 con->write( &(format->bpp), 1 ); 315 con->write( &(format->bpp), 1 );
316 con->write( &(format->depth), 1 ); 316 con->write( &(format->depth), 1 );
317 con->write( &(format->bigEndian), 1 ); 317 con->write( &(format->bigEndian), 1 );
318 con->write( &(format->trueColor), 1 ); 318 con->write( &(format->trueColor), 1 );
319 319
320 con->write( &(format->redMax), 2 ); 320 con->write( &(format->redMax), 2 );
321 con->write( &(format->greenMax), 2 ); 321 con->write( &(format->greenMax), 2 );
322 con->write( &(format->blueMax), 2 ); 322 con->write( &(format->blueMax), 2 );
323 323
324 con->write( &(format->redShift), 1 ); 324 con->write( &(format->redShift), 1 );
325 con->write( &(format->greenShift), 1 ); 325 con->write( &(format->greenShift), 1 );
326 con->write( &(format->blueShift), 1 ); 326 con->write( &(format->blueShift), 1 );
327 con->write( format->padding, 3 ); // Padding 327 con->write( format->padding, 3 ); // Padding
328} 328}
329 329
330void KRFBDecoder::sendAllowedEncodings() 330void KRFBDecoder::sendAllowedEncodings()
331{ 331{
332 static CARD8 padding[1]; 332 static CARD8 padding[1];
333 con->write( &SetEncodingsId, 1 ); 333 con->write( &SetEncodingsId, 1 );
334 con->write( padding, 1 ); 334 con->write( padding, 1 );
335 335
336 CARD16 noEncodings = con->options()->encodings(); 336 CARD16 noEncodings = con->options()->encodings();
337 noEncodings = Swap16IfLE( noEncodings ); 337 noEncodings = Swap16IfLE( noEncodings );
338 con->write( &noEncodings, 2 ); 338 con->write( &noEncodings, 2 );
339 339
340 if ( con->options()->corre ) 340 if ( con->options()->corre )
341 con->write( &CorreEncoding, 4 ); 341 con->write( &CorreEncoding, 4 );
342 if ( con->options()->hexTile ) 342 if ( con->options()->hexTile )
343 con->write( &HexTileEncoding, 4 ); 343 con->write( &HexTileEncoding, 4 );
344 if ( con->options()->rre ) 344 if ( con->options()->rre )
345 con->write( &RreEncoding, 4 ); 345 con->write( &RreEncoding, 4 );
346 if ( con->options()->copyrect ) 346 if ( con->options()->copyrect )
347 con->write( &CopyRectEncoding, 4 ); 347 con->write( &CopyRectEncoding, 4 );
348 // We always support this 348 // We always support this
349 con->write( &RawEncoding, 4 ); 349 con->write( &RawEncoding, 4 );
350} 350}
351 351
352void KRFBDecoder::sendUpdateRequest( bool incremental ) 352void KRFBDecoder::sendUpdateRequest( bool incremental )
353{ 353{
354 if ( currentState != Idle ) 354 if ( currentState != Idle )
355 return; 355 return;
356 356
357 con->write( &UpdateRequestId, 1 ); 357 con->write( &UpdateRequestId, 1 );
358 con->write( &incremental, 1 ); 358 con->write( &incremental, 1 );
359 359
360 static CARD16 x = 0, y = 0; 360 static CARD16 x = 0, y = 0;
361 static CARD16 w = Swap16IfLE( info->width ); 361 static CARD16 w = Swap16IfLE( info->width );
362 static CARD16 h = Swap16IfLE( info->height ); 362 static CARD16 h = Swap16IfLE( info->height );
363 363
364 con->write( &x, 2 ); 364 con->write( &x, 2 );
365 con->write( &y, 2 ); 365 con->write( &y, 2 );
366 con->write( &w, 2 ); 366 con->write( &w, 2 );
367 con->write( &h, 2 ); 367 con->write( &h, 2 );
368 368
369 // Now wait for the update 369 // Now wait for the update
370 currentState = AwaitingUpdate; 370 currentState = AwaitingUpdate;
371 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 371 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
372 con->waitForData( UpdateHeaderLength ); 372 con->waitForData( UpdateHeaderLength );
373} 373}
374 374
375void KRFBDecoder::gotUpdateHeader() 375void KRFBDecoder::gotUpdateHeader()
376{ 376{
377 assert( currentState == AwaitingUpdate ); 377 assert( currentState == AwaitingUpdate );
378 378
379 // owarn << "Got update header" << oendl; 379 // owarn << "Got update header" << oendl;
380 380
381 disconnect( con, SIGNAL( gotEnoughData() ), 381 disconnect( con, SIGNAL( gotEnoughData() ),
382 this, SLOT( gotUpdateHeader() ) ); 382 this, SLOT( gotUpdateHeader() ) );
383 383
384 CARD8 msgType; 384 CARD8 msgType;
385 con->read( &msgType, 1 ); 385 con->read( &msgType, 1 );
386 386
387 if ( msgType != UpdateId ) { 387 if ( msgType != UpdateId ) {
388 // We might have a bell or server cut 388 // We might have a bell or server cut
389 if ( msgType == ServerCutId ) { 389 if ( msgType == ServerCutId ) {
390 oldState = currentState; 390 oldState = currentState;
391 gotServerCut(); 391 gotServerCut();
392 } 392 }
393 else if ( msgType == BellId ) { 393 else if ( msgType == BellId ) {
394 oldState = currentState; 394 oldState = currentState;
395 gotBell(); 395 gotBell();
396 } 396 }
397 else { 397 else {
398 int msg = msgType; 398 int msg = msgType;
399 QString protocolError = tr( "Protocol Error: Message Id %1 was " 399 QString protocolError = tr( "Protocol Error: Message Id %1 was "
400 "found when expecting an update " 400 "found when expecting an update "
401 "message." ).arg( msg ); 401 "message." ).arg( msg );
402 currentState = Error; 402 currentState = Error;
403 emit error( protocolError ); 403 emit error( protocolError );
404 } 404 }
405 return; 405 return;
406 } 406 }
407 407
408 CARD8 padding; 408 CARD8 padding;
409 con->read( &padding, 1 ); 409 con->read( &padding, 1 );
410 410
411 con->read( &noRects, 2 ); 411 con->read( &noRects, 2 );
412 noRects = Swap16IfLE( noRects ); 412 noRects = Swap16IfLE( noRects );
413 413
414 // owarn << "Expecting " << noRects << " rects" << oendl; 414 // owarn << "Expecting " << noRects << " rects" << oendl;
415 415
416 // Now wait for the data 416 // Now wait for the data
417 currentState = AwaitingRectHeader; 417 currentState = AwaitingRectHeader;
418 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 418 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
419 con->waitForData( RectHeaderLength ); 419 con->waitForData( RectHeaderLength );
420} 420}
421 421
422void KRFBDecoder::gotRectHeader() 422void KRFBDecoder::gotRectHeader()
423{ 423{
424 assert( currentState == AwaitingRectHeader ); 424 assert( currentState == AwaitingRectHeader );
425 425
426 // owarn << "Got rect header" << oendl; 426 // owarn << "Got rect header" << oendl;
427 427
428 disconnect( con, SIGNAL( gotEnoughData() ), 428 disconnect( con, SIGNAL( gotEnoughData() ),
429 this, SLOT( gotRectHeader() ) ); 429 this, SLOT( gotRectHeader() ) );
430 430
431 con->read( &x, 2 ); 431 con->read( &x, 2 );
432 x = Swap16IfLE( x ); 432 x = Swap16IfLE( x );
433 con->read( &y, 2 ); 433 con->read( &y, 2 );
434 y = Swap16IfLE( y ); 434 y = Swap16IfLE( y );
435 435
436 con->read( &w, 2 ); 436 con->read( &w, 2 );
437 w = Swap16IfLE( w ); 437 w = Swap16IfLE( w );
438 con->read( &h, 2 ); 438 con->read( &h, 2 );
439 h = Swap16IfLE( h ); 439 h = Swap16IfLE( h );
440 440
441 con->read( &encoding, 4 ); 441 con->read( &encoding, 4 );
442 442
443 // CARD32 encodingLocal = Swap32IfLE( encoding ); 443 // CARD32 encodingLocal = Swap32IfLE( encoding );
444 // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", 444 // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld",
445 // x, y, w, h, encodingLocal ); 445 // x, y, w, h, encodingLocal );
446 446
447 // 447 //
448 // Each encoding needs to be handled differently. Some require 448 // Each encoding needs to be handled differently. Some require
449 // waiting for more data, but others like a copyrect do not. 449 // waiting for more data, but others like a copyrect do not.
450 // Our constants have already been byte swapped, so we use 450 // Our constants have already been byte swapped, so we use
451 // the remote value as is. 451 // the remote value as is.
452 // 452 //
453 if ( encoding == RawEncoding ) { 453 if ( encoding == RawEncoding ) {
454 // owarn << "Raw encoding" << oendl; 454 // owarn << "Raw encoding" << oendl;
455 handleRawRect(); 455 handleRawRect();
456 } 456 }
457 else if ( encoding == CopyRectEncoding ) { 457 else if ( encoding == CopyRectEncoding ) {
458// owarn << "CopyRect encoding" << oendl; 458// owarn << "CopyRect encoding" << oendl;
459 handleCopyRect(); 459 handleCopyRect();
460 } 460 }
461 else if ( encoding == RreEncoding ) { 461 else if ( encoding == RreEncoding ) {
462 owarn << "RRE encoding" << oendl; 462 owarn << "RRE encoding" << oendl;
463 handleRRERect(); 463 handleRRERect();
464 } 464 }
465 else if ( encoding == CorreEncoding ) { 465 else if ( encoding == CorreEncoding ) {
466 owarn << "CoRRE encoding" << oendl; 466 owarn << "CoRRE encoding" << oendl;
467 handleCoRRERect(); 467 handleCoRRERect();
468 } 468 }
469 else if ( encoding == HexTileEncoding ) { 469 else if ( encoding == HexTileEncoding ) {
470 owarn << "HexTile encoding" << oendl; 470 owarn << "HexTile encoding" << oendl;
471 handleHexTileRect(); 471 handleHexTileRect();
472 } 472 }
473 else { 473 else {
474 int msg = Swap32IfLE( encoding ); 474 int msg = Swap32IfLE( encoding );
475 QString protocolError = tr( "Protocol Error: An unknown encoding was " 475 QString protocolError = tr( "Protocol Error: An unknown encoding was "
476 "used by the server %1" ).arg( msg ); 476 "used by the server %1" ).arg( msg );
477 currentState = Error; 477 currentState = Error;
478 owarn << "Unknown encoding, " << msg << "" << oendl; 478 owarn << "Unknown encoding, " << msg << "" << oendl;
479 emit error( protocolError ); 479 emit error( protocolError );
480 return; 480 return;
481 } 481 }
482} 482}
483 483
484// 484//
485// Raw Encoding 485// Raw Encoding
486// 486//
487 487
488void KRFBDecoder::handleRawRect() 488void KRFBDecoder::handleRawRect()
489{ 489{
490 // We need something a bit cleverer here to handle large 490 // We need something a bit cleverer here to handle large
491 // rectanges nicely. The chunking should be based on the 491 // rectanges nicely. The chunking should be based on the
492 // overall size (but has to be in complete lines). 492 // overall size (but has to be in complete lines).
493 493
494 // owarn << "Handling a raw rect chunk" << oendl; 494 // owarn << "Handling a raw rect chunk" << oendl;
495 495
496 // CARD32 lineCount = w * format->bpp / 8; 496 // CARD32 lineCount = w * format->bpp / 8;
497 497
498 if ( h > RectChunkSize ) { 498 if ( h > RectChunkSize ) {
499 // if ( con->sock->size() / lineCount ) { 499 // if ( con->sock->size() / lineCount ) {
500 // getRawRectChunk( con->sock->size() / lineCount ); 500 // getRawRectChunk( con->sock->size() / lineCount );
501 // } 501 // }
502 // else { 502 // else {
503 getRawRectChunk( RectChunkSize ); 503 getRawRectChunk( RectChunkSize );
504 // } 504 // }
505 } 505 }
506 else { 506 else {
507 getRawRectChunk( h ); 507 getRawRectChunk( h );
508 } 508 }
509} 509}
510 510
511void KRFBDecoder::getRawRectChunk( int lines ) 511void KRFBDecoder::getRawRectChunk( int lines )
512{ 512{
513 this->lines = lines; 513 this->lines = lines;
514 CARD32 count = lines * w * format->bpp / 8; 514 CARD32 count = lines * w * format->bpp / 8;
515 515
516 // Wait for server init 516 // Wait for server init
517 // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; 517 // owarn << "Waiting for raw rect chunk, " << count << "" << oendl;
518 518
519 currentState = AwaitingRawRectChunk; 519 currentState = AwaitingRawRectChunk;
520 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); 520 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) );
521 con->waitForData( count ); 521 con->waitForData( count );
522} 522}
523 523
524void KRFBDecoder::gotRawRectChunk() 524void KRFBDecoder::gotRawRectChunk()
525{ 525{
526 assert( currentState == AwaitingRawRectChunk ); 526 assert( currentState == AwaitingRawRectChunk );
527 527
528 disconnect( con, SIGNAL( gotEnoughData() ), 528 disconnect( con, SIGNAL( gotEnoughData() ),
529 this, SLOT( gotRawRectChunk() ) ); 529 this, SLOT( gotRawRectChunk() ) );
530 530
531 // owarn << "Got raw rect chunk" << oendl; 531 // owarn << "Got raw rect chunk" << oendl;
532 532
533 // 533 //
534 // Read the rect data and copy it to the buffer. 534 // Read the rect data and copy it to the buffer.
535 // 535 //
536 536
537 // TODO: Replace this! 537 // TODO: Replace this!
538 int count = lines * w * format->bpp / 8; 538 int count = lines * w * format->bpp / 8;
539 char *hack = new char[ count ]; 539 char *hack = new char[ count ];
540 con->read( hack, count ); 540 con->read( hack, count );
541 buf->drawRawRectChunk( hack, x, y, w, lines ); 541 buf->drawRawRectChunk( hack, x, y, w, lines );
542 delete hack; 542 delete hack;
543 // /TODO: 543 // /TODO:
544 544
545 h = h - lines; 545 h = h - lines;
546 y = y + lines; 546 y = y + lines;
547 547
548 if ( h > 0 ) { 548 if ( h > 0 ) {
549 handleRawRect(); 549 handleRawRect();
550 } 550 }
551 else { 551 else {
552 noRects--; 552 noRects--;
553 553
554 // owarn << "There are " << noRects << " rects left" << oendl; 554 // owarn << "There are " << noRects << " rects left" << oendl;
555 555
556 if ( noRects ) { 556 if ( noRects ) {
557 currentState = AwaitingRectHeader; 557 currentState = AwaitingRectHeader;
558 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 558 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
559 con->waitForData( RectHeaderLength ); 559 con->waitForData( RectHeaderLength );
560 } 560 }
561 else { 561 else {
562 // we are now ready for the next update - no need to wait for the timer 562 // we are now ready for the next update - no need to wait for the timer
563 currentState = Idle; 563 currentState = Idle;
564 sendUpdateRequest (1); 564 sendUpdateRequest (1);
565 } 565 }
566 } 566 }
567} 567}
568 568
569// 569//
570// Copy Rectangle Encoding 570// Copy Rectangle Encoding
571// 571//
572 572
573void KRFBDecoder::handleCopyRect() 573void KRFBDecoder::handleCopyRect()
574{ 574{
575 currentState = AwaitingCopyRectPos; 575 currentState = AwaitingCopyRectPos;
576 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); 576 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) );
577 con->waitForData( CopyRectPosLength ); 577 con->waitForData( CopyRectPosLength );
578} 578}
579 579
580void KRFBDecoder::gotCopyRectPos() 580void KRFBDecoder::gotCopyRectPos()
581{ 581{
582 disconnect( con, SIGNAL( gotEnoughData() ), 582 disconnect( con, SIGNAL( gotEnoughData() ),
583 this, SLOT( gotCopyRectPos() ) ); 583 this, SLOT( gotCopyRectPos() ) );
584 584
585 CARD16 srcX; 585 CARD16 srcX;
586 CARD16 srcY; 586 CARD16 srcY;
587 587
588 con->read( &srcX, 2 ); 588 con->read( &srcX, 2 );
589 con->read( &srcY, 2 ); 589 con->read( &srcY, 2 );
590 590
591 srcX = Swap16IfLE( srcX ); 591 srcX = Swap16IfLE( srcX );
592 srcY = Swap16IfLE( srcY ); 592 srcY = Swap16IfLE( srcY );
593 593
594 buf->copyRect( srcX, srcY, x, y, w, h ); 594 buf->copyRect( srcX, srcY, x, y, w, h );
595 595
596 noRects--; 596 noRects--;
597 597
598 // owarn << "There are " << noRects << " rects left" << oendl; 598 // owarn << "There are " << noRects << " rects left" << oendl;
599 599
600 if ( noRects ) { 600 if ( noRects ) {
601 currentState = AwaitingRectHeader; 601 currentState = AwaitingRectHeader;
602 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 602 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
603 con->waitForData( RectHeaderLength ); 603 con->waitForData( RectHeaderLength );
604 } 604 }
605 else 605 else
606 currentState = Idle; 606 currentState = Idle;
607} 607}
608 608
609void KRFBDecoder::handleRRERect() 609void KRFBDecoder::handleRRERect()
610{ 610{
611 owarn << "RRE not implemented" << oendl; 611 owarn << "RRE not implemented" << oendl;
612} 612}
613 613
614void KRFBDecoder::handleCoRRERect() 614void KRFBDecoder::handleCoRRERect()
615{ 615{
616 owarn << "CoRRE not implemented" << oendl; 616 owarn << "CoRRE not implemented" << oendl;
617} 617}
618 618
619void KRFBDecoder::handleHexTileRect() 619void KRFBDecoder::handleHexTileRect()
620{ 620{
621 owarn << "HexTile not implemented" << oendl; 621 owarn << "HexTile not implemented" << oendl;
622} 622}
623 623
624void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) 624void KRFBDecoder::sendMouseEvent( QMouseEvent *e )
625{ 625{
626 // Deal with the buttons 626 // Deal with the buttons
627 if ( e->type() != QEvent::MouseMove ) { 627 if ( e->type() != QEvent::MouseMove ) {
628 buttonMask = 0; 628 buttonMask = 0;
629 if ( e->type() == QEvent::MouseButtonPress ) { 629 if ( e->type() == QEvent::MouseButtonPress ) {
630 if ( e->button() & LeftButton ) 630 if ( e->button() & LeftButton )
631 buttonMask |= 0x01; 631 buttonMask |= 0x01;
632 if ( e->button() & MidButton ) 632 if ( e->button() & MidButton )
633 buttonMask |= 0x04; 633 buttonMask |= 0x04;
634 if ( e->button() & RightButton ) 634 if ( e->button() & RightButton )
635 buttonMask |= 0x02; 635 buttonMask |= 0x02;
636 } 636 }
637 else if ( e->type() == QEvent::MouseButtonRelease ) { 637 else if ( e->type() == QEvent::MouseButtonRelease ) {
638 if ( e->button() & LeftButton ) 638 if ( e->button() & LeftButton )
639 buttonMask &= 0x06; 639 buttonMask &= 0x06;
640 if ( e->button() & MidButton ) 640 if ( e->button() & MidButton )
641 buttonMask |= 0x03; 641 buttonMask |= 0x03;
642 if ( e->button() & RightButton ) 642 if ( e->button() & RightButton )
643 buttonMask |= 0x05; 643 buttonMask |= 0x05;
644 } 644 }
645 } 645 }
646 646
647 // HACK: Scaling 647 // HACK: Scaling
648 CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); 648 CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor );
649 CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); 649 CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor );
650 650
651 con->write( &PointerEventId, 1 ); 651 con->write( &PointerEventId, 1 );
652 con->write( &buttonMask, 1 ); 652 con->write( &buttonMask, 1 );
653 con->write( &x, 2 ); 653 con->write( &x, 2 );
654 con->write( &y, 2 ); 654 con->write( &y, 2 );
655} 655}
656 656
657 657
658void KRFBDecoder::sendCutEvent( const QString &unicode ) 658void KRFBDecoder::sendCutEvent( const QString &unicode )
659{ 659{
660 // 660 //
661 // Warning: There is a bug in the RFB protocol because there is no way to find 661 // Warning: There is a bug in the RFB protocol because there is no way to find
662 // out the codepage in use on the remote machine. This could be fixed by requiring 662 // out the codepage in use on the remote machine. This could be fixed by requiring
663 // the remote server to use utf8 etc. but for now we have to assume they're the 663 // the remote server to use utf8 etc. but for now we have to assume they're the
664 // same. I've reported this problem to the ORL guys, but they apparantly have no 664 // same. I've reported this problem to the ORL guys, but they apparantly have no
665 // immediate plans to fix the issue. :-( (rich) 665 // immediate plans to fix the issue. :-( (rich)
666 // 666 //
667 667
668 CARD8 padding[3]; 668 CARD8 padding[3];
669 QCString text = unicode.local8Bit(); 669 QCString text = unicode.local8Bit();
670 CARD32 length = text.length(); 670 CARD32 length = text.length();
671 length = Swap32IfLE( length ); 671 length = Swap32IfLE( length );
672 672
673 con->write( &ClientCutTextId, 1 ); 673 con->write( &ClientCutTextId, 1 );
674 con->write( &padding, 3 ); 674 con->write( &padding, 3 );
675 con->write( &length, 4 ); 675 con->write( &length, 4 );
676 con->write( text.data(), length ); 676 con->write( text.data(), length );
677} 677}
678 678
679void KRFBDecoder::gotServerCut() 679void KRFBDecoder::gotServerCut()
680{ 680{
681 owarn << "Got server cut" << oendl; 681 owarn << "Got server cut" << oendl;
682 682
683 currentState = AwaitingServerCutLength; 683 currentState = AwaitingServerCutLength;
684 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); 684 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) );
685 con->waitForData( ServerCutLenLength ); 685 con->waitForData( ServerCutLenLength );
686} 686}
687 687
688void KRFBDecoder::gotServerCutLength() 688void KRFBDecoder::gotServerCutLength()
689{ 689{
690 assert( currentState = AwaitingServerCutLength ); 690 assert( currentState = AwaitingServerCutLength );
691 disconnect( con, SIGNAL( gotEnoughData() ), 691 disconnect( con, SIGNAL( gotEnoughData() ),
692 this, SLOT( gotServerCutLength() ) ); 692 this, SLOT( gotServerCutLength() ) );
693 693
694 CARD8 padding[3]; 694 CARD8 padding[3];
695 con->read( padding, 3 ); 695 con->read( padding, 3 );
696 696
697 con->read( &serverCutTextLen, 4 ); 697 con->read( &serverCutTextLen, 4 );
698 serverCutTextLen = Swap32IfLE( serverCutTextLen ); 698 serverCutTextLen = Swap32IfLE( serverCutTextLen );
699 699
700 currentState = AwaitingServerCutText; 700 currentState = AwaitingServerCutText;
701 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); 701 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) );
702 con->waitForData( serverCutTextLen ); 702 con->waitForData( serverCutTextLen );
703} 703}
704 704
705void KRFBDecoder::gotServerCutText() 705void KRFBDecoder::gotServerCutText()
706{ 706{
707 assert( currentState = AwaitingServerCutText ); 707 assert( currentState = AwaitingServerCutText );
708 708
709 disconnect( con, SIGNAL( gotEnoughData() ), 709 disconnect( con, SIGNAL( gotEnoughData() ),
710 this, SLOT( gotServerCutText() ) ); 710 this, SLOT( gotServerCutText() ) );
711 711
712 712
713 // 713 //
714 // Warning: There is a bug in the RFB protocol because there is no way to find 714 // Warning: There is a bug in the RFB protocol because there is no way to find
715 // out the codepage in use on the remote machine. This could be fixed by requiring 715 // out the codepage in use on the remote machine. This could be fixed by requiring
716 // the remote server to use utf8 etc. but for now we have to assume they're the 716 // the remote server to use utf8 etc. but for now we have to assume they're the
717 // same. I've reported this problem to the ORL guys, but they apparantly have no 717 // same. I've reported this problem to the ORL guys, but they apparantly have no
718 // immediate plans to fix the issue. :-( (rich) 718 // immediate plans to fix the issue. :-( (rich)
719 // 719 //
720 720
721 char *cutbuf = new char[ serverCutTextLen + 1 ]; 721 char *cutbuf = new char[ serverCutTextLen + 1 ];
722 CHECK_PTR( cutbuf ); 722 CHECK_PTR( cutbuf );
723 723
724 con->read( cutbuf, serverCutTextLen ); 724 con->read( cutbuf, serverCutTextLen );
725 cutbuf[ serverCutTextLen ] = '\0'; 725 cutbuf[ serverCutTextLen ] = '\0';
726 726
727 /* For some reason QApplication::clipboard()->setText() segfaults when called 727 /* For some reason QApplication::clipboard()->setText() segfaults when called
728 * from within keypebble's mass of signals and slots 728 * from within keypebble's mass of signals and slots
729 owarn << "Server cut: " << cutbuf << "" << oendl; 729 owarn << "Server cut: " << cutbuf << "" << oendl;
730 730
731 QString cutText( cutbuf ); // DANGER!! 731 QString cutText( cutbuf ); // DANGER!!
732 qApp->clipboard()->setText( cutText ); 732 qApp->clipboard()->setText( cutText );
733 */ 733 */
734 734
735 delete cutbuf; 735 delete cutbuf;
736 // Now wait for the update (again) 736 // Now wait for the update (again)
737 if ( oldState == AwaitingUpdate ) { 737 if ( oldState == AwaitingUpdate ) {
738 currentState = AwaitingUpdate; 738 currentState = AwaitingUpdate;
739 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 739 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
740 con->waitForData( UpdateHeaderLength ); 740 con->waitForData( UpdateHeaderLength );
741 } 741 }
742 else if ( oldState == Idle ) { 742 else if ( oldState == Idle ) {
743 currentState = Idle; 743 currentState = Idle;
744 } 744 }
745 else { 745 else {
746 owarn << "Async handled in weird state" << oendl; 746 owarn << "Async handled in weird state" << oendl;
747 currentState = oldState; 747 currentState = oldState;
748 }; 748 };
749} 749}
750 750
751void KRFBDecoder::gotBell() 751void KRFBDecoder::gotBell()
752{ 752{
753 owarn << "Got server bell" << oendl; 753 owarn << "Got server bell" << oendl;
754 buf->soundBell(); 754 buf->soundBell();
755 755
756 // Now wait for the update (again) 756 // Now wait for the update (again)
757 if ( oldState == AwaitingUpdate ) { 757 if ( oldState == AwaitingUpdate ) {
758 currentState = AwaitingUpdate; 758 currentState = AwaitingUpdate;
759 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 759 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
760 con->waitForData( UpdateHeaderLength ); 760 con->waitForData( UpdateHeaderLength );
761 } 761 }
762 else if ( oldState == Idle ) { 762 else if ( oldState == Idle ) {
763 currentState = Idle; 763 currentState = Idle;
764 } 764 }
765 else { 765 else {
766 owarn << "Async handled in weird state" << oendl; 766 owarn << "Async handled in weird state" << oendl;
767 currentState = oldState; 767 currentState = oldState;
768 }; 768 };
769} 769}
770 770
771void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) 771void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event )
772{ 772{
773 int key; 773 int key;
774 key = toKeySym( event ); 774 key = toKeySym( event );
775 if ( key ) { 775 if ( key ) {
776 key = Swap32IfLE( key ); 776 key = Swap32IfLE( key );
777 777
778 CARD8 mask = true; 778 CARD8 mask = true;
779 779
780 CARD16 padding = 0; 780 CARD16 padding = 0;
781 con->write( &KeyEventId, 1 ); 781 con->write( &KeyEventId, 1 );
782 con->write( &mask, 1 ); 782 con->write( &mask, 1 );
783 con->write( &padding, 2 ); 783 con->write( &padding, 2 );
784 con->write( &key, 4 ); 784 con->write( &key, 4 );
785 } 785 }
786} 786}
787 787
788void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) 788void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event )
789{ 789{