You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OptionsDialog.cxx 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. /* Copyright 2011-2021 Pierre Ossman <ossman@cendio.se> for Cendio AB
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #include <stdlib.h>
  22. #include <list>
  23. #include <rdr/types.h>
  24. #include <rfb/encodings.h>
  25. #ifdef HAVE_GNUTLS
  26. #include <rfb/Security.h>
  27. #include <rfb/SecurityClient.h>
  28. #include <rfb/CSecurityTLS.h>
  29. #endif
  30. #include "OptionsDialog.h"
  31. #include "fltk_layout.h"
  32. #include "i18n.h"
  33. #include "menukey.h"
  34. #include "parameters.h"
  35. #include "MonitorArrangement.h"
  36. #include <FL/Fl_Tabs.H>
  37. #include <FL/Fl_Button.H>
  38. #include <FL/Fl_Check_Button.H>
  39. #include <FL/Fl_Return_Button.H>
  40. #include <FL/Fl_Round_Button.H>
  41. #include <FL/Fl_Int_Input.H>
  42. #include <FL/Fl_Choice.H>
  43. using namespace std;
  44. using namespace rdr;
  45. using namespace rfb;
  46. std::map<OptionsCallback*, void*> OptionsDialog::callbacks;
  47. OptionsDialog::OptionsDialog()
  48. : Fl_Window(450, 460, _("VNC Viewer: Connection Options"))
  49. {
  50. int x, y;
  51. Fl_Button *button;
  52. Fl_Tabs *tabs = new Fl_Tabs(OUTER_MARGIN, OUTER_MARGIN,
  53. w() - OUTER_MARGIN*2,
  54. h() - OUTER_MARGIN*2 - INNER_MARGIN - BUTTON_HEIGHT);
  55. {
  56. int tx, ty, tw, th;
  57. tabs->client_area(tx, ty, tw, th, TABS_HEIGHT);
  58. createCompressionPage(tx, ty, tw, th);
  59. createSecurityPage(tx, ty, tw, th);
  60. createInputPage(tx, ty, tw, th);
  61. createDisplayPage(tx, ty, tw, th);
  62. createMiscPage(tx, ty, tw, th);
  63. }
  64. tabs->end();
  65. x = w() - BUTTON_WIDTH * 2 - INNER_MARGIN - OUTER_MARGIN;
  66. y = h() - BUTTON_HEIGHT - OUTER_MARGIN;
  67. button = new Fl_Button(x, y, BUTTON_WIDTH, BUTTON_HEIGHT, _("Cancel"));
  68. button->callback(this->handleCancel, this);
  69. x += BUTTON_WIDTH + INNER_MARGIN;
  70. button = new Fl_Return_Button(x, y, BUTTON_WIDTH, BUTTON_HEIGHT, _("OK"));
  71. button->callback(this->handleOK, this);
  72. callback(this->handleCancel, this);
  73. set_modal();
  74. }
  75. OptionsDialog::~OptionsDialog()
  76. {
  77. }
  78. void OptionsDialog::showDialog(void)
  79. {
  80. static OptionsDialog *dialog = NULL;
  81. if (!dialog)
  82. dialog = new OptionsDialog();
  83. if (dialog->shown())
  84. return;
  85. dialog->show();
  86. }
  87. void OptionsDialog::addCallback(OptionsCallback *cb, void *data)
  88. {
  89. callbacks[cb] = data;
  90. }
  91. void OptionsDialog::removeCallback(OptionsCallback *cb)
  92. {
  93. callbacks.erase(cb);
  94. }
  95. void OptionsDialog::show(void)
  96. {
  97. /* show() gets called for raise events as well */
  98. if (!shown())
  99. loadOptions();
  100. Fl_Window::show();
  101. }
  102. void OptionsDialog::loadOptions(void)
  103. {
  104. /* Compression */
  105. autoselectCheckbox->value(autoSelect);
  106. int encNum = encodingNum(preferredEncoding);
  107. switch (encNum) {
  108. case encodingTight:
  109. tightButton->setonly();
  110. break;
  111. case encodingZRLE:
  112. zrleButton->setonly();
  113. break;
  114. case encodingHextile:
  115. hextileButton->setonly();
  116. break;
  117. case encodingRaw:
  118. rawButton->setonly();
  119. break;
  120. }
  121. if (fullColour)
  122. fullcolorCheckbox->setonly();
  123. else {
  124. switch (lowColourLevel) {
  125. case 0:
  126. verylowcolorCheckbox->setonly();
  127. break;
  128. case 1:
  129. lowcolorCheckbox->setonly();
  130. break;
  131. case 2:
  132. mediumcolorCheckbox->setonly();
  133. break;
  134. }
  135. }
  136. char digit[2] = "0";
  137. compressionCheckbox->value(customCompressLevel);
  138. jpegCheckbox->value(!noJpeg);
  139. digit[0] = '0' + compressLevel;
  140. compressionInput->value(digit);
  141. digit[0] = '0' + qualityLevel;
  142. jpegInput->value(digit);
  143. handleAutoselect(autoselectCheckbox, this);
  144. handleCompression(compressionCheckbox, this);
  145. handleJpeg(jpegCheckbox, this);
  146. #ifdef HAVE_GNUTLS
  147. /* Security */
  148. Security security(SecurityClient::secTypes);
  149. list<U8> secTypes;
  150. list<U8>::iterator iter;
  151. list<U32> secTypesExt;
  152. list<U32>::iterator iterExt;
  153. encNoneCheckbox->value(false);
  154. encTLSCheckbox->value(false);
  155. encX509Checkbox->value(false);
  156. authNoneCheckbox->value(false);
  157. authVncCheckbox->value(false);
  158. authPlainCheckbox->value(false);
  159. secTypes = security.GetEnabledSecTypes();
  160. for (iter = secTypes.begin(); iter != secTypes.end(); ++iter) {
  161. switch (*iter) {
  162. case secTypeNone:
  163. encNoneCheckbox->value(true);
  164. authNoneCheckbox->value(true);
  165. break;
  166. case secTypeVncAuth:
  167. encNoneCheckbox->value(true);
  168. authVncCheckbox->value(true);
  169. break;
  170. }
  171. }
  172. secTypesExt = security.GetEnabledExtSecTypes();
  173. for (iterExt = secTypesExt.begin(); iterExt != secTypesExt.end(); ++iterExt) {
  174. switch (*iterExt) {
  175. case secTypePlain:
  176. encNoneCheckbox->value(true);
  177. authPlainCheckbox->value(true);
  178. break;
  179. case secTypeTLSNone:
  180. encTLSCheckbox->value(true);
  181. authNoneCheckbox->value(true);
  182. break;
  183. case secTypeTLSVnc:
  184. encTLSCheckbox->value(true);
  185. authVncCheckbox->value(true);
  186. break;
  187. case secTypeTLSPlain:
  188. encTLSCheckbox->value(true);
  189. authPlainCheckbox->value(true);
  190. break;
  191. case secTypeX509None:
  192. encX509Checkbox->value(true);
  193. authNoneCheckbox->value(true);
  194. break;
  195. case secTypeX509Vnc:
  196. encX509Checkbox->value(true);
  197. authVncCheckbox->value(true);
  198. break;
  199. case secTypeX509Plain:
  200. encX509Checkbox->value(true);
  201. authPlainCheckbox->value(true);
  202. break;
  203. }
  204. }
  205. caInput->value(CSecurityTLS::X509CA);
  206. crlInput->value(CSecurityTLS::X509CRL);
  207. handleX509(encX509Checkbox, this);
  208. #endif
  209. /* Input */
  210. const char *menuKeyBuf;
  211. viewOnlyCheckbox->value(viewOnly);
  212. emulateMBCheckbox->value(emulateMiddleButton);
  213. acceptClipboardCheckbox->value(acceptClipboard);
  214. #if !defined(WIN32) && !defined(__APPLE__)
  215. setPrimaryCheckbox->value(setPrimary);
  216. #endif
  217. sendClipboardCheckbox->value(sendClipboard);
  218. #if !defined(WIN32) && !defined(__APPLE__)
  219. sendPrimaryCheckbox->value(sendPrimary);
  220. #endif
  221. systemKeysCheckbox->value(fullscreenSystemKeys);
  222. menuKeyChoice->value(0);
  223. menuKeyBuf = menuKey;
  224. for (int i = 0; i < getMenuKeySymbolCount(); i++)
  225. if (!strcmp(getMenuKeySymbols()[i].name, menuKeyBuf))
  226. menuKeyChoice->value(i + 1);
  227. /* Display */
  228. if (!fullScreen) {
  229. windowedButton->setonly();
  230. } else {
  231. if (!strcasecmp(fullScreenMode, "all")) {
  232. allMonitorsButton->setonly();
  233. } else if (!strcasecmp(fullScreenMode, "selected")) {
  234. selectedMonitorsButton->setonly();
  235. } else {
  236. currentMonitorButton->setonly();
  237. }
  238. }
  239. monitorArrangement->set(fullScreenSelectedMonitors.getParam());
  240. handleFullScreenMode(selectedMonitorsButton, this);
  241. /* Misc. */
  242. sharedCheckbox->value(shared);
  243. reconnectCheckbox->value(reconnectOnError);
  244. dotCursorCheckbox->value(dotWhenNoCursor);
  245. }
  246. void OptionsDialog::storeOptions(void)
  247. {
  248. /* Compression */
  249. autoSelect.setParam(autoselectCheckbox->value());
  250. if (tightButton->value())
  251. preferredEncoding.setParam(encodingName(encodingTight));
  252. else if (zrleButton->value())
  253. preferredEncoding.setParam(encodingName(encodingZRLE));
  254. else if (hextileButton->value())
  255. preferredEncoding.setParam(encodingName(encodingHextile));
  256. else if (rawButton->value())
  257. preferredEncoding.setParam(encodingName(encodingRaw));
  258. fullColour.setParam(fullcolorCheckbox->value());
  259. if (verylowcolorCheckbox->value())
  260. lowColourLevel.setParam(0);
  261. else if (lowcolorCheckbox->value())
  262. lowColourLevel.setParam(1);
  263. else if (mediumcolorCheckbox->value())
  264. lowColourLevel.setParam(2);
  265. customCompressLevel.setParam(compressionCheckbox->value());
  266. noJpeg.setParam(!jpegCheckbox->value());
  267. compressLevel.setParam(atoi(compressionInput->value()));
  268. qualityLevel.setParam(atoi(jpegInput->value()));
  269. #ifdef HAVE_GNUTLS
  270. /* Security */
  271. Security security;
  272. /* Process security types which don't use encryption */
  273. if (encNoneCheckbox->value()) {
  274. if (authNoneCheckbox->value())
  275. security.EnableSecType(secTypeNone);
  276. if (authVncCheckbox->value())
  277. security.EnableSecType(secTypeVncAuth);
  278. if (authPlainCheckbox->value())
  279. security.EnableSecType(secTypePlain);
  280. }
  281. /* Process security types which use TLS encryption */
  282. if (encTLSCheckbox->value()) {
  283. if (authNoneCheckbox->value())
  284. security.EnableSecType(secTypeTLSNone);
  285. if (authVncCheckbox->value())
  286. security.EnableSecType(secTypeTLSVnc);
  287. if (authPlainCheckbox->value())
  288. security.EnableSecType(secTypeTLSPlain);
  289. }
  290. /* Process security types which use X509 encryption */
  291. if (encX509Checkbox->value()) {
  292. if (authNoneCheckbox->value())
  293. security.EnableSecType(secTypeX509None);
  294. if (authVncCheckbox->value())
  295. security.EnableSecType(secTypeX509Vnc);
  296. if (authPlainCheckbox->value())
  297. security.EnableSecType(secTypeX509Plain);
  298. }
  299. SecurityClient::secTypes.setParam(security.ToString());
  300. CSecurityTLS::X509CA.setParam(caInput->value());
  301. CSecurityTLS::X509CRL.setParam(crlInput->value());
  302. #endif
  303. /* Input */
  304. viewOnly.setParam(viewOnlyCheckbox->value());
  305. emulateMiddleButton.setParam(emulateMBCheckbox->value());
  306. acceptClipboard.setParam(acceptClipboardCheckbox->value());
  307. #if !defined(WIN32) && !defined(__APPLE__)
  308. setPrimary.setParam(setPrimaryCheckbox->value());
  309. #endif
  310. sendClipboard.setParam(sendClipboardCheckbox->value());
  311. #if !defined(WIN32) && !defined(__APPLE__)
  312. sendPrimary.setParam(sendPrimaryCheckbox->value());
  313. #endif
  314. fullscreenSystemKeys.setParam(systemKeysCheckbox->value());
  315. if (menuKeyChoice->value() == 0)
  316. menuKey.setParam("");
  317. else {
  318. menuKey.setParam(menuKeyChoice->text());
  319. }
  320. /* Display */
  321. if (windowedButton->value()) {
  322. fullScreen.setParam(false);
  323. } else {
  324. fullScreen.setParam(true);
  325. if (allMonitorsButton->value()) {
  326. fullScreenMode.setParam("All");
  327. } else if (selectedMonitorsButton->value()) {
  328. fullScreenMode.setParam("Selected");
  329. } else {
  330. fullScreenMode.setParam("Current");
  331. }
  332. }
  333. fullScreenSelectedMonitors.setParam(monitorArrangement->get());
  334. /* Misc. */
  335. shared.setParam(sharedCheckbox->value());
  336. reconnectOnError.setParam(reconnectCheckbox->value());
  337. dotWhenNoCursor.setParam(dotCursorCheckbox->value());
  338. std::map<OptionsCallback*, void*>::const_iterator iter;
  339. for (iter = callbacks.begin();iter != callbacks.end();++iter)
  340. iter->first(iter->second);
  341. }
  342. void OptionsDialog::createCompressionPage(int tx, int ty, int tw, int th)
  343. {
  344. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Compression"));
  345. int orig_tx, orig_ty;
  346. int half_width, full_width;
  347. int height;
  348. tx += OUTER_MARGIN;
  349. ty += OUTER_MARGIN;
  350. full_width = tw - OUTER_MARGIN * 2;
  351. half_width = (full_width - INNER_MARGIN) / 2;
  352. /* AutoSelect checkbox */
  353. autoselectCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  354. CHECK_MIN_WIDTH,
  355. CHECK_HEIGHT,
  356. _("Auto select")));
  357. autoselectCheckbox->callback(handleAutoselect, this);
  358. ty += CHECK_HEIGHT + INNER_MARGIN;
  359. /* Two columns */
  360. orig_tx = tx;
  361. orig_ty = ty;
  362. /* VNC encoding box */
  363. ty += GROUP_LABEL_OFFSET;
  364. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 3 + RADIO_HEIGHT * 4;
  365. encodingGroup = new Fl_Group(tx, ty, half_width, height,
  366. _("Preferred encoding"));
  367. encodingGroup->box(FL_ENGRAVED_BOX);
  368. encodingGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  369. {
  370. tx += GROUP_MARGIN;
  371. ty += GROUP_MARGIN;
  372. tightButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  373. RADIO_MIN_WIDTH,
  374. RADIO_HEIGHT,
  375. "Tight"));
  376. tightButton->type(FL_RADIO_BUTTON);
  377. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  378. zrleButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  379. RADIO_MIN_WIDTH,
  380. RADIO_HEIGHT,
  381. "ZRLE"));
  382. zrleButton->type(FL_RADIO_BUTTON);
  383. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  384. hextileButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  385. RADIO_MIN_WIDTH,
  386. RADIO_HEIGHT,
  387. "Hextile"));
  388. hextileButton->type(FL_RADIO_BUTTON);
  389. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  390. rawButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  391. RADIO_MIN_WIDTH,
  392. RADIO_HEIGHT,
  393. "Raw"));
  394. rawButton->type(FL_RADIO_BUTTON);
  395. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  396. }
  397. ty += GROUP_MARGIN - TIGHT_MARGIN;
  398. encodingGroup->end();
  399. /* Second column */
  400. tx = orig_tx + half_width + INNER_MARGIN;
  401. ty = orig_ty;
  402. /* Color box */
  403. ty += GROUP_LABEL_OFFSET;
  404. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 3 + RADIO_HEIGHT * 4;
  405. colorlevelGroup = new Fl_Group(tx, ty, half_width, height, _("Color level"));
  406. colorlevelGroup->box(FL_ENGRAVED_BOX);
  407. colorlevelGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  408. {
  409. tx += GROUP_MARGIN;
  410. ty += GROUP_MARGIN;
  411. fullcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  412. RADIO_MIN_WIDTH,
  413. RADIO_HEIGHT,
  414. _("Full")));
  415. fullcolorCheckbox->type(FL_RADIO_BUTTON);
  416. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  417. mediumcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  418. RADIO_MIN_WIDTH,
  419. RADIO_HEIGHT,
  420. _("Medium")));
  421. mediumcolorCheckbox->type(FL_RADIO_BUTTON);
  422. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  423. lowcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  424. RADIO_MIN_WIDTH,
  425. RADIO_HEIGHT,
  426. _("Low")));
  427. lowcolorCheckbox->type(FL_RADIO_BUTTON);
  428. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  429. verylowcolorCheckbox = new Fl_Round_Button(LBLRIGHT(tx, ty,
  430. RADIO_MIN_WIDTH,
  431. RADIO_HEIGHT,
  432. _("Very low")));
  433. verylowcolorCheckbox->type(FL_RADIO_BUTTON);
  434. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  435. }
  436. ty += GROUP_MARGIN - TIGHT_MARGIN;
  437. colorlevelGroup->end();
  438. /* Back to normal */
  439. tx = orig_tx;
  440. ty += INNER_MARGIN;
  441. /* Checkboxes */
  442. compressionCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  443. CHECK_MIN_WIDTH,
  444. CHECK_HEIGHT,
  445. _("Custom compression level:")));
  446. compressionCheckbox->callback(handleCompression, this);
  447. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  448. compressionInput = new Fl_Int_Input(tx + INDENT, ty,
  449. INPUT_HEIGHT, INPUT_HEIGHT,
  450. _("level (0=fast, 9=best)"));
  451. compressionInput->align(FL_ALIGN_RIGHT);
  452. ty += INPUT_HEIGHT + INNER_MARGIN;
  453. jpegCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  454. CHECK_MIN_WIDTH,
  455. CHECK_HEIGHT,
  456. _("Allow JPEG compression:")));
  457. jpegCheckbox->callback(handleJpeg, this);
  458. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  459. jpegInput = new Fl_Int_Input(tx + INDENT, ty,
  460. INPUT_HEIGHT, INPUT_HEIGHT,
  461. _("quality (0=poor, 9=best)"));
  462. jpegInput->align(FL_ALIGN_RIGHT);
  463. ty += INPUT_HEIGHT + INNER_MARGIN;
  464. group->end();
  465. }
  466. void OptionsDialog::createSecurityPage(int tx, int ty, int tw, int th)
  467. {
  468. #ifdef HAVE_GNUTLS
  469. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Security"));
  470. int orig_tx;
  471. int width, height;
  472. tx += OUTER_MARGIN;
  473. ty += OUTER_MARGIN;
  474. width = tw - OUTER_MARGIN * 2;
  475. orig_tx = tx;
  476. /* Encryption */
  477. ty += GROUP_LABEL_OFFSET;
  478. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 4 + CHECK_HEIGHT * 3 + (INPUT_LABEL_OFFSET + INPUT_HEIGHT) * 2;
  479. encryptionGroup = new Fl_Group(tx, ty, width, height, _("Encryption"));
  480. encryptionGroup->box(FL_ENGRAVED_BOX);
  481. encryptionGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  482. {
  483. tx += GROUP_MARGIN;
  484. ty += GROUP_MARGIN;
  485. encNoneCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  486. CHECK_MIN_WIDTH,
  487. CHECK_HEIGHT,
  488. _("None")));
  489. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  490. encTLSCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  491. CHECK_MIN_WIDTH,
  492. CHECK_HEIGHT,
  493. _("TLS with anonymous certificates")));
  494. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  495. encX509Checkbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  496. CHECK_MIN_WIDTH,
  497. CHECK_HEIGHT,
  498. _("TLS with X509 certificates")));
  499. encX509Checkbox->callback(handleX509, this);
  500. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  501. ty += INPUT_LABEL_OFFSET;
  502. caInput = new Fl_Input(tx + INDENT, ty,
  503. width - GROUP_MARGIN*2 - INDENT, INPUT_HEIGHT,
  504. _("Path to X509 CA certificate"));
  505. caInput->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  506. ty += INPUT_HEIGHT + TIGHT_MARGIN;
  507. ty += INPUT_LABEL_OFFSET;
  508. crlInput = new Fl_Input(tx + INDENT, ty,
  509. width - GROUP_MARGIN*2 - INDENT, INPUT_HEIGHT,
  510. _("Path to X509 CRL file"));
  511. crlInput->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  512. ty += INPUT_HEIGHT + TIGHT_MARGIN;
  513. }
  514. ty += GROUP_MARGIN - TIGHT_MARGIN;
  515. encryptionGroup->end();
  516. /* Back to normal */
  517. tx = orig_tx;
  518. ty += INNER_MARGIN;
  519. /* Authentication */
  520. ty += GROUP_LABEL_OFFSET;
  521. height = GROUP_MARGIN * 2 + TIGHT_MARGIN * 2 + CHECK_HEIGHT * 3;
  522. authenticationGroup = new Fl_Group(tx, ty, width, height, _("Authentication"));
  523. authenticationGroup->box(FL_ENGRAVED_BOX);
  524. authenticationGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  525. {
  526. tx += GROUP_MARGIN;
  527. ty += GROUP_MARGIN;
  528. authNoneCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  529. CHECK_MIN_WIDTH,
  530. CHECK_HEIGHT,
  531. _("None")));
  532. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  533. authVncCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  534. CHECK_MIN_WIDTH,
  535. CHECK_HEIGHT,
  536. _("Standard VNC (insecure without encryption)")));
  537. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  538. authPlainCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  539. CHECK_MIN_WIDTH,
  540. CHECK_HEIGHT,
  541. _("Username and password (insecure without encryption)")));
  542. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  543. }
  544. ty += GROUP_MARGIN - TIGHT_MARGIN;
  545. authenticationGroup->end();
  546. /* Back to normal */
  547. tx = orig_tx;
  548. ty += INNER_MARGIN;
  549. group->end();
  550. #endif
  551. }
  552. void OptionsDialog::createInputPage(int tx, int ty, int tw, int th)
  553. {
  554. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Input"));
  555. int orig_tx;
  556. int width;
  557. tx += OUTER_MARGIN;
  558. ty += OUTER_MARGIN;
  559. width = tw - OUTER_MARGIN * 2;
  560. viewOnlyCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  561. CHECK_MIN_WIDTH,
  562. CHECK_HEIGHT,
  563. _("View only (ignore mouse and keyboard)")));
  564. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  565. orig_tx = tx;
  566. /* Mouse */
  567. ty += GROUP_LABEL_OFFSET;
  568. mouseGroup = new Fl_Group(tx, ty, width, 0, _("Mouse"));
  569. mouseGroup->box(FL_ENGRAVED_BOX);
  570. mouseGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  571. /* Needed for final resize to work sanely */
  572. mouseGroup->resizable(NULL);
  573. {
  574. tx += GROUP_MARGIN;
  575. ty += GROUP_MARGIN;
  576. emulateMBCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  577. CHECK_MIN_WIDTH,
  578. CHECK_HEIGHT,
  579. _("Emulate middle mouse button")));
  580. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  581. dotCursorCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  582. CHECK_MIN_WIDTH,
  583. CHECK_HEIGHT,
  584. _("Show dot when no cursor")));
  585. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  586. }
  587. ty += GROUP_MARGIN - TIGHT_MARGIN;
  588. mouseGroup->end();
  589. mouseGroup->size(mouseGroup->w(), ty - mouseGroup->y());
  590. /* Back to normal */
  591. tx = orig_tx;
  592. ty += INNER_MARGIN;
  593. /* Keyboard */
  594. ty += GROUP_LABEL_OFFSET;
  595. keyboardGroup = new Fl_Group(tx, ty, width, 0, _("Keyboard"));
  596. keyboardGroup->box(FL_ENGRAVED_BOX);
  597. keyboardGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  598. /* Needed for final resize to work sanely */
  599. keyboardGroup->resizable(NULL);
  600. {
  601. tx += GROUP_MARGIN;
  602. ty += GROUP_MARGIN;
  603. systemKeysCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  604. CHECK_MIN_WIDTH,
  605. CHECK_HEIGHT,
  606. _("Pass system keys directly to server (full screen)")));
  607. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  608. menuKeyChoice = new Fl_Choice(LBLLEFT(tx, ty, 150, CHOICE_HEIGHT, _("Menu key")));
  609. fltk_menu_add(menuKeyChoice, _("None"), 0, NULL, (void*)0, FL_MENU_DIVIDER);
  610. for (int i = 0; i < getMenuKeySymbolCount(); i++)
  611. fltk_menu_add(menuKeyChoice, getMenuKeySymbols()[i].name, 0, NULL, 0, 0);
  612. ty += CHOICE_HEIGHT + TIGHT_MARGIN;
  613. }
  614. ty += GROUP_MARGIN - TIGHT_MARGIN;
  615. keyboardGroup->end();
  616. keyboardGroup->size(keyboardGroup->w(), ty - keyboardGroup->y());
  617. /* Back to normal */
  618. tx = orig_tx;
  619. ty += INNER_MARGIN;
  620. /* Clipboard */
  621. ty += GROUP_LABEL_OFFSET;
  622. clipboardGroup = new Fl_Group(tx, ty, width, 0, _("Clipboard"));
  623. clipboardGroup->box(FL_ENGRAVED_BOX);
  624. clipboardGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  625. /* Needed for final resize to work sanely */
  626. clipboardGroup->resizable(NULL);
  627. {
  628. tx += GROUP_MARGIN;
  629. ty += GROUP_MARGIN;
  630. acceptClipboardCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  631. CHECK_MIN_WIDTH,
  632. CHECK_HEIGHT,
  633. _("Accept clipboard from server")));
  634. acceptClipboardCheckbox->callback(handleClipboard, this);
  635. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  636. #if !defined(WIN32) && !defined(__APPLE__)
  637. setPrimaryCheckbox = new Fl_Check_Button(LBLRIGHT(tx + INDENT, ty,
  638. CHECK_MIN_WIDTH,
  639. CHECK_HEIGHT,
  640. _("Also set primary selection")));
  641. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  642. #endif
  643. sendClipboardCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  644. CHECK_MIN_WIDTH,
  645. CHECK_HEIGHT,
  646. _("Send clipboard to server")));
  647. sendClipboardCheckbox->callback(handleClipboard, this);
  648. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  649. #if !defined(WIN32) && !defined(__APPLE__)
  650. sendPrimaryCheckbox = new Fl_Check_Button(LBLRIGHT(tx + INDENT, ty,
  651. CHECK_MIN_WIDTH,
  652. CHECK_HEIGHT,
  653. _("Send primary selection as clipboard")));
  654. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  655. #endif
  656. }
  657. ty += GROUP_MARGIN - TIGHT_MARGIN;
  658. clipboardGroup->end();
  659. clipboardGroup->size(clipboardGroup->w(), ty - clipboardGroup->y());
  660. /* Back to normal */
  661. tx = orig_tx;
  662. ty += INNER_MARGIN;
  663. group->end();
  664. }
  665. void OptionsDialog::createDisplayPage(int tx, int ty, int tw, int th)
  666. {
  667. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Display"));
  668. int orig_tx;
  669. int width;
  670. tx += OUTER_MARGIN;
  671. ty += OUTER_MARGIN;
  672. width = tw - OUTER_MARGIN * 2;
  673. orig_tx = tx;
  674. /* Display mode */
  675. ty += GROUP_LABEL_OFFSET;
  676. displayModeGroup = new Fl_Group(tx, ty, width, 0, _("Display mode"));
  677. displayModeGroup->box(FL_ENGRAVED_BOX);
  678. displayModeGroup->align(FL_ALIGN_LEFT | FL_ALIGN_TOP);
  679. /* Needed for final resize to work sanely */
  680. displayModeGroup->resizable(NULL);
  681. {
  682. tx += GROUP_MARGIN;
  683. ty += GROUP_MARGIN;
  684. width -= GROUP_MARGIN * 2;
  685. windowedButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  686. RADIO_MIN_WIDTH,
  687. RADIO_HEIGHT,
  688. _("Windowed")));
  689. windowedButton->type(FL_RADIO_BUTTON);
  690. windowedButton->callback(handleFullScreenMode, this);
  691. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  692. currentMonitorButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  693. RADIO_MIN_WIDTH,
  694. RADIO_HEIGHT,
  695. _("Full screen on current monitor")));
  696. currentMonitorButton->type(FL_RADIO_BUTTON);
  697. currentMonitorButton->callback(handleFullScreenMode, this);
  698. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  699. allMonitorsButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  700. RADIO_MIN_WIDTH,
  701. RADIO_HEIGHT,
  702. _("Full screen on all monitors")));
  703. allMonitorsButton->type(FL_RADIO_BUTTON);
  704. allMonitorsButton->callback(handleFullScreenMode, this);
  705. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  706. selectedMonitorsButton = new Fl_Round_Button(LBLRIGHT(tx, ty,
  707. RADIO_MIN_WIDTH,
  708. RADIO_HEIGHT,
  709. _("Full screen on selected monitor(s)")));
  710. selectedMonitorsButton->type(FL_RADIO_BUTTON);
  711. selectedMonitorsButton->callback(handleFullScreenMode, this);
  712. ty += RADIO_HEIGHT + TIGHT_MARGIN;
  713. monitorArrangement = new MonitorArrangement(
  714. tx + INDENT, ty,
  715. width - INDENT, 150);
  716. ty += 150 + TIGHT_MARGIN;
  717. }
  718. ty += GROUP_MARGIN - TIGHT_MARGIN;
  719. displayModeGroup->end();
  720. displayModeGroup->size(displayModeGroup->w(),
  721. ty - displayModeGroup->y());
  722. /* Back to normal */
  723. tx = orig_tx;
  724. ty += INNER_MARGIN;
  725. width = tw - OUTER_MARGIN * 2;
  726. group->end();
  727. }
  728. void OptionsDialog::createMiscPage(int tx, int ty, int tw, int th)
  729. {
  730. Fl_Group *group = new Fl_Group(tx, ty, tw, th, _("Misc."));
  731. tx += OUTER_MARGIN;
  732. ty += OUTER_MARGIN;
  733. sharedCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  734. CHECK_MIN_WIDTH,
  735. CHECK_HEIGHT,
  736. _("Shared (don't disconnect other viewers)")));
  737. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  738. reconnectCheckbox = new Fl_Check_Button(LBLRIGHT(tx, ty,
  739. CHECK_MIN_WIDTH,
  740. CHECK_HEIGHT,
  741. _("Ask to reconnect on connection errors")));
  742. ty += CHECK_HEIGHT + TIGHT_MARGIN;
  743. group->end();
  744. }
  745. void OptionsDialog::handleAutoselect(Fl_Widget *widget, void *data)
  746. {
  747. OptionsDialog *dialog = (OptionsDialog*)data;
  748. if (dialog->autoselectCheckbox->value()) {
  749. dialog->encodingGroup->deactivate();
  750. dialog->colorlevelGroup->deactivate();
  751. } else {
  752. dialog->encodingGroup->activate();
  753. dialog->colorlevelGroup->activate();
  754. }
  755. // JPEG setting is also affected by autoselection
  756. dialog->handleJpeg(dialog->jpegCheckbox, dialog);
  757. }
  758. void OptionsDialog::handleCompression(Fl_Widget *widget, void *data)
  759. {
  760. OptionsDialog *dialog = (OptionsDialog*)data;
  761. if (dialog->compressionCheckbox->value())
  762. dialog->compressionInput->activate();
  763. else
  764. dialog->compressionInput->deactivate();
  765. }
  766. void OptionsDialog::handleJpeg(Fl_Widget *widget, void *data)
  767. {
  768. OptionsDialog *dialog = (OptionsDialog*)data;
  769. if (dialog->jpegCheckbox->value() &&
  770. !dialog->autoselectCheckbox->value())
  771. dialog->jpegInput->activate();
  772. else
  773. dialog->jpegInput->deactivate();
  774. }
  775. void OptionsDialog::handleX509(Fl_Widget *widget, void *data)
  776. {
  777. OptionsDialog *dialog = (OptionsDialog*)data;
  778. if (dialog->encX509Checkbox->value()) {
  779. dialog->caInput->activate();
  780. dialog->crlInput->activate();
  781. } else {
  782. dialog->caInput->deactivate();
  783. dialog->crlInput->deactivate();
  784. }
  785. }
  786. void OptionsDialog::handleClipboard(Fl_Widget *widget, void *data)
  787. {
  788. #if !defined(WIN32) && !defined(__APPLE__)
  789. OptionsDialog *dialog = (OptionsDialog*)data;
  790. if (dialog->acceptClipboardCheckbox->value())
  791. dialog->setPrimaryCheckbox->activate();
  792. else
  793. dialog->setPrimaryCheckbox->deactivate();
  794. if (dialog->sendClipboardCheckbox->value())
  795. dialog->sendPrimaryCheckbox->activate();
  796. else
  797. dialog->sendPrimaryCheckbox->deactivate();
  798. #endif
  799. }
  800. void OptionsDialog::handleFullScreenMode(Fl_Widget *widget, void *data)
  801. {
  802. OptionsDialog *dialog = (OptionsDialog*)data;
  803. if (dialog->selectedMonitorsButton->value()) {
  804. dialog->monitorArrangement->activate();
  805. } else {
  806. dialog->monitorArrangement->deactivate();
  807. }
  808. }
  809. void OptionsDialog::handleCancel(Fl_Widget *widget, void *data)
  810. {
  811. OptionsDialog *dialog = (OptionsDialog*)data;
  812. dialog->hide();
  813. }
  814. void OptionsDialog::handleOK(Fl_Widget *widget, void *data)
  815. {
  816. OptionsDialog *dialog = (OptionsDialog*)data;
  817. dialog->hide();
  818. dialog->storeOptions();
  819. }