Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 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 | |
| 19 | #include <vncviewer/OptionsDialog.h> |
| 20 | #include <vncviewer/CConn.h> |
| 21 | #include <vncviewer/resource.h> |
| 22 | #include <rfb_win32/Registry.h> |
| 23 | #include <rfb_win32/MsgBox.h> |
| 24 | #include <rfb_win32/OSVersion.h> |
| 25 | #include <rfb/encodings.h> |
| 26 | #include <rfb/CConnection.h> |
| 27 | #include <commdlg.h> |
| 28 | #include <rfb/LogWriter.h> |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 29 | #include <rfb/Security.h> |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 30 | |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 31 | #include <list> |
| 32 | |
| 33 | using namespace rdr; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 34 | using namespace rfb; |
| 35 | using namespace rfb::win32; |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 36 | using namespace std; |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 37 | |
| 38 | static LogWriter vlog("Options"); |
| 39 | |
| 40 | |
| 41 | struct OptionsInfo { |
| 42 | CConn* view; |
| 43 | CConnOptions options; |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | OptionsDialog rfb::win32::OptionsDialog::global; |
| 48 | |
| 49 | |
| 50 | class ViewerOptions : public PropSheet { |
| 51 | public: |
| 52 | ViewerOptions(OptionsInfo& info_, std::list<PropSheetPage*> pages) |
| 53 | : PropSheet(GetModuleHandle(0), |
| 54 | info_.view ? _T("VNC Viewer Options") : _T("VNC Viewer Defaults"), pages), |
Peter Åstrand | e133cba | 2008-12-11 09:35:12 +0000 | [diff] [blame] | 55 | changed(false), info(info_) { |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 56 | } |
| 57 | ~ViewerOptions() { |
| 58 | if (changed) { |
| 59 | if (info.view) |
| 60 | // Apply the settings to the supplied session object |
| 61 | info.view->applyOptions(info.options); |
| 62 | else { |
| 63 | // Commit the settings to the user's registry area |
| 64 | info.options.writeDefaults(); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void setChanged() {changed = true;} |
| 70 | |
| 71 | bool changed; |
| 72 | OptionsInfo& info; |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | class FormatPage : public PropSheetPage { |
| 77 | public: |
| 78 | FormatPage(OptionsInfo* dlg_) |
| 79 | : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_FORMAT)), dlg(dlg_) { |
| 80 | } |
| 81 | virtual void initDialog() { |
| 82 | setItemChecked(IDC_ENCODING_AUTO, dlg->options.autoSelect); |
| 83 | setItemChecked(IDC_FORMAT_FULLCOLOUR, dlg->options.fullColour); |
| 84 | if (!dlg->options.fullColour) { |
| 85 | switch (dlg->options.lowColourLevel) { |
| 86 | case 0: setItemChecked(IDC_FORMAT_VERYLOWCOLOUR, true); break; |
| 87 | case 1: setItemChecked(IDC_FORMAT_LOWCOLOUR, true); break; |
| 88 | case 2: setItemChecked(IDC_FORMAT_MEDIUMCOLOUR, true); break; |
| 89 | } |
| 90 | } |
| 91 | switch (dlg->options.preferredEncoding) { |
| 92 | case encodingTight: setItemChecked(IDC_ENCODING_TIGHT, true); break; |
| 93 | case encodingZRLE: setItemChecked(IDC_ENCODING_ZRLE, true); break; |
| 94 | case encodingHextile: setItemChecked(IDC_ENCODING_HEXTILE, true); break; |
| 95 | case encodingRaw: setItemChecked(IDC_ENCODING_RAW, true); break; |
| 96 | } |
| 97 | setItemChecked(IDC_CUSTOM_COMPRESSLEVEL, dlg->options.customCompressLevel); |
| 98 | setItemInt(IDC_COMPRESSLEVEL, dlg->options.compressLevel); |
| 99 | setItemChecked(IDC_ALLOW_JPEG, !dlg->options.noJpeg); |
| 100 | setItemInt(IDC_QUALITYLEVEL, dlg->options.qualityLevel); |
| 101 | onCommand(IDC_ENCODING_AUTO, 0 /* ? */); // Force enableItem status to refresh |
| 102 | onCommand(IDC_CUSTOM_COMPRESSLEVEL, 0 /* ? */); // Force enableItem status to refresh |
| 103 | onCommand(IDC_ALLOW_JPEG, 0 /* ? */); // Force enableItem status to refresh |
| 104 | } |
| 105 | virtual bool onOk() { |
| 106 | dlg->options.autoSelect = isItemChecked(IDC_ENCODING_AUTO); |
| 107 | dlg->options.fullColour = isItemChecked(IDC_FORMAT_FULLCOLOUR); |
| 108 | dlg->options.customCompressLevel = isItemChecked(IDC_CUSTOM_COMPRESSLEVEL); |
| 109 | dlg->options.compressLevel = getItemInt(IDC_COMPRESSLEVEL); |
| 110 | dlg->options.noJpeg = !isItemChecked(IDC_ALLOW_JPEG); |
| 111 | dlg->options.qualityLevel = getItemInt(IDC_QUALITYLEVEL); |
| 112 | if (isItemChecked(IDC_FORMAT_VERYLOWCOLOUR)) |
| 113 | dlg->options.lowColourLevel = 0; |
| 114 | if (isItemChecked(IDC_FORMAT_LOWCOLOUR)) |
| 115 | dlg->options.lowColourLevel = 1; |
| 116 | if (isItemChecked(IDC_FORMAT_MEDIUMCOLOUR)) |
| 117 | dlg->options.lowColourLevel = 2; |
| 118 | dlg->options.preferredEncoding = encodingTight; |
| 119 | if (isItemChecked(IDC_ENCODING_ZRLE)) |
| 120 | dlg->options.preferredEncoding = encodingZRLE; |
| 121 | if (isItemChecked(IDC_ENCODING_HEXTILE)) |
| 122 | dlg->options.preferredEncoding = encodingHextile; |
| 123 | if (isItemChecked(IDC_ENCODING_RAW)) |
| 124 | dlg->options.preferredEncoding = encodingRaw; |
| 125 | ((ViewerOptions*)propSheet)->setChanged(); |
| 126 | return true; |
| 127 | } |
| 128 | virtual bool onCommand(int id, int cmd) { |
Pierre Ossman | 78b2359 | 2009-03-12 12:25:11 +0000 | [diff] [blame] | 129 | bool aut = isItemChecked(IDC_ENCODING_AUTO); |
| 130 | bool jpeg = isItemChecked(IDC_ALLOW_JPEG); |
| 131 | bool custom_comp = isItemChecked(IDC_CUSTOM_COMPRESSLEVEL); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 132 | if (id == IDC_ENCODING_AUTO) { |
Pierre Ossman | 78b2359 | 2009-03-12 12:25:11 +0000 | [diff] [blame] | 133 | enableItem(IDC_ENCODING_TIGHT, !aut); |
| 134 | enableItem(IDC_ENCODING_ZRLE, !aut); |
| 135 | enableItem(IDC_ENCODING_HEXTILE, !aut); |
| 136 | enableItem(IDC_ENCODING_RAW, !aut); |
| 137 | enableItem(IDC_FORMAT_FULLCOLOUR, !aut); |
| 138 | enableItem(IDC_FORMAT_MEDIUMCOLOUR, !aut); |
| 139 | enableItem(IDC_FORMAT_LOWCOLOUR, !aut); |
| 140 | enableItem(IDC_FORMAT_VERYLOWCOLOUR, !aut); |
| 141 | enableItem(IDC_QUALITYLEVEL, !aut && jpeg); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 142 | return true; |
| 143 | } |
| 144 | if (id == IDC_CUSTOM_COMPRESSLEVEL) { |
Pierre Ossman | 78b2359 | 2009-03-12 12:25:11 +0000 | [diff] [blame] | 145 | enableItem(IDC_COMPRESSLEVEL, custom_comp); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 146 | return true; |
| 147 | } |
| 148 | if (id == IDC_ALLOW_JPEG) { |
Pierre Ossman | 78b2359 | 2009-03-12 12:25:11 +0000 | [diff] [blame] | 149 | enableItem(IDC_QUALITYLEVEL, !aut && jpeg); |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 150 | return true; |
| 151 | } |
| 152 | return false; |
| 153 | } |
| 154 | protected: |
| 155 | OptionsInfo* dlg; |
| 156 | }; |
| 157 | |
| 158 | class MiscPage : public PropSheetPage { |
| 159 | public: |
| 160 | MiscPage(OptionsInfo* dlg_) |
| 161 | : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_MISC)), dlg(dlg_) { |
| 162 | } |
| 163 | virtual void initDialog() { |
| 164 | setItemChecked(IDC_CONN_SHARED, dlg->options.shared); |
| 165 | enableItem(IDC_CONN_SHARED, (!dlg->view) || (dlg->view->state() != CConnection::RFBSTATE_NORMAL)); |
| 166 | setItemChecked(IDC_FULL_SCREEN, dlg->options.fullScreen); |
| 167 | setItemChecked(IDC_LOCAL_CURSOR, dlg->options.useLocalCursor); |
| 168 | setItemChecked(IDC_DESKTOP_RESIZE, dlg->options.useDesktopResize); |
| 169 | enableItem(IDC_PROTOCOL_3_3, (!dlg->view) || (dlg->view->state() != CConnection::RFBSTATE_NORMAL)); |
| 170 | setItemChecked(IDC_PROTOCOL_3_3, dlg->options.protocol3_3); |
| 171 | setItemChecked(IDC_ACCEPT_BELL, dlg->options.acceptBell); |
| 172 | setItemChecked(IDC_AUTO_RECONNECT, dlg->options.autoReconnect); |
| 173 | setItemChecked(IDC_SHOW_TOOLBAR, dlg->options.showToolbar); |
george82 | 57160b0 | 2006-09-11 04:11:51 +0000 | [diff] [blame] | 174 | char scale_values[10][20] = { |
| 175 | "10","25","50","75","90","100","125","150","200","Auto" |
Constantin Kaplinsky | 1ae2eb0 | 2006-05-26 05:24:24 +0000 | [diff] [blame] | 176 | }; |
| 177 | HWND hScaleCombo = GetDlgItem(handle, IDC_COMBO_SCALE); |
george82 | 57160b0 | 2006-09-11 04:11:51 +0000 | [diff] [blame] | 178 | for (int i = 0; i <= 9; i++) { |
Constantin Kaplinsky | 1ae2eb0 | 2006-05-26 05:24:24 +0000 | [diff] [blame] | 179 | SendMessage(hScaleCombo, CB_INSERTSTRING, |
| 180 | (WPARAM)i, (LPARAM)(int FAR*)scale_values[i]); |
| 181 | } |
george82 | 04a7771 | 2006-05-29 14:18:14 +0000 | [diff] [blame] | 182 | if (dlg->options.autoScaling) { |
Adam Tkac | 8517ea5 | 2009-10-08 11:49:12 +0000 | [diff] [blame] | 183 | SetDlgItemText(handle, IDC_COMBO_SCALE, (LPCTSTR) "Auto"); |
george82 | 04a7771 | 2006-05-29 14:18:14 +0000 | [diff] [blame] | 184 | } else { |
| 185 | SetDlgItemInt(handle, IDC_COMBO_SCALE, dlg->options.scale, FALSE); |
| 186 | } |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 187 | } |
| 188 | virtual bool onOk() { |
| 189 | dlg->options.shared = isItemChecked(IDC_CONN_SHARED); |
| 190 | dlg->options.fullScreen = isItemChecked(IDC_FULL_SCREEN); |
| 191 | dlg->options.useLocalCursor = isItemChecked(IDC_LOCAL_CURSOR); |
| 192 | dlg->options.useDesktopResize = isItemChecked(IDC_DESKTOP_RESIZE); |
| 193 | dlg->options.protocol3_3 = isItemChecked(IDC_PROTOCOL_3_3); |
| 194 | dlg->options.acceptBell = isItemChecked(IDC_ACCEPT_BELL); |
| 195 | dlg->options.autoReconnect = isItemChecked(IDC_AUTO_RECONNECT); |
| 196 | dlg->options.showToolbar = isItemChecked(IDC_SHOW_TOOLBAR); |
george82 | 04a7771 | 2006-05-29 14:18:14 +0000 | [diff] [blame] | 197 | int s = GetDlgItemInt(handle, IDC_COMBO_SCALE, NULL, FALSE); |
| 198 | if (s > 0) { |
| 199 | dlg->options.scale = s; |
| 200 | dlg->options.autoScaling = false; |
george82 | 04a7771 | 2006-05-29 14:18:14 +0000 | [diff] [blame] | 201 | } else { |
| 202 | char scaleStr[20]; |
Adam Tkac | 8517ea5 | 2009-10-08 11:49:12 +0000 | [diff] [blame] | 203 | GetDlgItemText(handle, IDC_COMBO_SCALE, (LPTSTR) scaleStr, 20); |
| 204 | if (strcmp(scaleStr, (const char *) "Auto") == 0) { |
george82 | 04a7771 | 2006-05-29 14:18:14 +0000 | [diff] [blame] | 205 | dlg->options.autoScaling = true; |
george82 | 04a7771 | 2006-05-29 14:18:14 +0000 | [diff] [blame] | 206 | } |
| 207 | } |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 208 | ((ViewerOptions*)propSheet)->setChanged(); |
| 209 | return true; |
| 210 | } |
george82 | a9a3387 | 2007-04-30 11:37:36 +0000 | [diff] [blame] | 211 | virtual bool onCommand(int id, int cmd) { |
| 212 | if (id == IDC_COMBO_SCALE) { |
| 213 | if (cmd == CBN_SELENDOK || cmd == CBN_EDITCHANGE) { |
| 214 | char scaleStr[20]; |
| 215 | if (cmd == CBN_SELENDOK) { |
| 216 | HWND handleComboScale = GetDlgItem(handle, IDC_COMBO_SCALE); |
| 217 | int index = SendMessage(handleComboScale, CB_GETCURSEL, 0, 0); |
| 218 | SendMessage(handleComboScale, CB_GETLBTEXT, (WPARAM)index, (LPARAM)scaleStr); |
| 219 | } else { |
Adam Tkac | 8517ea5 | 2009-10-08 11:49:12 +0000 | [diff] [blame] | 220 | GetDlgItemText(handle, IDC_COMBO_SCALE, (LPTSTR) scaleStr, 20); |
george82 | a9a3387 | 2007-04-30 11:37:36 +0000 | [diff] [blame] | 221 | } |
george82 | a9a3387 | 2007-04-30 11:37:36 +0000 | [diff] [blame] | 222 | return true; |
| 223 | } |
| 224 | } |
| 225 | return false; |
| 226 | } |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 227 | protected: |
| 228 | OptionsInfo* dlg; |
| 229 | }; |
| 230 | |
| 231 | class InputsPage : public PropSheetPage { |
| 232 | public: |
| 233 | InputsPage(OptionsInfo* dlg_) |
| 234 | : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_INPUTS)), dlg(dlg_) { |
| 235 | } |
| 236 | virtual void initDialog() { |
| 237 | setItemChecked(IDC_SEND_POINTER, dlg->options.sendPtrEvents); |
| 238 | setItemChecked(IDC_SEND_KEYS, dlg->options.sendKeyEvents); |
| 239 | setItemChecked(IDC_CLIENT_CUTTEXT, dlg->options.clientCutText); |
| 240 | setItemChecked(IDC_SERVER_CUTTEXT, dlg->options.serverCutText); |
| 241 | setItemChecked(IDC_DISABLE_WINKEYS, dlg->options.disableWinKeys && !osVersion.isPlatformWindows); |
| 242 | enableItem(IDC_DISABLE_WINKEYS, !osVersion.isPlatformWindows); |
| 243 | setItemChecked(IDC_EMULATE3, dlg->options.emulate3); |
| 244 | setItemChecked(IDC_POINTER_INTERVAL, dlg->options.pointerEventInterval != 0); |
| 245 | |
| 246 | // Populate the Menu Key tab |
| 247 | HWND menuKey = GetDlgItem(handle, IDC_MENU_KEY); |
| 248 | SendMessage(menuKey, CB_RESETCONTENT, 0, 0); |
| 249 | SendMessage(menuKey, CB_ADDSTRING, 0, (LPARAM)_T("none")); |
| 250 | if (!dlg->options.menuKey) |
| 251 | SendMessage(menuKey, CB_SETCURSEL, 0, 0); |
Peter Åstrand | ebf7775 | 2010-02-10 12:45:50 +0000 | [diff] [blame] | 252 | for (unsigned int i=0; i<12; i++) { |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 253 | TCHAR buf[4]; |
| 254 | _stprintf(buf, _T("F%d"), i+1); |
| 255 | int index = SendMessage(menuKey, CB_ADDSTRING, 0, (LPARAM)buf); |
| 256 | if (i == (dlg->options.menuKey - VK_F1)) |
| 257 | SendMessage(menuKey, CB_SETCURSEL, index, 0); |
| 258 | } |
| 259 | } |
| 260 | virtual bool onOk() { |
| 261 | dlg->options.sendPtrEvents = isItemChecked(IDC_SEND_POINTER); |
| 262 | dlg->options.sendKeyEvents = isItemChecked(IDC_SEND_KEYS); |
| 263 | dlg->options.clientCutText = isItemChecked(IDC_CLIENT_CUTTEXT); |
| 264 | dlg->options.serverCutText = isItemChecked(IDC_SERVER_CUTTEXT); |
| 265 | dlg->options.disableWinKeys = isItemChecked(IDC_DISABLE_WINKEYS); |
| 266 | dlg->options.emulate3 = isItemChecked(IDC_EMULATE3); |
| 267 | dlg->options.pointerEventInterval = |
| 268 | isItemChecked(IDC_POINTER_INTERVAL) ? 200 : 0; |
| 269 | |
| 270 | HWND mkHwnd = GetDlgItem(handle, IDC_MENU_KEY); |
| 271 | int index = SendMessage(mkHwnd, CB_GETCURSEL, 0, 0); |
| 272 | TCharArray keyName(SendMessage(mkHwnd, CB_GETLBTEXTLEN, index, 0)+1); |
| 273 | SendMessage(mkHwnd, CB_GETLBTEXT, index, (LPARAM)keyName.buf); |
| 274 | if (_tcscmp(keyName.buf, _T("none")) == 0) |
| 275 | dlg->options.setMenuKey(""); |
| 276 | else |
| 277 | dlg->options.setMenuKey(CStr(keyName.buf)); |
| 278 | |
| 279 | ((ViewerOptions*)propSheet)->setChanged(); |
| 280 | return true; |
| 281 | } |
| 282 | protected: |
| 283 | OptionsInfo* dlg; |
| 284 | }; |
| 285 | |
| 286 | class DefaultsPage : public PropSheetPage { |
| 287 | public: |
| 288 | DefaultsPage(OptionsInfo* dlg_) |
| 289 | : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_DEFAULTS)), dlg(dlg_) { |
| 290 | } |
| 291 | virtual void initDialog() { |
| 292 | enableItem(IDC_LOAD_CONFIG, dlg->options.configFileName.buf); |
| 293 | enableItem(IDC_SAVE_CONFIG, dlg->options.configFileName.buf); |
| 294 | } |
| 295 | virtual bool onCommand(int id, int cmd) { |
| 296 | switch (id) { |
| 297 | case IDC_LOAD_DEFAULTS: |
| 298 | dlg->options = CConnOptions(); |
| 299 | break; |
| 300 | case IDC_SAVE_DEFAULTS: |
| 301 | propSheet->commitPages(); |
| 302 | dlg->options.writeDefaults(); |
| 303 | break; |
| 304 | case IDC_LOAD_CONFIG: |
| 305 | dlg->options.readFromFile(dlg->options.configFileName.buf); |
| 306 | break; |
| 307 | case IDC_SAVE_CONFIG: |
| 308 | propSheet->commitPages(); |
| 309 | dlg->options.writeToFile(dlg->options.configFileName.buf); |
| 310 | MsgBox(handle, _T("Options saved successfully"), |
| 311 | MB_OK | MB_ICONINFORMATION); |
| 312 | return 0; |
| 313 | case IDC_SAVE_CONFIG_AS: |
| 314 | propSheet->commitPages(); |
| 315 | // Get a filename to save to |
| 316 | TCHAR newFilename[4096]; |
| 317 | TCHAR currentDir[4096]; |
| 318 | if (dlg->options.configFileName.buf) |
| 319 | _tcscpy(newFilename, TStr(dlg->options.configFileName.buf)); |
| 320 | else |
| 321 | newFilename[0] = 0; |
| 322 | OPENFILENAME ofn; |
| 323 | memset(&ofn, 0, sizeof(ofn)); |
| 324 | #ifdef OPENFILENAME_SIZE_VERSION_400 |
| 325 | ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; |
| 326 | #else |
| 327 | ofn.lStructSize = sizeof(ofn); |
| 328 | #endif |
| 329 | ofn.hwndOwner = handle; |
| 330 | ofn.lpstrFilter = _T("VNC Connection Options\000*.vnc\000"); |
| 331 | ofn.lpstrFile = newFilename; |
| 332 | currentDir[0] = 0; |
| 333 | GetCurrentDirectory(4096, currentDir); |
| 334 | ofn.lpstrInitialDir = currentDir; |
| 335 | ofn.nMaxFile = 4096; |
| 336 | ofn.lpstrDefExt = _T(".vnc"); |
| 337 | ofn.Flags = OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST; |
| 338 | if (!GetSaveFileName(&ofn)) { |
| 339 | if (CommDlgExtendedError()) |
| 340 | throw rdr::Exception("GetSaveFileName failed"); |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | // Save the Options |
| 345 | dlg->options.writeToFile(CStr(newFilename)); |
| 346 | MsgBox(handle, _T("Options saved successfully"), |
| 347 | MB_OK | MB_ICONINFORMATION); |
| 348 | return 0; |
| 349 | }; |
| 350 | propSheet->reInitPages(); |
| 351 | return true; |
| 352 | } |
| 353 | protected: |
| 354 | OptionsInfo* dlg; |
| 355 | }; |
| 356 | |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 357 | #ifdef HAVE_GNUTLS |
| 358 | /* XXX: This class contains bunch of similar code to unix/vncviewer/CConn.cxx */ |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 359 | class SecurityPage : public PropSheetPage { |
| 360 | public: |
| 361 | SecurityPage(OptionsInfo* dlg_, Security *security_) |
| 362 | : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_SECURITY)), |
| 363 | dlg(dlg_), security(security_) { |
| 364 | } |
| 365 | virtual void initDialog() { |
| 366 | enableVeNCryptFeatures(false); |
| 367 | |
| 368 | /* Process non-VeNCrypt sectypes */ |
| 369 | list<U8> secTypes = security->GetEnabledSecTypes(); |
| 370 | list<U8>::iterator i; |
| 371 | |
| 372 | for (i = secTypes.begin(); i != secTypes.end(); i++) { |
| 373 | switch (*i) { |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 374 | case secTypeVeNCrypt: |
| 375 | enableVeNCryptFeatures(true); |
| 376 | setItemChecked(IDC_VENCRYPT, true); |
| 377 | break; |
| 378 | case secTypeNone: |
| 379 | setItemChecked(IDC_ENC_NONE, true); |
| 380 | setItemChecked(IDC_AUTH_NONE, true); |
| 381 | break; |
| 382 | case secTypeVncAuth: |
| 383 | setItemChecked(IDC_ENC_NONE, true); |
| 384 | setItemChecked(IDC_AUTH_VNC, true); |
| 385 | break; |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | /* Process VeNCrypt subtypes */ |
| 390 | if (isItemChecked(IDC_VENCRYPT)) { |
| 391 | list<U32> secTypesExt = security->GetEnabledExtSecTypes(); |
| 392 | list<U32>::iterator iext; |
| 393 | for (iext = secTypesExt.begin(); iext != secTypesExt.end(); iext++) { |
| 394 | switch (*iext) { |
| 395 | case secTypePlain: |
| 396 | setItemChecked(IDC_ENC_NONE, true); |
| 397 | setItemChecked(IDC_AUTH_PLAIN, true); |
| 398 | break; |
| 399 | case secTypeTLSNone: |
| 400 | setItemChecked(IDC_ENC_TLS, true); |
| 401 | setItemChecked(IDC_AUTH_NONE, true); |
| 402 | break; |
| 403 | case secTypeTLSVnc: |
| 404 | setItemChecked(IDC_ENC_TLS, true); |
| 405 | setItemChecked(IDC_AUTH_VNC, true); |
| 406 | break; |
| 407 | case secTypeTLSPlain: |
| 408 | setItemChecked(IDC_ENC_TLS, true); |
| 409 | setItemChecked(IDC_AUTH_PLAIN, true); |
| 410 | break; |
| 411 | case secTypeX509None: |
| 412 | setItemChecked(IDC_ENC_X509, true); |
| 413 | setItemChecked(IDC_AUTH_NONE, true); |
| 414 | enableItem(IDC_LOAD_CACERT, true); |
| 415 | enableItem(IDC_LOAD_CRLCERT, true); |
| 416 | break; |
| 417 | case secTypeX509Vnc: |
| 418 | setItemChecked(IDC_ENC_X509, true); |
| 419 | setItemChecked(IDC_AUTH_VNC, true); |
| 420 | enableItem(IDC_LOAD_CACERT, true); |
| 421 | enableItem(IDC_LOAD_CRLCERT, true); |
| 422 | break; |
| 423 | case secTypeX509Plain: |
| 424 | setItemChecked(IDC_ENC_X509, true); |
| 425 | setItemChecked(IDC_AUTH_PLAIN, true); |
| 426 | enableItem(IDC_LOAD_CACERT, true); |
| 427 | enableItem(IDC_LOAD_CRLCERT, true); |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 433 | |
Adam Tkac | 3fed5a4 | 2010-12-08 13:48:29 +0000 | [diff] [blame^] | 434 | virtual bool onOk() { |
| 435 | dlg->options.secTypes = security->GetEnabledExtSecTypes(); |
| 436 | if (isItemChecked(IDC_VENCRYPT)) |
| 437 | dlg->options.secTypes.push_front(secTypeVeNCrypt); |
| 438 | return true; |
| 439 | } |
| 440 | |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 441 | virtual bool onCommand(int id, int cmd) { |
| 442 | switch (id) { |
| 443 | case IDC_VENCRYPT: |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 444 | if (isItemChecked(IDC_VENCRYPT)) { |
| 445 | enableVeNCryptFeatures(true); |
| 446 | security->EnableSecType(secTypeVeNCrypt); |
| 447 | } else { |
| 448 | enableVeNCryptFeatures(false); |
| 449 | security->DisableSecType(secTypeVeNCrypt); |
| 450 | } |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 451 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 452 | |
| 453 | /* Process types without encryption */ |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 454 | case IDC_ENC_NONE: |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 455 | if (isItemChecked(IDC_ENC_NONE)) { |
| 456 | vlog.debug("here"); |
| 457 | if (isItemChecked(IDC_AUTH_NONE)) |
| 458 | security->EnableSecType(secTypeNone); |
| 459 | if (isItemChecked(IDC_AUTH_VNC)) |
| 460 | security->EnableSecType(secTypeVncAuth); |
| 461 | if (isItemChecked(IDC_AUTH_PLAIN)) |
| 462 | security->EnableSecType(secTypePlain); |
| 463 | } else { |
| 464 | security->DisableSecType(secTypeNone); |
| 465 | security->DisableSecType(secTypeVncAuth); |
| 466 | security->DisableSecType(secTypePlain); |
| 467 | } |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 468 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 469 | |
| 470 | /* Process security types which use TLS encryption */ |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 471 | case IDC_ENC_TLS: |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 472 | if (isItemChecked(IDC_ENC_TLS)) { |
| 473 | if (isItemChecked(IDC_AUTH_NONE)) |
| 474 | security->EnableSecType(secTypeTLSNone); |
| 475 | if (isItemChecked(IDC_AUTH_VNC)) |
| 476 | security->EnableSecType(secTypeTLSVnc); |
| 477 | if (isItemChecked(IDC_AUTH_PLAIN)) |
| 478 | security->EnableSecType(secTypeTLSPlain); |
| 479 | } else { |
| 480 | security->DisableSecType(secTypeTLSNone); |
| 481 | security->DisableSecType(secTypeTLSVnc); |
| 482 | security->DisableSecType(secTypeTLSPlain); |
| 483 | } |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 484 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 485 | |
| 486 | /* Process security types which use X509 encryption */ |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 487 | case IDC_ENC_X509: |
| 488 | if (isItemChecked(IDC_ENC_X509)) { |
| 489 | enableItem(IDC_LOAD_CACERT, true); |
| 490 | enableItem(IDC_LOAD_CRLCERT, true); |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 491 | if (isItemChecked(IDC_AUTH_NONE)) |
| 492 | security->EnableSecType(secTypeX509None); |
| 493 | if (isItemChecked(IDC_AUTH_VNC)) |
| 494 | security->EnableSecType(secTypeX509Vnc); |
| 495 | if (isItemChecked(IDC_AUTH_PLAIN)) |
| 496 | security->EnableSecType(secTypeX509Plain); |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 497 | } else { |
| 498 | enableItem(IDC_LOAD_CACERT, false); |
| 499 | enableItem(IDC_LOAD_CRLCERT, false); |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 500 | security->DisableSecType(secTypeX509None); |
| 501 | security->DisableSecType(secTypeX509Vnc); |
| 502 | security->DisableSecType(secTypeX509Plain); |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 503 | } |
| 504 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 505 | |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 506 | case IDC_LOAD_CACERT: |
| 507 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 508 | |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 509 | case IDC_LOAD_CRLCERT: |
| 510 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 511 | |
| 512 | /* Process *None security types */ |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 513 | case IDC_AUTH_NONE: |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 514 | if (isItemChecked(IDC_AUTH_NONE)) { |
| 515 | if (isItemChecked(IDC_ENC_NONE)) |
| 516 | security->EnableSecType(secTypeNone); |
| 517 | if (isItemChecked(IDC_ENC_TLS)) |
| 518 | security->EnableSecType(secTypeTLSNone); |
| 519 | if (isItemChecked(IDC_ENC_X509)) |
| 520 | security->EnableSecType(secTypeX509None); |
| 521 | } else { |
| 522 | security->DisableSecType(secTypeNone); |
| 523 | security->DisableSecType(secTypeTLSNone); |
| 524 | security->DisableSecType(secTypeX509None); |
| 525 | } |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 526 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 527 | |
| 528 | /* Process *Vnc security types */ |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 529 | case IDC_AUTH_VNC: |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 530 | if (isItemChecked(IDC_AUTH_VNC)) { |
| 531 | if (isItemChecked(IDC_ENC_NONE)) |
| 532 | security->EnableSecType(secTypeVncAuth); |
| 533 | if (isItemChecked(IDC_ENC_TLS)) |
| 534 | security->EnableSecType(secTypeTLSVnc); |
| 535 | if (isItemChecked(IDC_ENC_X509)) |
| 536 | security->EnableSecType(secTypeX509Vnc); |
| 537 | } else { |
| 538 | security->DisableSecType(secTypeVncAuth); |
| 539 | security->DisableSecType(secTypeTLSVnc); |
| 540 | security->DisableSecType(secTypeX509Vnc); |
| 541 | } |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 542 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 543 | |
| 544 | /* Process *Plain security types */ |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 545 | case IDC_AUTH_PLAIN: |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 546 | if (isItemChecked(IDC_AUTH_PLAIN)) { |
| 547 | if (isItemChecked(IDC_ENC_NONE)) |
| 548 | security->EnableSecType(secTypePlain); |
| 549 | if (isItemChecked(IDC_ENC_TLS)) |
| 550 | security->EnableSecType(secTypeTLSPlain); |
| 551 | if (isItemChecked(IDC_ENC_X509)) |
| 552 | security->EnableSecType(secTypeX509Plain); |
| 553 | } else { |
| 554 | security->DisableSecType(secTypePlain); |
| 555 | security->DisableSecType(secTypeTLSPlain); |
| 556 | security->DisableSecType(secTypeX509Plain); |
| 557 | } |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 558 | break; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 559 | |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 560 | default: |
| 561 | throw rdr::Exception("Unhandled action in SecurityPage"); |
| 562 | } |
| 563 | return true; |
| 564 | } |
| 565 | protected: |
| 566 | OptionsInfo* dlg; |
| 567 | private: |
| 568 | Security *security; |
| 569 | |
| 570 | void enableVeNCryptFeatures(bool enable) { |
| 571 | if (enable) { |
| 572 | enableItem(IDC_ENC_TLS, true); |
| 573 | enableItem(IDC_ENC_X509, true); |
| 574 | enableItem(IDC_AUTH_PLAIN, true); |
| 575 | } else { |
| 576 | disableFeature(IDC_ENC_TLS); |
| 577 | disableFeature(IDC_ENC_X509); |
| 578 | disableFeature(IDC_AUTH_PLAIN); |
| 579 | enableItem(IDC_LOAD_CACERT, false); |
| 580 | enableItem(IDC_LOAD_CRLCERT, false); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | void disableFeature(int id) { |
| 585 | enableItem(id, false); |
| 586 | setItemChecked(id, false); |
| 587 | } |
| 588 | }; |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 589 | #endif |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 590 | |
| 591 | OptionsDialog::OptionsDialog() : visible(false) { |
| 592 | } |
| 593 | |
| 594 | bool OptionsDialog::showDialog(CConn* view, bool capture) { |
| 595 | if (visible) return false; |
| 596 | visible = true; |
| 597 | |
| 598 | // Grab the current properties |
| 599 | OptionsInfo info; |
| 600 | if (view) |
| 601 | info.options = view->getOptions(); |
| 602 | info.view = view; |
| 603 | |
| 604 | // Build a list of pages to display |
| 605 | std::list<PropSheetPage*> pages; |
| 606 | FormatPage formatPage(&info); pages.push_back(&formatPage); |
| 607 | InputsPage inputsPage(&info); pages.push_back(&inputsPage); |
| 608 | MiscPage miscPage(&info); pages.push_back(&miscPage); |
| 609 | DefaultsPage defPage(&info); if (view) pages.push_back(&defPage); |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 610 | #ifdef HAVE_GNUTLS |
Adam Tkac | d3b4dea | 2010-12-08 13:45:40 +0000 | [diff] [blame] | 611 | SecurityPage secPage(&info, view->security); pages.push_back(&secPage); |
Adam Tkac | 243fd7c | 2010-12-08 13:47:41 +0000 | [diff] [blame] | 612 | #endif |
Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 613 | |
| 614 | // Show the property sheet |
| 615 | ViewerOptions dialog(info, pages); |
| 616 | dialog.showPropSheet(view && view->getWindow() ? view->getWindow()->getHandle() : 0, |
| 617 | false, false, capture); |
| 618 | |
| 619 | visible = false; |
| 620 | return dialog.changed; |
| 621 | } |