author | treke <treke> | 2002-12-22 00:58:46 (UTC) |
---|---|---|
committer | treke <treke> | 2002-12-22 00:58:46 (UTC) |
commit | 17d7f11b16b650f6ee2b5c440506167ea41fbfe5 (patch) (unidiff) | |
tree | cd5924c9e374a82c1cac6433dce098f3f45f4286 | |
parent | 6853d02989fc01e5a65048aca9749c20e0f5d095 (diff) | |
download | opie-17d7f11b16b650f6ee2b5c440506167ea41fbfe5.zip opie-17d7f11b16b650f6ee2b5c440506167ea41fbfe5.tar.gz opie-17d7f11b16b650f6ee2b5c440506167ea41fbfe5.tar.bz2 |
1) Fixed a bug where double clicking a blank spot on the bookmark list
caused a segfault.
2) Removed support for copying from the server. Trying to setText in the
clipboard would segfault everytime from within the KRFBDecoder. Doesnt
seem to like being called from within a slot.
-rw-r--r-- | noncore/comm/keypebble/krfbcanvas.cpp | 4 | ||||
-rw-r--r-- | noncore/comm/keypebble/krfbdecoder.cpp | 5 | ||||
-rw-r--r-- | noncore/comm/keypebble/kvnc.cpp | 3 |
3 files changed, 6 insertions, 6 deletions
diff --git a/noncore/comm/keypebble/krfbcanvas.cpp b/noncore/comm/keypebble/krfbcanvas.cpp index 049bbd4..bc71c90 100644 --- a/noncore/comm/keypebble/krfbcanvas.cpp +++ b/noncore/comm/keypebble/krfbcanvas.cpp | |||
@@ -1,213 +1,209 @@ | |||
1 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
2 | #include "krfbcanvas.h" | 2 | #include "krfbcanvas.h" |
3 | #include "krfbserver.h" | 3 | #include "krfbserver.h" |
4 | #include "krfbbuffer.h" | 4 | #include "krfbbuffer.h" |
5 | 5 | ||
6 | #include <qpe/config.h> | 6 | #include <qpe/config.h> |
7 | #include <qpe/qpeapplication.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 <qpoint.h> | 13 | #include <qpoint.h> |
14 | #include <qapplication.h> | 14 | #include <qapplication.h> |
15 | #include <qmainwindow.h> | 15 | #include <qmainwindow.h> |
16 | #include <qiconset.h> | 16 | #include <qiconset.h> |
17 | 17 | ||
18 | KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name ) | 18 | KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name ) |
19 | : QScrollView( parent, name ) | 19 | : QScrollView( parent, name ) |
20 | { | 20 | { |
21 | connection_ = new KRFBConnection(); | 21 | connection_ = new KRFBConnection(); |
22 | connect( connection_, SIGNAL( loggedIn() ), | 22 | connect( connection_, SIGNAL( loggedIn() ), |
23 | this, SLOT( loggedIn() ) ); | 23 | this, SLOT( loggedIn() ) ); |
24 | 24 | ||
25 | loggedIn_ = false; | 25 | loggedIn_ = false; |
26 | 26 | ||
27 | //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold); | 27 | //QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold); |
28 | 28 | ||
29 | viewport()->setFocusPolicy( QWidget::StrongFocus ); | 29 | viewport()->setFocusPolicy( QWidget::StrongFocus ); |
30 | viewport()->setFocus(); | 30 | viewport()->setFocus(); |
31 | 31 | ||
32 | nextRightClick=0; | 32 | nextRightClick=0; |
33 | nextDoubleClick=0; | 33 | nextDoubleClick=0; |
34 | } | 34 | } |
35 | 35 | ||
36 | KRFBCanvas::~KRFBCanvas() | 36 | KRFBCanvas::~KRFBCanvas() |
37 | { | 37 | { |
38 | } | 38 | } |
39 | 39 | ||
40 | 40 | ||
41 | void KRFBCanvas::openConnection(KRFBServer server) | 41 | void KRFBCanvas::openConnection(KRFBServer server) |
42 | { | 42 | { |
43 | 43 | ||
44 | 44 | ||
45 | QCString host = server.hostname.latin1(); | 45 | QCString host = server.hostname.latin1(); |
46 | password=server.password; | 46 | password=server.password; |
47 | connection_->connectTo( server); | 47 | connection_->connectTo( server); |
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | void KRFBCanvas::openURL( const QUrl &url ) | 51 | void KRFBCanvas::openURL( const QUrl &url ) |
52 | { | 52 | { |
53 | if ( loggedIn_ ) { | 53 | if ( loggedIn_ ) { |
54 | qWarning( "openURL invoked when logged in\n" ); | 54 | qWarning( "openURL invoked when logged in\n" ); |
55 | return; | 55 | return; |
56 | } | 56 | } |
57 | 57 | ||
58 | QCString host = url.host().latin1(); | 58 | QCString host = url.host().latin1(); |
59 | int display = url.port(); | 59 | int display = url.port(); |
60 | 60 | ||
61 | // connection_->connectTo( host, display ); | 61 | // connection_->connectTo( host, display ); |
62 | } | 62 | } |
63 | 63 | ||
64 | void KRFBCanvas::closeConnection() | 64 | void KRFBCanvas::closeConnection() |
65 | { | 65 | { |
66 | loggedIn_ = false; | 66 | loggedIn_ = false; |
67 | connection_->disconnect(); | 67 | connection_->disconnect(); |
68 | 68 | ||
69 | viewport()->setMouseTracking( false ); | 69 | viewport()->setMouseTracking( false ); |
70 | viewport()->setBackgroundMode( PaletteDark ); | 70 | viewport()->setBackgroundMode( PaletteDark ); |
71 | setBackgroundMode( PaletteDark ); | 71 | setBackgroundMode( PaletteDark ); |
72 | update(); | 72 | update(); |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | void KRFBCanvas::bell() | 76 | void KRFBCanvas::bell() |
77 | { | 77 | { |
78 | if ( connection_->options()->deIconify ) { | 78 | if ( connection_->options()->deIconify ) { |
79 | topLevelWidget()->raise(); | 79 | topLevelWidget()->raise(); |
80 | topLevelWidget()->show(); | 80 | topLevelWidget()->show(); |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | void KRFBCanvas::loggedIn() | 84 | void KRFBCanvas::loggedIn() |
85 | { | 85 | { |
86 | qWarning( "Ok, we're logged in" ); | 86 | qWarning( "Ok, we're logged in" ); |
87 | 87 | ||
88 | // | 88 | // |
89 | // Get ready for action | 89 | // Get ready for action |
90 | // | 90 | // |
91 | loggedIn_ = true; | 91 | loggedIn_ = true; |
92 | viewport()->setMouseTracking( true ); | 92 | viewport()->setMouseTracking( true ); |
93 | viewport()->setBackgroundMode( NoBackground ); | 93 | viewport()->setBackgroundMode( NoBackground ); |
94 | setBackgroundMode( NoBackground ); | 94 | setBackgroundMode( NoBackground ); |
95 | 95 | ||
96 | // Start using the buffer | 96 | // Start using the buffer |
97 | connect( connection_->buffer(), SIGNAL( sizeChanged( int, int ) ), | 97 | connect( connection_->buffer(), SIGNAL( sizeChanged( int, int ) ), |
98 | this, SLOT( resizeContents(int,int) ) ); | 98 | this, SLOT( resizeContents(int,int) ) ); |
99 | connect( connection_->buffer(), SIGNAL( updated( int, int, int, int ) ), | 99 | connect( connection_->buffer(), SIGNAL( updated( int, int, int, int ) ), |
100 | this, SLOT( viewportUpdate(int,int,int,int) ) ); | 100 | this, SLOT( viewportUpdate(int,int,int,int) ) ); |
101 | connect( connection_->buffer(), SIGNAL( bell() ), | 101 | connect( connection_->buffer(), SIGNAL( bell() ), |
102 | this, SLOT( bell() ) ); | 102 | this, SLOT( bell() ) ); |
103 | connect( qApp->clipboard(), SIGNAL( dataChanged() ), | 103 | connect( qApp->clipboard(), SIGNAL( dataChanged() ), |
104 | this, SLOT( clipboardChanged() ) ); | 104 | this, SLOT( clipboardChanged() ) ); |
105 | } | 105 | } |
106 | 106 | ||
107 | void KRFBCanvas::viewportPaintEvent( QPaintEvent *e ) | 107 | void KRFBCanvas::viewportPaintEvent( QPaintEvent *e ) |
108 | { | 108 | { |
109 | QRect r = e->rect(); | 109 | QRect r = e->rect(); |
110 | 110 | ||
111 | if ( loggedIn_ ) { | 111 | if ( loggedIn_ ) { |
112 | QPixmap p; | 112 | QPixmap p; |
113 | 113 | ||
114 | bitBlt( viewport(), r.x(), r.y(), | 114 | bitBlt( viewport(), r.x(), r.y(), |
115 | connection_->buffer()->pixmap(), | 115 | connection_->buffer()->pixmap(), |
116 | r.x() + contentsX(), r.y() + contentsY(), | 116 | r.x() + contentsX(), r.y() + contentsY(), |
117 | r.width(), r.height() ); | 117 | r.width(), r.height() ); |
118 | } | 118 | } |
119 | else { | 119 | else { |
120 | QScrollView::viewportPaintEvent( e ); | 120 | QScrollView::viewportPaintEvent( e ); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | void KRFBCanvas::viewportUpdate( int x, int y, int w, int h ) | 124 | void KRFBCanvas::viewportUpdate( int x, int y, int w, int h ) |
125 | { | 125 | { |
126 | updateContents( x, y, w, h ); | 126 | updateContents( x, y, w, h ); |
127 | } | 127 | } |
128 | 128 | ||
129 | void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e ) | 129 | void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e ) |
130 | { | 130 | { |
131 | 131 | ||
132 | if (nextDoubleClick) { | 132 | if (nextDoubleClick) { |
133 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),LeftButton,LeftButton)); | 133 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),LeftButton,LeftButton)); |
134 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0)); | 134 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0)); |
135 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0)); | 135 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0)); |
136 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton)); | 136 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton)); |
137 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0)); | 137 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0)); |
138 | } if (nextRightClick) { | 138 | } if (nextRightClick) { |
139 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),RightButton,RightButton)); | 139 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),RightButton,RightButton)); |
140 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),RightButton,0)); | 140 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),RightButton,0)); |
141 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton)); | 141 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton)); |
142 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0)); | 142 | connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0)); |
143 | } else if ( loggedIn_ ) | 143 | } else if ( loggedIn_ ) |
144 | connection_->buffer()->mouseEvent( e ); | 144 | connection_->buffer()->mouseEvent( e ); |
145 | 145 | ||
146 | qDebug("Press"); | ||
147 | qDebug(QString::number(e->type()==QEvent::MouseButtonPress)); | ||
148 | } | 146 | } |
149 | 147 | ||
150 | void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e ) | 148 | void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e ) |
151 | { | 149 | { |
152 | if ( loggedIn_ && !nextRightClick && !nextDoubleClick) { | 150 | if ( loggedIn_ && !nextRightClick && !nextDoubleClick) { |
153 | connection_->buffer()->mouseEvent( e ); | 151 | connection_->buffer()->mouseEvent( e ); |
154 | } | 152 | } |
155 | 153 | ||
156 | nextRightClick=0; | 154 | nextRightClick=0; |
157 | nextDoubleClick=0; | 155 | nextDoubleClick=0; |
158 | qDebug("Release"); | ||
159 | qDebug(QString::number(e->button())); | ||
160 | } | 156 | } |
161 | 157 | ||
162 | void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e ) | 158 | void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e ) |
163 | { | 159 | { |
164 | if ( loggedIn_ ) | 160 | if ( loggedIn_ ) |
165 | connection_->buffer()->mouseEvent( e ); | 161 | connection_->buffer()->mouseEvent( e ); |
166 | } | 162 | } |
167 | 163 | ||
168 | void KRFBCanvas::keyPressEvent( QKeyEvent *e ) | 164 | void KRFBCanvas::keyPressEvent( QKeyEvent *e ) |
169 | { | 165 | { |
170 | if ( loggedIn_ ) | 166 | if ( loggedIn_ ) |
171 | connection_->buffer()->keyPressEvent( e ); | 167 | connection_->buffer()->keyPressEvent( e ); |
172 | } | 168 | } |
173 | 169 | ||
174 | void KRFBCanvas::keyReleaseEvent( QKeyEvent *e ) | 170 | void KRFBCanvas::keyReleaseEvent( QKeyEvent *e ) |
175 | { | 171 | { |
176 | if ( loggedIn_ ) | 172 | if ( loggedIn_ ) |
177 | connection_->buffer()->keyReleaseEvent( e ); | 173 | connection_->buffer()->keyReleaseEvent( e ); |
178 | } | 174 | } |
179 | 175 | ||
180 | void KRFBCanvas::refresh() | 176 | void KRFBCanvas::refresh() |
181 | { | 177 | { |
182 | if ( loggedIn_ ) | 178 | if ( loggedIn_ ) |
183 | connection_->refresh(); | 179 | connection_->refresh(); |
184 | } | 180 | } |
185 | 181 | ||
186 | void KRFBCanvas::clipboardChanged() | 182 | void KRFBCanvas::clipboardChanged() |
187 | { | 183 | { |
188 | if ( loggedIn_ ) { | 184 | if ( loggedIn_ ) { |
189 | connection_->sendCutText( qApp->clipboard()->text() ); | 185 | connection_->sendCutText( qApp->clipboard()->text() ); |
190 | } | 186 | } |
191 | } | 187 | } |
192 | void KRFBCanvas::sendCtlAltDel( void) | 188 | void KRFBCanvas::sendCtlAltDel( void) |
193 | { | 189 | { |
194 | 190 | ||
195 | if ( loggedIn_ ) { | 191 | if ( loggedIn_ ) { |
196 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Control, 0,0)); | 192 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Control, 0,0)); |
197 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Alt, 0,0)); | 193 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Alt, 0,0)); |
198 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Delete, 0,0)); | 194 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Delete, 0,0)); |
199 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Control, 0,0)); | 195 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Control, 0,0)); |
200 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Alt, 0,0)); | 196 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Alt, 0,0)); |
201 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Delete, 0,0)); | 197 | connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Delete, 0,0)); |
202 | } | 198 | } |
203 | } | 199 | } |
204 | 200 | ||
205 | void KRFBCanvas::markDoubleClick( void) | 201 | void KRFBCanvas::markDoubleClick( void) |
206 | { | 202 | { |
207 | nextRightClick=1; | 203 | nextRightClick=1; |
208 | } | 204 | } |
209 | 205 | ||
210 | void KRFBCanvas::markRightClick( void) | 206 | void KRFBCanvas::markRightClick( void) |
211 | { | 207 | { |
212 | nextRightClick=1; | 208 | nextRightClick=1; |
213 | } | 209 | } |
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index 94e3b79..33418ae 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -198,644 +198,647 @@ void KRFBDecoder::gotServerInit() | |||
198 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); | 198 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); |
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 | ||
211 | void KRFBDecoder::gotDesktopName() | 211 | void 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 | ||
246 | void KRFBDecoder::decidePixelFormat() | 246 | void 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 | ||
310 | void KRFBDecoder::sendPixelFormat() | 310 | void 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 | ||
331 | void KRFBDecoder::sendAllowedEncodings() | 331 | void 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 | ||
353 | void KRFBDecoder::sendUpdateRequest( bool incremental ) | 353 | void 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 | ||
376 | void KRFBDecoder::gotUpdateHeader() | 376 | void 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 ); |
387 | 387 | ||
388 | if ( msgType != UpdateId ) { | 388 | if ( msgType != UpdateId ) { |
389 | // We might have a bell or server cut | 389 | // We might have a bell or server cut |
390 | if ( msgType == ServerCutId ) { | 390 | if ( msgType == ServerCutId ) { |
391 | oldState = currentState; | 391 | oldState = currentState; |
392 | gotServerCut(); | 392 | gotServerCut(); |
393 | } | 393 | } |
394 | else if ( msgType == BellId ) { | 394 | else if ( msgType == BellId ) { |
395 | oldState = currentState; | 395 | oldState = currentState; |
396 | gotBell(); | 396 | gotBell(); |
397 | } | 397 | } |
398 | else { | 398 | else { |
399 | int msg = msgType; | 399 | int msg = msgType; |
400 | QString protocolError = tr( "Protocol Error: Message Id %1 was " | 400 | QString protocolError = tr( "Protocol Error: Message Id %1 was " |
401 | "found when expecting an update " | 401 | "found when expecting an update " |
402 | "message." ).arg( msg ); | 402 | "message." ).arg( msg ); |
403 | currentState = Error; | 403 | currentState = Error; |
404 | emit error( protocolError ); | 404 | emit error( protocolError ); |
405 | } | 405 | } |
406 | return; | 406 | return; |
407 | } | 407 | } |
408 | 408 | ||
409 | CARD8 padding; | 409 | CARD8 padding; |
410 | con->read( &padding, 1 ); | 410 | con->read( &padding, 1 ); |
411 | 411 | ||
412 | con->read( &noRects, 2 ); | 412 | con->read( &noRects, 2 ); |
413 | noRects = Swap16IfLE( noRects ); | 413 | noRects = Swap16IfLE( noRects ); |
414 | 414 | ||
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 | ||
423 | void KRFBDecoder::gotRectHeader() | 423 | void 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 | ||
489 | void KRFBDecoder::handleRawRect() | 489 | void 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 | ||
512 | void KRFBDecoder::getRawRectChunk( int lines ) | 512 | void 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 | ||
525 | void KRFBDecoder::gotRawRectChunk() | 525 | void 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 | ||
571 | void KRFBDecoder::handleCopyRect() | 571 | void 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 | ||
578 | void KRFBDecoder::gotCopyRectPos() | 578 | void 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 | ||
607 | void KRFBDecoder::handleRRERect() | 607 | void KRFBDecoder::handleRRERect() |
608 | { | 608 | { |
609 | qWarning( "RRE not implemented" ); | 609 | qWarning( "RRE not implemented" ); |
610 | } | 610 | } |
611 | 611 | ||
612 | void KRFBDecoder::handleCoRRERect() | 612 | void KRFBDecoder::handleCoRRERect() |
613 | { | 613 | { |
614 | qWarning( "CoRRE not implemented" ); | 614 | qWarning( "CoRRE not implemented" ); |
615 | } | 615 | } |
616 | 616 | ||
617 | void KRFBDecoder::handleHexTileRect() | 617 | void KRFBDecoder::handleHexTileRect() |
618 | { | 618 | { |
619 | qWarning( "HexTile not implemented" ); | 619 | qWarning( "HexTile not implemented" ); |
620 | } | 620 | } |
621 | 621 | ||
622 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) | 622 | void 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 | // HACK: Scaling | 645 | // HACK: Scaling |
646 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); | 646 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); |
647 | CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); | 647 | CARD16 y = Swap16IfLE( e->y() *con->options()->scaleFactor ); |
648 | 648 | ||
649 | con->write( &PointerEventId, 1 ); | 649 | con->write( &PointerEventId, 1 ); |
650 | con->write( &buttonMask, 1 ); | 650 | con->write( &buttonMask, 1 ); |
651 | con->write( &x, 2 ); | 651 | con->write( &x, 2 ); |
652 | con->write( &y, 2 ); | 652 | con->write( &y, 2 ); |
653 | } | 653 | } |
654 | 654 | ||
655 | 655 | ||
656 | void KRFBDecoder::sendCutEvent( const QString &unicode ) | 656 | void KRFBDecoder::sendCutEvent( const QString &unicode ) |
657 | { | 657 | { |
658 | // | 658 | // |
659 | // Warning: There is a bug in the RFB protocol because there is no way to find | 659 | // Warning: There is a bug in the RFB protocol because there is no way to find |
660 | // out the codepage in use on the remote machine. This could be fixed by requiring | 660 | // out the codepage in use on the remote machine. This could be fixed by requiring |
661 | // the remote server to use utf8 etc. but for now we have to assume they're the | 661 | // the remote server to use utf8 etc. but for now we have to assume they're the |
662 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 662 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
663 | // immediate plans to fix the issue. :-( (rich) | 663 | // immediate plans to fix the issue. :-( (rich) |
664 | // | 664 | // |
665 | 665 | ||
666 | CARD8 padding[3]; | 666 | CARD8 padding[3]; |
667 | QCString text = unicode.local8Bit(); | 667 | QCString text = unicode.local8Bit(); |
668 | CARD32 length = text.length(); | 668 | CARD32 length = text.length(); |
669 | length = Swap32IfLE( length ); | 669 | length = Swap32IfLE( length ); |
670 | 670 | ||
671 | con->write( &ClientCutTextId, 1 ); | 671 | con->write( &ClientCutTextId, 1 ); |
672 | con->write( &padding, 3 ); | 672 | con->write( &padding, 3 ); |
673 | con->write( &length, 4 ); | 673 | con->write( &length, 4 ); |
674 | con->write( text.data(), length ); | 674 | con->write( text.data(), length ); |
675 | } | 675 | } |
676 | 676 | ||
677 | void KRFBDecoder::gotServerCut() | 677 | void KRFBDecoder::gotServerCut() |
678 | { | 678 | { |
679 | qWarning( "Got server cut" ); | 679 | qWarning( "Got server cut" ); |
680 | 680 | ||
681 | currentState = AwaitingServerCutLength; | 681 | currentState = AwaitingServerCutLength; |
682 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); | 682 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); |
683 | con->waitForData( ServerCutLenLength ); | 683 | con->waitForData( ServerCutLenLength ); |
684 | } | 684 | } |
685 | 685 | ||
686 | void KRFBDecoder::gotServerCutLength() | 686 | void KRFBDecoder::gotServerCutLength() |
687 | { | 687 | { |
688 | assert( currentState = AwaitingServerCutLength ); | 688 | assert( currentState = AwaitingServerCutLength ); |
689 | disconnect( con, SIGNAL( gotEnoughData() ), | 689 | disconnect( con, SIGNAL( gotEnoughData() ), |
690 | this, SLOT( gotServerCutLength() ) ); | 690 | this, SLOT( gotServerCutLength() ) ); |
691 | 691 | ||
692 | CARD8 padding[3]; | 692 | CARD8 padding[3]; |
693 | con->read( padding, 3 ); | 693 | con->read( padding, 3 ); |
694 | 694 | ||
695 | con->read( &serverCutTextLen, 4 ); | 695 | con->read( &serverCutTextLen, 4 ); |
696 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); | 696 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); |
697 | 697 | ||
698 | currentState = AwaitingServerCutText; | 698 | currentState = AwaitingServerCutText; |
699 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); | 699 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); |
700 | con->waitForData( serverCutTextLen ); | 700 | con->waitForData( serverCutTextLen ); |
701 | } | 701 | } |
702 | 702 | ||
703 | void KRFBDecoder::gotServerCutText() | 703 | void KRFBDecoder::gotServerCutText() |
704 | { | 704 | { |
705 | assert( currentState = AwaitingServerCutText ); | 705 | assert( currentState = AwaitingServerCutText ); |
706 | 706 | ||
707 | disconnect( con, SIGNAL( gotEnoughData() ), | 707 | disconnect( con, SIGNAL( gotEnoughData() ), |
708 | this, SLOT( gotServerCutText() ) ); | 708 | this, SLOT( gotServerCutText() ) ); |
709 | 709 | ||
710 | |||
710 | // | 711 | // |
711 | // Warning: There is a bug in the RFB protocol because there is no way to find | 712 | // Warning: There is a bug in the RFB protocol because there is no way to find |
712 | // out the codepage in use on the remote machine. This could be fixed by requiring | 713 | // out the codepage in use on the remote machine. This could be fixed by requiring |
713 | // the remote server to use utf8 etc. but for now we have to assume they're the | 714 | // the remote server to use utf8 etc. but for now we have to assume they're the |
714 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 715 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
715 | // immediate plans to fix the issue. :-( (rich) | 716 | // immediate plans to fix the issue. :-( (rich) |
716 | // | 717 | // |
717 | 718 | ||
718 | char *cutbuf = new char[ serverCutTextLen + 1 ]; | 719 | char *cutbuf = new char[ serverCutTextLen + 1 ]; |
719 | CHECK_PTR( cutbuf ); | 720 | CHECK_PTR( cutbuf ); |
720 | 721 | ||
721 | con->read( cutbuf, serverCutTextLen ); | 722 | con->read( cutbuf, serverCutTextLen ); |
722 | cutbuf[ serverCutTextLen ] = '\0'; | 723 | cutbuf[ serverCutTextLen ] = '\0'; |
723 | 724 | ||
725 | /* For some reason QApplication::clipboard()->setText() segfaults when called | ||
726 | * from within keypebble's mass of signals and slots | ||
724 | qWarning( "Server cut: %s", cutbuf ); | 727 | qWarning( "Server cut: %s", cutbuf ); |
725 | 728 | ||
726 | QString cutText( cutbuf ); // DANGER!! | 729 | QString cutText( cutbuf ); // DANGER!! |
727 | qApp->clipboard()->setText( cutText ); | 730 | qApp->clipboard()->setText( cutText ); |
731 | */ | ||
728 | 732 | ||
729 | delete cutbuf; | 733 | delete cutbuf; |
730 | |||
731 | // Now wait for the update (again) | 734 | // Now wait for the update (again) |
732 | if ( oldState == AwaitingUpdate ) { | 735 | if ( oldState == AwaitingUpdate ) { |
733 | currentState = AwaitingUpdate; | 736 | currentState = AwaitingUpdate; |
734 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 737 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
735 | con->waitForData( UpdateHeaderLength ); | 738 | con->waitForData( UpdateHeaderLength ); |
736 | } | 739 | } |
737 | else if ( oldState == Idle ) { | 740 | else if ( oldState == Idle ) { |
738 | currentState = Idle; | 741 | currentState = Idle; |
739 | } | 742 | } |
740 | else { | 743 | else { |
741 | qWarning( "Async handled in weird state" ); | 744 | qWarning( "Async handled in weird state" ); |
742 | currentState = oldState; | 745 | currentState = oldState; |
743 | }; | 746 | }; |
744 | } | 747 | } |
745 | 748 | ||
746 | void KRFBDecoder::gotBell() | 749 | void KRFBDecoder::gotBell() |
747 | { | 750 | { |
748 | qWarning( "Got server bell" ); | 751 | qWarning( "Got server bell" ); |
749 | buf->soundBell(); | 752 | buf->soundBell(); |
750 | 753 | ||
751 | // Now wait for the update (again) | 754 | // Now wait for the update (again) |
752 | if ( oldState == AwaitingUpdate ) { | 755 | if ( oldState == AwaitingUpdate ) { |
753 | currentState = AwaitingUpdate; | 756 | currentState = AwaitingUpdate; |
754 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 757 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
755 | con->waitForData( UpdateHeaderLength ); | 758 | con->waitForData( UpdateHeaderLength ); |
756 | } | 759 | } |
757 | else if ( oldState == Idle ) { | 760 | else if ( oldState == Idle ) { |
758 | currentState = Idle; | 761 | currentState = Idle; |
759 | } | 762 | } |
760 | else { | 763 | else { |
761 | qWarning( "Async handled in weird state" ); | 764 | qWarning( "Async handled in weird state" ); |
762 | currentState = oldState; | 765 | currentState = oldState; |
763 | }; | 766 | }; |
764 | } | 767 | } |
765 | 768 | ||
766 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) | 769 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) |
767 | { | 770 | { |
768 | int key; | 771 | int key; |
769 | key = toKeySym( event ); | 772 | key = toKeySym( event ); |
770 | if ( key ) { | 773 | if ( key ) { |
771 | key = Swap32IfLE( key ); | 774 | key = Swap32IfLE( key ); |
772 | 775 | ||
773 | CARD8 mask = true; | 776 | CARD8 mask = true; |
774 | 777 | ||
775 | CARD16 padding = 0; | 778 | CARD16 padding = 0; |
776 | con->write( &KeyEventId, 1 ); | 779 | con->write( &KeyEventId, 1 ); |
777 | con->write( &mask, 1 ); | 780 | con->write( &mask, 1 ); |
778 | con->write( &padding, 2 ); | 781 | con->write( &padding, 2 ); |
779 | con->write( &key, 4 ); | 782 | con->write( &key, 4 ); |
780 | } | 783 | } |
781 | } | 784 | } |
782 | 785 | ||
783 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) | 786 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) |
784 | { | 787 | { |
785 | int key; | 788 | int key; |
786 | key = toKeySym( event ); | 789 | key = toKeySym( event ); |
787 | if ( key ) { | 790 | if ( key ) { |
788 | key = Swap32IfLE( key ); | 791 | key = Swap32IfLE( key ); |
789 | 792 | ||
790 | CARD8 mask = false; | 793 | CARD8 mask = false; |
791 | 794 | ||
792 | CARD16 padding = 0; | 795 | CARD16 padding = 0; |
793 | con->write( &KeyEventId, 1 ); | 796 | con->write( &KeyEventId, 1 ); |
794 | con->write( &mask, 1 ); | 797 | con->write( &mask, 1 ); |
795 | con->write( &padding, 2 ); | 798 | con->write( &padding, 2 ); |
796 | con->write( &key, 4 ); | 799 | con->write( &key, 4 ); |
797 | } | 800 | } |
798 | } | 801 | } |
799 | 802 | ||
800 | 803 | ||
801 | int KRFBDecoder::toKeySym( QKeyEvent *k ) | 804 | int KRFBDecoder::toKeySym( QKeyEvent *k ) |
802 | { | 805 | { |
803 | int ke = 0; | 806 | int ke = 0; |
804 | 807 | ||
805 | ke = k->ascii(); | 808 | ke = k->ascii(); |
806 | // Markus: Crappy hack. I dont know why lower case letters are | 809 | // Markus: Crappy hack. I dont know why lower case letters are |
807 | // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'. | 810 | // not defined in qkeydefs.h. The key() for e.g. 'l' == 'L'. |
808 | // This sucks. :-( | 811 | // This sucks. :-( |
809 | 812 | ||
810 | if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd') | 813 | if ( (ke == 'a') || (ke == 'b') || (ke == 'c') || (ke == 'd') |
811 | || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h') | 814 | || (ke == 'e') || (ke == 'f') || (ke == 'g') || (ke == 'h') |
812 | || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l') | 815 | || (ke == 'i') || (ke == 'j') || (ke == 'k') || (ke == 'l') |
813 | || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p') | 816 | || (ke == 'm') || (ke == 'n') || (ke == 'o') || (ke == 'p') |
814 | || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't') | 817 | || (ke == 'q') || (ke == 'r') || (ke == 's') || (ke == 't') |
815 | || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x') | 818 | || (ke == 'u') || (ke == 'v') ||( ke == 'w') || (ke == 'x') |
816 | || (ke == 'y') || (ke == 'z') ) { | 819 | || (ke == 'y') || (ke == 'z') ) { |
817 | ke = k->key(); | 820 | ke = k->key(); |
818 | ke = ke + 0x20; | 821 | ke = ke + 0x20; |
819 | return ke; | 822 | return ke; |
820 | } | 823 | } |
821 | 824 | ||
822 | // qkeydefs = xkeydefs! :-) | 825 | // qkeydefs = xkeydefs! :-) |
823 | if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff ) | 826 | if ( ( k->key() >= 0x0a0 ) && k->key() <= 0x0ff ) |
824 | return k->key(); | 827 | return k->key(); |
825 | 828 | ||
826 | if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) ) | 829 | if ( ( k->key() >= 0x20 ) && ( k->key() <= 0x7e ) ) |
827 | return k->key(); | 830 | return k->key(); |
828 | 831 | ||
829 | // qkeydefs != xkeydefs! :-( | 832 | // qkeydefs != xkeydefs! :-( |
830 | // This is gonna suck :-( | 833 | // This is gonna suck :-( |
831 | 834 | ||
832 | int i = 0; | 835 | int i = 0; |
833 | while ( keyMap[i].keycode ) { | 836 | while ( keyMap[i].keycode ) { |
834 | if ( k->key() == keyMap[i].keycode ) | 837 | if ( k->key() == keyMap[i].keycode ) |
835 | return keyMap[i].keysym; | 838 | return keyMap[i].keysym; |
836 | i++; | 839 | i++; |
837 | } | 840 | } |
838 | 841 | ||
839 | return 0; | 842 | return 0; |
840 | } | 843 | } |
841 | 844 | ||
diff --git a/noncore/comm/keypebble/kvnc.cpp b/noncore/comm/keypebble/kvnc.cpp index 5b1dc9f..48a442c 100644 --- a/noncore/comm/keypebble/kvnc.cpp +++ b/noncore/comm/keypebble/kvnc.cpp | |||
@@ -1,294 +1,295 @@ | |||
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> | 13 | #include <qspinbox.h> |
14 | #include <qlistbox.h> | 14 | #include <qlistbox.h> |
15 | #include <qlineedit.h> | 15 | #include <qlineedit.h> |
16 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/global.h> | 17 | #include <qpe/global.h> |
18 | #include <qpe/qpetoolbar.h> | 18 | #include <qpe/qpetoolbar.h> |
19 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
20 | 20 | ||
21 | #include <assert.h> | 21 | #include <assert.h> |
22 | 22 | ||
23 | #include "kvnc.h" | 23 | #include "kvnc.h" |
24 | #include "krfbcanvas.h" | 24 | #include "krfbcanvas.h" |
25 | #include "krfbconnection.h" | 25 | #include "krfbconnection.h" |
26 | #include "kvncconndlg.h" | 26 | #include "kvncconndlg.h" |
27 | #include "krfbserver.h" | 27 | #include "krfbserver.h" |
28 | 28 | ||
29 | static int u_id = 1; | 29 | static int u_id = 1; |
30 | static int get_unique_id() | 30 | static int get_unique_id() |
31 | { | 31 | { |
32 | return u_id++; | 32 | return u_id++; |
33 | } | 33 | } |
34 | 34 | ||
35 | 35 | ||
36 | /* XPM */ | 36 | /* XPM */ |
37 | static char * menu_xpm[] = { | 37 | static char * menu_xpm[] = { |
38 | "12 12 5 1", | 38 | "12 12 5 1", |
39 | " c None", | 39 | " c None", |
40 | ".c #000000", | 40 | ".c #000000", |
41 | "+c #FFFDAD", | 41 | "+c #FFFDAD", |
42 | "@c #FFFF00", | 42 | "@c #FFFF00", |
43 | "#c #E5E100", | 43 | "#c #E5E100", |
44 | " ", | 44 | " ", |
45 | " ", | 45 | " ", |
46 | " ......... ", | 46 | " ......... ", |
47 | " .+++++++. ", | 47 | " .+++++++. ", |
48 | " .+@@@@#. ", | 48 | " .+@@@@#. ", |
49 | " .+@@@#. ", | 49 | " .+@@@#. ", |
50 | " .+@@#. ", | 50 | " .+@@#. ", |
51 | " .+@#. ", | 51 | " .+@#. ", |
52 | " .+#. ", | 52 | " .+#. ", |
53 | " .+. ", | 53 | " .+. ", |
54 | " .. ", | 54 | " .. ", |
55 | " "}; | 55 | " "}; |
56 | 56 | ||
57 | const int StatusTextId = 0; | 57 | const int StatusTextId = 0; |
58 | 58 | ||
59 | KVNC::KVNC( const char *name ) : QMainWindow( 0, name ,WStyle_ContextHelp) | 59 | KVNC::KVNC( const char *name ) : QMainWindow( 0, name ,WStyle_ContextHelp) |
60 | { | 60 | { |
61 | setCaption( tr("VNC Viewer") ); | 61 | setCaption( tr("VNC Viewer") ); |
62 | fullscreen = false; | 62 | fullscreen = false; |
63 | 63 | ||
64 | stack = new QWidgetStack( this ); | 64 | stack = new QWidgetStack( this ); |
65 | setCentralWidget( stack ); | 65 | setCentralWidget( stack ); |
66 | 66 | ||
67 | bookmarkSelector=new KVNCBookmarkDlg(); | 67 | bookmarkSelector=new KVNCBookmarkDlg(); |
68 | stack->addWidget(bookmarkSelector,get_unique_id()); | 68 | stack->addWidget(bookmarkSelector,get_unique_id()); |
69 | stack->raiseWidget( bookmarkSelector ); | 69 | stack->raiseWidget( bookmarkSelector ); |
70 | 70 | ||
71 | canvas = new KRFBCanvas( stack, "canvas" ); | 71 | canvas = new KRFBCanvas( stack, "canvas" ); |
72 | stack->addWidget(canvas,get_unique_id()); | 72 | stack->addWidget(canvas,get_unique_id()); |
73 | setCentralWidget( stack ); | 73 | setCentralWidget( stack ); |
74 | 74 | ||
75 | 75 | ||
76 | connect( bookmarkSelector->bookmarkList, SIGNAL(clicked(QListBoxItem *)), | 76 | connect( bookmarkSelector->bookmarkList, SIGNAL(clicked(QListBoxItem *)), |
77 | this, SLOT(openConnection(QListBoxItem *)) ); | 77 | this, SLOT(openConnection(QListBoxItem *)) ); |
78 | connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), | 78 | connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), |
79 | this, SLOT(statusMessage(const QString &)) ); | 79 | this, SLOT(statusMessage(const QString &)) ); |
80 | connect( canvas->connection(), SIGNAL(error(const QString &)), | 80 | connect( canvas->connection(), SIGNAL(error(const QString &)), |
81 | this, SLOT(error(const QString &)) ); | 81 | this, SLOT(error(const QString &)) ); |
82 | connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); | 82 | connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); |
83 | connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); | 83 | connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); |
84 | connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) ); | 84 | connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) ); |
85 | 85 | ||
86 | setupActions(); | 86 | setupActions(); |
87 | 87 | ||
88 | cornerButton = new QPushButton( this ); | 88 | cornerButton = new QPushButton( this ); |
89 | cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); | 89 | cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); |
90 | connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); | 90 | connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); |
91 | canvas->setCornerWidget( cornerButton ); | 91 | canvas->setCornerWidget( cornerButton ); |
92 | 92 | ||
93 | stack->raiseWidget( bookmarkSelector ); | 93 | stack->raiseWidget( bookmarkSelector ); |
94 | 94 | ||
95 | 95 | ||
96 | bar= new QToolBar( this ); | 96 | bar= new QToolBar( this ); |
97 | setToolBarsMovable( false ); | 97 | setToolBarsMovable( false ); |
98 | setRightJustification(false); | 98 | setRightJustification(false); |
99 | 99 | ||
100 | 100 | ||
101 | QAction *n = new QAction( tr( "New Connection" ), Resource::loadPixmap( "new" ), | 101 | QAction *n = new QAction( tr( "New Connection" ), Resource::loadPixmap( "new" ), |
102 | QString::null, 0, this, 0 ); | 102 | QString::null, 0, this, 0 ); |
103 | connect( n, SIGNAL( activated() ), | 103 | connect( n, SIGNAL( activated() ), |
104 | this, SLOT( newConnection() ) ); | 104 | this, SLOT( newConnection() ) ); |
105 | n->addTo( bar ); | 105 | n->addTo( bar ); |
106 | 106 | ||
107 | QAction *o = new QAction( tr( "Open Bookmark" ), Resource::loadPixmap( "fileopen" ), | 107 | QAction *o = new QAction( tr( "Open Bookmark" ), Resource::loadPixmap( "fileopen" ), |
108 | QString::null, 0, this, 0 ); | 108 | QString::null, 0, this, 0 ); |
109 | connect( o, SIGNAL( activated() ), | 109 | connect( o, SIGNAL( activated() ), |
110 | this, SLOT( openConnection() ) ); | 110 | this, SLOT( openConnection() ) ); |
111 | o->addTo( bar ); | 111 | o->addTo( bar ); |
112 | 112 | ||
113 | QAction *d = new QAction( tr( "Delete Bookmark" ), Resource::loadPixmap( "trash" ), | 113 | QAction *d = new QAction( tr( "Delete Bookmark" ), Resource::loadPixmap( "trash" ), |
114 | QString::null, 0, this, 0 ); | 114 | QString::null, 0, this, 0 ); |
115 | connect( d, SIGNAL( activated() ), | 115 | connect( d, SIGNAL( activated() ), |
116 | this, SLOT( deleteBookmark() ) ); | 116 | this, SLOT( deleteBookmark() ) ); |
117 | d->addTo( bar ); | 117 | d->addTo( bar ); |
118 | } | 118 | } |
119 | 119 | ||
120 | KVNC::~KVNC() | 120 | KVNC::~KVNC() |
121 | { | 121 | { |
122 | 122 | ||
123 | } | 123 | } |
124 | 124 | ||
125 | void KVNC::newConnection() | 125 | void KVNC::newConnection() |
126 | { | 126 | { |
127 | curServer=new KRFBServer; | 127 | curServer=new KRFBServer; |
128 | 128 | ||
129 | KVNCConnDlg dlg( curServer,this); | 129 | KVNCConnDlg dlg( curServer,this); |
130 | dlg.showMaximized(); | 130 | dlg.showMaximized(); |
131 | if (dlg.exec()) { | 131 | if (dlg.exec()) { |
132 | if (!curServer->name.isEmpty()) | 132 | if (!curServer->name.isEmpty()) |
133 | bookmarkSelector->addBookmark(curServer); | 133 | bookmarkSelector->addBookmark(curServer); |
134 | canvas->openConnection(*curServer); | 134 | canvas->openConnection(*curServer); |
135 | } else | 135 | } else |
136 | curServer=0; | 136 | curServer=0; |
137 | } | 137 | } |
138 | 138 | ||
139 | void KVNC::openConnection( QString name) | 139 | void KVNC::openConnection( QString name) |
140 | { | 140 | { |
141 | curServer=bookmarkSelector->getServer(name); | 141 | curServer=bookmarkSelector->getServer(name); |
142 | 142 | ||
143 | if (curServer) { | 143 | if (curServer) { |
144 | KVNCConnDlg dlg( curServer,this); | 144 | KVNCConnDlg dlg( curServer,this); |
145 | dlg.showMaximized(); | 145 | dlg.showMaximized(); |
146 | 146 | ||
147 | if ( dlg.exec() ) { | 147 | if ( dlg.exec() ) { |
148 | canvas->openConnection(*curServer); | 148 | canvas->openConnection(*curServer); |
149 | bookmarkSelector->writeBookmarks(); | 149 | bookmarkSelector->writeBookmarks(); |
150 | } else | 150 | } else |
151 | curServer=0; | 151 | curServer=0; |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | void KVNC::openConnection( void ) | 155 | void KVNC::openConnection( void ) |
156 | { | 156 | { |
157 | openConnection( bookmarkSelector->selectedBookmark()); | 157 | openConnection( bookmarkSelector->selectedBookmark()); |
158 | } | 158 | } |
159 | 159 | ||
160 | void KVNC::openConnection( QListBoxItem * item) | 160 | void KVNC::openConnection( QListBoxItem * item) |
161 | { | 161 | { |
162 | openConnection(item->text()); | 162 | if (item) |
163 | openConnection(item->text()); | ||
163 | } | 164 | } |
164 | 165 | ||
165 | void KVNC::setupActions() | 166 | void KVNC::setupActions() |
166 | { | 167 | { |
167 | cornerMenu = new QPopupMenu( this ); | 168 | cornerMenu = new QPopupMenu( this ); |
168 | 169 | ||
169 | fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); | 170 | fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); |
170 | connect( fullScreenAction, SIGNAL(activated()), | 171 | connect( fullScreenAction, SIGNAL(activated()), |
171 | this, SLOT( toggleFullScreen() ) ); | 172 | this, SLOT( toggleFullScreen() ) ); |
172 | fullScreenAction->addTo( cornerMenu ); | 173 | fullScreenAction->addTo( cornerMenu ); |
173 | fullScreenAction->setEnabled( false ); | 174 | fullScreenAction->setEnabled( false ); |
174 | 175 | ||
175 | ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 ); | 176 | ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 ); |
176 | connect( ctlAltDelAction, SIGNAL(activated()), | 177 | connect( ctlAltDelAction, SIGNAL(activated()), |
177 | canvas, SLOT( sendCtlAltDel() ) ); | 178 | canvas, SLOT( sendCtlAltDel() ) ); |
178 | ctlAltDelAction->addTo( cornerMenu ); | 179 | ctlAltDelAction->addTo( cornerMenu ); |
179 | ctlAltDelAction->setEnabled( false ); | 180 | ctlAltDelAction->setEnabled( false ); |
180 | 181 | ||
181 | disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); | 182 | disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); |
182 | connect( disconnectAction, SIGNAL(activated()), | 183 | connect( disconnectAction, SIGNAL(activated()), |
183 | this, SLOT( closeConnection() ) ); | 184 | this, SLOT( closeConnection() ) ); |
184 | disconnectAction->addTo( cornerMenu ); | 185 | disconnectAction->addTo( cornerMenu ); |
185 | disconnectAction->setEnabled( false ); | 186 | disconnectAction->setEnabled( false ); |
186 | 187 | ||
187 | doubleClickAction = new QAction( tr("Next Click is Double Click"), QString::null, 0, 0 ); | 188 | doubleClickAction = new QAction( tr("Next Click is Double Click"), QString::null, 0, 0 ); |
188 | connect( doubleClickAction, SIGNAL(activated()), | 189 | connect( doubleClickAction, SIGNAL(activated()), |
189 | canvas, SLOT( markDoubleClick() ) ); | 190 | canvas, SLOT( markDoubleClick() ) ); |
190 | doubleClickAction->addTo( cornerMenu ); | 191 | doubleClickAction->addTo( cornerMenu ); |
191 | doubleClickAction->setEnabled( false ); | 192 | doubleClickAction->setEnabled( false ); |
192 | 193 | ||
193 | rightClickAction = new QAction( tr("Next Click is Right Click"), QString::null, 0, 0 ); | 194 | rightClickAction = new QAction( tr("Next Click is Right Click"), QString::null, 0, 0 ); |
194 | connect( rightClickAction, SIGNAL(activated()), | 195 | connect( rightClickAction, SIGNAL(activated()), |
195 | canvas, SLOT( markRightClick() ) ); | 196 | canvas, SLOT( markRightClick() ) ); |
196 | rightClickAction->addTo( cornerMenu ); | 197 | rightClickAction->addTo( cornerMenu ); |
197 | rightClickAction->setEnabled( false ); | 198 | rightClickAction->setEnabled( false ); |
198 | } | 199 | } |
199 | 200 | ||
200 | void KVNC::toggleFullScreen() | 201 | void KVNC::toggleFullScreen() |
201 | { | 202 | { |
202 | if ( fullscreen ) { | 203 | if ( fullscreen ) { |
203 | canvas->releaseKeyboard(); | 204 | canvas->releaseKeyboard(); |
204 | canvas->reparent( stack, 0, QPoint(0,0), false ); | 205 | canvas->reparent( stack, 0, QPoint(0,0), false ); |
205 | canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 206 | canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
206 | setCentralWidget( stack ); | 207 | setCentralWidget( stack ); |
207 | stack->addWidget(canvas,get_unique_id()); | 208 | stack->addWidget(canvas,get_unique_id()); |
208 | stack->raiseWidget(canvas); | 209 | stack->raiseWidget(canvas); |
209 | canvas->show(); | 210 | canvas->show(); |
210 | stack->show(); | 211 | stack->show(); |
211 | fullScreenAction->setText( tr("Full Screen") ); | 212 | fullScreenAction->setText( tr("Full Screen") ); |
212 | } else { | 213 | } else { |
213 | canvas->setFrameStyle( QFrame::NoFrame ); | 214 | canvas->setFrameStyle( QFrame::NoFrame ); |
214 | stack->removeWidget(canvas); | 215 | stack->removeWidget(canvas); |
215 | canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, | 216 | canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, |
216 | QPoint(0,0),false); | 217 | QPoint(0,0),false); |
217 | canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); | 218 | canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); |
218 | canvas->raise(); | 219 | canvas->raise(); |
219 | canvas->setFocus(); | 220 | canvas->setFocus(); |
220 | canvas->grabKeyboard(); | 221 | canvas->grabKeyboard(); |
221 | canvas->show(); | 222 | canvas->show(); |
222 | 223 | ||
223 | fullScreenAction->setText( tr("Stop Full Screen") ); | 224 | fullScreenAction->setText( tr("Stop Full Screen") ); |
224 | } | 225 | } |
225 | 226 | ||
226 | 227 | ||
227 | fullscreen = !fullscreen; | 228 | fullscreen = !fullscreen; |
228 | } | 229 | } |
229 | 230 | ||
230 | void KVNC::closeConnection() | 231 | void KVNC::closeConnection() |
231 | { | 232 | { |
232 | if ( fullscreen ) | 233 | if ( fullscreen ) |
233 | toggleFullScreen(); | 234 | toggleFullScreen(); |
234 | canvas->closeConnection(); | 235 | canvas->closeConnection(); |
235 | } | 236 | } |
236 | 237 | ||
237 | void KVNC::showMenu() | 238 | void KVNC::showMenu() |
238 | { | 239 | { |
239 | QPoint pt = mapToGlobal(cornerButton->pos()); | 240 | QPoint pt = mapToGlobal(cornerButton->pos()); |
240 | QSize s = cornerMenu->sizeHint(); | 241 | QSize s = cornerMenu->sizeHint(); |
241 | pt.ry() -= s.height(); | 242 | pt.ry() -= s.height(); |
242 | pt.rx() -= s.width(); | 243 | pt.rx() -= s.width(); |
243 | cornerMenu->popup( pt ); | 244 | cornerMenu->popup( pt ); |
244 | } | 245 | } |
245 | 246 | ||
246 | void KVNC::connected() | 247 | void KVNC::connected() |
247 | { | 248 | { |
248 | static QString msg = tr( "Connected to remote host" ); | 249 | static QString msg = tr( "Connected to remote host" ); |
249 | statusMessage( msg ); | 250 | statusMessage( msg ); |
250 | ctlAltDelAction->setEnabled(true); | 251 | ctlAltDelAction->setEnabled(true); |
251 | disconnectAction->setEnabled( true ); | 252 | disconnectAction->setEnabled( true ); |
252 | fullScreenAction->setEnabled( true ); | 253 | fullScreenAction->setEnabled( true ); |
253 | doubleClickAction->setEnabled( false ); | 254 | doubleClickAction->setEnabled( false ); |
254 | rightClickAction->setEnabled( true ); | 255 | rightClickAction->setEnabled( true ); |
255 | stack->raiseWidget(canvas); | 256 | stack->raiseWidget(canvas); |
256 | bar->hide(); | 257 | bar->hide(); |
257 | } | 258 | } |
258 | 259 | ||
259 | void KVNC::loggedIn() | 260 | void KVNC::loggedIn() |
260 | { | 261 | { |
261 | static QString msg = tr( "Logged in to remote host" ); | 262 | static QString msg = tr( "Logged in to remote host" ); |
262 | statusMessage( msg ); | 263 | statusMessage( msg ); |
263 | } | 264 | } |
264 | 265 | ||
265 | void KVNC::disconnected() | 266 | void KVNC::disconnected() |
266 | { | 267 | { |
267 | 268 | ||
268 | if ( fullscreen ) | 269 | if ( fullscreen ) |
269 | toggleFullScreen(); | 270 | toggleFullScreen(); |
270 | static QString msg = tr( "Connection closed" ); | 271 | static QString msg = tr( "Connection closed" ); |
271 | statusMessage( msg ); | 272 | statusMessage( msg ); |
272 | ctlAltDelAction->setEnabled(false); | 273 | ctlAltDelAction->setEnabled(false); |
273 | disconnectAction->setEnabled( false ); | 274 | disconnectAction->setEnabled( false ); |
274 | fullScreenAction->setEnabled( false ); | 275 | fullScreenAction->setEnabled( false ); |
275 | doubleClickAction->setEnabled( false ); | 276 | doubleClickAction->setEnabled( false ); |
276 | rightClickAction->setEnabled( false ); | 277 | rightClickAction->setEnabled( false ); |
277 | stack->raiseWidget(bookmarkSelector); | 278 | stack->raiseWidget(bookmarkSelector); |
278 | bar->show(); | 279 | bar->show(); |
279 | } | 280 | } |
280 | 281 | ||
281 | void KVNC::statusMessage( const QString &m ) | 282 | void KVNC::statusMessage( const QString &m ) |
282 | { | 283 | { |
283 | Global::statusMessage( m ); | 284 | Global::statusMessage( m ); |
284 | } | 285 | } |
285 | 286 | ||
286 | void KVNC::error( const QString &msg ) | 287 | void KVNC::error( const QString &msg ) |
287 | { | 288 | { |
288 | statusMessage( msg ); | 289 | statusMessage( msg ); |
289 | QMessageBox::warning( this, tr("VNC Viewer"), msg ); | 290 | QMessageBox::warning( this, tr("VNC Viewer"), msg ); |
290 | } | 291 | } |
291 | void KVNC::deleteBookmark(void) | 292 | void KVNC::deleteBookmark(void) |
292 | { | 293 | { |
293 | bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark()); | 294 | bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark()); |
294 | } | 295 | } |