summaryrefslogtreecommitdiff
authortreke <treke>2002-09-04 17:53:12 (UTC)
committer treke <treke>2002-09-04 17:53:12 (UTC)
commit605d854057eb470a1d75210193b82eb0b1ad6b53 (patch) (unidiff)
treec411b661d5211fefbd83a7c8f63eef8c9cca72ee
parentc35a5eabd8f5ed18e4216f6c88ee6794bacfb491 (diff)
downloadopie-605d854057eb470a1d75210193b82eb0b1ad6b53.zip
opie-605d854057eb470a1d75210193b82eb0b1ad6b53.tar.gz
opie-605d854057eb470a1d75210193b82eb0b1ad6b53.tar.bz2
Major modifications to the User Interface
1) Bookmark support added, all options are stored on a per bookmark basis 2) 16 Bit color is now a supported bit depth for the server
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/comm/keypebble/keypebble.pro16
-rw-r--r--noncore/comm/keypebble/krfbbuffer.cpp33
-rw-r--r--noncore/comm/keypebble/krfbcanvas.cpp39
-rw-r--r--noncore/comm/keypebble/krfbcanvas.h6
-rw-r--r--noncore/comm/keypebble/krfbconnection.cpp272
-rw-r--r--noncore/comm/keypebble/krfbconnection.h19
-rw-r--r--noncore/comm/keypebble/krfbdecoder.cpp3
-rw-r--r--noncore/comm/keypebble/krfblogin.cpp8
-rw-r--r--noncore/comm/keypebble/krfboptions.cpp56
-rw-r--r--noncore/comm/keypebble/krfboptions.h31
-rw-r--r--noncore/comm/keypebble/krfbserver.cpp39
-rw-r--r--noncore/comm/keypebble/kvnc.cpp168
-rw-r--r--noncore/comm/keypebble/kvnc.h14
-rw-r--r--noncore/comm/keypebble/kvncbookmarkdlg.cpp220
-rw-r--r--noncore/comm/keypebble/kvncconndlg.cpp75
-rw-r--r--noncore/comm/keypebble/kvncconnectdlg.cpp79
-rw-r--r--noncore/comm/keypebble/kvncconnectdlg.h39
-rw-r--r--noncore/comm/keypebble/kvncoptionsdlg.cpp54
-rw-r--r--noncore/comm/keypebble/kvncoptionsdlg.h30
-rw-r--r--noncore/comm/keypebble/main.cpp4
20 files changed, 682 insertions, 523 deletions
diff --git a/noncore/comm/keypebble/keypebble.pro b/noncore/comm/keypebble/keypebble.pro
index a102381..1017133 100644
--- a/noncore/comm/keypebble/keypebble.pro
+++ b/noncore/comm/keypebble/keypebble.pro
@@ -1,47 +1,49 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3DESTDIR = $(OPIEDIR)/bin 3DESTDIR = $(OPIEDIR)/bin
4 HEADERS = d3des.h \ 4 HEADERS = d3des.h \
5 krfbbuffer.h \ 5 krfbbuffer.h \
6 krfbcanvas.h \ 6 krfbcanvas.h \
7 krfbconnection.h \ 7 krfbconnection.h \
8 krfbdecoder.h \ 8 krfbdecoder.h \
9 krfblogin.h \ 9 krfblogin.h \
10 krfboptions.h \ 10 krfbserver.h \
11 krfbserverinfo.h \ 11 krfbserverinfo.h \
12 kvnc.h \ 12 kvnc.h \
13 kvncconnectdlg.h \ 13 kvncconndlg.h \
14 kvncoptionsdlg.h \ 14 kvncbookmarkdlg.h \
15 version.h \
15 vncauth.h 16 vncauth.h
16 SOURCES = d3des.c \ 17 SOURCES = d3des.c \
17 vncauth.c \ 18 vncauth.c \
18 krfbbuffer.cpp \ 19 krfbbuffer.cpp \
19 krfbcanvas.cpp \ 20 krfbcanvas.cpp \
20 krfbconnection.cpp \ 21 krfbconnection.cpp \
21 krfbdecoder.cpp \ 22 krfbdecoder.cpp \
22 krfblogin.cpp \ 23 krfblogin.cpp \
23 krfboptions.cpp \ 24 krfbserver.cpp \
24 kvnc.cpp \ 25 kvnc.cpp \
25 kvncconnectdlg.cpp \ 26 kvncconndlg.cpp \
26 kvncoptionsdlg.cpp \ 27 kvncbookmarkdlg.cpp \
27 main.cpp 28 main.cpp
28 INTERFACES= vncoptionsbase.ui 29 INTERFACES= kvncconndlgbase.ui \
30 kvncbookmarkdlgbase.ui
29TARGET = keypebble 31TARGET = keypebble
30INCLUDEPATH += $(OPIEDIR)/include 32INCLUDEPATH += $(OPIEDIR)/include
31DEPENDPATH += $(OPIEDIR)/include 33DEPENDPATH += $(OPIEDIR)/include
32LIBS += -lqpe 34LIBS += -lqpe
33 35
34TRANSLATIONS = ../../../i18n/de/keypebble.ts \ 36TRANSLATIONS = ../../../i18n/de/keypebble.ts \
35 ../../../i18n/en/keypebble.ts \ 37 ../../../i18n/en/keypebble.ts \
36 ../../../i18n/es/keypebble.ts \ 38 ../../../i18n/es/keypebble.ts \
37 ../../../i18n/fr/keypebble.ts \ 39 ../../../i18n/fr/keypebble.ts \
38 ../../../i18n/hu/keypebble.ts \ 40 ../../../i18n/hu/keypebble.ts \
39 ../../../i18n/ja/keypebble.ts \ 41 ../../../i18n/ja/keypebble.ts \
40 ../../../i18n/ko/keypebble.ts \ 42 ../../../i18n/ko/keypebble.ts \
41 ../../../i18n/no/keypebble.ts \ 43 ../../../i18n/no/keypebble.ts \
42 ../../../i18n/pl/keypebble.ts \ 44 ../../../i18n/pl/keypebble.ts \
43 ../../../i18n/pt/keypebble.ts \ 45 ../../../i18n/pt/keypebble.ts \
44 ../../../i18n/pt_BR/keypebble.ts \ 46 ../../../i18n/pt_BR/keypebble.ts \
45 ../../../i18n/sl/keypebble.ts \ 47 ../../../i18n/sl/keypebble.ts \
46 ../../../i18n/zh_CN/keypebble.ts \ 48 ../../../i18n/zh_CN/keypebble.ts \
47 ../../../i18n/zh_TW/keypebble.ts 49 ../../../i18n/zh_TW/keypebble.ts
diff --git a/noncore/comm/keypebble/krfbbuffer.cpp b/noncore/comm/keypebble/krfbbuffer.cpp
index 4885261..5a52f31 100644
--- a/noncore/comm/keypebble/krfbbuffer.cpp
+++ b/noncore/comm/keypebble/krfbbuffer.cpp
@@ -1,163 +1,194 @@
1#include <assert.h> 1#include <assert.h>
2#include <qpixmap.h> 2#include <qpixmap.h>
3#include <qbrush.h> 3#include <qbrush.h>
4#include <qimage.h> 4#include <qimage.h>
5#include <qpainter.h> 5#include <qpainter.h>
6#include <qapplication.h> 6#include <qapplication.h>
7#include "krfbdecoder.h" 7#include "krfbdecoder.h"
8#include "krfbbuffer.h" 8#include "krfbbuffer.h"
9#include "krfbserverinfo.h" 9#include "krfbserverinfo.h"
10 10
11// 11//
12// Endian stuff 12// Endian stuff
13// 13//
14#ifndef KDE_USE_FINAL 14#ifndef KDE_USE_FINAL
15const int endianTest = 1; 15const int endianTest = 1;
16#endif 16#endif
17 17
18#define Swap16IfLE(s) \ 18#define Swap16IfLE(s) \
19 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) 19 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
20 20
21#define Swap32IfLE(l) \ 21#define Swap32IfLE(l) \
22 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ 22 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
23 (((l) & 0x00ff0000) >> 8) | \ 23 (((l) & 0x00ff0000) >> 8) | \
24 (((l) & 0x0000ff00) << 8) | \ 24 (((l) & 0x0000ff00) << 8) | \
25 (((l) & 0x000000ff) << 24)) : (l)) 25 (((l) & 0x000000ff) << 24)) : (l))
26 26
27KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder, 27KRFBBuffer::KRFBBuffer( KRFBDecoder *decoder,
28 QObject *parent, const char *name ) 28 QObject *parent, const char *name )
29 : QObject( parent, name ) 29 : QObject( parent, name )
30{ 30{
31 assert( decoder ); 31 assert( decoder );
32 this->decoder = decoder; 32 this->decoder = decoder;
33 pix = new QPixmap(); 33 pix = new QPixmap();
34} 34}
35 35
36KRFBBuffer::~KRFBBuffer() 36KRFBBuffer::~KRFBBuffer()
37{ 37{
38 delete pix; 38 delete pix;
39} 39}
40 40
41void KRFBBuffer::resize( int w, int h ) 41void KRFBBuffer::resize( int w, int h )
42{ 42{
43 qWarning( "Resizing buffer" ); 43 qWarning( "Resizing buffer" );
44 44
45 pix->resize( w, h ); 45 pix->resize( w, h );
46 46
47 QPalette pal = qApp->palette(); 47 QPalette pal = qApp->palette();
48 pix->fill( pal.active().base() ); 48 pix->fill( pal.active().base() );
49 49
50 emit sizeChanged( w, h ); 50 emit sizeChanged( w, h );
51} 51}
52 52
53void KRFBBuffer::soundBell() 53void KRFBBuffer::soundBell()
54{ 54{
55 emit bell(); 55 emit bell();
56} 56}
57 57
58void KRFBBuffer::mouseEvent( QMouseEvent *e ) 58void KRFBBuffer::mouseEvent( QMouseEvent *e )
59{ 59{
60 decoder->sendMouseEvent( e ); 60 decoder->sendMouseEvent( e );
61} 61}
62 62
63void KRFBBuffer::keyPressEvent( QKeyEvent *e ) 63void KRFBBuffer::keyPressEvent( QKeyEvent *e )
64{ 64{
65 qWarning( "Buffer got a key" ); 65 qWarning( "Buffer got a key" );
66 66
67 decoder->sendKeyPressEvent( e ); 67 decoder->sendKeyPressEvent( e );
68} 68}
69 69
70void KRFBBuffer::keyReleaseEvent( QKeyEvent *e ) 70void KRFBBuffer::keyReleaseEvent( QKeyEvent *e )
71{ 71{
72 decoder->sendKeyReleaseEvent( e ); 72 decoder->sendKeyReleaseEvent( e );
73} 73}
74 74
75void KRFBBuffer::copyRect( int srcX, int srcY, 75void KRFBBuffer::copyRect( int srcX, int srcY,
76 int destX, int destY, int w, int h ) 76 int destX, int destY, int w, int h )
77{ 77{
78// qWarning( "Got copy rect" ); 78// qWarning( "Got copy rect" );
79 bitBlt( pix, destX, destY, pix, srcX, srcY, w, h, CopyROP ); 79 bitBlt( pix, destX, destY, pix, srcX, srcY, w, h, CopyROP );
80 80
81 emit updated( destX, destY, w, h ); 81 emit updated( destX, destY, w, h );
82} 82}
83 83
84void KRFBBuffer::drawRawRectChunk( void *data, 84void KRFBBuffer::drawRawRectChunk( void *data,
85 int x, int y, int w, int h ) 85 int x, int y, int w, int h )
86{ 86{
87 QImage img( w, h, 32 ); 87 QImage img( w, h, 32 );
88 88
89 int redMax = Swap16IfLE( decoder->format->redMax ); 89 int redMax = Swap16IfLE( decoder->format->redMax );
90 int greenMax = Swap16IfLE( decoder->format->greenMax ); 90 int greenMax = Swap16IfLE( decoder->format->greenMax );
91 int blueMax = Swap16IfLE( decoder->format->blueMax ); 91 int blueMax = Swap16IfLE( decoder->format->blueMax );
92 92
93 QPainter p( pix ); 93 QPainter p( pix );
94 94
95 if ( decoder->format->bpp == 8 ) { 95 if ( decoder->format->bpp == 8 ) {
96 uchar *d = (unsigned char *) data; 96 uchar *d = (unsigned char *) data;
97 97
98 uint r,g,b; 98 uint r,g,b;
99 99
100 for ( int j = 0; j < h; j++ ) { 100 for ( int j = 0; j < h; j++ ) {
101 for ( int i = 0; i < w ; i++ ) { 101 for ( int i = 0; i < w ; i++ ) {
102 r = d[ j * w + i ]; 102 r = d[ j * w + i ];
103 r = r >> decoder->format->redShift; 103 r = r >> decoder->format->redShift;
104 r = r & redMax; 104 r = r & redMax;
105 105
106 g = d[ j * w + i ]; 106 g = d[ j * w + i ];
107 g = g >> decoder->format->greenShift; 107 g = g >> decoder->format->greenShift;
108 g = g & greenMax; 108 g = g & greenMax;
109 109
110 b = d[ j * w + i ]; 110 b = d[ j * w + i ];
111 b = b >> decoder->format->blueShift; 111 b = b >> decoder->format->blueShift;
112 b = b & blueMax; 112 b = b & blueMax;
113 113
114 r = ( r * 255 ) / redMax; 114 r = ( r * 255 ) / redMax;
115 g = ( g * 255 ) / greenMax; 115 g = ( g * 255 ) / greenMax;
116 b = ( b * 255 ) / blueMax; 116 b = ( b * 255 ) / blueMax;
117 117
118 uint *p = ( uint * ) img.scanLine( j ) + i; 118 uint *p = ( uint * ) img.scanLine( j ) + i;
119 *p = qRgb( r,g,b ); 119 *p = qRgb( r,g,b );
120 } 120 }
121 } 121 }
122 } 122 }
123 else if ( decoder->format->bpp == 32 ) { 123 else if ( decoder->format->bpp == 32 ) {
124 ulong *d = (ulong *) data; 124 ulong *d = (ulong *) data;
125 125
126 ulong r,g,b; 126 ulong r,g,b;
127 127
128 for ( int j = 0; j < h; j++ ) { 128 for ( int j = 0; j < h; j++ ) {
129 for ( int i = 0; i < w ; i++ ) { 129 for ( int i = 0; i < w ; i++ ) {
130 ulong pixel = d[ j * w + i ]; 130 ulong pixel = d[ j * w + i ];
131 pixel = Swap32IfLE( pixel ); 131 pixel = Swap32IfLE( pixel );
132 132
133 r = pixel; 133 r = pixel;
134 r = r >> decoder->format->redShift; 134 r = r >> decoder->format->redShift;
135 r = r & redMax; 135 r = r & redMax;
136 136
137 g = pixel; 137 g = pixel;
138 g = g >> decoder->format->greenShift; 138 g = g >> decoder->format->greenShift;
139 g = g & greenMax; 139 g = g & greenMax;
140 140
141 b = pixel; 141 b = pixel;
142 b = b >> decoder->format->blueShift; 142 b = b >> decoder->format->blueShift;
143 b = b & blueMax; 143 b = b & blueMax;
144 144
145 r = ( r * 255 ) / redMax; 145 r = ( r * 255 ) / redMax;
146 g = ( g * 255 ) / greenMax; 146 g = ( g * 255 ) / greenMax;
147 b = ( b * 255 ) / blueMax; 147 b = ( b * 255 ) / blueMax;
148 148
149 uint *p = ( uint * ) img.scanLine( j ) + i; 149 uint *p = ( uint * ) img.scanLine( j ) + i;
150 *p = qRgb( r,g,b ); 150 *p = qRgb( r,g,b );
151 } 151 }
152 } 152 }
153 } 153 } else if (decoder->format->bpp == 16 ) {
154
155 CARD16 *d = (CARD16 *) data;
156
157 uint r,g,b;
158
159 for ( int j = 0; j < h; j++ ) {
160 for ( int i = 0; i < w ; i++ ) {
161 CARD16 pixel = d[ j * w + i ];
162 pixel = Swap16IfLE( pixel );
163
164 r = pixel;
165 r = r >> decoder->format->redShift;
166 r = r & redMax;
167
168 g = pixel;
169 g = g >> decoder->format->greenShift;
170 g = g & greenMax;
171
172 b = pixel;
173 b = b >> decoder->format->blueShift;
174 b = b & blueMax;
175
176 r = ( r * 255 ) / redMax;
177 g = ( g * 255 ) / greenMax;
178 b = ( b * 255 ) / blueMax;
179
180 ulong *p = ( ulong * ) img.scanLine( j ) + i;
181 *p = qRgb( r,g,b );
182 }
183 }
184 }
154 else { 185 else {
155 p.setBrush( QBrush( Qt::black ) ); 186 p.setBrush( QBrush( Qt::black ) );
156 p.drawRect( x, y, w, h ); 187 p.drawRect( x, y, w, h );
157 } 188 }
158 189
159 p.drawImage( x, y, img ); 190 p.drawImage( x, y, img );
160 191
161 emit updated( x, y, w, h ); 192 emit updated( x, y, w, h );
162} 193}
163 194
diff --git a/noncore/comm/keypebble/krfbcanvas.cpp b/noncore/comm/keypebble/krfbcanvas.cpp
index f74ab7b..8b56795 100644
--- a/noncore/comm/keypebble/krfbcanvas.cpp
+++ b/noncore/comm/keypebble/krfbcanvas.cpp
@@ -1,169 +1,172 @@
1#include "kvncconnectdlg.h"
2#include "krfbconnection.h" 1#include "krfbconnection.h"
3#include "krfbcanvas.h" 2#include "krfbcanvas.h"
4#include "krfboptions.h" 3#include "krfbserver.h"
5#include "krfbbuffer.h" 4#include "krfbbuffer.h"
6 5
7#include <qpe/config.h> 6#include <qpe/config.h>
7#include <qpe/qpeapplication.h>
8 8
9#include <qapplication.h> 9#include <qapplication.h>
10#include <qclipboard.h> 10#include <qclipboard.h>
11#include <qaction.h> 11#include <qaction.h>
12#include <qpixmap.h> 12#include <qpixmap.h>
13#include <qapplication.h> 13#include <qapplication.h>
14#include <qmainwindow.h> 14#include <qmainwindow.h>
15#include <qiconset.h> 15#include <qiconset.h>
16 16
17KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name ) 17KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name )
18 : QScrollView( parent, name ) 18 : QScrollView( parent, name )
19{ 19{
20 connection_ = new KRFBConnection(); 20 connection_ = new KRFBConnection();
21 connect( connection_, SIGNAL( passwordRequired( KRFBConnection * ) ),
22 this, SLOT( passwordRequired( KRFBConnection * ) ) );
23 connect( connection_, SIGNAL( loggedIn() ), 21 connect( connection_, SIGNAL( loggedIn() ),
24 this, SLOT( loggedIn() ) ); 22 this, SLOT( loggedIn() ) );
25 23
26 loggedIn_ = false; 24 loggedIn_ = false;
25 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold);
27 26
28 viewport()->setFocusPolicy( QWidget::StrongFocus ); 27 viewport()->setFocusPolicy( QWidget::StrongFocus );
29 viewport()->setFocus(); 28 viewport()->setFocus();
30} 29}
31 30
32KRFBCanvas::~KRFBCanvas() 31KRFBCanvas::~KRFBCanvas()
33{ 32{
34} 33}
35 34
36void KRFBCanvas::openConnection() 35
36void KRFBCanvas::openConnection(KRFBServer server)
37{ 37{
38 KVNCConnectDlg dlg( connection_, this, "connect dialog" ); 38
39 if ( dlg.exec() ) { 39
40 QCString host = dlg.hostname().latin1(); 40 QCString host = server.hostname.latin1();
41 password = dlg.password(); 41 password=server.password;
42 connection_->connectTo( host, dlg.display() ); 42 connection_->connectTo( server);
43 }
44} 43}
45 44
45
46void KRFBCanvas::openURL( const QUrl &url ) 46void KRFBCanvas::openURL( const QUrl &url )
47{ 47{
48 if ( loggedIn_ ) { 48 if ( loggedIn_ ) {
49 qWarning( "openURL invoked when logged in\n" ); 49 qWarning( "openURL invoked when logged in\n" );
50 return; 50 return;
51 } 51 }
52 52
53 QCString host = url.host().latin1(); 53 QCString host = url.host().latin1();
54 int display = url.port(); 54 int display = url.port();
55 if ( url.hasPassword() )
56 connection_->setPassword( url.password().latin1() );
57 55
58 connection_->connectTo( host, display ); 56// connection_->connectTo( host, display );
59} 57}
60 58
61void KRFBCanvas::closeConnection() 59void KRFBCanvas::closeConnection()
62{ 60{
63 loggedIn_ = false; 61 loggedIn_ = false;
64 connection_->disconnect(); 62 connection_->disconnect();
65 63
66 viewport()->setMouseTracking( false ); 64 viewport()->setMouseTracking( false );
67 viewport()->setBackgroundMode( PaletteDark ); 65 viewport()->setBackgroundMode( PaletteDark );
68 setBackgroundMode( PaletteDark ); 66 setBackgroundMode( PaletteDark );
69 update(); 67 update();
70} 68}
71 69
72void KRFBCanvas::passwordRequired( KRFBConnection *con )
73{
74 con->setPassword( password.latin1() );
75}
76 70
77void KRFBCanvas::bell() 71void KRFBCanvas::bell()
78{ 72{
79 if ( connection_->options()->deIconify ) { 73 if ( connection_->options()->deIconify ) {
80 topLevelWidget()->raise(); 74 topLevelWidget()->raise();
81 topLevelWidget()->show(); 75 topLevelWidget()->show();
82 } 76 }
83} 77}
84 78
85void KRFBCanvas::loggedIn() 79void KRFBCanvas::loggedIn()
86{ 80{
87 qWarning( "Ok, we're logged in" ); 81 qWarning( "Ok, we're logged in" );
88 82
89 // 83 //
90 // Get ready for action 84 // Get ready for action
91 // 85 //
92 loggedIn_ = true; 86 loggedIn_ = true;
93 viewport()->setMouseTracking( true ); 87 viewport()->setMouseTracking( true );
94 viewport()->setBackgroundMode( NoBackground ); 88 viewport()->setBackgroundMode( NoBackground );
95 setBackgroundMode( NoBackground ); 89 setBackgroundMode( NoBackground );
96 90
97 // Start using the buffer 91 // Start using the buffer
98 connect( connection_->buffer(), SIGNAL( sizeChanged( int, int ) ), 92 connect( connection_->buffer(), SIGNAL( sizeChanged( int, int ) ),
99 this, SLOT( resizeContents(int,int) ) ); 93 this, SLOT( resizeContents(int,int) ) );
100 connect( connection_->buffer(), SIGNAL( updated( int, int, int, int ) ), 94 connect( connection_->buffer(), SIGNAL( updated( int, int, int, int ) ),
101 this, SLOT( viewportUpdate(int,int,int,int) ) ); 95 this, SLOT( viewportUpdate(int,int,int,int) ) );
102 connect( connection_->buffer(), SIGNAL( bell() ), 96 connect( connection_->buffer(), SIGNAL( bell() ),
103 this, SLOT( bell() ) ); 97 this, SLOT( bell() ) );
104 connect( qApp->clipboard(), SIGNAL( dataChanged() ), 98 connect( qApp->clipboard(), SIGNAL( dataChanged() ),
105 this, SLOT( clipboardChanged() ) ); 99 this, SLOT( clipboardChanged() ) );
106} 100}
107 101
108void KRFBCanvas::viewportPaintEvent( QPaintEvent *e ) 102void KRFBCanvas::viewportPaintEvent( QPaintEvent *e )
109{ 103{
110 QRect r = e->rect(); 104 QRect r = e->rect();
111 105
112 if ( loggedIn_ ) { 106 if ( loggedIn_ ) {
113 bitBlt( viewport(), r.x(), r.y(), 107 bitBlt( viewport(), r.x(), r.y(),
114 connection_->buffer()->pixmap(), 108 connection_->buffer()->pixmap(),
115 r.x() + contentsX(), r.y() + contentsY(), 109 r.x() + contentsX(), r.y() + contentsY(),
116 r.width(), r.height() ); 110 r.width(), r.height() );
117 } 111 }
118 else { 112 else {
119 QScrollView::viewportPaintEvent( e ); 113 QScrollView::viewportPaintEvent( e );
120 } 114 }
121} 115}
122 116
123void KRFBCanvas::viewportUpdate( int x, int y, int w, int h ) 117void KRFBCanvas::viewportUpdate( int x, int y, int w, int h )
124{ 118{
125 updateContents( x, y, w, h ); 119 updateContents( x, y, w, h );
126} 120}
127 121
128void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e ) 122void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e )
129{ 123{
130 if ( loggedIn_ ) 124 if ( loggedIn_ )
131 connection_->buffer()->mouseEvent( e ); 125 connection_->buffer()->mouseEvent( e );
132} 126}
133 127
134void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e ) 128void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e )
135{ 129{
136 if ( loggedIn_ ) 130 if ( loggedIn_ )
137 connection_->buffer()->mouseEvent( e ); 131 connection_->buffer()->mouseEvent( e );
138} 132}
139 133
140void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e ) 134void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e )
141{ 135{
142 if ( loggedIn_ ) 136 if ( loggedIn_ )
143 connection_->buffer()->mouseEvent( e ); 137 connection_->buffer()->mouseEvent( e );
144} 138}
145 139
146void KRFBCanvas::keyPressEvent( QKeyEvent *e ) 140void KRFBCanvas::keyPressEvent( QKeyEvent *e )
147{ 141{
148 if ( loggedIn_ ) 142 if ( loggedIn_ )
149 connection_->buffer()->keyPressEvent( e ); 143 connection_->buffer()->keyPressEvent( e );
150} 144}
151 145
152void KRFBCanvas::keyReleaseEvent( QKeyEvent *e ) 146void KRFBCanvas::keyReleaseEvent( QKeyEvent *e )
153{ 147{
154 if ( loggedIn_ ) 148 if ( loggedIn_ )
155 connection_->buffer()->keyReleaseEvent( e ); 149 connection_->buffer()->keyReleaseEvent( e );
156} 150}
157 151
158void KRFBCanvas::refresh() 152void KRFBCanvas::refresh()
159{ 153{
160 if ( loggedIn_ ) 154 if ( loggedIn_ )
161 connection_->refresh(); 155 connection_->refresh();
162} 156}
163 157
164void KRFBCanvas::clipboardChanged() 158void KRFBCanvas::clipboardChanged()
165{ 159{
166 if ( loggedIn_ ) { 160 if ( loggedIn_ ) {
167 connection_->sendCutText( qApp->clipboard()->text() ); 161 connection_->sendCutText( qApp->clipboard()->text() );
168 } 162 }
169} 163}
164void KRFBCanvas::sendCtlAltDel( void)
165{
166
167 qDebug("Here");
168 if ( loggedIn_ ) {
169 connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Delete, 0x7f,ControlButton|AltButton));
170 // connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Delete, 0x7f,ControlButton|AltButton));
171 }
172}
diff --git a/noncore/comm/keypebble/krfbcanvas.h b/noncore/comm/keypebble/krfbcanvas.h
index 7864f1c..cd3047c 100644
--- a/noncore/comm/keypebble/krfbcanvas.h
+++ b/noncore/comm/keypebble/krfbcanvas.h
@@ -1,54 +1,56 @@
1// -*- c++ -*- 1// -*- c++ -*-
2 2
3#ifndef KRFBCANVAS_H 3#ifndef KRFBCANVAS_H
4#define KRFBCANVAS_H 4#define KRFBCANVAS_H
5 5
6#include <qscrollview.h> 6#include <qscrollview.h>
7#include <qurl.h> 7#include <qurl.h>
8 8
9class KRFBConnection; 9class KRFBConnection;
10class KRFBServer;
10 11
11/** 12/**
12 * Displays data from an KRFBDecoder, and sends events to the 13 * Displays data from an KRFBDecoder, and sends events to the
13 * KRFBConnection. 14 * KRFBConnection.
14 */ 15 */
15class KRFBCanvas : public QScrollView 16class KRFBCanvas : public QScrollView
16{ 17{
17 Q_OBJECT 18 Q_OBJECT
18public: 19public:
19 KRFBCanvas( QWidget *parent, const char *name=0 ); 20 KRFBCanvas( QWidget *parent, const char *name=0 );
20 ~KRFBCanvas(); 21 ~KRFBCanvas();
21 22
22 void setConnection( KRFBConnection * ); 23 void setConnection( KRFBConnection * );
23 KRFBConnection *connection() { return connection_; }; 24 KRFBConnection *connection() { return connection_; };
24 25
25public slots: 26public slots:
26 void openConnection(); 27
28 void openConnection (KRFBServer);
27 void openURL( const QUrl & ); 29 void openURL( const QUrl & );
28 void closeConnection(); 30 void closeConnection();
29 void passwordRequired( KRFBConnection * );
30 31
31 void refresh(); 32 void refresh();
32 void bell(); 33 void bell();
34 void sendCtlAltDel(void);
33 35
34protected: 36protected:
35 virtual void keyPressEvent( QKeyEvent * ); 37 virtual void keyPressEvent( QKeyEvent * );
36 virtual void keyReleaseEvent( QKeyEvent * ); 38 virtual void keyReleaseEvent( QKeyEvent * );
37 virtual void contentsMousePressEvent( QMouseEvent * ); 39 virtual void contentsMousePressEvent( QMouseEvent * );
38 virtual void contentsMouseReleaseEvent( QMouseEvent * ); 40 virtual void contentsMouseReleaseEvent( QMouseEvent * );
39 virtual void contentsMouseMoveEvent( QMouseEvent * ); 41 virtual void contentsMouseMoveEvent( QMouseEvent * );
40 42
41 virtual void viewportPaintEvent( QPaintEvent *e ); 43 virtual void viewportPaintEvent( QPaintEvent *e );
42 44
43protected slots: 45protected slots:
44 void loggedIn(); 46 void loggedIn();
45 void viewportUpdate( int x, int y, int w, int h ); 47 void viewportUpdate( int x, int y, int w, int h );
46 void clipboardChanged(); 48 void clipboardChanged();
47 49
48private: 50private:
49 KRFBConnection *connection_; 51 KRFBConnection *connection_;
50 QString password; 52 QString password;
51 bool loggedIn_; 53 bool loggedIn_;
52}; 54};
53 55
54#endif // KRFBCANVAS_H 56#endif // KRFBCANVAS_H
diff --git a/noncore/comm/keypebble/krfbconnection.cpp b/noncore/comm/keypebble/krfbconnection.cpp
index c51f18a..389c836 100644
--- a/noncore/comm/keypebble/krfbconnection.cpp
+++ b/noncore/comm/keypebble/krfbconnection.cpp
@@ -1,242 +1,234 @@
1#include <assert.h> 1#include <assert.h>
2#include <qsocket.h> 2#include <qsocket.h>
3#include <qtimer.h> 3#include <qtimer.h>
4#include <string.h> 4#include <string.h>
5 5
6#include "krfbconnection.h" 6#include "krfbconnection.h"
7#include "krfblogin.h" 7#include "krfblogin.h"
8#include "krfboptions.h" 8#include "krfbserver.h"
9#include "krfbdecoder.h" 9#include "krfbdecoder.h"
10#include "krfbbuffer.h" 10#include "krfbbuffer.h"
11 11
12KRFBConnection::KRFBConnection( QObject *parent ) 12KRFBConnection::KRFBConnection( QObject *parent )
13 : QObject( parent, "KRFBConnection" ) 13 : QObject( parent, "KRFBConnection" )
14{ 14{
15 portBase_ = 5900; 15 portBase_ = 5900;
16 currentState_ = Disconnected; 16 currentState_ = Disconnected;
17 sock = 0; 17 sock = 0;
18 minData_ = 0; 18 minData_ = 0;
19 options_ = new KRFBOptions(); 19 options_ = new KRFBServer();
20 updater = 0; 20 updater = 0;
21 decoder_ = 0; 21 decoder_ = 0;
22 buffer_ = 0; 22 buffer_ = 0;
23} 23}
24 24
25KRFBConnection::~KRFBConnection() 25KRFBConnection::~KRFBConnection()
26{ 26{
27 if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) { 27 if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) {
28 disconnectDone(); 28 disconnectDone();
29 } 29 }
30 delete options_; 30 delete options_;
31} 31}
32 32
33void KRFBConnection::connectTo( const QCString &host, int display ) 33void KRFBConnection::connectTo( KRFBServer server)
34{ 34{
35 if ( currentState_ != Disconnected ); 35 if ( currentState_ != Disconnected )
36 disconnect(); 36 disconnect();
37
38 (*options_)=server;
37 39
38 this->host_= host; 40 sock = new QSocket( this, "rfbSocket" );
39 this->display_ = display; 41 CHECK_PTR( sock );
40 42
41 sock = new QSocket( this, "rfbSocket" ); 43 // Connect to something to notice connection or error
42 CHECK_PTR( sock ); 44 connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) );
45 connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) );
43 46
44 // Connect to something to notice connection or error 47 qWarning( "Connecting..." );
45 connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) );
46 connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) );
47 48
48 qWarning( "Connecting..." ); 49 currentState_ = Connecting;
49 50 sock->connectToHost( options_->hostname.latin1(), portBase_ + options_->display );
50 currentState_ = Connecting;
51 sock->connectToHost( host_, portBase_ + display_ );
52} 51}
53 52
54void KRFBConnection::disconnect() 53void KRFBConnection::disconnect()
55{ 54{
56 qWarning( "Disconnecting from server" ); 55 qWarning( "Disconnecting from server" );
57 56
58 if ( ( currentState_ != Disconnected ) 57 if ( ( currentState_ != Disconnected )
59 && ( currentState_ != Disconnecting ) 58 && ( currentState_ != Disconnecting )
60 && sock ) { 59 && sock ) {
61 currentState_ = Disconnecting; 60 currentState_ = Disconnecting;
62 61
63 connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); 62 connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) );
64 sock->close(); 63 sock->close();
65 64
66 if ( sock->state() != QSocket::Closing ) 65 if ( sock->state() != QSocket::Closing )
67 disconnectDone(); 66 disconnectDone();
68 } 67 }
69} 68}
70 69
71void KRFBConnection::disconnectDone() 70void KRFBConnection::disconnectDone()
72{ 71{
73 qWarning( "KRFBConnection disconnected" ); 72 currentState_ = Disconnected;
74 currentState_ = Disconnected; 73 delete sock;
75 delete sock; 74 sock = 0;
76 sock = 0; 75 minData_ = 0;
77 minData_ = 0; 76 delete updater;
78 delete updater; 77 delete decoder_;
79 delete decoder_; 78 delete buffer_;
80 delete buffer_; 79 emit disconnected();
81 emit disconnected();
82} 80}
83 81
84void KRFBConnection::gotSocketConnection() 82void KRFBConnection::gotSocketConnection()
85{ 83{
86 currentState_ = LoggingIn; 84 currentState_ = LoggingIn;
87 85
88 qWarning( "Connected, logging in..." ); 86 qWarning( "Connected, logging in..." );
89 87
90 static QString statusMsg = tr( "Connected" ); 88 static QString statusMsg = tr( "Connected" );
91 emit statusChanged( statusMsg ); 89 emit statusChanged( statusMsg );
92 90
93 // Do some login stuff 91 // Do some login stuff
94 login = new KRFBLogin( this ); 92 login = new KRFBLogin( this );
95} 93}
96 94
97void KRFBConnection::gotRFBConnection() 95void KRFBConnection::gotRFBConnection()
98{ 96{
99 qWarning( "Logged into server" ); 97 qWarning( "Logged into server" );
100 98
101 currentState_ = Connected; 99 currentState_ = Connected;
102 emit connected(); 100 emit connected();
103 101
104 // Create the decoder and start doing stuff 102 // Create the decoder and start doing stuff
105 decoder_ = new KRFBDecoder( this ); 103 decoder_ = new KRFBDecoder( this );
106 CHECK_PTR( decoder_ ); 104 CHECK_PTR( decoder_ );
107 105
108 buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" ); 106 buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" );
109 CHECK_PTR( buffer_ ); 107 CHECK_PTR( buffer_ );
110 decoder_->setBuffer( buffer_ ); 108 decoder_->setBuffer( buffer_ );
111 109
112 connect( decoder_, SIGNAL( status( const QString & ) ), 110 connect( decoder_, SIGNAL( status( const QString & ) ),
113 this, SIGNAL( statusChanged( const QString & ) ) ); 111 this, SIGNAL( statusChanged( const QString & ) ) );
114 emit loggedIn(); 112 emit loggedIn();
115 113
116 decoder_->start(); 114 decoder_->start();
117 115
118 updater = new QTimer; 116 updater = new QTimer;
119 connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) ); 117 connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) );
120 updater->start( options_->updateRate ); 118 updater->start( options_->updateRate );
121} 119}
122 120
123void KRFBConnection::gotSocketError( int err ) 121void KRFBConnection::gotSocketError( int err )
124{ 122{
125 currentState_ = Error; 123 currentState_ = Error;
126 124
127 // Do some error handling stuff 125 // Do some error handling stuff
128 qWarning( "KRFBConnection: Socket error %d", err ); 126 qWarning( "KRFBConnection: Socket error %d", err );
129 127
130 static QString refused = tr( "Connection Refused" ); 128 static QString refused = tr( "Connection Refused" );
131 static QString host = tr( "Host not found" ); 129 static QString host = tr( "Host not found" );
132 static QString read = tr( "Read Error: QSocket reported an error reading\n" 130 static QString read = tr( "Read Error: QSocket reported an error reading\n"
133 "data, the remote host has probably dropped the\n" 131 "data, the remote host has probably dropped the\n"
134 "connection." ); 132 "connection." );
135 static QString confused = tr( "QSocket reported an invalid error code" ); 133 static QString confused = tr( "QSocket reported an invalid error code" );
136 134
137 QString msg; 135 QString msg;
138 switch ( err ) { 136 switch ( err ) {
139 case QSocket::ErrConnectionRefused: 137 case QSocket::ErrConnectionRefused:
140 msg = refused; 138 msg = refused;
141 break; 139 break;
142 case QSocket::ErrHostNotFound: 140 case QSocket::ErrHostNotFound:
143 msg = host; 141 msg = host;
144 break; 142 break;
145 case QSocket::ErrSocketRead: 143 case QSocket::ErrSocketRead:
146 msg = read; 144 msg = read;
147 break; 145 break;
148 default: 146 default:
149 msg = confused; 147 msg = confused;
150 }; 148 };
151 149
152 QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); 150 QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) );
153 delete sock; 151 delete sock;
154 sock = 0; 152 sock = 0;
155 currentState_ = Disconnected; 153 currentState_ = Disconnected;
156 154
157 emit error( msg ); 155 emit error( msg );
158} 156}
159 157
160void KRFBConnection::gotMoreData() 158void KRFBConnection::gotMoreData()
161{ 159{
162 assert( minData_ > 0 ); 160 assert( minData_ > 0 );
163 161
164 if ( sock->size() >= minData_ ) { 162 if ( sock->size() >= minData_ ) {
165 minData_ = 0; 163 minData_ = 0;
166 QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); 164 QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) );
167 emit gotEnoughData(); 165 emit gotEnoughData();
168 } 166 }
169} 167}
170 168
171void KRFBConnection::waitForData( unsigned int sz ) 169void KRFBConnection::waitForData( unsigned int sz )
172{ 170{
173 assert( minData_ == 0 ); 171 assert( minData_ == 0 );
174 assert( sz > 0 ); 172 assert( sz > 0 );
175 assert( currentState_ != Error ); 173 assert( currentState_ != Error );
176 174
177 if ( sock->size() >= sz ) { 175 if ( sock->size() >= sz ) {
178 // qWarning( "No need to wait for data" ); 176 // qWarning( "No need to wait for data" );
179 emit gotEnoughData(); 177 emit gotEnoughData();
180 } 178 }
181 else { 179 else {
182 // qWarning( "Waiting for %u bytes", sz ); 180 // qWarning( "Waiting for %u bytes", sz );
183 181 minData_ = sz;
184 minData_ = sz; 182 connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) );
185 connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); 183 }
186 }
187} 184}
188 185
189int KRFBConnection::read( void *buf, int sz ) 186int KRFBConnection::read( void *buf, int sz )
190{ 187{
191 return sock->readBlock( (char *) buf, sz ); 188 return sock->readBlock( (char *) buf, sz );
192} 189}
193 190
194int KRFBConnection::write( void *buf, int sz ) 191int KRFBConnection::write( void *buf, int sz )
195{ 192{
196 return sock->writeBlock( (const char *) buf, sz ); 193 return sock->writeBlock( (const char *) buf, sz );
197} 194}
198 195
199KRFBConnection::State KRFBConnection::state() const 196KRFBConnection::State KRFBConnection::state() const
200{ 197{
201 return currentState_; 198 return currentState_;
202} 199}
203 200
204void KRFBConnection::setPortBase( int base ) 201void KRFBConnection::setPortBase( int base )
205{ 202{
206 portBase_ = base; 203 portBase_ = base;
207} 204}
208 205
209int KRFBConnection::portBase() const 206int KRFBConnection::portBase() const
210{ 207{
211 return portBase_; 208 return portBase_;
212}
213
214void KRFBConnection::setPassword( const QCString &pass )
215{
216 this->pass_ = pass;
217} 209}
218 210
219void KRFBConnection::updateTimer() 211void KRFBConnection::updateTimer()
220{ 212{
221 decoder_->sendUpdateRequest( true ); 213 decoder_->sendUpdateRequest( true );
222} 214}
223 215
224void KRFBConnection::refresh() 216void KRFBConnection::refresh()
225{ 217{
226 decoder_->sendUpdateRequest( false ); 218 decoder_->sendUpdateRequest( false );
227} 219}
228 220
229void KRFBConnection::sendCutText( const QString &text ) 221void KRFBConnection::sendCutText( const QString &text )
230{ 222{
231 decoder_->sendCutEvent( text ); 223 decoder_->sendCutEvent( text );
232} 224}
233 225
234const QUrl &KRFBConnection::url() 226const QUrl &KRFBConnection::url()
235{ 227{
236 url_.setProtocol( "vnc" ); 228 url_.setProtocol( "vnc" );
237 url_.setPort( display() ); 229 url_.setPort( display() );
238 url_.setHost( host() ); 230 url_.setHost( host() );
239 url_.setPath( "/" ); 231 url_.setPath( "/" );
240 232
241 return url_; 233 return url_;
242} 234}
diff --git a/noncore/comm/keypebble/krfbconnection.h b/noncore/comm/keypebble/krfbconnection.h
index fe477c1..a8d3457 100644
--- a/noncore/comm/keypebble/krfbconnection.h
+++ b/noncore/comm/keypebble/krfbconnection.h
@@ -1,152 +1,147 @@
1// -*- c++ -*- 1// -*- c++ -*-
2 2
3#ifndef KRFBCONNECTION_H 3#ifndef KRFBCONNECTION_H
4#define KRFBCONNECTION_H 4#define KRFBCONNECTION_H
5 5
6#include <qobject.h> 6#include <qobject.h>
7#include <qstring.h> 7#include <qstring.h>
8#include <qcstring.h> 8#include <qcstring.h>
9#include "krfbserver.h"
9#include <qurl.h> 10#include <qurl.h>
10 11
11class KRFBLogin; 12class KRFBLogin;
12class KRBUpdateHandler; 13class KRBUpdateHandler;
13class KRFBOptions; 14class KRFBServer;
14class QSocket; 15class QSocket;
15class KRFBDecoder; 16class KRFBDecoder;
16class KRFBBuffer; 17class KRFBBuffer;
17class QTimer; 18class QTimer;
18 19
19/** 20/**
20 * Encapsulates the RFB socket. 21 * Encapsulates the RFB socket.
21 * 22 *
22 */ 23 */
23class KRFBConnection : public QObject 24class KRFBConnection : public QObject
24{ 25{
25 Q_OBJECT 26 Q_OBJECT
26 27
27public: 28public:
28 friend class KRFBLogin; 29 friend class KRFBLogin;
29 friend class KRFBDecoder; 30 friend class KRFBDecoder;
30 31
31 //* The state of the connection. 32 //* The state of the connection.
32 enum State { 33 enum State {
33 Connecting, 34 Connecting,
34 LoggingIn, 35 LoggingIn,
35 Connected, 36 Connected,
36 Disconnecting, 37 Disconnecting,
37 Disconnected, 38 Disconnected,
38 Error 39 Error
39 }; 40 };
40 41
41 KRFBConnection( QObject *parent = 0 ); 42 KRFBConnection( QObject *parent = 0 );
42 ~KRFBConnection(); 43 ~KRFBConnection();
43 44
44 //* Get the state of a connection. 45 //* Get the state of a connection.
45 State state() const; 46 State state() const;
46 47
47 //* Get the options for this connection 48 //* Get the options for this connection
48 KRFBOptions *options() const { return options_; }; 49 KRFBServer *options() const { return options_; };
49 50
50 KRFBBuffer *buffer() const { return buffer_; }; 51 KRFBBuffer *buffer() const { return buffer_; };
51 52
52 KRFBDecoder *decoder() const { return decoder_; }; 53 KRFBDecoder *decoder() const { return decoder_; };
53 54
54 //* Set the base from which the port for a given display will be calculated. 55 //* Set the base from which the port for a given display will be calculated.
55 void setPortBase( int base ); 56 void setPortBase( int base );
56 57
57 //* Get the base from which the port for a given display is calculated. 58 //* Get the base from which the port for a given display is calculated.
58 int portBase() const; 59 int portBase() const;
59 60
60 //* Set the password which will be used to login
61 void setPassword( const QCString &pass );
62
63 //* Open a connection 61 //* Open a connection
64 void connectTo( const QCString &host, int display ); 62 void connectTo( KRFBServer);
65 63
66 //* Close the connection 64 //* Close the connection
67 void disconnect(); 65 void disconnect();
68 66
69 //* Get the host 67 //* Get the host
70 const QCString host() const { return host_; }; 68 const QCString host() const { return options_->hostname.latin1(); };
71 69
72 //* Get the display 70 //* Get the display
73 int display() const { return display_; }; 71 int display() const { return options_->display; };
74 72
75 //* Get the current host/display as a URL 73 //* Get the current host/display as a URL
76 const QUrl &url(); 74 const QUrl &url();
77 75
78 //* Reload the display 76 //* Reload the display
79 void refresh(); 77 void refresh();
80 78
81 //* Send text to the remote clipboard 79 //* Send text to the remote clipboard
82 void sendCutText( const QString & ); 80 void sendCutText( const QString & );
83 81
84protected slots: 82protected slots:
85 //* When the shit hits the fan 83 //* When the shit hits the fan
86 void gotSocketError( int ); 84 void gotSocketError( int );
87 85
88 //* When we have an open socket 86 //* When we have an open socket
89 void gotSocketConnection(); 87 void gotSocketConnection();
90 88
91 //* When we have logged in 89 //* When we have logged in
92 void gotRFBConnection(); 90 void gotRFBConnection();
93 91
94 //* When some more data arrived 92 //* When some more data arrived
95 void gotMoreData(); 93 void gotMoreData();
96 94
97 void updateTimer(); 95 void updateTimer();
98 96
99 void disconnectDone(); 97 void disconnectDone();
100 98
101signals: 99signals:
102 //* Emitted when the status of the connection changes. 100 //* Emitted when the status of the connection changes.
103 void statusChanged( const QString & ); 101 void statusChanged( const QString & );
104 102
105 /** 103 /**
106 * Emitted when we *really* need a password. If the password 104 * Emitted when we *really* need a password. If the password
107 * was specified before you tried to connect then you won't 105 * was specified before you tried to connect then you won't
108 * see this. 106 * see this.
109 */ 107 */
110 void passwordRequired( KRFBConnection * ); 108 void passwordRequired( KRFBConnection * );
111 109
112 //* When we have a working RFB connection 110 //* When we have a working RFB connection
113 void connected(); 111 void connected();
114 112
115 void loggedIn(); 113 void loggedIn();
116 114
117 void disconnected(); 115 void disconnected();
118 116
119 //* What happened? 117 //* What happened?
120 void error( const QString &msg ); 118 void error( const QString &msg );
121 119
122 //* Emitted in response to a waitForData() call. 120 //* Emitted in response to a waitForData() call.
123 void gotEnoughData(); 121 void gotEnoughData();
124 122
125private: 123private:
126 // 124 //
127 // The following are called by our friends. 125 // The following are called by our friends.
128 // 126 //
129 127
130 void waitForData( unsigned int ); 128 void waitForData( unsigned int );
131 129
132 int read( void *buf, int sz ); 130 int read( void *buf, int sz );
133 int write( void *buf, int sz ); 131 int write( void *buf, int sz );
134 132
135private: 133private:
136 QCString host_;
137 int portBase_; 134 int portBase_;
138 int display_;
139 QCString pass_;
140 QSocket *sock; 135 QSocket *sock;
141 State currentState_; 136 State currentState_;
142 unsigned int minData_; 137 unsigned int minData_;
143 QTimer *updater; 138 QTimer *updater;
144 KRFBLogin *login; 139 KRFBLogin *login;
145 KRFBDecoder *decoder_; 140 KRFBDecoder *decoder_;
146 KRFBOptions *options_; 141 KRFBServer *options_;
147 KRFBBuffer *buffer_; 142 KRFBBuffer *buffer_;
148 QUrl url_; 143 QUrl url_;
149}; 144};
150 145
151#endif // KRFBCONNECTION_H 146#endif // KRFBCONNECTION_H
152 147
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp
index 174dd7b..a964c09 100644
--- a/noncore/comm/keypebble/krfbdecoder.cpp
+++ b/noncore/comm/keypebble/krfbdecoder.cpp
@@ -1,386 +1,386 @@
1#include "krfbconnection.h" 1#include "krfbconnection.h"
2#include "krfboptions.h" 2#include "krfbserver.h"
3#include "krfbserverinfo.h" 3#include "krfbserverinfo.h"
4#include "krfbdecoder.h" 4#include "krfbdecoder.h"
5#include "krfbbuffer.h" 5#include "krfbbuffer.h"
6 6
7#include <qpe/qpeapplication.h> 7#include <qpe/qpeapplication.h>
8 8
9#include <qpixmap.h> 9#include <qpixmap.h>
10#include <qsocket.h> 10#include <qsocket.h>
11#include <qevent.h> 11#include <qevent.h>
12#include <qstring.h> 12#include <qstring.h>
13#include <qclipboard.h> 13#include <qclipboard.h>
14 14
15#include <assert.h> 15#include <assert.h>
16 16
17// 17//
18// Endian stuff 18// Endian stuff
19// 19//
20#ifndef KDE_USE_FINAL 20#ifndef KDE_USE_FINAL
21const int endianTest = 1; 21const int endianTest = 1;
22#endif 22#endif
23 23
24#define Swap16IfLE(s) \ 24#define Swap16IfLE(s) \
25 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) 25 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
26 26
27#define Swap32IfLE(l) \ 27#define Swap32IfLE(l) \
28 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ 28 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
29 (((l) & 0x00ff0000) >> 8) | \ 29 (((l) & 0x00ff0000) >> 8) | \
30 (((l) & 0x0000ff00) << 8) | \ 30 (((l) & 0x0000ff00) << 8) | \
31 (((l) & 0x000000ff) << 24)) : (l)) 31 (((l) & 0x000000ff) << 24)) : (l))
32 32
33// 33//
34// The lengths of the messages we need to wait for 34// The lengths of the messages we need to wait for
35// 35//
36const int ServerInitLength = 24; 36const int ServerInitLength = 24;
37const int UpdateHeaderLength = 4; 37const int UpdateHeaderLength = 4;
38const int RectHeaderLength = 12; 38const int RectHeaderLength = 12;
39const int RectChunkSize = 4; 39const int RectChunkSize = 4;
40const int CopyRectPosLength = 4; 40const int CopyRectPosLength = 4;
41const int ServerCutLenLength = 7; 41const int ServerCutLenLength = 7;
42 42
43// 43//
44// Client -> Server Message Identifiers 44// Client -> Server Message Identifiers
45// 45//
46static CARD8 SetPixelFormatId = 0; 46static CARD8 SetPixelFormatId = 0;
47//static CARD8 FixColourMapEntriesId = 1; // Not used 47//static CARD8 FixColourMapEntriesId = 1; // Not used
48static CARD8 SetEncodingsId = 2; 48static CARD8 SetEncodingsId = 2;
49static CARD8 UpdateRequestId = 3; 49static CARD8 UpdateRequestId = 3;
50static CARD8 KeyEventId = 4; 50static CARD8 KeyEventId = 4;
51static CARD8 PointerEventId = 5; 51static CARD8 PointerEventId = 5;
52static CARD8 ClientCutTextId = 6; 52static CARD8 ClientCutTextId = 6;
53 53
54// 54//
55// Server -> Client Message Identifiers 55// Server -> Client Message Identifiers
56// 56//
57static CARD8 UpdateId = 0; 57static CARD8 UpdateId = 0;
58static CARD8 BellId = 2; 58static CARD8 BellId = 2;
59static CARD8 ServerCutId = 3; 59static CARD8 ServerCutId = 3;
60 60
61// 61//
62// Encoding identifiers 62// Encoding identifiers
63// 63//
64static CARD32 RawEncoding = Swap32IfLE( 0 ); 64static CARD32 RawEncoding = Swap32IfLE( 0 );
65static CARD32 CopyRectEncoding = Swap32IfLE(1 ); 65static CARD32 CopyRectEncoding = Swap32IfLE(1 );
66static CARD32 RreEncoding = Swap32IfLE( 2 ); 66static CARD32 RreEncoding = Swap32IfLE( 2 );
67static CARD32 CorreEncoding = Swap32IfLE( 4 ); 67static CARD32 CorreEncoding = Swap32IfLE( 4 );
68static CARD32 HexTileEncoding = Swap32IfLE( 5 ); 68static CARD32 HexTileEncoding = Swap32IfLE( 5 );
69 69
70static struct { 70static struct {
71 int keysym; 71 int keysym;
72 int keycode; 72 int keycode;
73} keyMap[] = { 73} keyMap[] = {
74 { 0xff08, Qt::Key_Backspace }, 74 { 0xff08, Qt::Key_Backspace },
75 { 0xff09, Qt::Key_Tab }, 75 { 0xff09, Qt::Key_Tab },
76 { 0xff0d, Qt::Key_Return }, 76 { 0xff0d, Qt::Key_Return },
77 { 0xff1b, Qt::Key_Escape }, 77 { 0xff1b, Qt::Key_Escape },
78 { 0xff63, Qt::Key_Insert }, 78 { 0xff63, Qt::Key_Insert },
79 { 0xffff, Qt::Key_Delete }, 79 { 0xffff, Qt::Key_Delete },
80 { 0xff50, Qt::Key_Home }, 80 { 0xff50, Qt::Key_Home },
81 { 0xff57, Qt::Key_End }, 81 { 0xff57, Qt::Key_End },
82 { 0xff55, Qt::Key_Prior }, 82 { 0xff55, Qt::Key_Prior },
83 { 0xff56, Qt::Key_Next }, 83 { 0xff56, Qt::Key_Next },
84 { 0xff51, Qt::Key_Left }, 84 { 0xff51, Qt::Key_Left },
85 { 0xff52, Qt::Key_Up }, 85 { 0xff52, Qt::Key_Up },
86 { 0xff53, Qt::Key_Right }, 86 { 0xff53, Qt::Key_Right },
87 { 0xff54, Qt::Key_Down }, 87 { 0xff54, Qt::Key_Down },
88 { 0xffbe, Qt::Key_F1 }, 88 { 0xffbe, Qt::Key_F1 },
89 { 0xffbf, Qt::Key_F2 }, 89 { 0xffbf, Qt::Key_F2 },
90 { 0xffc0, Qt::Key_F3 }, 90 { 0xffc0, Qt::Key_F3 },
91 { 0xffc1, Qt::Key_F4 }, 91 { 0xffc1, Qt::Key_F4 },
92 { 0xffc2, Qt::Key_F5 }, 92 { 0xffc2, Qt::Key_F5 },
93 { 0xffc3, Qt::Key_F6 }, 93 { 0xffc3, Qt::Key_F6 },
94 { 0xffc4, Qt::Key_F7 }, 94 { 0xffc4, Qt::Key_F7 },
95 { 0xffc5, Qt::Key_F8 }, 95 { 0xffc5, Qt::Key_F8 },
96 { 0xffc6, Qt::Key_F9 }, 96 { 0xffc6, Qt::Key_F9 },
97 { 0xffc7, Qt::Key_F10 }, 97 { 0xffc7, Qt::Key_F10 },
98 { 0xffc8, Qt::Key_F11 }, 98 { 0xffc8, Qt::Key_F11 },
99 { 0xffc9, Qt::Key_F12 }, 99 { 0xffc9, Qt::Key_F12 },
100 { 0xffe1, Qt::Key_Shift }, 100 { 0xffe1, Qt::Key_Shift },
101 { 0xffe2, Qt::Key_Shift }, 101 { 0xffe2, Qt::Key_Shift },
102 { 0xffe3, Qt::Key_Control }, 102 { 0xffe3, Qt::Key_Control },
103 { 0xffe4, Qt::Key_Control }, 103 { 0xffe4, Qt::Key_Control },
104 { 0xffe7, Qt::Key_Meta }, 104 { 0xffe7, Qt::Key_Meta },
105 { 0xffe8, Qt::Key_Meta }, 105 { 0xffe8, Qt::Key_Meta },
106 { 0xffe9, Qt::Key_Alt }, 106 { 0xffe9, Qt::Key_Alt },
107 { 0xffea, Qt::Key_Alt }, 107 { 0xffea, Qt::Key_Alt },
108 { 0, 0 } 108 { 0, 0 }
109}; 109};
110 110
111 111
112KRFBDecoder::KRFBDecoder( KRFBConnection *con ) 112KRFBDecoder::KRFBDecoder( KRFBConnection *con )
113 : QObject( con, "RFB Decoder" ) 113 : QObject( con, "RFB Decoder" )
114{ 114{
115 assert( con ); 115 assert( con );
116 assert( con->state() == KRFBConnection::Connected ); 116 assert( con->state() == KRFBConnection::Connected );
117 117
118 this->con = con; 118 this->con = con;
119 this->buf = 0; 119 this->buf = 0;
120 this->info = 0; 120 this->info = 0;
121 this->format = 0; 121 this->format = 0;
122 this->buttonMask = 0; 122 this->buttonMask = 0;
123 currentState = Idle; 123 currentState = Idle;
124} 124}
125 125
126KRFBDecoder::~KRFBDecoder() 126KRFBDecoder::~KRFBDecoder()
127{ 127{
128 if ( info ) 128 if ( info )
129 delete info; 129 delete info;
130 if ( format ) 130 if ( format )
131 delete format; 131 delete format;
132} 132}
133 133
134void KRFBDecoder::start() 134void KRFBDecoder::start()
135{ 135{
136 sendClientInit(); 136 sendClientInit();
137} 137}
138 138
139void KRFBDecoder::sendClientInit() 139void KRFBDecoder::sendClientInit()
140{ 140{
141 con->write( &( con->options()->shared ), 1 ); 141 con->write( &( con->options()->shared ), 1 );
142 142
143 // Wait for server init 143 // Wait for server init
144 qWarning( "Waiting for server init" ); 144 qWarning( "Waiting for server init" );
145 145
146 static QString statusMsg = tr( "Waiting for server initialisation..." ); 146 static QString statusMsg = tr( "Waiting for server initialisation..." );
147 emit status( statusMsg ); 147 emit status( statusMsg );
148 148
149 currentState = AwaitingServerInit; 149 currentState = AwaitingServerInit;
150 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); 150 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) );
151 con->waitForData( ServerInitLength ); 151 con->waitForData( ServerInitLength );
152} 152}
153 153
154void KRFBDecoder::gotServerInit() 154void KRFBDecoder::gotServerInit()
155{ 155{
156 qWarning( "Got server init" ); 156 qWarning( "Got server init" );
157 disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); 157 disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) );
158 158
159 if ( info ) 159 if ( info )
160 delete info; 160 delete info;
161 info = new KRFBServerInfo; 161 info = new KRFBServerInfo;
162 CHECK_PTR( info ); 162 CHECK_PTR( info );
163 163
164 con->read( &(info->width), 2 ); 164 con->read( &(info->width), 2 );
165 info->width = Swap16IfLE( info->width ); 165 info->width = Swap16IfLE( info->width );
166 con->read( &info->height, 2 ); 166 con->read( &info->height, 2 );
167 info->height = Swap16IfLE( info->height ); 167 info->height = Swap16IfLE( info->height );
168 168
169 con->read( &(info->bpp), 1 ); 169 con->read( &(info->bpp), 1 );
170 con->read( &(info->depth), 1 ); 170 con->read( &(info->depth), 1 );
171 con->read( &(info->bigEndian), 1 ); 171 con->read( &(info->bigEndian), 1 );
172 con->read( &(info->trueColor), 1 ); 172 con->read( &(info->trueColor), 1 );
173 173
174 con->read( &(info->redMax), 2 ); 174 con->read( &(info->redMax), 2 );
175 info->redMax = Swap16IfLE( info->redMax ); 175 info->redMax = Swap16IfLE( info->redMax );
176 con->read( &(info->greenMax), 2 ); 176 con->read( &(info->greenMax), 2 );
177 info->greenMax = Swap16IfLE( info->greenMax ); 177 info->greenMax = Swap16IfLE( info->greenMax );
178 con->read( &(info->blueMax), 2 ); 178 con->read( &(info->blueMax), 2 );
179 info->blueMax = Swap16IfLE( info->blueMax ); 179 info->blueMax = Swap16IfLE( info->blueMax );
180 180
181 con->read( &(info->redShift), 1 ); 181 con->read( &(info->redShift), 1 );
182 con->read( &(info->greenShift), 1 ); 182 con->read( &(info->greenShift), 1 );
183 con->read( &(info->blueShift), 1 ); 183 con->read( &(info->blueShift), 1 );
184 184
185 con->read( info->padding, 3 ); 185 con->read( info->padding, 3 );
186 186
187 con->read( &(info->nameLength), 4 ); 187 con->read( &(info->nameLength), 4 );
188 info->nameLength = Swap32IfLE( info->nameLength ); 188 info->nameLength = Swap32IfLE( info->nameLength );
189 189
190 qWarning( "Width = %d, Height = %d", info->width, info->height ); 190 qWarning( "Width = %d, Height = %d", info->width, info->height );
191 qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d", 191 qWarning( "Bpp = %d, Depth = %d, Big = %d, True = %d",
192 info->bpp, info->depth, info->bigEndian, info->trueColor ); 192 info->bpp, info->depth, info->bigEndian, info->trueColor );
193 qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d", 193 qWarning( "RedMax = %d, GreenMax = %d, BlueMax = %d",
194 info->redMax, info->greenMax, info->blueMax ); 194 info->redMax, info->greenMax, info->blueMax );
195 qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d", 195 qWarning( "RedShift = %d, GreenShift = %d, BlueShift = %d",
196 info->redShift, info->greenShift,info-> blueShift ); 196 info->redShift, info->greenShift,info-> blueShift );
197 197
198 buf->resize( info->width, info->height ); 198 buf->resize( info->width, info->height );
199 199
200 // Wait for desktop name 200 // Wait for desktop name
201 qWarning( "Waiting for desktop name" ); 201 qWarning( "Waiting for desktop name" );
202 202
203 static QString statusMsg = tr( "Waiting for desktop name..." ); 203 static QString statusMsg = tr( "Waiting for desktop name..." );
204 emit status( statusMsg ); 204 emit status( statusMsg );
205 205
206 currentState = AwaitingDesktopName; 206 currentState = AwaitingDesktopName;
207 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); 207 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) );
208 con->waitForData( info->nameLength ); 208 con->waitForData( info->nameLength );
209} 209}
210 210
211void KRFBDecoder::gotDesktopName() 211void KRFBDecoder::gotDesktopName()
212{ 212{
213 assert( info ); 213 assert( info );
214 assert( currentState == AwaitingDesktopName ); 214 assert( currentState == AwaitingDesktopName );
215 215
216 qWarning( "Got desktop name" ); 216 qWarning( "Got desktop name" );
217 217
218 disconnect( con, SIGNAL( gotEnoughData() ), 218 disconnect( con, SIGNAL( gotEnoughData() ),
219 this, SLOT( gotDesktopName() ) ); 219 this, SLOT( gotDesktopName() ) );
220 220
221 char *buf = new char[ info->nameLength + 1 ]; 221 char *buf = new char[ info->nameLength + 1 ];
222 CHECK_PTR( buf ); 222 CHECK_PTR( buf );
223 223
224 con->read( buf, info->nameLength ); 224 con->read( buf, info->nameLength );
225 buf[ info->nameLength ] = '\0'; 225 buf[ info->nameLength ] = '\0';
226 info->name = buf; 226 info->name = buf;
227 227
228 qWarning( "Desktop: %s", info->name.latin1() ); 228 qWarning( "Desktop: %s", info->name.latin1() );
229 229
230 delete buf; 230 delete buf;
231 231
232 // Get the format we'll really use and tell the server 232 // Get the format we'll really use and tell the server
233 decidePixelFormat(); 233 decidePixelFormat();
234 sendPixelFormat(); 234 sendPixelFormat();
235 sendAllowedEncodings(); 235 sendAllowedEncodings();
236 currentState = Idle; 236 currentState = Idle;
237 237
238 QString msg; 238 QString msg;
239 msg = tr( "Connected to %1" ); 239 msg = tr( "Connected to %1" );
240 msg = msg.arg( info->name ); 240 msg = msg.arg( info->name );
241 emit status( msg ); 241 emit status( msg );
242 242
243 sendUpdateRequest( false ); 243 sendUpdateRequest( false );
244} 244}
245 245
246void KRFBDecoder::decidePixelFormat() 246void KRFBDecoder::decidePixelFormat()
247{ 247{
248 assert( info ); 248 assert( info );
249 249
250 if ( format ) 250 if ( format )
251 delete format; 251 delete format;
252 format = new KRFBPixelFormat; 252 format = new KRFBPixelFormat;
253 CHECK_PTR( format ); 253 CHECK_PTR( format );
254 254
255 // What depth do we want? 255 // What depth do we want?
256 // 256 //
257 // We'll use the minimum of the remote and local depths, UNLESS an 257 // We'll use the minimum of the remote and local depths, UNLESS an
258 // eight bit session has been specifically requested by the user. 258 // eight bit session has been specifically requested by the user.
259 int screenDepth = QPixmap::defaultDepth(); 259 int screenDepth = QPixmap::defaultDepth();
260 int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; 260 int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth;
261 int chosenDepth; 261 int chosenDepth;
262 262
263 if ( con->options()->colors256 ) 263 if ( con->options()->colors256 )
264 chosenDepth = 8; 264 chosenDepth = 8;
265 else 265 else
266 chosenDepth = bestDepth; 266 chosenDepth = bestDepth;
267 267
268 qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \ 268 qWarning( "Screen depth=%d, server depth=%d, best depth=%d, " \
269 "eight bit %d, chosenDepth=%d", 269 "eight bit %d, chosenDepth=%d",
270 screenDepth, 270 screenDepth,
271 info->depth, 271 info->depth,
272 bestDepth, 272 bestDepth,
273 con->options()->colors256, chosenDepth ); 273 con->options()->colors256, chosenDepth );
274 274
275 format->depth = chosenDepth; 275 format->depth = chosenDepth;
276 276
277 // If we're using the servers native depth 277 // If we're using the servers native depth
278 if ( chosenDepth == info->depth ) { 278 if ( chosenDepth == info->depth ) {
279 // Use the servers native format 279 // Use the servers native format
280 format->bpp = info->bpp; 280 format->bpp = info->bpp;
281 // format->bigEndian = info->bigEndian; 281 // format->bigEndian = info->bigEndian;
282 format->bigEndian = true; 282 format->bigEndian = true;
283 format->trueColor = info->trueColor; 283 format->trueColor = info->trueColor;
284 format->redMax = info->redMax; 284 format->redMax = info->redMax;
285 format->greenMax = info->greenMax; 285 format->greenMax = info->greenMax;
286 format->blueMax = info->blueMax; 286 format->blueMax = info->blueMax;
287 format->redShift = info->redShift; 287 format->redShift = info->redShift;
288 format->greenShift = info->greenShift; 288 format->greenShift = info->greenShift;
289 format->blueShift = info->blueShift; 289 format->blueShift = info->blueShift;
290 } 290 }
291 else { 291 else {
292 if ( chosenDepth == 8 ) { 292 if ( chosenDepth == 8 ) {
293 format->bpp = 8; 293 format->bpp = 8;
294 format->bigEndian = true; 294 format->bigEndian = true;
295 format->trueColor = true; 295 format->trueColor = true;
296 format->redMax = 7; 296 format->redMax = 7;
297 format->greenMax = 7; 297 format->greenMax = 7;
298 format->blueMax = 3; 298 format->blueMax = 3;
299 format->redShift = 0; 299 format->redShift = 0;
300 format->greenShift = 3; 300 format->greenShift = 3;
301 format->blueShift = 6; 301 format->blueShift = 6;
302 } 302 }
303 } 303 }
304 304
305 format->redMax = Swap16IfLE( format->redMax ); 305 format->redMax = Swap16IfLE( format->redMax );
306 format->greenMax = Swap16IfLE( format->greenMax ); 306 format->greenMax = Swap16IfLE( format->greenMax );
307 format->blueMax = Swap16IfLE( format->blueMax ); 307 format->blueMax = Swap16IfLE( format->blueMax );
308} 308}
309 309
310void KRFBDecoder::sendPixelFormat() 310void KRFBDecoder::sendPixelFormat()
311{ 311{
312 static char padding[3]; 312 static char padding[3];
313 con->write( &SetPixelFormatId, 1 ); 313 con->write( &SetPixelFormatId, 1 );
314 con->write( padding, 3 ); 314 con->write( padding, 3 );
315 315
316 con->write( &(format->bpp), 1 ); 316 con->write( &(format->bpp), 1 );
317 con->write( &(format->depth), 1 ); 317 con->write( &(format->depth), 1 );
318 con->write( &(format->bigEndian), 1 ); 318 con->write( &(format->bigEndian), 1 );
319 con->write( &(format->trueColor), 1 ); 319 con->write( &(format->trueColor), 1 );
320 320
321 con->write( &(format->redMax), 2 ); 321 con->write( &(format->redMax), 2 );
322 con->write( &(format->greenMax), 2 ); 322 con->write( &(format->greenMax), 2 );
323 con->write( &(format->blueMax), 2 ); 323 con->write( &(format->blueMax), 2 );
324 324
325 con->write( &(format->redShift), 1 ); 325 con->write( &(format->redShift), 1 );
326 con->write( &(format->greenShift), 1 ); 326 con->write( &(format->greenShift), 1 );
327 con->write( &(format->blueShift), 1 ); 327 con->write( &(format->blueShift), 1 );
328 con->write( format->padding, 3 ); // Padding 328 con->write( format->padding, 3 ); // Padding
329} 329}
330 330
331void KRFBDecoder::sendAllowedEncodings() 331void KRFBDecoder::sendAllowedEncodings()
332{ 332{
333 static CARD8 padding[1]; 333 static CARD8 padding[1];
334 con->write( &SetEncodingsId, 1 ); 334 con->write( &SetEncodingsId, 1 );
335 con->write( padding, 1 ); 335 con->write( padding, 1 );
336 336
337 static CARD16 noEncodings = con->options()->encodings(); 337 static CARD16 noEncodings = con->options()->encodings();
338 noEncodings = Swap16IfLE( noEncodings ); 338 noEncodings = Swap16IfLE( noEncodings );
339 con->write( &noEncodings, 2 ); 339 con->write( &noEncodings, 2 );
340 340
341 if ( con->options()->corre ) 341 if ( con->options()->corre )
342 con->write( &CorreEncoding, 4 ); 342 con->write( &CorreEncoding, 4 );
343 if ( con->options()->hexTile ) 343 if ( con->options()->hexTile )
344 con->write( &HexTileEncoding, 4 ); 344 con->write( &HexTileEncoding, 4 );
345 if ( con->options()->rre ) 345 if ( con->options()->rre )
346 con->write( &RreEncoding, 4 ); 346 con->write( &RreEncoding, 4 );
347 if ( con->options()->copyrect ) 347 if ( con->options()->copyrect )
348 con->write( &CopyRectEncoding, 4 ); 348 con->write( &CopyRectEncoding, 4 );
349 // We always support this 349 // We always support this
350 con->write( &RawEncoding, 4 ); 350 con->write( &RawEncoding, 4 );
351} 351}
352 352
353void KRFBDecoder::sendUpdateRequest( bool incremental ) 353void KRFBDecoder::sendUpdateRequest( bool incremental )
354{ 354{
355 if ( currentState != Idle ) 355 if ( currentState != Idle )
356 return; 356 return;
357 357
358 con->write( &UpdateRequestId, 1 ); 358 con->write( &UpdateRequestId, 1 );
359 con->write( &incremental, 1 ); 359 con->write( &incremental, 1 );
360 360
361 static CARD16 x = 0, y = 0; 361 static CARD16 x = 0, y = 0;
362 static CARD16 w = Swap16IfLE( info->width ); 362 static CARD16 w = Swap16IfLE( info->width );
363 static CARD16 h = Swap16IfLE( info->height ); 363 static CARD16 h = Swap16IfLE( info->height );
364 364
365 con->write( &x, 2 ); 365 con->write( &x, 2 );
366 con->write( &y, 2 ); 366 con->write( &y, 2 );
367 con->write( &w, 2 ); 367 con->write( &w, 2 );
368 con->write( &h, 2 ); 368 con->write( &h, 2 );
369 369
370 // Now wait for the update 370 // Now wait for the update
371 currentState = AwaitingUpdate; 371 currentState = AwaitingUpdate;
372 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 372 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
373 con->waitForData( UpdateHeaderLength ); 373 con->waitForData( UpdateHeaderLength );
374} 374}
375 375
376void KRFBDecoder::gotUpdateHeader() 376void KRFBDecoder::gotUpdateHeader()
377{ 377{
378 assert( currentState == AwaitingUpdate ); 378 assert( currentState == AwaitingUpdate );
379 379
380 // qWarning( "Got update header" ); 380 // qWarning( "Got update header" );
381 381
382 disconnect( con, SIGNAL( gotEnoughData() ), 382 disconnect( con, SIGNAL( gotEnoughData() ),
383 this, SLOT( gotUpdateHeader() ) ); 383 this, SLOT( gotUpdateHeader() ) );
384 384
385 CARD8 msgType; 385 CARD8 msgType;
386 con->read( &msgType, 1 ); 386 con->read( &msgType, 1 );
@@ -415,425 +415,426 @@ void KRFBDecoder::gotUpdateHeader()
415 // qWarning( "Expecting %d rects", noRects ); 415 // qWarning( "Expecting %d rects", noRects );
416 416
417 // Now wait for the data 417 // Now wait for the data
418 currentState = AwaitingRectHeader; 418 currentState = AwaitingRectHeader;
419 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 419 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
420 con->waitForData( RectHeaderLength ); 420 con->waitForData( RectHeaderLength );
421} 421}
422 422
423void KRFBDecoder::gotRectHeader() 423void KRFBDecoder::gotRectHeader()
424{ 424{
425 assert( currentState == AwaitingRectHeader ); 425 assert( currentState == AwaitingRectHeader );
426 426
427 // qWarning( "Got rect header" ); 427 // qWarning( "Got rect header" );
428 428
429 disconnect( con, SIGNAL( gotEnoughData() ), 429 disconnect( con, SIGNAL( gotEnoughData() ),
430 this, SLOT( gotRectHeader() ) ); 430 this, SLOT( gotRectHeader() ) );
431 431
432 con->read( &x, 2 ); 432 con->read( &x, 2 );
433 x = Swap16IfLE( x ); 433 x = Swap16IfLE( x );
434 con->read( &y, 2 ); 434 con->read( &y, 2 );
435 y = Swap16IfLE( y ); 435 y = Swap16IfLE( y );
436 436
437 con->read( &w, 2 ); 437 con->read( &w, 2 );
438 w = Swap16IfLE( w ); 438 w = Swap16IfLE( w );
439 con->read( &h, 2 ); 439 con->read( &h, 2 );
440 h = Swap16IfLE( h ); 440 h = Swap16IfLE( h );
441 441
442 con->read( &encoding, 4 ); 442 con->read( &encoding, 4 );
443 443
444 // CARD32 encodingLocal = Swap32IfLE( encoding ); 444 // CARD32 encodingLocal = Swap32IfLE( encoding );
445 // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld", 445 // qWarning( "Rect: x=%d, y= %d, w=%d, h=%d, encoding=%ld",
446 // x, y, w, h, encodingLocal ); 446 // x, y, w, h, encodingLocal );
447 447
448 // 448 //
449 // Each encoding needs to be handled differently. Some require 449 // Each encoding needs to be handled differently. Some require
450 // waiting for more data, but others like a copyrect do not. 450 // waiting for more data, but others like a copyrect do not.
451 // Our constants have already been byte swapped, so we use 451 // Our constants have already been byte swapped, so we use
452 // the remote value as is. 452 // the remote value as is.
453 // 453 //
454 if ( encoding == RawEncoding ) { 454 if ( encoding == RawEncoding ) {
455 // qWarning( "Raw encoding" ); 455 // qWarning( "Raw encoding" );
456 handleRawRect(); 456 handleRawRect();
457 } 457 }
458 else if ( encoding == CopyRectEncoding ) { 458 else if ( encoding == CopyRectEncoding ) {
459// qWarning( "CopyRect encoding" ); 459// qWarning( "CopyRect encoding" );
460 handleCopyRect(); 460 handleCopyRect();
461 } 461 }
462 else if ( encoding == RreEncoding ) { 462 else if ( encoding == RreEncoding ) {
463 qWarning( "RRE encoding" ); 463 qWarning( "RRE encoding" );
464 handleRRERect(); 464 handleRRERect();
465 } 465 }
466 else if ( encoding == CorreEncoding ) { 466 else if ( encoding == CorreEncoding ) {
467 qWarning( "CoRRE encoding" ); 467 qWarning( "CoRRE encoding" );
468 handleCoRRERect(); 468 handleCoRRERect();
469 } 469 }
470 else if ( encoding == HexTileEncoding ) { 470 else if ( encoding == HexTileEncoding ) {
471 qWarning( "HexTile encoding" ); 471 qWarning( "HexTile encoding" );
472 handleHexTileRect(); 472 handleHexTileRect();
473 } 473 }
474 else { 474 else {
475 int msg = Swap32IfLE( encoding ); 475 int msg = Swap32IfLE( encoding );
476 QString protocolError = tr( "Protocol Error: An unknown encoding was " 476 QString protocolError = tr( "Protocol Error: An unknown encoding was "
477 "used by the server %1" ).arg( msg ); 477 "used by the server %1" ).arg( msg );
478 currentState = Error; 478 currentState = Error;
479 qWarning( "Unknown encoding, %d", msg ); 479 qWarning( "Unknown encoding, %d", msg );
480 emit error( protocolError ); 480 emit error( protocolError );
481 return; 481 return;
482 } 482 }
483} 483}
484 484
485// 485//
486// Raw Encoding 486// Raw Encoding
487// 487//
488 488
489void KRFBDecoder::handleRawRect() 489void KRFBDecoder::handleRawRect()
490{ 490{
491 // We need something a bit cleverer here to handle large 491 // We need something a bit cleverer here to handle large
492 // rectanges nicely. The chunking should be based on the 492 // rectanges nicely. The chunking should be based on the
493 // overall size (but has to be in complete lines). 493 // overall size (but has to be in complete lines).
494 494
495 // qWarning( "Handling a raw rect chunk" ); 495 // qWarning( "Handling a raw rect chunk" );
496 496
497 // CARD32 lineCount = w * format->bpp / 8; 497 // CARD32 lineCount = w * format->bpp / 8;
498 498
499 if ( h > RectChunkSize ) { 499 if ( h > RectChunkSize ) {
500 // if ( con->sock->size() / lineCount ) { 500 // if ( con->sock->size() / lineCount ) {
501 // getRawRectChunk( con->sock->size() / lineCount ); 501 // getRawRectChunk( con->sock->size() / lineCount );
502 // } 502 // }
503 // else { 503 // else {
504 getRawRectChunk( RectChunkSize ); 504 getRawRectChunk( RectChunkSize );
505 // } 505 // }
506 } 506 }
507 else { 507 else {
508 getRawRectChunk( h ); 508 getRawRectChunk( h );
509 } 509 }
510} 510}
511 511
512void KRFBDecoder::getRawRectChunk( int lines ) 512void KRFBDecoder::getRawRectChunk( int lines )
513{ 513{
514 this->lines = lines; 514 this->lines = lines;
515 CARD32 count = lines * w * format->bpp / 8; 515 CARD32 count = lines * w * format->bpp / 8;
516 516
517 // Wait for server init 517 // Wait for server init
518 // qWarning( "Waiting for raw rect chunk, %ld", count ); 518 // qWarning( "Waiting for raw rect chunk, %ld", count );
519 519
520 currentState = AwaitingRawRectChunk; 520 currentState = AwaitingRawRectChunk;
521 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); 521 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) );
522 con->waitForData( count ); 522 con->waitForData( count );
523} 523}
524 524
525void KRFBDecoder::gotRawRectChunk() 525void KRFBDecoder::gotRawRectChunk()
526{ 526{
527 assert( currentState == AwaitingRawRectChunk ); 527 assert( currentState == AwaitingRawRectChunk );
528 528
529 disconnect( con, SIGNAL( gotEnoughData() ), 529 disconnect( con, SIGNAL( gotEnoughData() ),
530 this, SLOT( gotRawRectChunk() ) ); 530 this, SLOT( gotRawRectChunk() ) );
531 531
532 // qWarning( "Got raw rect chunk" ); 532 // qWarning( "Got raw rect chunk" );
533 533
534 // 534 //
535 // Read the rect data and copy it to the buffer. 535 // Read the rect data and copy it to the buffer.
536 // 536 //
537 537
538 // TODO: Replace this! 538 // TODO: Replace this!
539 int count = lines * w * format->bpp / 8; 539 int count = lines * w * format->bpp / 8;
540 char *hack = new char[ count ]; 540 char *hack = new char[ count ];
541 con->read( hack, count ); 541 con->read( hack, count );
542 buf->drawRawRectChunk( hack, x, y, w, lines ); 542 buf->drawRawRectChunk( hack, x, y, w, lines );
543 delete hack; 543 delete hack;
544 // /TODO: 544 // /TODO:
545 545
546 h = h - lines; 546 h = h - lines;
547 y = y + lines; 547 y = y + lines;
548 548
549 if ( h > 0 ) { 549 if ( h > 0 ) {
550 handleRawRect(); 550 handleRawRect();
551 } 551 }
552 else { 552 else {
553 noRects--; 553 noRects--;
554 554
555 // qWarning( "There are %d rects left", noRects ); 555 // qWarning( "There are %d rects left", noRects );
556 556
557 if ( noRects ) { 557 if ( noRects ) {
558 currentState = AwaitingRectHeader; 558 currentState = AwaitingRectHeader;
559 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 559 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
560 con->waitForData( RectHeaderLength ); 560 con->waitForData( RectHeaderLength );
561 } 561 }
562 else 562 else
563 currentState = Idle; 563 currentState = Idle;
564 } 564 }
565} 565}
566 566
567// 567//
568// Copy Rectangle Encoding 568// Copy Rectangle Encoding
569// 569//
570 570
571void KRFBDecoder::handleCopyRect() 571void KRFBDecoder::handleCopyRect()
572{ 572{
573 currentState = AwaitingCopyRectPos; 573 currentState = AwaitingCopyRectPos;
574 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); 574 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) );
575 con->waitForData( CopyRectPosLength ); 575 con->waitForData( CopyRectPosLength );
576} 576}
577 577
578void KRFBDecoder::gotCopyRectPos() 578void KRFBDecoder::gotCopyRectPos()
579{ 579{
580 disconnect( con, SIGNAL( gotEnoughData() ), 580 disconnect( con, SIGNAL( gotEnoughData() ),
581 this, SLOT( gotCopyRectPos() ) ); 581 this, SLOT( gotCopyRectPos() ) );
582 582
583 CARD16 srcX; 583 CARD16 srcX;
584 CARD16 srcY; 584 CARD16 srcY;
585 585
586 con->read( &srcX, 2 ); 586 con->read( &srcX, 2 );
587 con->read( &srcY, 2 ); 587 con->read( &srcY, 2 );
588 588
589 srcX = Swap16IfLE( srcX ); 589 srcX = Swap16IfLE( srcX );
590 srcY = Swap16IfLE( srcY ); 590 srcY = Swap16IfLE( srcY );
591 591
592 buf->copyRect( srcX, srcY, x, y, w, h ); 592 buf->copyRect( srcX, srcY, x, y, w, h );
593 593
594 noRects--; 594 noRects--;
595 595
596 // qWarning( "There are %d rects left", noRects ); 596 // qWarning( "There are %d rects left", noRects );
597 597
598 if ( noRects ) { 598 if ( noRects ) {
599 currentState = AwaitingRectHeader; 599 currentState = AwaitingRectHeader;
600 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); 600 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) );
601 con->waitForData( RectHeaderLength ); 601 con->waitForData( RectHeaderLength );
602 } 602 }
603 else 603 else
604 currentState = Idle; 604 currentState = Idle;
605} 605}
606 606
607void KRFBDecoder::handleRRERect() 607void KRFBDecoder::handleRRERect()
608{ 608{
609 qWarning( "RRE not implemented" ); 609 qWarning( "RRE not implemented" );
610} 610}
611 611
612void KRFBDecoder::handleCoRRERect() 612void KRFBDecoder::handleCoRRERect()
613{ 613{
614 qWarning( "CoRRE not implemented" ); 614 qWarning( "CoRRE not implemented" );
615} 615}
616 616
617void KRFBDecoder::handleHexTileRect() 617void KRFBDecoder::handleHexTileRect()
618{ 618{
619 qWarning( "HexTile not implemented" ); 619 qWarning( "HexTile not implemented" );
620} 620}
621 621
622void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) 622void KRFBDecoder::sendMouseEvent( QMouseEvent *e )
623{ 623{
624 // Deal with the buttons 624 // Deal with the buttons
625 if ( e->type() != QEvent::MouseMove ) { 625 if ( e->type() != QEvent::MouseMove ) {
626 buttonMask = 0; 626 buttonMask = 0;
627 if ( e->type() == QEvent::MouseButtonPress ) { 627 if ( e->type() == QEvent::MouseButtonPress ) {
628 if ( e->button() & LeftButton ) 628 if ( e->button() & LeftButton )
629 buttonMask |= 0x01; 629 buttonMask |= 0x01;
630 if ( e->button() & MidButton ) 630 if ( e->button() & MidButton )
631 buttonMask |= 0x04; 631 buttonMask |= 0x04;
632 if ( e->button() & RightButton ) 632 if ( e->button() & RightButton )
633 buttonMask |= 0x02; 633 buttonMask |= 0x02;
634 } 634 }
635 else if ( e->type() == QEvent::MouseButtonRelease ) { 635 else if ( e->type() == QEvent::MouseButtonRelease ) {
636 if ( e->button() & LeftButton ) 636 if ( e->button() & LeftButton )
637 buttonMask &= 0x06; 637 buttonMask &= 0x06;
638 if ( e->button() & MidButton ) 638 if ( e->button() & MidButton )
639 buttonMask |= 0x03; 639 buttonMask |= 0x03;
640 if ( e->button() & RightButton ) 640 if ( e->button() & RightButton )
641 buttonMask |= 0x05; 641 buttonMask |= 0x05;
642 } 642 }
643 } 643 }
644 644
645 CARD16 x = Swap16IfLE( e->x() ); 645 CARD16 x = Swap16IfLE( e->x() );
646 CARD16 y = Swap16IfLE( e->y() ); 646 CARD16 y = Swap16IfLE( e->y() );
647 647
648 con->write( &PointerEventId, 1 ); 648 con->write( &PointerEventId, 1 );
649 con->write( &buttonMask, 1 ); 649 con->write( &buttonMask, 1 );
650 con->write( &x, 2 ); 650 con->write( &x, 2 );
651 con->write( &y, 2 ); 651 con->write( &y, 2 );
652} 652}
653 653
654 654
655void KRFBDecoder::sendCutEvent( const QString &unicode ) 655void KRFBDecoder::sendCutEvent( const QString &unicode )
656{ 656{
657 // 657 //
658 // Warning: There is a bug in the RFB protocol because there is no way to find 658 // Warning: There is a bug in the RFB protocol because there is no way to find
659 // out the codepage in use on the remote machine. This could be fixed by requiring 659 // out the codepage in use on the remote machine. This could be fixed by requiring
660 // the remote server to use utf8 etc. but for now we have to assume they're the 660 // the remote server to use utf8 etc. but for now we have to assume they're the
661 // same. I've reported this problem to the ORL guys, but they apparantly have no 661 // same. I've reported this problem to the ORL guys, but they apparantly have no
662 // immediate plans to fix the issue. :-( (rich) 662 // immediate plans to fix the issue. :-( (rich)
663 // 663 //
664 664
665 CARD8 padding[3]; 665 CARD8 padding[3];
666 QCString text = unicode.local8Bit(); 666 QCString text = unicode.local8Bit();
667 CARD32 length = text.length(); 667 CARD32 length = text.length();
668 length = Swap32IfLE( length ); 668 length = Swap32IfLE( length );
669 669
670 con->write( &ClientCutTextId, 1 ); 670 con->write( &ClientCutTextId, 1 );
671 con->write( &padding, 3 ); 671 con->write( &padding, 3 );
672 con->write( &length, 4 ); 672 con->write( &length, 4 );
673 con->write( text.data(), length ); 673 con->write( text.data(), length );
674} 674}
675 675
676void KRFBDecoder::gotServerCut() 676void KRFBDecoder::gotServerCut()
677{ 677{
678 qWarning( "Got server cut" ); 678 qWarning( "Got server cut" );
679 679
680 currentState = AwaitingServerCutLength; 680 currentState = AwaitingServerCutLength;
681 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); 681 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) );
682 con->waitForData( ServerCutLenLength ); 682 con->waitForData( ServerCutLenLength );
683} 683}
684 684
685void KRFBDecoder::gotServerCutLength() 685void KRFBDecoder::gotServerCutLength()
686{ 686{
687 assert( currentState = AwaitingServerCutLength ); 687 assert( currentState = AwaitingServerCutLength );
688 disconnect( con, SIGNAL( gotEnoughData() ), 688 disconnect( con, SIGNAL( gotEnoughData() ),
689 this, SLOT( gotServerCutLength() ) ); 689 this, SLOT( gotServerCutLength() ) );
690 690
691 CARD8 padding[3]; 691 CARD8 padding[3];
692 con->read( padding, 3 ); 692 con->read( padding, 3 );
693 693
694 con->read( &serverCutTextLen, 4 ); 694 con->read( &serverCutTextLen, 4 );
695 serverCutTextLen = Swap32IfLE( serverCutTextLen ); 695 serverCutTextLen = Swap32IfLE( serverCutTextLen );
696 696
697 currentState = AwaitingServerCutText; 697 currentState = AwaitingServerCutText;
698 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); 698 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) );
699 con->waitForData( serverCutTextLen ); 699 con->waitForData( serverCutTextLen );
700} 700}
701 701
702void KRFBDecoder::gotServerCutText() 702void KRFBDecoder::gotServerCutText()
703{ 703{
704 assert( currentState = AwaitingServerCutText ); 704 assert( currentState = AwaitingServerCutText );
705 705
706 disconnect( con, SIGNAL( gotEnoughData() ), 706 disconnect( con, SIGNAL( gotEnoughData() ),
707 this, SLOT( gotServerCutText() ) ); 707 this, SLOT( gotServerCutText() ) );
708 708
709 // 709 //
710 // Warning: There is a bug in the RFB protocol because there is no way to find 710 // Warning: There is a bug in the RFB protocol because there is no way to find
711 // out the codepage in use on the remote machine. This could be fixed by requiring 711 // out the codepage in use on the remote machine. This could be fixed by requiring
712 // the remote server to use utf8 etc. but for now we have to assume they're the 712 // the remote server to use utf8 etc. but for now we have to assume they're the
713 // 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
714 // immediate plans to fix the issue. :-( (rich) 714 // immediate plans to fix the issue. :-( (rich)
715 // 715 //
716 716
717 char *cutbuf = new char[ serverCutTextLen + 1 ]; 717 char *cutbuf = new char[ serverCutTextLen + 1 ];
718 CHECK_PTR( cutbuf ); 718 CHECK_PTR( cutbuf );
719 719
720 con->read( cutbuf, serverCutTextLen ); 720 con->read( cutbuf, serverCutTextLen );
721 cutbuf[ serverCutTextLen ] = '\0'; 721 cutbuf[ serverCutTextLen ] = '\0';
722 722
723 qWarning( "Server cut: %s", cutbuf ); 723 qWarning( "Server cut: %s", cutbuf );
724 724
725 QString cutText( cutbuf ); // DANGER!! 725 QString cutText( cutbuf ); // DANGER!!
726 qApp->clipboard()->setText( cutText ); 726 qApp->clipboard()->setText( cutText );
727 727
728 delete cutbuf; 728 delete cutbuf;
729 729
730 // Now wait for the update (again) 730 // Now wait for the update (again)
731 if ( oldState == AwaitingUpdate ) { 731 if ( oldState == AwaitingUpdate ) {
732 currentState = AwaitingUpdate; 732 currentState = AwaitingUpdate;
733 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 733 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
734 con->waitForData( UpdateHeaderLength ); 734 con->waitForData( UpdateHeaderLength );
735 } 735 }
736 else if ( oldState == Idle ) { 736 else if ( oldState == Idle ) {
737 currentState = Idle; 737 currentState = Idle;
738 } 738 }
739 else { 739 else {
740 qWarning( "Async handled in weird state" ); 740 qWarning( "Async handled in weird state" );
741 currentState = oldState; 741 currentState = oldState;
742 }; 742 };
743} 743}
744 744
745void KRFBDecoder::gotBell() 745void KRFBDecoder::gotBell()
746{ 746{
747 qWarning( "Got server bell" ); 747 qWarning( "Got server bell" );
748 buf->soundBell(); 748 buf->soundBell();
749 749
750 // Now wait for the update (again) 750 // Now wait for the update (again)
751 if ( oldState == AwaitingUpdate ) { 751 if ( oldState == AwaitingUpdate ) {
752 currentState = AwaitingUpdate; 752 currentState = AwaitingUpdate;
753 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); 753 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) );
754 con->waitForData( UpdateHeaderLength ); 754 con->waitForData( UpdateHeaderLength );
755 } 755 }
756 else if ( oldState == Idle ) { 756 else if ( oldState == Idle ) {
757 currentState = Idle; 757 currentState = Idle;
758 } 758 }
759 else { 759 else {
760 qWarning( "Async handled in weird state" ); 760 qWarning( "Async handled in weird state" );
761 currentState = oldState; 761 currentState = oldState;
762 }; 762 };
763} 763}
764 764
765void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) 765void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event )
766{ 766{
767 int key; 767 int key;
768 key = toKeySym( event ); 768 key = toKeySym( event );
769 if ( key ) { 769 if ( key ) {
770 key = Swap32IfLE( key ); 770 key = Swap32IfLE( key );
771 771
772 CARD8 mask = true; 772 CARD8 mask = true;
773 773
774 CARD16 padding = 0; 774 CARD16 padding = 0;
775 con->write( &KeyEventId, 1 ); 775 con->write( &KeyEventId, 1 );
776 con->write( &mask, 1 ); 776 con->write( &mask, 1 );
777 con->write( &padding, 2 ); 777 con->write( &padding, 2 );
778 con->write( &key, 4 ); 778 con->write( &key, 4 );
779 } 779 }
780} 780}
781 781
782void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) 782void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event )
783{ 783{
784 int key; 784 int key;
785 key = toKeySym( event ); 785 key = toKeySym( event );
786 if ( key ) { 786 if ( key ) {
787 key = Swap32IfLE( key ); 787 key = Swap32IfLE( key );
788 788
789 CARD8 mask = false; 789 CARD8 mask = false;
790 790
791 CARD16 padding = 0; 791 CARD16 padding = 0;
792 con->write( &KeyEventId, 1 ); 792 con->write( &KeyEventId, 1 );
793 con->write( &mask, 1 ); 793 con->write( &mask, 1 );
794 con->write( &padding, 2 ); 794 con->write( &padding, 2 );
795 con->write( &key, 4 ); 795 con->write( &key, 4 );
796 } 796 }
797} 797}
798 798
799
799int KRFBDecoder::toKeySym( QKeyEvent *k ) 800int KRFBDecoder::toKeySym( QKeyEvent *k )
800{ 801{
801 int ke = 0; 802 int ke = 0;
802 803
803 ke = k->ascii(); 804 ke = k->ascii();
804 // Markus: Crappy hack. I dont know why lower case letters are 805 // Markus: Crappy hack. I dont know why lower case letters are
805 // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'. 806 // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'.
806 // This sucks. :-( 807 // This sucks. :-(
807 808
808 if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd') 809 if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd')
809 || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h') 810 || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h')
810 || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l') 811 || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l')
811 || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p') 812 || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p')
812 || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't') 813 || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't')
813 || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x') 814 || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x')
814 || (ke == 'y') || (ke == 'z') ) { 815 || (ke == 'y') || (ke == 'z') ) {
815 ke = k->key(); 816 ke = k->key();
816 ke = ke + 0x20; 817 ke = ke + 0x20;
817 return ke; 818 return ke;
818 } 819 }
819 820
820 // qkeydefs = xkeydefs! :-) 821 // qkeydefs = xkeydefs! :-)
821 if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff ) 822 if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff )
822 return k->key(); 823 return k->key();
823 824
824 if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) ) 825 if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) )
825 return k->key(); 826 return k->key();
826 827
827 // qkeydefs != xkeydefs! :-( 828 // qkeydefs != xkeydefs! :-(
828 // This is gonna suck :-( 829 // This is gonna suck :-(
829 830
830 int i = 0; 831 int i = 0;
831 while ( keyMap[i].keycode ) { 832 while ( keyMap[i].keycode ) {
832 if ( k->key() == keyMap[i].keycode ) 833 if ( k->key() == keyMap[i].keycode )
833 return keyMap[i].keysym; 834 return keyMap[i].keysym;
834 i++; 835 i++;
835 } 836 }
836 837
837 return 0; 838 return 0;
838} 839}
839 840
diff --git a/noncore/comm/keypebble/krfblogin.cpp b/noncore/comm/keypebble/krfblogin.cpp
index cc3a8fa..0d2a205 100644
--- a/noncore/comm/keypebble/krfblogin.cpp
+++ b/noncore/comm/keypebble/krfblogin.cpp
@@ -1,256 +1,254 @@
1#include <assert.h> 1#include <assert.h>
2 2
3 3
4extern "C" { 4extern "C" {
5#include "vncauth.h" 5#include "vncauth.h"
6} 6}
7 7
8#include "krfblogin.h" 8#include "krfblogin.h"
9#include "krfbconnection.h" 9#include "krfbconnection.h"
10#include <qtimer.h> 10#include <qtimer.h>
11#include <qregexp.h> 11#include <qregexp.h>
12 12
13// The length of the various messages (used to decide how many bytes to 13// The length of the various messages (used to decide how many bytes to
14// wait for). 14// wait for).
15const int ServerVersionLength = 12; 15const int ServerVersionLength = 12;
16const int ClientVersionLength = 12; 16const int ClientVersionLength = 12;
17const int AuthSchemeLength = 4; 17const int AuthSchemeLength = 4;
18const int FailureReasonSizeLength = 4; 18const int FailureReasonSizeLength = 4;
19const int ChallengeLength = 16; 19const int ChallengeLength = 16;
20const int AuthResultLength = 4; 20const int AuthResultLength = 4;
21 21
22// Authentication results 22// Authentication results
23enum AuthResult { 23enum AuthResult {
24 AuthOk, 24 AuthOk,
25 AuthFailed, 25 AuthFailed,
26 AuthTooMany 26 AuthTooMany
27}; 27};
28 28
29typedef unsigned char CARD8; 29typedef unsigned char CARD8;
30typedef unsigned short CARD16; 30typedef unsigned short CARD16;
31typedef unsigned long CARD32; 31typedef unsigned long CARD32;
32 32
33const int endianTest = 1; 33const int endianTest = 1;
34 34
35// Endian stuff 35// Endian stuff
36#define Swap16IfLE(s) \ 36#define Swap16IfLE(s) \
37 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) 37 (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
38 38
39#define Swap32IfLE(l) \ 39#define Swap32IfLE(l) \
40 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ 40 (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \
41 (((l) & 0x00ff0000) >> 8) | \ 41 (((l) & 0x00ff0000) >> 8) | \
42 (((l) & 0x0000ff00) << 8) | \ 42 (((l) & 0x0000ff00) << 8) | \
43 (((l) & 0x000000ff) << 24)) : (l)) 43 (((l) & 0x000000ff) << 24)) : (l))
44 44
45KRFBLogin::KRFBLogin( KRFBConnection *con ) 45KRFBLogin::KRFBLogin( KRFBConnection *con )
46 : QObject( con, "RFB login manager" ) 46 : QObject( con, "RFB login manager" )
47{ 47{
48 assert( con ); 48 assert( con );
49 this->con = con; 49 this->con = con;
50 currentState = AwaitingServerVersion; 50 currentState = AwaitingServerVersion;
51 51
52 connect( this, SIGNAL( error( const QString & ) ), 52 connect( this, SIGNAL( error( const QString & ) ),
53 con, SIGNAL( error( const QString & ) ) ); 53 con, SIGNAL( error( const QString & ) ) );
54 54
55 connect( this, SIGNAL( passwordRequired( KRFBConnection * ) ),
56 con, SIGNAL( passwordRequired( KRFBConnection * ) ) );
57 55
58 qWarning( "Waiting for server version..." ); 56 qWarning( "Waiting for server version..." );
59 57
60 static QString statusMsg = tr( "Waiting for server version..." ); 58 static QString statusMsg = tr( "Waiting for server version..." );
61 emit status( statusMsg ); 59 emit status( statusMsg );
62 60
63 // Kick off the state machine 61 // Kick off the state machine
64 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) ); 62 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerVersion() ) );
65 con->waitForData( ServerVersionLength ); 63 con->waitForData( ServerVersionLength );
66} 64}
67 65
68KRFBLogin::~KRFBLogin() 66KRFBLogin::~KRFBLogin()
69{ 67{
70 68
71} 69}
72 70
73KRFBLogin::State KRFBLogin::state() const 71KRFBLogin::State KRFBLogin::state() const
74{ 72{
75 return currentState; 73 return currentState;
76} 74}
77 75
78void KRFBLogin::gotServerVersion() 76void KRFBLogin::gotServerVersion()
79{ 77{
80 qWarning( "Got server version" ); 78 qWarning( "Got server version" );
81 79
82 disconnect( con, SIGNAL( gotEnoughData() ), 80 disconnect( con, SIGNAL( gotEnoughData() ),
83 this, SLOT( gotServerVersion() ) ); 81 this, SLOT( gotServerVersion() ) );
84 82
85 // Read the server's version message 83 // Read the server's version message
86 char serverVersion[ ServerVersionLength + 1 ]; 84 char serverVersion[ ServerVersionLength + 1 ];
87 con->read( serverVersion, ServerVersionLength ); 85 con->read( serverVersion, ServerVersionLength );
88 serverVersion[ ServerVersionLength ] = '\0'; 86 serverVersion[ ServerVersionLength ] = '\0';
89 87
90 QCString rfbString( serverVersion, ServerVersionLength + 1 ); 88 QCString rfbString( serverVersion, ServerVersionLength + 1 );
91 versionString = rfbString; 89 versionString = rfbString;
92 90
93 QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" ); 91 QRegExp regexp( "RFB [0-9][0-9][0-9]\\.[0-9][0-9][0-9]\n" );
94 92
95 if ( rfbString.find( regexp ) == -1 ) { 93 if ( rfbString.find( regexp ) == -1 ) {
96 static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString ); 94 static QString msg = tr( "Error: Invalid server version, %1" ).arg( rfbString );
97 95
98 qWarning( msg ); 96 qWarning( msg );
99 emit error( msg ); 97 emit error( msg );
100 currentState = Error; 98 currentState = Error;
101 return; 99 return;
102 } 100 }
103 101
104 // Calculate the actual version number 102 // Calculate the actual version number
105 serverMajor = (serverVersion[4] - '0') * 100 103 serverMajor = (serverVersion[4] - '0') * 100
106 + (serverVersion[5] - '0') * 10 104 + (serverVersion[5] - '0') * 10
107 + (serverVersion[6] - '0'); 105 + (serverVersion[6] - '0');
108 serverMinor = (serverVersion[8] - '0') * 100 106 serverMinor = (serverVersion[8] - '0') * 100
109 + (serverVersion[9] - '0') * 10 107 + (serverVersion[9] - '0') * 10
110 + (serverVersion[10] - '0'); 108 + (serverVersion[10] - '0');
111 109
112 qWarning("Server Version: %03d.%03d", serverMajor, serverMinor ); 110 qWarning("Server Version: %03d.%03d", serverMajor, serverMinor );
113 111
114 if ( serverMajor != 3 ) { 112 if ( serverMajor != 3 ) {
115 QString msg = tr( "Error: Unsupported server version, %1" ) 113 QString msg = tr( "Error: Unsupported server version, %1" )
116 .arg( rfbString ); 114 .arg( rfbString );
117 115
118 qWarning( msg ); 116 qWarning( msg );
119 emit error( msg ); 117 emit error( msg );
120 currentState = Error; 118 currentState = Error;
121 return; 119 return;
122 } 120 }
123 121
124 if ( serverMinor != 3 ) { 122 if ( serverMinor != 3 ) {
125 qWarning( "Minor version mismatch: %d", serverMinor ); 123 qWarning( "Minor version mismatch: %d", serverMinor );
126 } 124 }
127 125
128 // Setup for the next state 126 // Setup for the next state
129 sendClientVersion(); 127 sendClientVersion();
130 128
131 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) ); 129 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthScheme() ) );
132 con->waitForData( AuthSchemeLength ); 130 con->waitForData( AuthSchemeLength );
133} 131}
134 132
135void KRFBLogin::gotAuthScheme() 133void KRFBLogin::gotAuthScheme()
136{ 134{
137 disconnect( con, SIGNAL( gotEnoughData() ), 135 disconnect( con, SIGNAL( gotEnoughData() ),
138 this, SLOT( gotAuthScheme() ) ); 136 this, SLOT( gotAuthScheme() ) );
139 137
140 // Got data 138 // Got data
141 CARD32 scheme; 139 CARD32 scheme;
142 con->read( &scheme, AuthSchemeLength ); 140 con->read( &scheme, AuthSchemeLength );
143 scheme = Swap32IfLE( scheme ); 141 scheme = Swap32IfLE( scheme );
144 142
145 static QString statusMsgOk = tr( "Logged in" ); 143 static QString statusMsgOk = tr( "Logged in" );
146 144
147 switch ( scheme ) { 145 switch ( scheme ) {
148 case 0: 146 case 0:
149 qWarning( "Failed" ); 147 qWarning( "Failed" );
150 // Handle failure 148 // Handle failure
151 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) ); 149 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotFailureReasonSize() ) );
152 con->waitForData( FailureReasonSizeLength ); 150 con->waitForData( FailureReasonSizeLength );
153 break; 151 break;
154 case 1: 152 case 1:
155 // Handle no auth 153 // Handle no auth
156 emit status( statusMsgOk ); 154 emit status( statusMsgOk );
157 con->gotRFBConnection(); 155 con->gotRFBConnection();
158 break; 156 break;
159 case 2: 157 case 2:
160 // Handle VNC auth 158 // Handle VNC auth
161 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) ); 159 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotChallenge() ) );
162 con->waitForData( ChallengeLength ); 160 con->waitForData( ChallengeLength );
163 break; 161 break;
164 default: 162 default:
165 qWarning( "Unknown authentication scheme, 0x%08lx", scheme ); 163 qWarning( "Unknown authentication scheme, 0x%08lx", scheme );
166 currentState = Error; 164 currentState = Error;
167 break; 165 break;
168 }; 166 };
169} 167}
170 168
171void KRFBLogin::gotChallenge() 169void KRFBLogin::gotChallenge()
172{ 170{
173 disconnect( con, SIGNAL( gotEnoughData() ), 171 disconnect( con, SIGNAL( gotEnoughData() ),
174 this, SLOT( gotChallenge() ) ); 172 this, SLOT( gotChallenge() ) );
175 173
176 QTimer::singleShot( 0, this, SLOT(getPassword()) ); 174 QTimer::singleShot( 0, this, SLOT(getPassword()) );
177} 175}
178 176
179void KRFBLogin::getPassword() 177void KRFBLogin::getPassword()
180{ 178{
181 // Got data 179 // Got data
182 CARD8 challenge[ ChallengeLength ]; 180 CARD8 challenge[ ChallengeLength ];
183 con->read( challenge, ChallengeLength ); 181 con->read( challenge, ChallengeLength );
184 182
185 // Last chance to enter a password 183 // Last chance to enter a password
186 if ( con->pass_.isNull() ) { 184 if ( con->options_->password.isNull() ) {
187 qWarning( "krfblogin needs a password" ); 185 qWarning( "krfblogin needs a password" );
188 emit passwordRequired( con ); 186 emit passwordRequired( con );
189 } 187 }
190 188
191 if ( con->pass_.isNull() ) { 189 if ( con->options_->password.isNull() ) {
192 QString msg = tr( "Error: This server requires a password, but none " 190 QString msg = tr( "Error: This server requires a password, but none "
193 "has been specified.\n" ); 191 "has been specified.\n" );
194 192
195 emit error( msg ); 193 emit error( msg );
196 return; 194 return;
197 } 195 }
198 196
199 vncEncryptBytes( (unsigned char *) challenge, con->pass_.data() ); 197 vncEncryptBytes( (unsigned char *) challenge, QCString(con->options_->password.latin1()).data() );
200 con->write( challenge, ChallengeLength ); 198 con->write( challenge, ChallengeLength );
201 199
202 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthResult() ) ); 200 connect( con, SIGNAL( gotEnoughData() ), SLOT( gotAuthResult() ) );
203 con->waitForData( AuthResultLength ); 201 con->waitForData( AuthResultLength );
204} 202}
205 203
206void KRFBLogin::gotFailureReasonSize() 204void KRFBLogin::gotFailureReasonSize()
207{ 205{
208 disconnect( con, SIGNAL( gotEnoughData() ), this, 206 disconnect( con, SIGNAL( gotEnoughData() ), this,
209 SLOT( gotFailureReasonSize() ) ); 207 SLOT( gotFailureReasonSize() ) );
210} 208}
211 209
212void KRFBLogin::gotAuthResult() 210void KRFBLogin::gotAuthResult()
213{ 211{
214 // Got data 212 // Got data
215 disconnect( con, SIGNAL( gotEnoughData() ), this, 213 disconnect( con, SIGNAL( gotEnoughData() ), this,
216 SLOT( gotAuthResult() ) ); 214 SLOT( gotAuthResult() ) );
217 215
218 long result; 216 long result;
219 con->read( &result, AuthResultLength ); 217 con->read( &result, AuthResultLength );
220 result = Swap32IfLE( result ); 218 result = Swap32IfLE( result );
221 219
222 qWarning( "Authentication Result is 0x%08lx", result ); 220 qWarning( "Authentication Result is 0x%08lx", result );
223 221
224 static QString failed = tr( "Error: The password you specified was incorrect." ); 222 static QString failed = tr( "Error: The password you specified was incorrect." );
225 static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n" 223 static QString tooMany = tr( "Error: Too many invalid login attempts have been made\n"
226 "to this account, please try later." ); 224 "to this account, please try later." );
227 225
228 static QString statusMsgOk = tr( "Logged in" ); 226 static QString statusMsgOk = tr( "Logged in" );
229 static QString statusMsgFailed = tr( "Login Failed" ); 227 static QString statusMsgFailed = tr( "Login Failed" );
230 static QString statusMsgTooMany = tr( "Too many failures" ); 228 static QString statusMsgTooMany = tr( "Too many failures" );
231 229
232 switch( result ) { 230 switch( result ) {
233 case AuthOk: 231 case AuthOk:
234 emit status( statusMsgOk ); 232 emit status( statusMsgOk );
235 con->gotRFBConnection(); 233 con->gotRFBConnection();
236 break; 234 break;
237 case AuthFailed: 235 case AuthFailed:
238 qWarning( "Dammit" ); 236 qWarning( "Dammit" );
239 emit status( statusMsgFailed ); 237 emit status( statusMsgFailed );
240 emit error( failed ); 238 emit error( failed );
241 break; 239 break;
242 case AuthTooMany: 240 case AuthTooMany:
243 emit status( statusMsgTooMany ); 241 emit status( statusMsgTooMany );
244 emit error( tooMany ); 242 emit error( tooMany );
245 break; 243 break;
246 default: 244 default:
247 qWarning( "Invalid authentication result, %lx", result ); 245 qWarning( "Invalid authentication result, %lx", result );
248 break; 246 break;
249 } 247 }
250} 248}
251 249
252void KRFBLogin::sendClientVersion() 250void KRFBLogin::sendClientVersion()
253{ 251{
254 qWarning( "Sending client version" ); 252 qWarning( "Sending client version" );
255 con->write( (void*)"RFB 003.003\n", ClientVersionLength ); 253 con->write( (void*)"RFB 003.003\n", ClientVersionLength );
256} 254}
diff --git a/noncore/comm/keypebble/krfboptions.cpp b/noncore/comm/keypebble/krfboptions.cpp
deleted file mode 100644
index 8c4320b..0000000
--- a/noncore/comm/keypebble/krfboptions.cpp
+++ b/dev/null
@@ -1,56 +0,0 @@
1#include <qpe/config.h>
2#include <qpe/qpeapplication.h>
3#include "krfboptions.h"
4
5KRFBOptions::KRFBOptions()
6{
7 readSettings();
8}
9
10KRFBOptions::~KRFBOptions()
11{
12 writeSettings();
13}
14
15void KRFBOptions::readSettings()
16{
17 Config config( "keypebble" );
18 config.setGroup("Settings");
19 hexTile = config.readBoolEntry( "HexTile", 0 );
20 corre = config.readBoolEntry( "CORRE", 0 );
21 rre = config.readBoolEntry( "RRE", 0 );
22 copyrect = config.readBoolEntry( "CopyRect", 1 );
23 colors256 = config.readBoolEntry( "Colors256", 0 );
24 shared = config.readBoolEntry( "Shared", 0 );
25 readOnly = config.readBoolEntry( "ReadOnly", 0 );
26 updateRate = config.readNumEntry( "UpdateRate", 50 );
27 deIconify = config.readBoolEntry( "DeIconify", 0 );
28}
29
30void KRFBOptions::writeSettings()
31{
32 Config config( "keypebble" );
33 config.setGroup("Settings");
34 config.writeEntry( "HexTile", hexTile );
35 config.writeEntry( "CORRE", corre );
36 config.writeEntry( "RRE", rre );
37 config.writeEntry( "CopyRect", copyrect );
38 config.writeEntry( "Colors256", colors256 );
39 config.writeEntry( "Shared", shared );
40 config.writeEntry( "ReadOnly", readOnly );
41 config.writeEntry( "UpdateRate", updateRate );
42 config.writeEntry( "DeIconify", deIconify );
43}
44
45int KRFBOptions::encodings()
46{
47 // Initially one because we always support raw encoding
48 int count = 1;
49
50 count += hexTile ? 1 : 0;
51 count += corre ? 1 : 0;
52 count += rre ? 1 : 0;
53 count += copyrect ? 1 : 0;
54
55 return count;
56}
diff --git a/noncore/comm/keypebble/krfboptions.h b/noncore/comm/keypebble/krfboptions.h
deleted file mode 100644
index fd2b65c..0000000
--- a/noncore/comm/keypebble/krfboptions.h
+++ b/dev/null
@@ -1,31 +0,0 @@
1// -*- c++ -*-
2
3#ifndef KRFBOPTIONS_H
4#define KRFBOPTIONS_H
5
6class Config;
7
8class KRFBOptions
9{
10public:
11 KRFBOptions();
12 ~KRFBOptions();
13
14 int encodings();
15 void readSettings();
16 void writeSettings();
17
18 bool hexTile;
19 bool corre;
20 bool rre;
21 bool copyrect;
22
23 bool colors256;
24 bool shared;
25 bool readOnly;
26 bool deIconify;
27
28 int updateRate;
29};
30
31#endif // KRFBOPTIONS_H
diff --git a/noncore/comm/keypebble/krfbserver.cpp b/noncore/comm/keypebble/krfbserver.cpp
new file mode 100644
index 0000000..5775f09
--- a/dev/null
+++ b/noncore/comm/keypebble/krfbserver.cpp
@@ -0,0 +1,39 @@
1#include <qpe/config.h>
2#include <qpe/qpeapplication.h>
3#include "krfbserver.h"
4
5KRFBServer::KRFBServer()
6{
7 QString name;
8 QString hostname;
9 QString password;
10 display=0;
11
12 hexTile=0;
13 corre=0;
14 rre=0;
15 copyrect=1;
16
17 colors256=1;
18 shared=0;
19 readOnly=0;
20 deIconify=0;
21
22 updateRate=0;
23}
24KRFBServer::~KRFBServer()
25{
26}
27
28int KRFBServer::encodings()
29{
30 // Initially one because we always support raw encoding
31 int count = 1;
32
33 count += hexTile ? 1 : 0;
34 count += corre ? 1 : 0;
35 count += rre ? 1 : 0;
36 count += copyrect ? 1 : 0;
37
38 return count;
39}
diff --git a/noncore/comm/keypebble/kvnc.cpp b/noncore/comm/keypebble/kvnc.cpp
index 43cffc5..aa46e2f 100644
--- a/noncore/comm/keypebble/kvnc.cpp
+++ b/noncore/comm/keypebble/kvnc.cpp
@@ -1,190 +1,272 @@
1#include <qiconset.h> 1#include <qiconset.h>
2#include <qdialog.h> 2#include <qdialog.h>
3#include <qpixmap.h> 3#include <qpixmap.h>
4#include <qdom.h> 4#include <qdom.h>
5#include <qaction.h> 5#include <qaction.h>
6#include <qpe/qpemenubar.h> 6#include <qpe/qpemenubar.h>
7#include <qstatusbar.h> 7#include <qstatusbar.h>
8#include <qpopupmenu.h> 8#include <qpopupmenu.h>
9#include <qpushbutton.h> 9#include <qpushbutton.h>
10#include <qpe/qpetoolbar.h> 10#include <qpe/qpetoolbar.h>
11#include <qtimer.h> 11#include <qtimer.h>
12#include <qmessagebox.h> 12#include <qmessagebox.h>
13#include <qspinbox.h>
14#include <qlistbox.h>
15#include <qlineedit.h>
13#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
14#include <qpe/global.h> 17#include <qpe/global.h>
18#include <qpe/qpetoolbar.h>
19#include <qpe/resource.h>
20
15#include <assert.h> 21#include <assert.h>
16 22
17#include "kvnc.h" 23#include "kvnc.h"
18#include "krfbcanvas.h" 24#include "krfbcanvas.h"
19#include "kvncoptionsdlg.h"
20#include "krfbconnection.h" 25#include "krfbconnection.h"
26#include "kvncconndlg.h"
27#include "krfbserver.h"
28
29static int u_id = 1;
30static int get_unique_id()
31{
32 return u_id++;
33}
21 34
22 35
23/* XPM */ 36/* XPM */
24static char * menu_xpm[] = { 37static char * menu_xpm[] = {
25"12 12 5 1", 38"12 12 5 1",
26 " c None", 39 " c None",
27 ".c #000000", 40 ".c #000000",
28 "+c #FFFDAD", 41 "+c #FFFDAD",
29 "@c #FFFF00", 42 "@c #FFFF00",
30 "#c #E5E100", 43 "#c #E5E100",
31" ", 44" ",
32" ", 45" ",
33" ......... ", 46" ......... ",
34" .+++++++. ", 47" .+++++++. ",
35" .+@@@@#. ", 48" .+@@@@#. ",
36" .+@@@#. ", 49" .+@@@#. ",
37" .+@@#. ", 50" .+@@#. ",
38" .+@#. ", 51" .+@#. ",
39" .+#. ", 52" .+#. ",
40" .+. ", 53" .+. ",
41" .. ", 54" .. ",
42" "}; 55" "};
43 56
44const int StatusTextId = 0; 57const int StatusTextId = 0;
45 58
46KVNC::KVNC( const char *name ) : QMainWindow( 0, name ) 59KVNC::KVNC( const char *name ) : QMainWindow( 0, name )
47{ 60{
48 setCaption( tr("VNC Viewer") ); 61 setCaption( tr("VNC Viewer") );
49 fullscreen = false; 62 fullscreen = false;
50 63
51 canvas = new KRFBCanvas( this, "canvas" ); 64 stack = new QWidgetStack( this );
52 setCentralWidget( canvas ); 65 setCentralWidget( stack );
53 66
67 bookmarkSelector=new KVNCBookmarkDlg();
68 stack->addWidget(bookmarkSelector,get_unique_id());
69 stack->raiseWidget( bookmarkSelector );
70
71 canvas = new KRFBCanvas( stack, "canvas" );
72 stack->addWidget(canvas,get_unique_id());
73 setCentralWidget( stack );
74
75 connect( bookmarkSelector->bookmarkList, SIGNAL(doubleClicked(QListBoxItem *)),
76 this, SLOT(openConnection(QListBoxItem *)) );
54 connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), 77 connect( canvas->connection(), SIGNAL(statusChanged(const QString &)),
55 this, SLOT(statusMessage(const QString &)) ); 78 this, SLOT(statusMessage(const QString &)) );
56 connect( canvas->connection(), SIGNAL(error(const QString &)), 79 connect( canvas->connection(), SIGNAL(error(const QString &)),
57 this, SLOT(error(const QString &)) ); 80 this, SLOT(error(const QString &)) );
58 connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); 81 connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) );
59 connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); 82 connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) );
60 connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) ); 83 connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) );
61 84
62 setupActions(); 85 setupActions();
63 86
64 cornerButton = new QPushButton( this ); 87 cornerButton = new QPushButton( this );
65 cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); 88 cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) );
66 connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); 89 connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) );
67 canvas->setCornerWidget( cornerButton ); 90 canvas->setCornerWidget( cornerButton );
68 91
69 QTimer::singleShot( 0, canvas, SLOT(openConnection()) ); 92 stack->raiseWidget( bookmarkSelector );
93
94
95 QPEToolBar *bar = new QPEToolBar( this );
96
97 QAction *n = new QAction( tr( "New Connection" ), Resource::loadPixmap( "new" ),
98 QString::null, 0, this, 0 );
99 connect( n, SIGNAL( activated() ),
100 this, SLOT( newConnection() ) );
101 n->addTo( bar );
102
103 QAction *o = new QAction( tr( "Open Bookmark" ), Resource::loadPixmap( "edit" ),
104 QString::null, 0, this, 0 );
105 connect( o, SIGNAL( activated() ),
106 this, SLOT( openConnection() ) );
107 o->addTo( bar );
108
109 QAction *d = new QAction( tr( "Delete Bookmark" ), Resource::loadPixmap( "trash" ),
110 QString::null, 0, this, 0 );
111 connect( d, SIGNAL( activated() ),
112 this, SLOT( deleteBookmark() ) );
113 d->addTo( bar );
70} 114}
71 115
72KVNC::~KVNC() 116KVNC::~KVNC()
73{ 117{
118
119}
120
121void KVNC::newConnection()
122{
123 curServer=new KRFBServer;
124
125 KVNCConnDlg dlg( curServer,this);
126 dlg.showMaximized();
127 if (dlg.exec()) {
128 if (!curServer->name.isEmpty())
129 bookmarkSelector->addBookmark(curServer);
130 canvas->openConnection(*curServer);
131 } else
132 curServer=0;
133}
134
135void KVNC::openConnection( QString name)
136{
137 curServer=bookmarkSelector->getServer(name);
138
139 if (curServer) {
140 KVNCConnDlg dlg( curServer,this);
141 dlg.showMaximized();
142
143 if ( dlg.exec() ) {
144 canvas->openConnection(*curServer);
145 bookmarkSelector->writeBookmarks();
146 } else
147 curServer=0;
148 }
149}
150
151void KVNC::openConnection( void )
152{
153 openConnection( bookmarkSelector->selectedBookmark());
74} 154}
75 155
76void KVNC::openURL( const QUrl &url ) 156void KVNC::openConnection( QListBoxItem * item)
77{ 157{
78 canvas->openURL( url ); 158 openConnection(item->text());
79} 159}
80 160
81void KVNC::setupActions() 161void KVNC::setupActions()
82{ 162{
83 cornerMenu = new QPopupMenu( this ); 163 cornerMenu = new QPopupMenu( this );
84 164
85 fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); 165 fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 );
86 connect( fullScreenAction, SIGNAL(activated()), 166 connect( fullScreenAction, SIGNAL(activated()),
87 this, SLOT( toggleFullScreen() ) ); 167 this, SLOT( toggleFullScreen() ) );
88 fullScreenAction->addTo( cornerMenu ); 168 fullScreenAction->addTo( cornerMenu );
89 fullScreenAction->setEnabled( false ); 169 fullScreenAction->setEnabled( false );
90 170
91 optionsAction = new QAction( tr("Settings"), QString::null, 0, 0 ); 171 ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 );
92 connect( optionsAction, SIGNAL(activated()), this, SLOT( showOptions() ) ); 172 connect( ctlAltDelAction, SIGNAL(activated()),
93 optionsAction->addTo( cornerMenu ); 173 canvas, SLOT( sendCtlAltDel() ) );
94 174 ctlAltDelAction->addTo( cornerMenu );
95 connectAction = new QAction( tr("Connect..."), QString::null, 0, 0 ); 175 ctlAltDelAction->setEnabled( false );
96 connect( connectAction, SIGNAL(activated()),
97 canvas, SLOT( openConnection() ) );
98 connectAction->addTo( cornerMenu );
99 176
100 disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); 177 disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 );
101 connect( disconnectAction, SIGNAL(activated()), 178 connect( disconnectAction, SIGNAL(activated()),
102 this, SLOT( closeConnection() ) ); 179 this, SLOT( closeConnection() ) );
103 disconnectAction->addTo( cornerMenu ); 180 disconnectAction->addTo( cornerMenu );
104 disconnectAction->setEnabled( false ); 181 disconnectAction->setEnabled( false );
105} 182}
106 183
107void KVNC::toggleFullScreen() 184void KVNC::toggleFullScreen()
108{ 185{
109 if ( fullscreen ) { 186 if ( fullscreen ) {
110 canvas->releaseKeyboard(); 187 canvas->releaseKeyboard();
111 canvas->reparent( this, 0, QPoint(0,0), false ); 188 canvas->reparent( stack, 0, QPoint(0,0), false );
112 canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 189 canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken );
113 setCentralWidget( canvas ); 190 setCentralWidget( stack );
114 canvas->show(); 191 stack->addWidget(canvas,get_unique_id());
115 fullScreenAction->setText( tr("Full Screen") ); 192 stack->raiseWidget(canvas);
116 } else { 193 canvas->show();
117 canvas->setFrameStyle( QFrame::NoFrame ); 194 stack->show();
118 canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, 195 fullScreenAction->setText( tr("Full Screen") );
119 QPoint(0,0),false); 196 } else {
120 canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); 197 canvas->setFrameStyle( QFrame::NoFrame );
121 canvas->raise(); 198 stack->removeWidget(canvas);
122 canvas->setFocus(); 199 canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop,
123 canvas->grabKeyboard(); 200 QPoint(0,0),false);
124 canvas->show(); 201 canvas->resize(qApp->desktop()->width(), qApp->desktop()->height());
125 202 canvas->raise();
126 fullScreenAction->setText( tr("Stop Full Screen") ); 203 canvas->setFocus();
127 } 204 canvas->grabKeyboard();
128 205 canvas->show();
206
207 fullScreenAction->setText( tr("Stop Full Screen") );
208 }
209
210
129 fullscreen = !fullscreen; 211 fullscreen = !fullscreen;
130} 212}
131 213
132void KVNC::closeConnection() 214void KVNC::closeConnection()
133{ 215{
134 if ( fullscreen ) 216 if ( fullscreen )
135 toggleFullScreen(); 217 toggleFullScreen();
136 canvas->closeConnection(); 218 canvas->closeConnection();
137} 219}
138 220
139void KVNC::showMenu() 221void KVNC::showMenu()
140{ 222{
141 QPoint pt = mapToGlobal(cornerButton->pos()); 223 QPoint pt = mapToGlobal(cornerButton->pos());
142 QSize s = cornerMenu->sizeHint(); 224 QSize s = cornerMenu->sizeHint();
143 pt.ry() -= s.height(); 225 pt.ry() -= s.height();
144 pt.rx() -= s.width(); 226 pt.rx() -= s.width();
145 cornerMenu->popup( pt ); 227 cornerMenu->popup( pt );
146} 228}
147 229
148void KVNC::connected() 230void KVNC::connected()
149{ 231{
150 static QString msg = tr( "Connected to remote host" ); 232 static QString msg = tr( "Connected to remote host" );
151 statusMessage( msg ); 233 statusMessage( msg );
152 connectAction->setEnabled( false ); 234 ctlAltDelAction->setEnabled(true);
153 disconnectAction->setEnabled( true ); 235 disconnectAction->setEnabled( true );
154 fullScreenAction->setEnabled( true ); 236 fullScreenAction->setEnabled( true );
237 stack->raiseWidget(canvas);
155} 238}
156 239
157void KVNC::loggedIn() 240void KVNC::loggedIn()
158{ 241{
159 static QString msg = tr( "Logged in to remote host" ); 242 static QString msg = tr( "Logged in to remote host" );
160 statusMessage( msg ); 243 statusMessage( msg );
161} 244}
162 245
163void KVNC::disconnected() 246void KVNC::disconnected()
164{ 247{
248
249 if ( fullscreen )
250 toggleFullScreen();
165 static QString msg = tr( "Connection closed" ); 251 static QString msg = tr( "Connection closed" );
166 statusMessage( msg ); 252 statusMessage( msg );
167 connectAction->setEnabled( true ); 253 ctlAltDelAction->setEnabled(false);
168 disconnectAction->setEnabled( false ); 254 disconnectAction->setEnabled( false );
169 fullScreenAction->setEnabled( false ); 255 fullScreenAction->setEnabled( false );
256 stack->raiseWidget(bookmarkSelector);
170} 257}
171 258
172void KVNC::statusMessage( const QString &m ) 259void KVNC::statusMessage( const QString &m )
173{ 260{
174 Global::statusMessage( m ); 261 Global::statusMessage( m );
175} 262}
176 263
177void KVNC::error( const QString &msg ) 264void KVNC::error( const QString &msg )
178{ 265{
179 statusMessage( msg ); 266 statusMessage( msg );
180 QMessageBox::warning( this, tr("VNC Viewer"), msg ); 267 QMessageBox::warning( this, tr("VNC Viewer"), msg );
181} 268}
182 269void KVNC::deleteBookmark(void)
183void KVNC::showOptions()
184{ 270{
185 KVNCOptionsDlg *wdg = new KVNCOptionsDlg( canvas->connection()->options(), this ); 271 bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark());
186 wdg->showMaximized();
187 wdg->exec();
188 delete wdg;
189} 272}
190
diff --git a/noncore/comm/keypebble/kvnc.h b/noncore/comm/keypebble/kvnc.h
index 92666c5..6e0a385 100644
--- a/noncore/comm/keypebble/kvnc.h
+++ b/noncore/comm/keypebble/kvnc.h
@@ -1,56 +1,66 @@
1// -*- c++ -*- 1// -*- c++ -*-
2 2
3#ifndef KVNC_H 3#ifndef KVNC_H
4#define KVNC_H 4#define KVNC_H
5 5
6#include <qmainwindow.h> 6#include <qmainwindow.h>
7#include <qurl.h> 7#include <qurl.h>
8#include <qwidgetstack.h>
9#include "kvncbookmarkdlg.h"
8 10
9class QAction; 11class QAction;
10class KRFBCanvas; 12class KRFBCanvas;
11class QPushButton; 13class QPushButton;
12class QToolBar; 14class QToolBar;
13 15
14/** 16/**
15 * Top level window for Keystone. 17 * Top level window for Keystone.
16 * 18 *
17 * @author Richard Moore, rich@kde.org 19 * @author Richard Moore, rich@kde.org
18 * @version $Id$ 20 * @version $Id$
19 */ 21 */
20class KVNC : public QMainWindow 22class KVNC : public QMainWindow
21{ 23{
22 Q_OBJECT 24 Q_OBJECT
23public: 25public:
24 KVNC( const char *name = 0 ); 26 KVNC( const char *name = 0 );
25 ~KVNC(); 27 ~KVNC();
26 28
27public slots: 29public slots:
30 void newConnection();
31 void deleteBookmark();
32 void openConnection(QListBoxItem *);
33 void openConnection(QString);
34 void openConnection(void);
28 void toggleFullScreen(); 35 void toggleFullScreen();
29 void openURL( const QUrl & );
30 void closeConnection(); 36 void closeConnection();
31 void showOptions();
32 37
33protected: 38protected:
34 void setupActions(); 39 void setupActions();
35 40
36protected slots: 41protected slots:
37 void showMenu(); 42 void showMenu();
38 43
39 void connected(); 44 void connected();
40 void loggedIn(); 45 void loggedIn();
41 void disconnected(); 46 void disconnected();
42 void statusMessage( const QString & ); 47 void statusMessage( const QString & );
43 void error( const QString & ); 48 void error( const QString & );
44 49
45private: 50private:
46 bool fullscreen; 51 bool fullscreen;
47 KRFBCanvas *canvas; 52 KRFBCanvas *canvas;
48 QPopupMenu *cornerMenu; 53 QPopupMenu *cornerMenu;
49 QPushButton *cornerButton; 54 QPushButton *cornerButton;
50 QAction *fullScreenAction; 55 QAction *fullScreenAction;
51 QAction *optionsAction; 56 QAction *optionsAction;
52 QAction *disconnectAction; 57 QAction *disconnectAction;
58 QAction *ctlAltDelAction;;
53 QAction *connectAction; 59 QAction *connectAction;
60
61 KVNCBookmarkDlg * bookmarkSelector;
62 QWidgetStack * stack;
63 KRFBServer * curServer;
54}; 64};
55 65
56#endif // KVNC_H 66#endif // KVNC_H
diff --git a/noncore/comm/keypebble/kvncbookmarkdlg.cpp b/noncore/comm/keypebble/kvncbookmarkdlg.cpp
new file mode 100644
index 0000000..1f97d13
--- a/dev/null
+++ b/noncore/comm/keypebble/kvncbookmarkdlg.cpp
@@ -0,0 +1,220 @@
1#include <qframe.h>
2#include <qvbox.h>
3#include <qcheckbox.h>
4#include <qspinbox.h>
5#include <qlabel.h>
6#include <qlayout.h>
7#include <qwhatsthis.h>
8#include <qfile.h>
9#include <qdir.h>
10#include <qstring.h>
11#include <qapplication.h>
12#include <qlineedit.h>
13#include <qtextstream.h>
14#include <qpushbutton.h>
15#include <qlistbox.h>
16#include <qpe/config.h>
17#include <qpe/global.h>
18#include "krfbserver.h"
19#include "kvncbookmarkdlg.h"
20
21KVNCBookmarkDlg::KVNCBookmarkDlg( QWidget * parent=0, const char * name=0, WFlags f=0 )
22
23: KVNCBookmarkDlgBase( parent, name,f)
24{
25 readBookmarks();
26 refresh();
27
28}
29
30KVNCBookmarkDlg::~KVNCBookmarkDlg()
31{
32}
33
34void KVNCBookmarkDlg::addBookmark(KRFBServer * server)
35{
36 if (server) {
37 servers.append(server);
38 bookmarkList->insertItem(server->name);
39 writeBookmarks();
40 refresh();
41 }
42}
43
44void KVNCBookmarkDlg::deleteBookmark(QString name)
45{
46 KRFBServer * server=0;
47 for ( server=servers.first(); server != 0; server=servers.next() ) {
48 if (server->name==name) {
49 servers.remove(servers.at());
50 writeBookmarks();
51 refresh();
52 return;
53 }
54 }
55}
56KRFBServer *KVNCBookmarkDlg::getServer(QString name)
57{
58 KRFBServer * server=0;
59 for ( server=servers.first(); server != 0; server=servers.next() ) {
60 if (server->name==name)
61
62 return server;
63 }
64 return 0;
65}
66
67
68/*
69 Note that the degree of protection offered by the encryption here is
70 only sufficient to avoid the most casual observation of the configuration
71 files. People with access to the files can write down the contents and
72 decrypt it using this source code.
73
74 Conceivably, and at some burden to the user, this encryption could
75 be improved.
76*/
77QString KVNCBookmarkDlg::encipher(const QString& plain)
78{
79 // mainly, we make it long
80 QString cipher;
81 int mix=28730492;
82 for (int i=0; i<(int)plain.length(); i++) {
83 int u = plain[i].unicode();
84 int c = u ^ mix;
85 QString x = QString::number(c,36);
86 cipher.append(QChar('a'+x.length()));
87 cipher.append(x);
88 mix *= u;
89 }
90 return cipher;
91}
92
93QString KVNCBookmarkDlg::decipher(const QString& cipher)
94{
95 QString plain;
96 int mix=28730492;
97 for (int i=0; i<(int)cipher.length();) {
98 int l = cipher[i].unicode()-'a';
99 QString x = cipher.mid(i+1,l); i+=l+1;
100 int u = x.toInt(0,36) ^ mix;
101 plain.append(QChar(u));
102 mix *= u;
103 }
104 return plain;
105}
106
107void KVNCBookmarkDlg::readBookmarks(void)
108{
109 QFile f(QDir::homeDirPath() + QString("/Applications/keypebble/bookmarks"));
110
111 QStringList entry;
112 QString key, val;
113 KRFBServer * server=0;
114
115 if ( f.open(IO_ReadOnly) ) {
116 QTextStream t( &f );
117 QString s;
118 int n = 1;
119 while ( !t.eof() ) {
120 s = t.readLine();
121
122
123 entry=QStringList::split('=',s);
124 key=entry[0].stripWhiteSpace().lower();
125 val=entry[1].stripWhiteSpace();
126
127 if (key=="server") {
128
129 if (server){
130 servers.append(server);
131 server=0;
132 }
133 server = new KRFBServer();
134
135 if (!server)
136 return;
137 server->name=val;
138
139 }
140 else if (key=="hostname")
141 server->hostname=val;
142 else if (key=="password")
143 server->password=decipher(val);
144 else if (key=="display")
145 server->display=val.toInt();
146 else if (key=="hextile")
147 server->hexTile=val.toInt();
148 else if (key=="corre")
149 server->corre=val.toInt();
150 else if (key=="rre")
151 server->rre=val.toInt();
152 else if (key=="copyrect")
153 server->copyrect=val.toInt();
154 else if (key=="colors256")
155 server->colors256=val.toInt();
156 else if (key=="shared")
157 server->shared=val.toInt();
158 else if (key=="readonly")
159 server->readOnly=val.toInt();
160 else if (key=="deiconify")
161 server->deIconify=val.toInt();
162 else if (key=="updaterate")
163 server->updateRate=val.toInt();
164
165 }
166 if (server){
167 servers.append(server);
168 server=0;
169 }
170 f.close();
171 }
172}
173
174void KVNCBookmarkDlg::writeBookmarks(void)
175{
176 QString filename=Global::applicationFileName("keypebble","bookmarks");
177
178 QFile f(filename);
179
180 QString key, val;
181 KRFBServer * server=0;
182
183 if ( f.open(IO_ReadWrite) ) {
184 QTextStream t( &f );
185 QString s;
186 int n = 1;
187 KRFBServer *server;
188
189 for ( server=servers.first(); server != 0; server=servers.next() ) {
190 qDebug(server->name);
191 t << "server=" << server->name << '\n';
192 t << "\thostname=" << server->hostname << '\n';
193 t << "\tpassword=" << encipher(server->password )<< '\n';
194 t << "\tdisplay=" << server->display << '\n';
195 t << "\thextile=" << server->hexTile << '\n';
196 t << "\tcorre=" << server->corre << '\n';
197 t << "\trre=" << server->rre << '\n';
198 t << "\tcopyrect=" << server->copyrect << '\n';
199 t << "\tshared=" << server->shared << '\n';
200 t << "\treadonly=" << server->readOnly << '\n';
201 t << "\tdeiconify=" << server->deIconify << '\n';
202 t << "\tupdaterate=" << server->updateRate << '\n';
203
204 }
205 f.close();
206 }
207}
208void KVNCBookmarkDlg::refresh(void)
209{
210 bookmarkList->clear();
211 KRFBServer * server=0;
212 for ( server=servers.first(); server != 0; server=servers.next() ) {
213 bookmarkList->insertItem(server->name);
214 }
215}
216
217QString KVNCBookmarkDlg::selectedBookmark()
218{
219 return bookmarkList->currentText();
220}
diff --git a/noncore/comm/keypebble/kvncconndlg.cpp b/noncore/comm/keypebble/kvncconndlg.cpp
new file mode 100644
index 0000000..6873feb
--- a/dev/null
+++ b/noncore/comm/keypebble/kvncconndlg.cpp
@@ -0,0 +1,75 @@
1#include <qframe.h>
2#include <qvbox.h>
3#include <qcheckbox.h>
4#include <qspinbox.h>
5#include <qlabel.h>
6#include <qlayout.h>
7#include <qwhatsthis.h>
8#include <qapplication.h>
9#include <qlineedit.h>
10#include <qpushbutton.h>
11#include "krfbserver.h"
12
13#include "kvncconndlg.h"
14
15KVNCConnDlg::KVNCConnDlg( KRFBServer *options,
16 QWidget *parent, char *name, bool modal )
17: KVNCConnDlgBase( parent, name, modal )
18{
19 this->options=options;
20 tmpOptions=*options;
21
22 serverHostname->setText(options->hostname);
23 serverDisplay->setValue(options->display);
24 serverPassword->setText(options->password);
25 serverBookmark->setText(options->name);
26
27 hex->setChecked( options->hexTile );
28 corre->setChecked( options->corre );
29 rre->setChecked( options->rre );
30 copyRect->setChecked( options->copyrect );
31
32 // TODO
33 hex->setEnabled( false );
34 corre->setEnabled( false );
35 rre->setEnabled( false );
36 // /TODO
37
38 deIconify->setChecked( options->deIconify );
39 bit->setChecked( options->colors256 );
40 shared->setChecked( options->shared );
41 timeBox->setValue( options->updateRate );
42
43
44}
45
46KVNCConnDlg::~KVNCConnDlg()
47{
48}
49
50void KVNCConnDlg::accept()
51{
52 save();
53 QDialog::accept();
54}
55
56void KVNCConnDlg::save()
57{
58 tmpOptions.hexTile = hex->isChecked();
59 tmpOptions.corre = corre->isChecked();
60 tmpOptions.rre = rre->isChecked();
61 tmpOptions.copyrect = copyRect->isChecked();
62 tmpOptions.deIconify = deIconify->isChecked();
63 tmpOptions.colors256 = bit->isChecked();
64 tmpOptions.shared = shared->isChecked();
65 tmpOptions.hostname = serverHostname->text();
66 tmpOptions.password = serverPassword->text();
67 tmpOptions.display = serverDisplay->value();
68 tmpOptions.name = serverBookmark->text();
69
70 if (!serverBookmark->text().isEmpty()) {
71 if ( options) {
72 *options=tmpOptions;
73 }
74 }
75}
diff --git a/noncore/comm/keypebble/kvncconnectdlg.cpp b/noncore/comm/keypebble/kvncconnectdlg.cpp
deleted file mode 100644
index 467cebf..0000000
--- a/noncore/comm/keypebble/kvncconnectdlg.cpp
+++ b/dev/null
@@ -1,79 +0,0 @@
1#include <qstring.h>
2#include <qlayout.h>
3#include <qframe.h>
4#include <qspinbox.h>
5#include <qcombobox.h>
6#include <qlabel.h>
7#include <qfont.h>
8
9#include <assert.h>
10
11#include "krfbconnection.h"
12#include "kvncoptionsdlg.h"
13#include "kvncconnectdlg.h"
14
15
16KVNCConnectDlg::KVNCConnectDlg( KRFBConnection *con,
17 QWidget *parent, const char *name )
18 : QDialog( parent, name, true )
19{
20 setCaption( tr("Connect to VNC server") );
21 assert( con );
22 this->con = con;
23
24 QGridLayout *inner = new QGridLayout( this, 3, 2, 6 );
25
26 QLabel *label = new QLabel( tr("Host Name:"),
27 this , "hostLabel");
28 hostNameCombo = new QComboBox( true, this );
29 hostNameCombo->setInsertionPolicy( QComboBox::AtTop );
30 hostNameCombo->setMaxCount( 10 );
31 hostNameCombo->insertItem( "localhost" );
32 hostNameCombo->setFocus();
33
34 inner->addWidget( label, 0, 0 );
35 inner->addWidget( hostNameCombo, 0, 1 );
36
37 label = new QLabel( tr("Display Number:"), this, "displayNumber" );
38 displayNumberEdit = new QSpinBox( this );
39
40 inner->addWidget( label, 1, 0 );
41 inner->addWidget( displayNumberEdit, 1, 1 );
42
43 // if ( viewer->display() != -1 ) {
44 // displayNumberEdit->setValue( viewer->display() );
45 displayNumberEdit->setValue( 1 );
46 // }
47
48 label = new QLabel( tr("Password:"), this );
49 inner->addWidget( label, 2, 0 );
50
51 passwordEdit = new QLineEdit( this );
52 passwordEdit->setEchoMode( QLineEdit::Password );
53 inner->addWidget( passwordEdit, 2, 1 );
54
55 inner->setColStretch( 0, 0 );
56 inner->setColStretch( 1, 15 );
57}
58
59
60void KVNCConnectDlg::accept()
61{
62 int dis;
63 // viewer->setHost(hostNameCombo->currentText());
64 QString temp = displayNumberEdit->text();
65 if(temp.isEmpty())
66 dis = -1;
67 else
68 dis = temp.toUInt();
69 // viewer->setDisplay(dis);
70 QDialog::accept();
71}
72
73void KVNCConnectDlg::options()
74{
75 KVNCOptionsDlg *wdg = new KVNCOptionsDlg( con->options(), this );
76 wdg->exec();
77 delete wdg;
78}
79
diff --git a/noncore/comm/keypebble/kvncconnectdlg.h b/noncore/comm/keypebble/kvncconnectdlg.h
deleted file mode 100644
index cf34aab..0000000
--- a/noncore/comm/keypebble/kvncconnectdlg.h
+++ b/dev/null
@@ -1,39 +0,0 @@
1// -*- c++ -*-
2
3#ifndef KVNCCONNECTDLG_H
4#define KVNCCONNECTDLG_H
5
6#include <qdialog.h>
7#include <qspinbox.h>
8#include <qcombobox.h>
9#include <qlineedit.h>
10#include <qurl.h>
11
12class KRFBConnection;
13
14class KVNCConnectDlg : public QDialog
15{
16 Q_OBJECT
17
18public:
19 KVNCConnectDlg( KRFBConnection *con,
20 QWidget *parent = 0, const char *name = 0 );
21
22 QString hostname() { return hostNameCombo->currentText(); };
23 int display() { return displayNumberEdit->value(); };
24 QString password() const { return passwordEdit->text(); }
25
26protected:
27 void accept();
28
29protected slots:
30 void options();
31
32private:
33 QComboBox *hostNameCombo;
34 QSpinBox *displayNumberEdit;
35 QLineEdit *passwordEdit;
36 KRFBConnection *con;
37};
38
39#endif // KVNCCONNECTDLG_H
diff --git a/noncore/comm/keypebble/kvncoptionsdlg.cpp b/noncore/comm/keypebble/kvncoptionsdlg.cpp
deleted file mode 100644
index 9d61c7b..0000000
--- a/noncore/comm/keypebble/kvncoptionsdlg.cpp
+++ b/dev/null
@@ -1,54 +0,0 @@
1#include <qframe.h>
2#include <qvbox.h>
3#include <qcheckbox.h>
4#include <qspinbox.h>
5#include <qlabel.h>
6#include <qlayout.h>
7#include <qwhatsthis.h>
8#include <qapplication.h>
9#include "krfboptions.h"
10
11#include "kvncoptionsdlg.h"
12
13KVNCOptionsDlg::KVNCOptionsDlg( KRFBOptions *options,
14 QWidget *parent, char *name, bool modal )
15 : VncOptionsBase( parent, name, modal )
16{
17 this->options = options;
18
19 hex->setChecked( options->hexTile );
20 corre->setChecked( options->corre );
21 rre->setChecked( options->rre );
22 copyRect->setChecked( options->copyrect );
23
24 // TODO
25 hex->setEnabled( false );
26 corre->setEnabled( false );
27 rre->setEnabled( false );
28 // /TODO
29
30 deIconify->setChecked( options->deIconify );
31 bit->setChecked( options->colors256 );
32 shared->setChecked( options->shared );
33 timeBox->setValue( options->updateRate );
34}
35
36KVNCOptionsDlg::~KVNCOptionsDlg()
37{
38}
39
40void KVNCOptionsDlg::accept()
41{
42 options->hexTile = hex->isChecked();
43 options->corre = corre->isChecked();
44 options->rre = rre->isChecked();
45 options->copyrect = copyRect->isChecked();
46 options->deIconify = deIconify->isChecked();
47 options->colors256 = bit->isChecked();
48 options->shared = shared->isChecked();
49 options->updateRate = timeBox->value();
50 options->writeSettings();
51
52 QDialog::accept();
53}
54
diff --git a/noncore/comm/keypebble/kvncoptionsdlg.h b/noncore/comm/keypebble/kvncoptionsdlg.h
deleted file mode 100644
index a166490..0000000
--- a/noncore/comm/keypebble/kvncoptionsdlg.h
+++ b/dev/null
@@ -1,30 +0,0 @@
1// -*- c++ -*-
2
3#ifndef KVNCOPTIONSDIALOG_H
4#define KVNCOPTIONSDIALOG_H
5
6#include "vncoptionsbase.h"
7
8class KRFBOptions;
9
10class KVNCOptionsDlg : public VncOptionsBase
11{
12Q_OBJECT
13
14public:
15 KVNCOptionsDlg( KRFBOptions *options,
16 QWidget *parent = 0, char *name = 0, bool modal = true );
17 ~KVNCOptionsDlg();
18
19protected:
20 void accept();
21
22private:
23 KRFBOptions *options;
24};
25
26#endif // KVNCOPTIONSDIALOG_H
27
28
29
30
diff --git a/noncore/comm/keypebble/main.cpp b/noncore/comm/keypebble/main.cpp
index ee3cd79..bc7782c 100644
--- a/noncore/comm/keypebble/main.cpp
+++ b/noncore/comm/keypebble/main.cpp
@@ -1,17 +1,15 @@
1 1
2 2
3#include <qurl.h> 3#include <qurl.h>
4#include <qpe/qpeapplication.h> 4#include <qpe/qpeapplication.h>
5#include "kvnc.h" 5#include "kvnc.h"
6 6
7int main( int argc, char **argv ) 7int main( int argc, char **argv )
8{ 8{
9 QPEApplication app( argc, argv ); 9 QPEApplication app( argc, argv );
10 KVNC *view = new KVNC( "Keypebble" ); 10 KVNC *view = new KVNC( "Keypebble" );
11 app.showMainWidget( view ); 11 app.showMainWidget( view );
12 12
13 if ( argc > 1 )
14 view->openURL( QUrl(argv[1]) );
15
16 return app.exec(); 13 return app.exec();
17} 14}
15