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 32KB

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