/[rdesktop]/sourceforge.net/trunk/rdesktop/uiports/qtwin.cpp
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sourceforge.net/trunk/rdesktop/uiports/qtwin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 850 - (show annotations)
Sun Mar 13 06:00:56 2005 UTC (19 years, 3 months ago) by jsorg71
File size: 41640 byte(s)
added makefile_qt and new orders to qt uiport

1 /*
2 rdesktop: A Remote Desktop Protocol client.
3 User interface services - QT Window System
4 Copyright (C) Jay Sorg 2004
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "../rdesktop.h"
22
23 #include <qapplication.h>
24 #include <qmainwindow.h>
25 #include <qwidget.h>
26 #include <qpainter.h>
27 #include <qpixmap.h>
28 #include <qbrush.h>
29 #include <qimage.h>
30 #include <qbitmap.h>
31 #include <qcursor.h>
32 #include <qsocketnotifier.h>
33 #include <qscrollview.h>
34 #include <qfile.h>
35
36 #include "qtwin.h"
37 #include <unistd.h> // gethostname
38 #include <pwd.h> // getpwuid
39 #include <stdarg.h> // va_list va_start va_end
40
41 /* rdesktop globals */
42 extern int g_tcp_port_rdp;
43 int g_use_rdp5 = 1;
44 char g_hostname[16];
45 char g_username[64];
46 int g_height = 600;
47 int g_width = 800;
48 int g_server_bpp = 8;
49 int g_encryption = 1;
50 int g_desktop_save = 1;
51 int g_polygon_ellipse_orders = 0;
52 int g_bitmap_cache = 1;
53 int g_bitmap_cache_persist_enable = False;
54 int g_bitmap_cache_precache = True;
55 int g_bitmap_compression = 1;
56 int g_rdp5_performanceflags = 0;
57 int g_console_session = 0;
58 int g_keylayout = 0x409; /* Defaults to US keyboard layout */
59
60 /* hack globals */
61 int g_argc = 0;
62 char** g_argv = 0;
63 int UpAndRunning = 0;
64 int g_sock = 0;
65 int deactivated = 0;
66 uint32 ext_disc_reason = 0;
67 char g_servername[128];
68 char g_title[128] = "";
69
70 /* qt globals */
71 QSocketNotifier* SocketNotifier;
72 QApplication* App;
73 QMyMainWindow* g_MW;
74 QMyScrollView* SV;
75 QPixmap* BS;
76 QPixmap* DS;
77 QPainter* P1;
78 QPainter* P2;
79 QColor Color1;
80 QColor Color2;
81 struct QColorMap
82 {
83 uint32 RGBColors[256];
84 int NumColors;
85 };
86 QColorMap* CM = 0;
87 QRegion* ClipRect;
88
89 Qt::RasterOp OpCodes[16] = {
90 Qt::ClearROP, // BLACKNESS 0
91 Qt::NorROP, // NOTSRCERASE DSon
92 Qt::NotAndROP, // DSna
93 Qt::NotCopyROP, // NOTSRCCOPY Sn
94 Qt::AndNotROP, // SRCERASE SDna
95 Qt::NotROP, // DSTINVERT Dn
96 Qt::XorROP, // SRCINVERT DSx
97 Qt::NandROP, // DSan
98 Qt::AndROP, // SRCAND DSa
99 Qt::NotXorROP, // DSxn
100 Qt::NopROP, // D
101 Qt::NotOrROP, // MERGEPAINT DSno
102 Qt::CopyROP, // SRCCOPY S
103 Qt::OrNotROP, // SDno
104 Qt::OrROP, // SRCPAINT DSo
105 Qt::SetROP}; // WHITENESS 1
106
107 //*****************************************************************************
108 uint32 Color15to32(uint32 InColor)
109 {
110 uint32 r, g, b;
111 r = (InColor & 0x7c00) >> 10;
112 r = (r * 0xff) / 0x1f;
113 g = (InColor & 0x03e0) >> 5;
114 g = (g * 0xff) / 0x1f;
115 b = (InColor & 0x001f);
116 b = (b * 0xff) / 0x1f;
117 return (r << 16) | (g << 8) | b;
118 }
119
120 //*****************************************************************************
121 uint32 Color16to32(uint32 InColor)
122 {
123 uint32 r, g, b;
124 r = (InColor & 0xf800) >> 11;
125 r = (r * 0xff) / 0x1f;
126 g = (InColor & 0x07e0) >> 5;
127 g = (g * 0xff) / 0x3f;
128 b = (InColor & 0x001f);
129 b = (b * 0xff) / 0x1f;
130 return (r << 16) | (g << 8) | b;
131 }
132
133 //*****************************************************************************
134 uint32 Color24to32(uint32 InColor)
135 {
136 return ((InColor & 0x00ff0000) >> 16) | ((InColor & 0x000000ff) << 16) |
137 (InColor & 0x0000ff00);
138 }
139
140 //*****************************************************************************
141 void SetColorx(QColor* Color, uint32 InColor)
142 {
143 switch (g_server_bpp)
144 {
145 case 8:
146 if (CM == NULL || InColor > 255)
147 {
148 Color->setRgb(0);
149 return;
150 }
151 Color->setRgb(CM->RGBColors[InColor]);
152 break;
153 case 15:
154 Color->setRgb(Color15to32(InColor));
155 break;
156 case 16:
157 Color->setRgb(Color16to32(InColor));
158 break;
159 case 24:
160 Color->setRgb(Color24to32(InColor));
161 break;
162 default:
163 Color->setRgb(0);
164 }
165 }
166
167 //*****************************************************************************
168 void SetOpCode(int opcode)
169 {
170 if (opcode >= 0 && opcode < 16)
171 {
172 Qt::RasterOp op = OpCodes[opcode];
173 if (op != Qt::CopyROP)
174 {
175 P1->setRasterOp(op);
176 P2->setRasterOp(op);
177 }
178 }
179 }
180
181 //*****************************************************************************
182 void ResetOpCode(int opcode)
183 {
184 if (opcode >= 0 && opcode < 16)
185 {
186 Qt::RasterOp op = OpCodes[opcode];
187 if (op != Qt::CopyROP)
188 {
189 P1->setRasterOp(Qt::CopyROP);
190 P2->setRasterOp(Qt::CopyROP);
191 }
192 }
193 }
194
195 /*****************************************************************************/
196 QMyMainWindow::QMyMainWindow() : QWidget()
197 {
198 }
199
200 /*****************************************************************************/
201 QMyMainWindow::~QMyMainWindow()
202 {
203 }
204
205 //*****************************************************************************
206 void QMyMainWindow::mouseMoveEvent(QMouseEvent* e)
207 {
208 if (!UpAndRunning)
209 return;
210 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, e->x(), e->y());
211 }
212
213 //*****************************************************************************
214 void QMyMainWindow::mousePressEvent(QMouseEvent* e)
215 {
216 if (!UpAndRunning)
217 return;
218 if (e->button() == LeftButton)
219 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
220 e->x(), e->y());
221 else if (e->button() == RightButton)
222 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
223 e->x(), e->y());
224 else if (e->button() == MidButton)
225 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3,
226 e->x(), e->y());
227 }
228
229 //*****************************************************************************
230 void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e)
231 {
232 if (!UpAndRunning)
233 return;
234 if (e->button() == LeftButton)
235 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, e->x(), e->y());
236 else if (e->button() == RightButton)
237 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, e->x(), e->y());
238 else if (e->button() == MidButton)
239 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, e->x(), e->y());
240 }
241
242 //*****************************************************************************
243 void QMyMainWindow::wheelEvent(QWheelEvent* e)
244 {
245 if (!UpAndRunning)
246 return;
247 if (e->delta() > 0)
248 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, e->x(), e->y());
249 else if (e->delta() < 0)
250 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, e->x(), e->y());
251 }
252
253 //*****************************************************************************
254 int GetScanCode(QKeyEvent* e)
255 {
256 int Key = e->key();
257 int ScanCode = 0;
258 Qt::ButtonState bs = e->state();
259 if (!(bs & Qt::ShiftButton)) // shift is not down
260 {
261 if (Key == 42) // *
262 return 0x37;
263 if (Key == 43) // +
264 return 0x4e;
265 }
266 switch (Key)
267 {
268 case 4100: ScanCode = 0x1c; break; // enter
269 case 4101: ScanCode = 0x1c; break;
270 case 4117: ScanCode = 0xd0; break; // down arrow
271 case 4115: ScanCode = 0xc8; break; // up arrow
272 case 4114: ScanCode = 0xcb; break; // left arrow
273 case 4116: ScanCode = 0xcd; break; // right arrow
274 case 4112: ScanCode = 0xc7; break; // home
275 case 4113: ScanCode = 0xcf; break; // end
276 case 4102: ScanCode = 0xd2; break; // insert
277 case 4103: ScanCode = 0xd3; break; // delete
278 case 4118: ScanCode = 0xc9; break; // page up
279 case 4119: ScanCode = 0xd1; break; // page down
280 case 4143: ScanCode = 0x00; break; // num lock
281 case 47: ScanCode = 0x35; break; // /
282 case 42: ScanCode = 0x37; break; // *
283 case 45: ScanCode = 0x0c; break; // -
284 case 95: ScanCode = 0x0c; break; // _
285 case 43: ScanCode = 0x0d; break; // +
286 case 46: ScanCode = 0x34; break; // .
287 case 48: ScanCode = 0x0b; break; // 0
288 case 41: ScanCode = 0x0b; break; // )
289 case 49: ScanCode = 0x02; break; // 1
290 case 33: ScanCode = 0x02; break; // !
291 case 50: ScanCode = 0x03; break; // 2
292 case 64: ScanCode = 0x03; break; // @
293 case 51: ScanCode = 0x04; break; // 3
294 case 35: ScanCode = 0x04; break; // #
295 case 52: ScanCode = 0x05; break; // 4
296 case 36: ScanCode = 0x05; break; // $
297 case 53: ScanCode = 0x06; break; // 5
298 case 37: ScanCode = 0x06; break; // %
299 case 54: ScanCode = 0x07; break; // 6
300 case 94: ScanCode = 0x07; break; // ^
301 case 55: ScanCode = 0x08; break; // 7
302 case 38: ScanCode = 0x08; break; // &
303 case 56: ScanCode = 0x09; break; // 8
304 case 57: ScanCode = 0x0a; break; // 9
305 case 40: ScanCode = 0x0a; break; // (
306 case 61: ScanCode = 0x0d; break; // =
307 case 65: ScanCode = 0x1e; break; // a
308 case 66: ScanCode = 0x30; break; // b
309 case 67: ScanCode = 0x2e; break; // c
310 case 68: ScanCode = 0x20; break; // d
311 case 69: ScanCode = 0x12; break; // e
312 case 70: ScanCode = 0x21; break; // f
313 case 71: ScanCode = 0x22; break; // g
314 case 72: ScanCode = 0x23; break; // h
315 case 73: ScanCode = 0x17; break; // i
316 case 74: ScanCode = 0x24; break; // j
317 case 75: ScanCode = 0x25; break; // k
318 case 76: ScanCode = 0x26; break; // l
319 case 77: ScanCode = 0x32; break; // m
320 case 78: ScanCode = 0x31; break; // n
321 case 79: ScanCode = 0x18; break; // o
322 case 80: ScanCode = 0x19; break; // p
323 case 81: ScanCode = 0x10; break; // q
324 case 82: ScanCode = 0x13; break; // r
325 case 83: ScanCode = 0x1f; break; // s
326 case 84: ScanCode = 0x14; break; // t
327 case 85: ScanCode = 0x16; break; // u
328 case 86: ScanCode = 0x2f; break; // v
329 case 87: ScanCode = 0x11; break; // w
330 case 88: ScanCode = 0x2d; break; // x
331 case 89: ScanCode = 0x15; break; // y
332 case 90: ScanCode = 0x2c; break; // z
333 case 32: ScanCode = 0x39; break; // space
334 case 44: ScanCode = 0x33; break; // ,
335 case 60: ScanCode = 0x33; break; // <
336 case 62: ScanCode = 0x34; break; // >
337 case 63: ScanCode = 0x35; break; // ?
338 case 92: ScanCode = 0x2b; break; // backslash
339 case 124: ScanCode = 0x2b; break; // bar
340 case 4097: ScanCode = 0x0f; break; // tab
341 case 4132: ScanCode = 0x3a; break; // caps lock
342 case 4096: ScanCode = 0x01; break; // esc
343 case 59: ScanCode = 0x27; break; // ;
344 case 58: ScanCode = 0x27; break; // :
345 case 39: ScanCode = 0x28; break; // '
346 case 34: ScanCode = 0x28; break; // "
347 case 91: ScanCode = 0x1a; break; // [
348 case 123: ScanCode = 0x1a; break; // {
349 case 93: ScanCode = 0x1b; break; // ]
350 case 125: ScanCode = 0x1b; break; // }
351 case 4144: ScanCode = 0x3b; break; // f1
352 case 4145: ScanCode = 0x3c; break; // f2
353 case 4146: ScanCode = 0x3d; break; // f3
354 case 4147: ScanCode = 0x3e; break; // f4
355 case 4148: ScanCode = 0x3f; break; // f5
356 case 4149: ScanCode = 0x40; break; // f6
357 case 4150: ScanCode = 0x41; break; // f7
358 case 4151: ScanCode = 0x42; break; // f8
359 case 4152: ScanCode = 0x43; break; // f9
360 case 4153: ScanCode = 0x44; break; // f10
361 case 4154: ScanCode = 0x57; break; // f11
362 case 4155: ScanCode = 0x58; break; // f12
363 case 4128: ScanCode = 0x2a; break; // shift
364 case 4131: ScanCode = 0x38; break; // alt
365 case 4129: ScanCode = 0x1d; break; // ctrl
366 case 96: ScanCode = 0x29; break; // `
367 case 126: ScanCode = 0x29; break; // ~
368 case 4099: ScanCode = 0x0e; break; // backspace
369 }
370 // if (ScanCode == 0)
371 // printf("key %d scancode %d\n", Key, ScanCode);
372 return ScanCode;
373 }
374
375 //*****************************************************************************
376 void QMyMainWindow::keyPressEvent(QKeyEvent* e)
377 {
378 if (!UpAndRunning)
379 return;
380 int ScanCode = GetScanCode(e);
381 if (ScanCode != 0)
382 {
383 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, ScanCode, 0);
384 e->accept();
385 }
386 }
387
388 //*****************************************************************************
389 void QMyMainWindow::keyReleaseEvent(QKeyEvent* e)
390 {
391 if (!UpAndRunning)
392 return;
393 int ScanCode = GetScanCode(e);
394 if (ScanCode != 0)
395 {
396 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, ScanCode, 0);
397 e->accept();
398 }
399 }
400
401 //*****************************************************************************
402 void QMyMainWindow::paintEvent(QPaintEvent* pe)
403 {
404 QRect Rect;
405 Rect = pe->rect();
406 bitBlt(this, Rect.left(), Rect.top(), BS, Rect.left(), Rect.top(),
407 Rect.width(), Rect.height());
408 }
409
410 //*****************************************************************************
411 void QMyMainWindow::closeEvent(QCloseEvent* e)
412 {
413 e->accept();
414 }
415
416 //*****************************************************************************
417 bool QMyMainWindow::event(QEvent* e)
418 {
419 return QWidget::event(e);
420 }
421
422 //*****************************************************************************
423 void QMyMainWindow::dataReceived()
424 {
425 if (!rdp_loop(&deactivated, &ext_disc_reason))
426 SV->close();
427 }
428
429 //*****************************************************************************
430 void QMyScrollView::keyPressEvent(QKeyEvent* e)
431 {
432 g_MW->keyPressEvent(e);
433 }
434
435 //*****************************************************************************
436 void QMyScrollView::keyReleaseEvent(QKeyEvent* e)
437 {
438 g_MW->keyReleaseEvent(e);
439 }
440
441
442 //*****************************************************************************
443 void ui_begin_update(void)
444 {
445 P1->begin(g_MW);
446 P2->begin(BS);
447 }
448
449 //*****************************************************************************
450 void ui_end_update(void)
451 {
452 P1->end();
453 P2->end();
454 }
455
456 /*****************************************************************************/
457 int ui_init(void)
458 {
459 App = new QApplication(g_argc, g_argv);
460 return 1;
461 }
462
463 /*****************************************************************************/
464 void ui_deinit(void)
465 {
466 delete App;
467 }
468
469 /*****************************************************************************/
470 int ui_create_window(void)
471 {
472 int w, h;
473 g_MW = new QMyMainWindow();
474 SV = new QMyScrollView();
475 SV->addChild(g_MW);
476 BS = new QPixmap(g_width, g_height);
477 QPainter* P = new QPainter(BS);
478 P->fillRect(0, 0, g_width, g_height, QBrush(QColor("white")));
479 P->fillRect(0, 0, g_width, g_height, QBrush(QBrush::CrossPattern));
480 delete P;
481 DS = new QPixmap(480, 480);
482 P1 = new QPainter();
483 P2 = new QPainter();
484 ClipRect = new QRegion(0, 0, g_width, g_height);
485 QWidget* d = QApplication::desktop();
486 w = d->width(); // returns screen width
487 h = d->height(); // returns screen height
488 g_MW->resize(g_width, g_height);
489 if (w < g_width || h < g_height)
490 SV->resize(w, h);
491 else
492 SV->resize(g_width + 4, g_height + 4);
493 SV->setMaximumWidth(g_width + 4);
494 SV->setMaximumHeight(g_height + 4);
495 App->setMainWidget(SV);
496 SV->show();
497 g_MW->setMouseTracking(true);
498 if (g_title[0] != 0)
499 SV->setCaption(g_title);
500
501 /* XGrayKey(0, 64, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
502 XGrayKey(0, 113, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
503 XGrayKey(0, 37, AnyModifie, SV-winId(), 0, GrabModeAsync, GrabModeAsync);
504 XGrayKey(0, 109, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
505 XGrayKey(0, 115, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
506 XGrayKey(0, 116, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
507 XGrayKey(0, 117, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
508 XGrayKey(0, 62, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
509 XGrayKey(0, 50, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);*/
510
511 return 1;
512 }
513
514 //*****************************************************************************
515 void ui_main_loop(void)
516 {
517 // connect
518 if (!rdp_connect(g_servername, RDP_LOGON_NORMAL, "", "", "", ""))
519 return;
520 // start notifier
521 SocketNotifier = new QSocketNotifier(g_sock, QSocketNotifier::Read, g_MW);
522 g_MW->connect(SocketNotifier, SIGNAL(activated(int)), g_MW, SLOT(dataReceived()));
523 UpAndRunning = 1;
524 // app main loop
525 App->exec();
526 }
527
528 //*****************************************************************************
529 void ui_destroy_window(void)
530 {
531 delete g_MW;
532 delete SV;
533 delete BS;
534 delete DS;
535 delete P1;
536 delete P2;
537 delete ClipRect;
538 }
539
540 /*****************************************************************************/
541 void ui_bell(void)
542 {
543 }
544
545 /*****************************************************************************/
546 int ui_select(int in_val)
547 {
548 g_sock = in_val;
549 return 1;
550 }
551
552 /*****************************************************************************/
553 void ui_destroy_cursor(void* cursor)
554 {
555 QCursor* Cursor;
556 Cursor = (QCursor*)cursor;
557 if (Cursor != NULL)
558 delete Cursor;
559 }
560
561 /*****************************************************************************/
562 void* ui_create_glyph(int width, int height, uint8* data)
563 {
564 QBitmap* Bitmap;
565 Bitmap = new QBitmap(width, height, data);
566 Bitmap->setMask(*Bitmap);
567 return (HGLYPH)Bitmap;
568 }
569
570 /*****************************************************************************/
571 void ui_destroy_glyph(void* glyph)
572 {
573 QBitmap* Bitmap;
574 Bitmap = (QBitmap*)glyph;
575 delete Bitmap;
576 }
577
578 /*****************************************************************************/
579 void ui_destroy_bitmap(void* bmp)
580 {
581 QPixmap* Pixmap;
582 Pixmap = (QPixmap*)bmp;
583 delete Pixmap;
584 }
585
586 /*****************************************************************************/
587 void ui_reset_clip(void)
588 {
589 P1->setClipRect(0, 0, g_width, g_height);
590 P2->setClipRect(0, 0, g_width, g_height);
591 delete ClipRect;
592 ClipRect = new QRegion(0, 0, g_width, g_height);
593 }
594
595 /*****************************************************************************/
596 void ui_set_clip(int x, int y, int cx, int cy)
597 {
598 P1->setClipRect(x, y, cx, cy);
599 P2->setClipRect(x, y, cx, cy);
600 delete ClipRect;
601 ClipRect = new QRegion(x, y, cx, cy);
602 }
603
604 /*****************************************************************************/
605 void* ui_create_colourmap(COLOURMAP* colours)
606 {
607 QColorMap* LCM;
608 int i, r, g, b;
609 LCM = (QColorMap*)malloc(sizeof(QColorMap));
610 memset(LCM, 0, sizeof(QColorMap));
611 i = 0;
612 while (i < colours->ncolours && i < 256)
613 {
614 r = colours->colours[i].red;
615 g = colours->colours[i].green;
616 b = colours->colours[i].blue;
617 LCM->RGBColors[i] = (r << 16) | (g << 8) | b;
618 i++;
619 }
620 LCM->NumColors = colours->ncolours;
621 return LCM;
622 }
623
624 //*****************************************************************************
625 // todo, does this leak at end of program
626 void ui_destroy_colourmap(HCOLOURMAP map)
627 {
628 QColorMap* LCM;
629 LCM = (QColorMap*)map;
630 if (LCM == NULL)
631 return;
632 free(LCM);
633 }
634
635 /*****************************************************************************/
636 void ui_set_colourmap(void* map)
637 {
638 // destoy old colormap
639 ui_destroy_colourmap(CM);
640 CM = (QColorMap*)map;
641 }
642
643 /*****************************************************************************/
644 HBITMAP ui_create_bitmap(int width, int height, uint8* data)
645 {
646 QImage* Image = NULL;
647 QPixmap* Pixmap;
648 uint32* d = NULL;
649 uint16* s;
650 switch (g_server_bpp)
651 {
652 case 8:
653 Image = new QImage(data, width, height, 8, (QRgb*)&CM->RGBColors,
654 CM->NumColors, QImage::IgnoreEndian);
655 break;
656 case 15:
657 d = (uint32*)malloc(width * height * 4);
658 s = (uint16*)data;
659 for (int i = 0; i < width * height; i++)
660 d[i] = Color15to32(s[i]);
661 Image = new QImage((uint8*)d, width, height, 32, NULL,
662 0, QImage::IgnoreEndian);
663 break;
664 case 16:
665 d = (uint32*)malloc(width * height * 4);
666 s = (uint16*)data;
667 for (int i = 0; i < width * height; i++)
668 d[i] = Color16to32(s[i]);
669 Image = new QImage((uint8*)d, width, height, 32, NULL,
670 0, QImage::IgnoreEndian);
671 break;
672 case 24:
673 d = (uint32*)malloc(width * height * 4);
674 memset(d, 0, width * height * 4);
675 for (int i = 0; i < width * height; i++)
676 memcpy(d + i, data + i * 3, 3);
677 Image = new QImage((uint8*)d, width, height, 32, NULL,
678 0, QImage::IgnoreEndian);
679 //Image = new QImage(data, width, height, 24, NULL,
680 // 0, QImage::IgnoreEndian);
681 break;
682 }
683 if (Image == NULL)
684 return NULL;
685 Pixmap = new QPixmap();
686 Pixmap->convertFromImage(*Image);
687 delete Image;
688 if (d != NULL)
689 free(d);
690 return (HBITMAP)Pixmap;
691 }
692
693 //******************************************************************************
694 // adjust coordinates for cliping rect
695 BOOL WarpCoords(int* x, int* y, int* cx, int* cy, int* srcx, int* srcy)
696 {
697 int dx, dy;
698 QRect InRect(*x, *y, *cx, *cy);
699 QRect OutRect;
700 QRect CRect = ClipRect->boundingRect();
701 OutRect = InRect.intersect(CRect);
702 if (OutRect.isEmpty())
703 return False;
704 dx = OutRect.x() - InRect.x();
705 dy = OutRect.y() - InRect.y();
706 *x = OutRect.x();
707 *y = OutRect.y();
708 *cx = OutRect.width();
709 *cy = OutRect.height();
710 *srcx = *srcx + dx;
711 *srcy = *srcy + dy;
712 return True;
713 }
714
715 //******************************************************************************
716 // needed because bitBlt don't seem to care about clipping rects
717 // also has 2 dsts and src can be nil
718 void bitBltClip(QPaintDevice* dst1, QPaintDevice* dst2, int dx, int dy,
719 QPaintDevice* src, int sx, int sy, int sw, int sh,
720 Qt::RasterOp rop, bool im)
721 {
722 if (WarpCoords(&dx, &dy, &sw, &sh, &sx, &sy))
723 {
724 if (dst1 != NULL)
725 if (src == NULL)
726 bitBlt(dst1, dx, dy, dst1, sx, sy, sw, sh, rop, im);
727 else
728 bitBlt(dst1, dx, dy, src, sx, sy, sw, sh, rop, im);
729 if (dst2 != NULL)
730 if (src == NULL)
731 bitBlt(dst2, dx, dy, dst2, sx, sy, sw, sh, rop, im);
732 else
733 bitBlt(dst2, dx, dy, src, sx, sy, sw, sh, rop, im);
734 }
735 }
736
737 #define DO_GLYPH(ttext,idx) \
738 {\
739 glyph = cache_get_font (font, ttext[idx]);\
740 if (!(flags & TEXT2_IMPLICIT_X))\
741 {\
742 xyoffset = ttext[++idx];\
743 if ((xyoffset & 0x80))\
744 {\
745 if (flags & TEXT2_VERTICAL) \
746 y += ttext[idx+1] | (ttext[idx+2] << 8);\
747 else\
748 x += ttext[idx+1] | (ttext[idx+2] << 8);\
749 idx += 2;\
750 }\
751 else\
752 {\
753 if (flags & TEXT2_VERTICAL) \
754 y += xyoffset;\
755 else\
756 x += xyoffset;\
757 }\
758 }\
759 if (glyph != NULL)\
760 {\
761 P2->drawPixmap(x + glyph->offset, y + glyph->baseline, *((QBitmap*)glyph->pixmap)); \
762 if (flags & TEXT2_IMPLICIT_X)\
763 x += glyph->width;\
764 }\
765 }
766
767 //*****************************************************************************
768 void ui_draw_text(uint8 font, uint8 flags, uint8 opcode, int mixmode,
769 int x, int y, int clipx, int clipy,
770 int clipcx, int clipcy, int boxx,
771 int boxy, int boxcx, int boxcy, BRUSH * brush,
772 int bgcolour, int fgcolour, uint8 * text, uint8 length)
773 {
774 FONTGLYPH *glyph;
775 int i, j, xyoffset;
776 DATABLOB *entry;
777
778 SetColorx(&Color1, fgcolour);
779 SetColorx(&Color2, bgcolour);
780 P2->setBackgroundColor(Color2);
781 P2->setPen(Color1);
782 if (boxcx > 1)
783 P2->fillRect(boxx, boxy, boxcx, boxcy, QBrush(Color2));
784 else if (mixmode == MIX_OPAQUE)
785 P2->fillRect(clipx, clipy, clipcx, clipcy, QBrush(Color2));
786
787 /* Paint text, character by character */
788 for (i = 0; i < length;)
789 {
790 switch (text[i])
791 {
792 case 0xff:
793 if (i + 2 < length)
794 cache_put_text(text[i + 1], text, text[i + 2]);
795 else
796 {
797 error("this shouldn't be happening\n");
798 exit(1);
799 }
800 /* this will move pointer from start to first character after FF command */
801 length -= i + 3;
802 text = &(text[i + 3]);
803 i = 0;
804 break;
805
806 case 0xfe:
807 entry = cache_get_text(text[i + 1]);
808 if (entry != NULL)
809 {
810 if ((((uint8 *) (entry->data))[1] == 0) && (!(flags & TEXT2_IMPLICIT_X)))
811 {
812 if (flags & TEXT2_VERTICAL)
813 y += text[i + 2];
814 else
815 x += text[i + 2];
816 }
817 for (j = 0; j < entry->size; j++)
818 DO_GLYPH(((uint8 *) (entry->data)), j);
819 }
820 if (i + 2 < length)
821 i += 3;
822 else
823 i += 2;
824 length -= i;
825 /* this will move pointer from start to first character after FE command */
826 text = &(text[i]);
827 i = 0;
828 break;
829
830 default:
831 DO_GLYPH(text, i);
832 i++;
833 break;
834 }
835 }
836 if (boxcx > 1)
837 bitBltClip(g_MW, NULL, boxx, boxy, BS, boxx, boxy, boxcx, boxcy, Qt::CopyROP, true);
838 else
839 bitBltClip(g_MW, NULL, clipx, clipy, BS, clipx, clipy, clipcx, clipcy, Qt::CopyROP, true);
840 }
841
842 /*****************************************************************************/
843 void ui_line(uint8 opcode, int startx, int starty, int endx, int endy,
844 PEN* pen)
845 {
846 SetColorx(&Color1, pen->colour);
847 SetOpCode(opcode);
848 P1->setPen(Color1);
849 P1->moveTo(startx, starty);
850 P1->lineTo(endx, endy);
851 P2->setPen(Color1);
852 P2->moveTo(startx, starty);
853 P2->lineTo(endx, endy);
854 ResetOpCode(opcode);
855 }
856
857 /*****************************************************************************/
858 void ui_triblt(uint8 opcode, int x, int y, int cx, int cy,
859 HBITMAP src, int srcx, int srcy,
860 BRUSH* brush, int bgcolour, int fgcolour)
861 {
862 }
863
864 /*****************************************************************************/
865 void ui_memblt(uint8 opcode, int x, int y, int cx, int cy,
866 HBITMAP src, int srcx, int srcy)
867 {
868 QPixmap* Pixmap;
869 Pixmap = (QPixmap*)src;
870 if (Pixmap != NULL)
871 {
872 SetOpCode(opcode);
873 P1->drawPixmap(x, y, *Pixmap, srcx, srcy, cx, cy);
874 P2->drawPixmap(x, y, *Pixmap, srcx, srcy, cx, cy);
875 ResetOpCode(opcode);
876 }
877 }
878
879 //******************************************************************************
880 void CommonDeskSave(QPixmap* Pixmap1, QPixmap* Pixmap2, int Offset, int x,
881 int y, int cx, int cy, int dir)
882 {
883 int lx;
884 int ly;
885 int x1;
886 int y1;
887 int width;
888 int lcx;
889 int right;
890 int bottom;
891 lx = Offset % 480;
892 ly = Offset / 480;
893 y1 = y;
894 right = x + cx;
895 bottom = y + cy;
896 while (y1 < bottom)
897 {
898 x1 = x;
899 lcx = cx;
900 while (x1 < right)
901 {
902 width = 480 - lx;
903 if (width > lcx)
904 width = lcx;
905 if (dir == 0)
906 bitBlt(Pixmap1, lx, ly, Pixmap2, x1, y1, width, 1, Qt::CopyROP, true);
907 else
908 bitBlt(Pixmap2, x1, y1, Pixmap1, lx, ly, width, 1, Qt::CopyROP, true);
909 lx = lx + width;
910 if (lx >= 480)
911 {
912 lx = 0;
913 ly++;
914 if (ly >= 480)
915 ly = 0;
916 }
917 lcx = lcx - width;
918 x1 = x1 + width;
919 }
920 y1++;
921 }
922 }
923
924 /*****************************************************************************/
925 void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
926 {
927 QPixmap* Pixmap;
928 Pixmap = new QPixmap(cx, cy);
929 CommonDeskSave(DS, Pixmap, offset, 0, 0, cx, cy, 1);
930 bitBltClip(g_MW, BS, x, y, Pixmap, 0, 0, cx, cy, Qt::CopyROP, true);
931 delete Pixmap;
932 }
933
934 /*****************************************************************************/
935 void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)
936 {
937 CommonDeskSave(DS, BS, offset, x, y, cx, cy, 0);
938 }
939
940 /*****************************************************************************/
941 void ui_rect(int x, int y, int cx, int cy, int colour)
942 {
943 SetColorx(&Color1, colour);
944 P1->fillRect(x, y, cx, cy, QBrush(Color1));
945 P2->fillRect(x, y, cx, cy, QBrush(Color1));
946 }
947
948 /*****************************************************************************/
949 void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy,
950 int srcx, int srcy)
951 {
952 SetOpCode(opcode);
953 bitBltClip(g_MW, BS, x, y, NULL, srcx, srcy, cx, cy, Qt::CopyROP, true);
954 ResetOpCode(opcode);
955 }
956
957 /*****************************************************************************/
958 void ui_patblt(uint8 opcode, int x, int y, int cx, int cy,
959 BRUSH* brush, int bgcolour, int fgcolour)
960 {
961 QBitmap* Bitmap;
962 QBrush* Brush;
963 uint8 ipattern[8], i;
964 SetOpCode(opcode);
965 switch (brush->style)
966 {
967 case 0:
968 SetColorx(&Color1, fgcolour);
969 P2->fillRect(x, y, cx, cy, QBrush(Color1));
970 break;
971 case 3:
972 SetColorx(&Color1, fgcolour);
973 SetColorx(&Color2, bgcolour);
974 for (i = 0; i != 8; i++)
975 ipattern[7 - i] = ~brush->pattern[i];
976 Bitmap = new QBitmap(8, 8, ipattern);
977 Brush = new QBrush(Color1, *Bitmap);
978 P2->setBackgroundMode(Qt::OpaqueMode);
979 P2->setBrushOrigin(brush->xorigin, brush->yorigin);
980 P2->setBackgroundColor(Color2);
981 P2->fillRect(x, y, cx, cy, *Brush);
982 delete Brush;
983 delete Bitmap;
984 P2->setBackgroundMode(Qt::TransparentMode);
985 P2->setBrushOrigin(0, 0);
986 break;
987 }
988 ResetOpCode(opcode);
989 bitBltClip(g_MW, NULL, x, y, BS, x, y, cx, cy, Qt::CopyROP, true);
990 }
991
992 /*****************************************************************************/
993 void ui_destblt(uint8 opcode, int x, int y, int cx, int cy)
994 {
995 SetOpCode(opcode);
996 P1->fillRect(x, y, cx, cy, QBrush(QColor("black")));
997 P2->fillRect(x, y, cx, cy, QBrush(QColor("black")));
998 ResetOpCode(opcode);
999 }
1000
1001 /*****************************************************************************/
1002 void ui_move_pointer(int x, int y)
1003 {
1004 }
1005
1006 /*****************************************************************************/
1007 void ui_set_null_cursor(void)
1008 {
1009 g_MW->setCursor(10); // Qt::BlankCursor
1010 }
1011
1012 /*****************************************************************************/
1013 void ui_paint_bitmap(int x, int y, int cx, int cy,
1014 int width, int height, uint8* data)
1015 {
1016 QImage* Image = NULL;
1017 QPixmap* Pixmap;
1018 uint32* d = NULL;
1019 uint16* s;
1020 switch (g_server_bpp)
1021 {
1022 case 8:
1023 Image = new QImage(data, width, height, 8, (QRgb*)&CM->RGBColors,
1024 CM->NumColors, QImage::IgnoreEndian);
1025 break;
1026 case 15:
1027 d = (uint32*)malloc(width * height * 4);
1028 s = (uint16*)data;
1029 for (int i = 0; i < width * height; i++)
1030 d[i] = Color15to32(s[i]);
1031 Image = new QImage((uint8*)d, width, height, 32, NULL,
1032 0, QImage::IgnoreEndian);
1033 break;
1034 case 16:
1035 d = (uint32*)malloc(width * height * 4);
1036 s = (uint16*)data;
1037 for (int i = 0; i < width * height; i++)
1038 d[i] = Color16to32(s[i]);
1039 Image = new QImage((uint8*)d, width, height, 32, NULL,
1040 0, QImage::IgnoreEndian);
1041 break;
1042 case 24:
1043 d = (uint32*)malloc(width * height * 4);
1044 memset(d, 0, width * height * 4);
1045 for (int i = 0; i < width * height; i++)
1046 memcpy(d + i, data + i * 3, 3);
1047 Image = new QImage((uint8*)d, width, height, 32, NULL,
1048 0, QImage::IgnoreEndian);
1049 break;
1050 }
1051 if (Image == NULL)
1052 return;
1053 Pixmap = new QPixmap();
1054 Pixmap->convertFromImage(*Image);
1055 P1->drawPixmap(x, y, *Pixmap, 0, 0, cx, cy);
1056 P2->drawPixmap(x, y, *Pixmap, 0, 0, cx, cy);
1057 delete Image;
1058 delete Pixmap;
1059 if (d != NULL)
1060 free(d);
1061 }
1062
1063 //******************************************************************************
1064 BOOL Is24On(uint8* Data, int X, int Y)
1065 {
1066 uint8 R, G, B;
1067 int Start;
1068 Start = Y * 32 * 3 + X * 3;
1069 R = Data[Start];
1070 G = Data[Start + 1];
1071 B = Data[Start + 2];
1072 return !((R == 0) && (G == 0) && (B == 0));
1073 }
1074
1075 //******************************************************************************
1076 BOOL Is1On(uint8* Data, int X, int Y)
1077 {
1078 int Start;
1079 int Shift;
1080 Start = (Y * 32) / 8 + X / 8;
1081 Shift = X % 8;
1082 return (Data[Start] & (0x80 >> Shift)) == 0;
1083 }
1084
1085 //******************************************************************************
1086 void Set1(uint8* Data, int X, int Y)
1087 {
1088 int Start;
1089 int Shift;
1090 Start = (Y * 32) / 8 + X / 8;
1091 Shift = X % 8;
1092 Data[Start] = Data[Start] | (0x80 >> Shift);
1093 }
1094
1095 //******************************************************************************
1096 void FlipOver(uint8* Data)
1097 {
1098 uint8 AData[128];
1099 int Index;
1100 memcpy(AData, Data, 128);
1101 for (Index = 0; Index <= 31; Index++)
1102 {
1103 Data[127 - (Index * 4 + 3)] = AData[Index * 4];
1104 Data[127 - (Index * 4 + 2)] = AData[Index * 4 + 1];
1105 Data[127 - (Index * 4 + 1)] = AData[Index * 4 + 2];
1106 Data[127 - Index * 4] = AData[Index * 4 + 3];
1107 }
1108 }
1109
1110 /*****************************************************************************/
1111 void ui_set_cursor(HCURSOR cursor)
1112 {
1113 QCursor* Cursor;
1114 Cursor = (QCursor*)cursor;
1115 if (Cursor != NULL)
1116 g_MW->setCursor(*Cursor);
1117 }
1118
1119 /*****************************************************************************/
1120 HCURSOR ui_create_cursor(unsigned int x, unsigned int y,
1121 int width, int height,
1122 uint8* andmask, uint8* xormask)
1123 {
1124 uint8 AData[128];
1125 uint8 AMask[128];
1126 QBitmap* DataBitmap;
1127 QBitmap* MaskBitmap;
1128 QCursor* Cursor;
1129 int I1;
1130 int I2;
1131 BOOL BOn;
1132 BOOL MOn;
1133 if (width != 32 || height != 32)
1134 return 0;
1135 memset(AData, 0, 128);
1136 memset(AMask, 0, 128);
1137 for (I1 = 0; I1 <= 31; I1++)
1138 for (I2 = 0; I2 <= 31; I2++)
1139 {
1140 MOn = Is24On(xormask, I1, I2);
1141 BOn = Is1On(andmask, I1, I2);
1142 if (BOn ^ MOn) // xor
1143 {
1144 Set1(AData, I1, I2);
1145 if (!MOn)
1146 Set1(AMask, I1, I2);
1147 }
1148 if (MOn)
1149 Set1(AMask, I1, I2);
1150 }
1151 FlipOver(AData);
1152 FlipOver(AMask);
1153 DataBitmap = new QBitmap(32, 32, AData);
1154 MaskBitmap = new QBitmap(32, 32, AMask);
1155 Cursor = new QCursor(*DataBitmap, *MaskBitmap, x, y);
1156 delete DataBitmap;
1157 delete MaskBitmap;
1158 return Cursor;
1159 }
1160
1161 /*****************************************************************************/
1162 uint16 ui_get_numlock_state(unsigned int state)
1163 {
1164 return 0;
1165 }
1166
1167 /*****************************************************************************/
1168 unsigned int read_keyboard_state(void)
1169 {
1170 return 0;
1171 }
1172
1173 /*****************************************************************************/
1174 void ui_resize_window(void)
1175 {
1176 }
1177
1178 /*****************************************************************************/
1179 void ui_polygon(uint8 opcode, uint8 fillmode, POINT * point, int npoints,
1180 BRUSH * brush, int bgcolour, int fgcolour)
1181 {
1182 }
1183
1184 /*****************************************************************************/
1185 /* todo, use qt function for this (QPainter::drawPolyline) */
1186 void ui_polyline(uint8 opcode, POINT * points, int npoints, PEN * pen)
1187 {
1188 int i, x, y, dx, dy;
1189 if (npoints > 0)
1190 {
1191 x = points[0].x;
1192 y = points[0].y;
1193 for (i = 1; i < npoints; i++)
1194 {
1195 dx = points[i].x;
1196 dy = points[i].y;
1197 ui_line(opcode, x, y, x + dx, y + dy, pen);
1198 x = x + dx;
1199 y = y + dy;
1200 }
1201 }
1202 }
1203
1204 /*****************************************************************************/
1205 void ui_ellipse(uint8 opcode, uint8 fillmode,
1206 int x, int y, int cx, int cy,
1207 BRUSH * brush, int bgcolour, int fgcolour)
1208 {
1209 }
1210
1211 /*****************************************************************************/
1212 void generate_random(uint8* random)
1213 {
1214 QFile File("/dev/random");
1215 File.open(IO_ReadOnly);
1216 if (File.readBlock((char*)random, 32) == 32)
1217 return;
1218 warning("no /dev/random\n");
1219 memcpy(random, "12345678901234567890123456789012", 32);
1220 }
1221
1222 /*****************************************************************************/
1223 void save_licence(uint8* data, int length)
1224 {
1225 }
1226
1227 /*****************************************************************************/
1228 int load_licence(uint8** data)
1229 {
1230 return 0;
1231 }
1232
1233 /*****************************************************************************/
1234 void* xrealloc(void* in_val, int size)
1235 {
1236 return realloc(in_val, size);
1237 }
1238
1239 /*****************************************************************************/
1240 void* xmalloc(int size)
1241 {
1242 return malloc(size);
1243 }
1244
1245 /*****************************************************************************/
1246 void xfree(void* in_val)
1247 {
1248 free(in_val);
1249 }
1250
1251 /*****************************************************************************/
1252 void warning(char* format, ...)
1253 {
1254 va_list ap;
1255
1256 fprintf(stderr, "WARNING: ");
1257 va_start(ap, format);
1258 vfprintf(stderr, format, ap);
1259 va_end(ap);
1260 }
1261
1262 /*****************************************************************************/
1263 void unimpl(char* format, ...)
1264 {
1265 va_list ap;
1266
1267 fprintf(stderr, "NOT IMPLEMENTED: ");
1268 va_start(ap, format);
1269 vfprintf(stderr, format, ap);
1270 va_end(ap);
1271 }
1272
1273 /*****************************************************************************/
1274 void error(char* format, ...)
1275 {
1276 va_list ap;
1277
1278 fprintf(stderr, "ERROR: ");
1279 va_start(ap, format);
1280 vfprintf(stderr, format, ap);
1281 va_end(ap);
1282 }
1283
1284 /*****************************************************************************/
1285 void out_params(void)
1286 {
1287 fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
1288 fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n");
1289 fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
1290 fprintf(stderr, "Usage: qtrdesktop [options] server\n");
1291 fprintf(stderr, " -g: desktop geometry (WxH)\n");
1292 fprintf(stderr, " -4: use RDP version 4\n");
1293 fprintf(stderr, " -5: use RDP version 5 (default)\n");
1294 fprintf(stderr, " -t: tcp port)\n");
1295 fprintf(stderr, " -a: connection colour depth\n");
1296 fprintf(stderr, " -T: window title\n");
1297 fprintf(stderr, "\n");
1298 }
1299
1300 /*****************************************************************************/
1301 /* produce a hex dump */
1302 void hexdump(unsigned char *p, unsigned int len)
1303 {
1304 unsigned char *line = p;
1305 int i, thisline;
1306 unsigned int offset = 0;
1307
1308 while (offset < len)
1309 {
1310 printf("%04x ", offset);
1311 thisline = len - offset;
1312 if (thisline > 16)
1313 thisline = 16;
1314 for (i = 0; i < thisline; i++)
1315 printf("%02x ", line[i]);
1316 for (; i < 16; i++)
1317 printf(" ");
1318 for (i = 0; i < thisline; i++)
1319 printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
1320 printf("\n");
1321 offset += thisline;
1322 line += thisline;
1323 }
1324 }
1325
1326 BOOL rd_pstcache_mkdir(void)
1327 {
1328 return 0;
1329 }
1330
1331 /*****************************************************************************/
1332 int rd_open_file(char *filename)
1333 {
1334 return 0;
1335 }
1336
1337 /*****************************************************************************/
1338 void rd_close_file(int fd)
1339 {
1340 return;
1341 }
1342
1343 /*****************************************************************************/
1344 int rd_read_file(int fd, void *ptr, int len)
1345 {
1346 return 0;
1347 }
1348
1349 /*****************************************************************************/
1350 int rd_write_file(int fd, void* ptr, int len)
1351 {
1352 return 0;
1353 }
1354
1355 /*****************************************************************************/
1356 int rd_lseek_file(int fd, int offset)
1357 {
1358 return 0;
1359 }
1360
1361 /*****************************************************************************/
1362 BOOL rd_lock_file(int fd, int start, int len)
1363 {
1364 return False;
1365 }
1366
1367 /*****************************************************************************/
1368 void get_username_and_hostname(void)
1369 {
1370 char fullhostname[64];
1371 char* p;
1372 struct passwd* pw;
1373
1374 STRNCPY(g_username, "unknown", sizeof(g_username));
1375 STRNCPY(g_hostname, "unknown", sizeof(g_hostname));
1376 pw = getpwuid(getuid());
1377 if (pw != NULL && pw->pw_name != NULL)
1378 {
1379 STRNCPY(g_username, pw->pw_name, sizeof(g_username));
1380 }
1381 if (gethostname(fullhostname, sizeof(fullhostname)) != -1)
1382 {
1383 p = strchr(fullhostname, '.');
1384 if (p != NULL)
1385 *p = 0;
1386 STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
1387 }
1388 }
1389
1390 /*****************************************************************************/
1391 int parse_parameters(int in_argc, char** in_argv)
1392 {
1393 int i;
1394 char* p;
1395
1396 if (in_argc <= 1)
1397 {
1398 out_params();
1399 return 0;
1400 }
1401 g_argc = in_argc;
1402 g_argv = in_argv;
1403 for (i = 1; i < in_argc; i++)
1404 {
1405 strcpy(g_servername, in_argv[i]);
1406 if (strcmp(in_argv[i], "-g") == 0)
1407 {
1408 g_width = strtol(in_argv[i + 1], &p, 10);
1409 if (g_width <= 0)
1410 {
1411 error("invalid geometry\n");
1412 return 0;
1413 }
1414 if (*p == 'x')
1415 g_height = strtol(p + 1, NULL, 10);
1416 if (g_height <= 0)
1417 {
1418 error("invalid geometry\n");
1419 return 0;
1420 }
1421 g_width = (g_width + 3) & ~3;
1422 }
1423 else if (strcmp(in_argv[i], "-T") == 0)
1424 strcpy(g_title, in_argv[i + 1]);
1425 else if (strcmp(in_argv[i], "-4") == 0)
1426 g_use_rdp5 = 0;
1427 else if (strcmp(in_argv[i], "-5") == 0)
1428 g_use_rdp5 = 1;
1429 else if (strcmp(in_argv[i], "-a") == 0)
1430 {
1431 g_server_bpp = strtol(in_argv[i + 1], &p, 10);
1432 if (g_server_bpp != 8 && g_server_bpp != 15 &&
1433 g_server_bpp != 16 && g_server_bpp != 24)
1434 {
1435 error("invalid bpp\n");
1436 return 0;
1437 }
1438 }
1439 else if (strcmp(in_argv[i], "-t") == 0)
1440 g_tcp_port_rdp = strtol(in_argv[i + 1], &p, 10);
1441 }
1442 return 1;
1443 }
1444
1445 /*****************************************************************************/
1446 int main(int in_argc, char** in_argv)
1447 {
1448 get_username_and_hostname();
1449 if (!parse_parameters(in_argc, in_argv))
1450 return 0;
1451 if (!ui_init())
1452 return 1;
1453 if (!ui_create_window())
1454 return 1;
1455 ui_main_loop();
1456 ui_destroy_window();
1457 ui_deinit();
1458 return 0;
1459 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26