summaryrefslogtreecommitdiff
path: root/noncore/comm/keypebble/krfbdecoder.cpp
Unidiff
Diffstat (limited to 'noncore/comm/keypebble/krfbdecoder.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/comm/keypebble/krfbdecoder.cpp108
1 files changed, 52 insertions, 56 deletions
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp
index d61433f..837fcc5 100644
--- a/noncore/comm/keypebble/krfbdecoder.cpp
+++ b/noncore/comm/keypebble/krfbdecoder.cpp
@@ -16,27 +16,27 @@ using namespace Opie::Core;
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//
@@ -131,37 +131,37 @@ KRFBDecoder::~KRFBDecoder()
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
@@ -177,63 +177,62 @@ void KRFBDecoder::gotServerInit()
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 owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian
191 info->bpp, info->depth, info->bigEndian, info->trueColor ); 191 << ", True = " << info->trueColor << oendl;
192 qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", 192 owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl;
193 info->redMax, info->greenMax, info->blueMax ); 193 owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift
194 qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", 194 << ", BlueShift = " << info-> blueShift << oendl;
195 info->redShift, info->greenShift,info-> blueShift );
196 195
197 buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); 196 buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor);
198 197
199 // Wait for desktop name 198 // Wait for desktop name
200 owarn << "Waiting for desktop name" << oendl; 199 owarn << "Waiting for desktop name" << oendl;
201 200
202 static QString statusMsg = tr( "Waiting for desktop name..." ); 201 static QString statusMsg = tr( "Waiting for desktop name..." );
203 emit status( statusMsg ); 202 emit status( statusMsg );
204 203
205 currentState = AwaitingDesktopName; 204 currentState = AwaitingDesktopName;
206 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); 205 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) );
207 con->waitForData( info->nameLength ); 206 con->waitForData( info->nameLength );
208} 207}
209 208
210void KRFBDecoder::gotDesktopName() 209void KRFBDecoder::gotDesktopName()
211{ 210{
212 assert( info ); 211 assert( info );
213 assert( currentState == AwaitingDesktopName ); 212 assert( currentState == AwaitingDesktopName );
214 213
215 owarn << "Got desktop name" << oendl; 214 owarn << "Got desktop name" << oendl;
216 215
217 disconnect( con, SIGNAL( gotEnoughData() ), 216 disconnect( con, SIGNAL( gotEnoughData() ),
218 this, SLOT( gotDesktopName() ) ); 217 this, SLOT( gotDesktopName() ) );
219 218
220 char *buf = new char[ info->nameLength + 1 ]; 219 char *buf = new char[ info->nameLength + 1 ];
221 CHECK_PTR( buf ); 220 CHECK_PTR( buf );
222 221
223 con->read( buf, info->nameLength ); 222 con->read( buf, info->nameLength );
224 buf[ info->nameLength ] = '\0'; 223 buf[ info->nameLength ] = '\0';
225 info->name = buf; 224 info->name = buf;
226 225
227 owarn << "Desktop: " << info->name.latin1() << "" << oendl; 226 owarn << "Desktop: " << info->name.latin1() << "" << oendl;
228 227
229 delete buf; 228 delete buf;
230 229
231 // Get the format we'll really use and tell the server 230 // Get the format we'll really use and tell the server
232 decidePixelFormat(); 231 decidePixelFormat();
233 sendPixelFormat(); 232 sendPixelFormat();
234 sendAllowedEncodings(); 233 sendAllowedEncodings();
235 currentState = Idle; 234 currentState = Idle;
236 235
237 QString msg; 236 QString msg;
238 msg = tr( "Connected to %1" ); 237 msg = tr( "Connected to %1" );
239 msg = msg.arg( info->name ); 238 msg = msg.arg( info->name );
@@ -255,30 +254,27 @@ void KRFBDecoder::decidePixelFormat()
255 // 254 //
256 // We'll use the minimum of the remote and local depths, UNLESS an 255 // We'll use the minimum of the remote and local depths, UNLESS an
257 // eight bit session has been specifically requested by the user. 256 // eight bit session has been specifically requested by the user.
258 int screenDepth = QPixmap::defaultDepth(); 257 int screenDepth = QPixmap::defaultDepth();
259 int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; 258 int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth;
260 int chosenDepth; 259 int chosenDepth;
261 260
262 if ( con->options()->colors256 ) 261 if ( con->options()->colors256 )
263 chosenDepth = 8; 262 chosenDepth = 8;
264 else 263 else
265 chosenDepth = bestDepth; 264 chosenDepth = bestDepth;
266 265
267 qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ 266 owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth
268 "eight bit %d, chosenDepth=%d", 267 << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256
269 screenDepth, 268 << ", chosenDepth=" << chosenDepth << oendl;
270 info->depth,
271 bestDepth,
272 con->options()->colors256, chosenDepth );
273 269
274 format->depth = chosenDepth; 270 format->depth = chosenDepth;
275 271
276 // If we're using the servers native depth 272 // If we're using the servers native depth
277 if ( chosenDepth == info->depth ) { 273 if ( chosenDepth == info->depth ) {
278 // Use the servers native format 274 // Use the servers native format
279 format->bpp = info->bpp; 275 format->bpp = info->bpp;
280 // format->bigEndian = info->bigEndian; 276 // format->bigEndian = info->bigEndian;
281 format->bigEndian = true; 277 format->bigEndian = true;
282 format->trueColor = info->trueColor; 278 format->trueColor = info->trueColor;
283 format->redMax = info->redMax; 279 format->redMax = info->redMax;
284 format->greenMax = info->greenMax; 280 format->greenMax = info->greenMax;
@@ -367,28 +363,28 @@ void KRFBDecoder::sendUpdateRequest( bool incremental )
367 con->write( &h, 2 ); 363 con->write( &h, 2 );
368 364
369 // Now wait for the update 365 // Now wait for the update
370 currentState = AwaitingUpdate; 366 currentState = AwaitingUpdate;
371 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 367 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
372 con->waitForData( UpdateHeaderLength ); 368 con->waitForData( UpdateHeaderLength );
373} 369}
374 370
375void KRFBDecoder::gotUpdateHeader() 371void KRFBDecoder::gotUpdateHeader()
376{ 372{
377 assert( currentState == AwaitingUpdate ); 373 assert( currentState == AwaitingUpdate );
378 374
379 // owarn << "Got update header" << oendl; 375 // owarn << "Got update header" << oendl;
380 376
381 disconnect( con, SIGNAL( gotEnoughData() ), 377 disconnect( con, SIGNAL( gotEnoughData() ),
382 this, SLOT( gotUpdateHeader() ) ); 378 this, SLOT( gotUpdateHeader() ) );
383 379
384 CARD8 msgType; 380 CARD8 msgType;
385 con->read( &msgType, 1 ); 381 con->read( &msgType, 1 );
386 382
387 if ( msgType != UpdateId ) { 383 if ( msgType != UpdateId ) {
388 // We might have a bell or server cut 384 // We might have a bell or server cut
389 if ( msgType == ServerCutId ) { 385 if ( msgType == ServerCutId ) {
390 oldState = currentState; 386 oldState = currentState;
391 gotServerCut(); 387 gotServerCut();
392 } 388 }
393 else if ( msgType == BellId ) { 389 else if ( msgType == BellId ) {
394 oldState = currentState; 390 oldState = currentState;
@@ -402,165 +398,165 @@ void KRFBDecoder::gotUpdateHeader()
402 currentState = Error; 398 currentState = Error;
403 emit error( protocolError ); 399 emit error( protocolError );
404 } 400 }
405 return; 401 return;
406 } 402 }
407 403
408 CARD8 padding; 404 CARD8 padding;
409 con->read( &padding, 1 ); 405 con->read( &padding, 1 );
410 406
411 con->read( &noRects, 2 ); 407 con->read( &noRects, 2 );
412 noRects = Swap16IfLE( noRects ); 408 noRects = Swap16IfLE( noRects );
413 409
414 // owarn << "Expecting " << noRects << " rects" << oendl; 410 // owarn << "Expecting " << noRects << " rects" << oendl;
415 411
416 // Now wait for the data 412 // Now wait for the data
417 currentState = AwaitingRectHeader; 413 currentState = AwaitingRectHeader;
418 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 414 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
419 con->waitForData( RectHeaderLength ); 415 con->waitForData( RectHeaderLength );
420} 416}
421 417
422void KRFBDecoder::gotRectHeader() 418void KRFBDecoder::gotRectHeader()
423{ 419{
424 assert( currentState == AwaitingRectHeader ); 420 assert( currentState == AwaitingRectHeader );
425 421
426 // owarn << "Got rect header" << oendl; 422 // owarn << "Got rect header" << oendl;
427 423
428 disconnect( con, SIGNAL( gotEnoughData() ), 424 disconnect( con, SIGNAL( gotEnoughData() ),
429 this, SLOT( gotRectHeader() ) ); 425 this, SLOT( gotRectHeader() ) );
430 426
431 con->read( &x, 2 ); 427 con->read( &x, 2 );
432 x = Swap16IfLE( x ); 428 x = Swap16IfLE( x );
433 con->read( &y, 2 ); 429 con->read( &y, 2 );
434 y = Swap16IfLE( y ); 430 y = Swap16IfLE( y );
435 431
436 con->read( &w, 2 ); 432 con->read( &w, 2 );
437 w = Swap16IfLE( w ); 433 w = Swap16IfLE( w );
438 con->read( &h, 2 ); 434 con->read( &h, 2 );
439 h = Swap16IfLE( h ); 435 h = Swap16IfLE( h );
440 436
441 con->read( &encoding, 4 ); 437 con->read( &encoding, 4 );
442 438
443 // CARD32 encodingLocal = Swap32IfLE( encoding ); 439 // CARD32 encodingLocal = Swap32IfLE( encoding );
444 // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", 440 // owarn << "Rect: x=" << x << ", y= " << y << ", w=" << w << ", h=" << h
445 // x, y, w, h, encodingLocal ); 441 // << ", encoding= " << encodingLocal << oendl;
446 442
447 // 443 //
448 // Each encoding needs to be handled differently. Some require 444 // Each encoding needs to be handled differently. Some require
449 // waiting for more data, but others like a copyrect do not. 445 // waiting for more data, but others like a copyrect do not.
450 // Our constants have already been byte swapped, so we use 446 // Our constants have already been byte swapped, so we use
451 // the remote value as is. 447 // the remote value as is.
452 // 448 //
453 if ( encoding == RawEncoding ) { 449 if ( encoding == RawEncoding ) {
454 // owarn << "Raw encoding" << oendl; 450 // owarn << "Raw encoding" << oendl;
455 handleRawRect(); 451 handleRawRect();
456 } 452 }
457 else if ( encoding == CopyRectEncoding ) { 453 else if ( encoding == CopyRectEncoding ) {
458// owarn << "CopyRect encoding" << oendl; 454// owarn << "CopyRect encoding" << oendl;
459 handleCopyRect(); 455 handleCopyRect();
460 } 456 }
461 else if ( encoding == RreEncoding ) { 457 else if ( encoding == RreEncoding ) {
462 owarn << "RRE encoding" << oendl; 458 owarn << "RRE encoding" << oendl;
463 handleRRERect(); 459 handleRRERect();
464 } 460 }
465 else if ( encoding == CorreEncoding ) { 461 else if ( encoding == CorreEncoding ) {
466 owarn << "CoRRE encoding" << oendl; 462 owarn << "CoRRE encoding" << oendl;
467 handleCoRRERect(); 463 handleCoRRERect();
468 } 464 }
469 else if ( encoding == HexTileEncoding ) { 465 else if ( encoding == HexTileEncoding ) {
470 owarn << "HexTile encoding" << oendl; 466 owarn << "HexTile encoding" << oendl;
471 handleHexTileRect(); 467 handleHexTileRect();
472 } 468 }
473 else { 469 else {
474 int msg = Swap32IfLE( encoding ); 470 int msg = Swap32IfLE( encoding );
475 QString protocolError = tr( "Protocol Error: An unknown encoding was " 471 QString protocolError = tr( "Protocol Error: An unknown encoding was "
476 "used by the server %1" ).arg( msg ); 472 "used by the server %1" ).arg( msg );
477 currentState = Error; 473 currentState = Error;
478 owarn << "Unknown encoding, " << msg << "" << oendl; 474 owarn << "Unknown encoding, " << msg << "" << oendl;
479 emit error( protocolError ); 475 emit error( protocolError );
480 return; 476 return;
481 } 477 }
482} 478}
483 479
484// 480//
485// Raw Encoding 481// Raw Encoding
486// 482//
487 483
488void KRFBDecoder::handleRawRect() 484void KRFBDecoder::handleRawRect()
489{ 485{
490 // We need something a bit cleverer here to handle large 486 // We need something a bit cleverer here to handle large
491 // rectanges nicely. The chunking should be based on the 487 // rectanges nicely. The chunking should be based on the
492 // overall size (but has to be in complete lines). 488 // overall size (but has to be in complete lines).
493 489
494 // owarn << "Handling a raw rect chunk" << oendl; 490 // owarn << "Handling a raw rect chunk" << oendl;
495 491
496 // CARD32 lineCount = w * format->bpp / 8; 492 // CARD32 lineCount = w * format->bpp / 8;
497 493
498 if ( h > RectChunkSize ) { 494 if ( h > RectChunkSize ) {
499 // if ( con->sock->size() / lineCount ) { 495 // if ( con->sock->size() / lineCount ) {
500 // getRawRectChunk( con->sock->size() / lineCount ); 496 // getRawRectChunk( con->sock->size() / lineCount );
501 // } 497 // }
502 // else { 498 // else {
503 getRawRectChunk( RectChunkSize ); 499 getRawRectChunk( RectChunkSize );
504 // } 500 // }
505 } 501 }
506 else { 502 else {
507 getRawRectChunk( h ); 503 getRawRectChunk( h );
508 } 504 }
509} 505}
510 506
511void KRFBDecoder::getRawRectChunk( int lines ) 507void KRFBDecoder::getRawRectChunk( int lines )
512{ 508{
513 this->lines = lines; 509 this->lines = lines;
514 CARD32 count = lines * w * format->bpp / 8; 510 CARD32 count = lines * w * format->bpp / 8;
515 511
516 // Wait for server init 512 // Wait for server init
517 // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; 513 // owarn << "Waiting for raw rect chunk, " << count << "" << oendl;
518 514
519 currentState = AwaitingRawRectChunk; 515 currentState = AwaitingRawRectChunk;
520 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); 516 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) );
521 con->waitForData( count ); 517 con->waitForData( count );
522} 518}
523 519
524void KRFBDecoder::gotRawRectChunk() 520void KRFBDecoder::gotRawRectChunk()
525{ 521{
526 assert( currentState == AwaitingRawRectChunk ); 522 assert( currentState == AwaitingRawRectChunk );
527 523
528 disconnect( con, SIGNAL( gotEnoughData() ), 524 disconnect( con, SIGNAL( gotEnoughData() ),
529 this, SLOT( gotRawRectChunk() ) ); 525 this, SLOT( gotRawRectChunk() ) );
530 526
531 // owarn << "Got raw rect chunk" << oendl; 527 // owarn << "Got raw rect chunk" << oendl;
532 528
533 // 529 //
534 // Read the rect data and copy it to the buffer. 530 // Read the rect data and copy it to the buffer.
535 // 531 //
536 532
537 // TODO: Replace this! 533 // TODO: Replace this!
538 int count = lines * w * format->bpp / 8; 534 int count = lines * w * format->bpp / 8;
539 char *hack = new char[ count ]; 535 char *hack = new char[ count ];
540 con->read( hack, count ); 536 con->read( hack, count );
541 buf->drawRawRectChunk( hack, x, y, w, lines ); 537 buf->drawRawRectChunk( hack, x, y, w, lines );
542 delete hack; 538 delete hack;
543 // /TODO: 539 // /TODO:
544 540
545 h = h - lines; 541 h = h - lines;
546 y = y + lines; 542 y = y + lines;
547 543
548 if ( h > 0 ) { 544 if ( h > 0 ) {
549 handleRawRect(); 545 handleRawRect();
550 } 546 }
551 else { 547 else {
552 noRects--; 548 noRects--;
553 549
554 // owarn << "There are " << noRects << " rects left" << oendl; 550 // owarn << "There are " << noRects << " rects left" << oendl;
555 551
556 if ( noRects ) { 552 if ( noRects ) {
557 currentState = AwaitingRectHeader; 553 currentState = AwaitingRectHeader;
558 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 554 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
559 con->waitForData( RectHeaderLength ); 555 con->waitForData( RectHeaderLength );
560 } 556 }
561 else { 557 else {
562 // we are now ready for the next update - no need to wait for the timer 558 // we are now ready for the next update - no need to wait for the timer
563 currentState = Idle; 559 currentState = Idle;
564 sendUpdateRequest (1); 560 sendUpdateRequest (1);
565 } 561 }
566 } 562 }
@@ -586,48 +582,48 @@ void KRFBDecoder::gotCopyRectPos()
586 CARD16 srcY; 582 CARD16 srcY;
587 583
588 con->read( &srcX, 2 ); 584 con->read( &srcX, 2 );
589 con->read( &srcY, 2 ); 585 con->read( &srcY, 2 );
590 586
591 srcX = Swap16IfLE( srcX ); 587 srcX = Swap16IfLE( srcX );
592 srcY = Swap16IfLE( srcY ); 588 srcY = Swap16IfLE( srcY );
593 589
594 buf->copyRect( srcX, srcY, x, y, w, h ); 590 buf->copyRect( srcX, srcY, x, y, w, h );
595 591
596 noRects--; 592 noRects--;
597 593
598 // owarn << "There are " << noRects << " rects left" << oendl; 594 // owarn << "There are " << noRects << " rects left" << oendl;
599 595
600 if ( noRects ) { 596 if ( noRects ) {
601 currentState = AwaitingRectHeader; 597 currentState = AwaitingRectHeader;
602 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 598 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
603 con->waitForData( RectHeaderLength ); 599 con->waitForData( RectHeaderLength );
604 } 600 }
605 else 601 else
606 currentState = Idle; 602 currentState = Idle;
607} 603}
608 604
609void KRFBDecoder::handleRRERect() 605void KRFBDecoder::handleRRERect()
610{ 606{
611 owarn << "RRE not implemented" << oendl; 607 owarn << "RRE not implemented" << oendl;
612} 608}
613 609
614void KRFBDecoder::handleCoRRERect() 610void KRFBDecoder::handleCoRRERect()
615{ 611{
616 owarn << "CoRRE not implemented" << oendl; 612 owarn << "CoRRE not implemented" << oendl;
617} 613}
618 614
619void KRFBDecoder::handleHexTileRect() 615void KRFBDecoder::handleHexTileRect()
620{ 616{
621 owarn << "HexTile not implemented" << oendl; 617 owarn << "HexTile not implemented" << oendl;
622} 618}
623 619
624void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) 620void KRFBDecoder::sendMouseEvent( QMouseEvent *e )
625{ 621{
626 // Deal with the buttons 622 // Deal with the buttons
627 if ( e->type() != QEvent::MouseMove ) { 623 if ( e->type() != QEvent::MouseMove ) {
628 buttonMask = 0; 624 buttonMask = 0;
629 if ( e->type() == QEvent::MouseButtonPress ) { 625 if ( e->type() == QEvent::MouseButtonPress ) {
630 if ( e->button() & LeftButton ) 626 if ( e->button() & LeftButton )
631 buttonMask |= 0x01; 627 buttonMask |= 0x01;
632 if ( e->button() & MidButton ) 628 if ( e->button() & MidButton )
633 buttonMask |= 0x04; 629 buttonMask |= 0x04;
@@ -635,27 +631,27 @@ void KRFBDecoder::sendMouseEvent( QMouseEvent *e )
635 buttonMask |= 0x02; 631 buttonMask |= 0x02;
636 } 632 }
637 else if ( e->type() == QEvent::MouseButtonRelease ) { 633 else if ( e->type() == QEvent::MouseButtonRelease ) {
638 if ( e->button() & LeftButton ) 634 if ( e->button() & LeftButton )
639 buttonMask &= 0x06; 635 buttonMask &= 0x06;
640 if ( e->button() & MidButton ) 636 if ( e->button() & MidButton )
641 buttonMask |= 0x03; 637 buttonMask |= 0x03;
642 if ( e->button() & RightButton ) 638 if ( e->button() & RightButton )
643 buttonMask |= 0x05; 639 buttonMask |= 0x05;
644 } 640 }
645 } 641 }
646 642
647 // HACK: Scaling 643 // HACK: Scaling
648 CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); 644 CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor );
649 CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); 645 CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor );
650 646
651 con->write( &PointerEventId, 1 ); 647 con->write( &PointerEventId, 1 );
652 con->write( &buttonMask, 1 ); 648 con->write( &buttonMask, 1 );
653 con->write( &x, 2 ); 649 con->write( &x, 2 );
654 con->write( &y, 2 ); 650 con->write( &y, 2 );
655} 651}
656 652
657 653
658void KRFBDecoder::sendCutEvent( const QString &unicode ) 654void KRFBDecoder::sendCutEvent( const QString &unicode )
659{ 655{
660 // 656 //
661 // Warning: There is a bug in the RFB protocol because there is no way to find 657 // Warning: There is a bug in the RFB protocol because there is no way to find
@@ -669,25 +665,25 @@ void KRFBDecoder::sendCutEvent( const QString &unicode )
669 QCString text = unicode.local8Bit(); 665 QCString text = unicode.local8Bit();
670 CARD32 length = text.length(); 666 CARD32 length = text.length();
671 length = Swap32IfLE( length ); 667 length = Swap32IfLE( length );
672 668
673 con->write( &ClientCutTextId, 1 ); 669 con->write( &ClientCutTextId, 1 );
674 con->write( &padding, 3 ); 670 con->write( &padding, 3 );
675 con->write( &length, 4 ); 671 con->write( &length, 4 );
676 con->write( text.data(), length ); 672 con->write( text.data(), length );
677} 673}
678 674
679void KRFBDecoder::gotServerCut() 675void KRFBDecoder::gotServerCut()
680{ 676{
681 owarn << "Got server cut" << oendl; 677 owarn << "Got server cut" << oendl;
682 678
683 currentState = AwaitingServerCutLength; 679 currentState = AwaitingServerCutLength;
684 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); 680 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) );
685 con->waitForData( ServerCutLenLength ); 681 con->waitForData( ServerCutLenLength );
686} 682}
687 683
688void KRFBDecoder::gotServerCutLength() 684void KRFBDecoder::gotServerCutLength()
689{ 685{
690 assert( currentState = AwaitingServerCutLength ); 686 assert( currentState = AwaitingServerCutLength );
691 disconnect( con, SIGNAL( gotEnoughData() ), 687 disconnect( con, SIGNAL( gotEnoughData() ),
692 this, SLOT( gotServerCutLength() ) ); 688 this, SLOT( gotServerCutLength() ) );
693 689
@@ -717,62 +713,62 @@ void KRFBDecoder::gotServerCutText()
717 // same. I've reported this problem to the ORL guys, but they apparantly have no 713 // same. I've reported this problem to the ORL guys, but they apparantly have no
718 // immediate plans to fix the issue. :-( (rich) 714 // immediate plans to fix the issue. :-( (rich)
719 // 715 //
720 716
721 char *cutbuf = new char[ serverCutTextLen + 1 ]; 717 char *cutbuf = new char[ serverCutTextLen + 1 ];
722 CHECK_PTR( cutbuf ); 718 CHECK_PTR( cutbuf );
723 719
724 con->read( cutbuf, serverCutTextLen ); 720 con->read( cutbuf, serverCutTextLen );
725 cutbuf[ serverCutTextLen ] = '\0'; 721 cutbuf[ serverCutTextLen ] = '\0';
726 722
727 /* For some reason QApplication::clipboard()->setText() segfaults when called 723 /* For some reason QApplication::clipboard()->setText() segfaults when called
728 * from within keypebble's mass of signals and slots 724 * from within keypebble's mass of signals and slots
729 owarn << "Server cut: " << cutbuf << "" << oendl; 725 owarn << "Server cut: " << cutbuf << "" << oendl;
730 726
731 QString cutText( cutbuf ); // DANGER!! 727 QString cutText( cutbuf ); // DANGER!!
732 qApp->clipboard()->setText( cutText ); 728 qApp->clipboard()->setText( cutText );
733 */ 729 */
734 730
735 delete cutbuf; 731 delete cutbuf;
736 // Now wait for the update (again) 732 // Now wait for the update (again)
737 if ( oldState == AwaitingUpdate ) { 733 if ( oldState == AwaitingUpdate ) {
738 currentState = AwaitingUpdate; 734 currentState = AwaitingUpdate;
739 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 735 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
740 con->waitForData( UpdateHeaderLength ); 736 con->waitForData( UpdateHeaderLength );
741 } 737 }
742 else if ( oldState == Idle ) { 738 else if ( oldState == Idle ) {
743 currentState = Idle; 739 currentState = Idle;
744 } 740 }
745 else { 741 else {
746 owarn << "Async handled in weird state" << oendl; 742 owarn << "Async handled in weird state" << oendl;
747 currentState = oldState; 743 currentState = oldState;
748 }; 744 };
749} 745}
750 746
751void KRFBDecoder::gotBell() 747void KRFBDecoder::gotBell()
752{ 748{
753 owarn << "Got server bell" << oendl; 749 owarn << "Got server bell" << oendl;
754 buf->soundBell(); 750 buf->soundBell();
755 751
756 // Now wait for the update (again) 752 // Now wait for the update (again)
757 if ( oldState == AwaitingUpdate ) { 753 if ( oldState == AwaitingUpdate ) {
758 currentState = AwaitingUpdate; 754 currentState = AwaitingUpdate;
759 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 755 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
760 con->waitForData( UpdateHeaderLength ); 756 con->waitForData( UpdateHeaderLength );
761 } 757 }
762 else if ( oldState == Idle ) { 758 else if ( oldState == Idle ) {
763 currentState = Idle; 759 currentState = Idle;
764 } 760 }
765 else { 761 else {
766 owarn << "Async handled in weird state" << oendl; 762 owarn << "Async handled in weird state" << oendl;
767 currentState = oldState; 763 currentState = oldState;
768 }; 764 };
769} 765}
770 766
771void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) 767void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event )
772{ 768{
773 int key; 769 int key;
774 key = toKeySym( event ); 770 key = toKeySym( event );
775 if ( key ) { 771 if ( key ) {
776 key = Swap32IfLE( key ); 772 key = Swap32IfLE( key );
777 773
778 CARD8 mask = true; 774 CARD8 mask = true;
@@ -810,26 +806,26 @@ void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event )
810// is the same as the corresponding ASCII value.', but doesn't 806// is the same as the corresponding ASCII value.', but doesn't
811// elaborate what the most ordinary keys are. The spec also lists 807// elaborate what the most ordinary keys are. The spec also lists
812// a set (possibly subset, it's unspecified) of mappings for 808// a set (possibly subset, it's unspecified) of mappings for
813// "other common keys" (backspace, tab, return, escape, etc). 809// "other common keys" (backspace, tab, return, escape, etc).
814// 810//
815int KRFBDecoder::toKeySym( QKeyEvent *k ) 811int KRFBDecoder::toKeySym( QKeyEvent *k )
816{ 812{
817 813
818 // 814 //
819 // Try and map these "other common keys" first. 815 // Try and map these "other common keys" first.
820 // 816 //
821 if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { 817 if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) {
822 for(int i = 0; keyMap[i].keycode != 0; i++) { 818 for(int i = 0; keyMap[i].keycode != 0; i++) {
823 if (k->key() == keyMap[i].keycode) { 819 if (k->key() == keyMap[i].keycode) {
824 return keyMap[i].keysym; 820 return keyMap[i].keysym;
825 } 821 }
826 } 822 }
827 } 823 }
828 824
829 // 825 //
830 // If these keys aren't matched, return the ascii code and let the 826 // If these keys aren't matched, return the ascii code and let the
831 // server figure it out. We don't return k->key(), as the data in 827 // server figure it out. We don't return k->key(), as the data in
832 // key differs between input methods, and we don't want special cases. 828 // key differs between input methods, and we don't want special cases.
833 // 829 //
834 return k->ascii(); 830 return k->ascii();
835} 831}