blob: 0c35accd4232e3cc9e8c64fcc47789ccf5a16898 [file] [log] [blame]
Constantin Kaplinskyac306682006-05-16 08:48:31 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00003 * 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
Constantin Kaplinskyac306682006-05-16 08:48:31 +000019#include <vncviewer/CConnOptions.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000020#include <rfb/Configuration.h>
21#include <rfb/encodings.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000022#include <rfb/LogWriter.h>
Constantin Kaplinskyac306682006-05-16 08:48:31 +000023#include <rfb_win32/MsgBox.h>
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000024#include <rfb_win32/Registry.h>
25#include <rdr/HexInStream.h>
26#include <rdr/HexOutStream.h>
27#include <stdlib.h>
28
29using namespace rfb;
30using namespace rfb::win32;
31
Peter Åstrand3e3c75e2005-01-03 13:32:28 +000032static StringParameter passwordFile("PasswordFile",
33 "Password file for VNC authentication", "");
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000034
Constantin Kaplinskyac306682006-05-16 08:48:31 +000035// - Settings stored in the registry & in .vnc files, by Save Defaults and
36// Save Configuration respectively.
37
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000038static BoolParameter useLocalCursor("UseLocalCursor", "Render the mouse cursor locally", true);
39static BoolParameter useDesktopResize("UseDesktopResize", "Support dynamic desktop resizing", true);
40
Peter Åstrandc81a6522004-12-30 11:32:08 +000041static BoolParameter fullColour("FullColor",
42 "Use full color", true);
43static AliasParameter fullColourAlias("FullColour", "Alias for FullColor", &fullColour);
44
45static IntParameter lowColourLevel("LowColorLevel",
46 "Color level to use on slow connections. "
47 "0 = Very Low (8 colors), 1 = Low (64 colors), 2 = Medium (256 colors)",
Peter Åstranddd747d82004-12-21 15:54:44 +000048 2);
Peter Åstrandc81a6522004-12-30 11:32:08 +000049static AliasParameter lowColourLevelAlias("LowColourLevel", "Alias for LowColorLevel", &lowColourLevel);
50
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000051static BoolParameter fullScreen("FullScreen",
52 "Use the whole display to show the remote desktop."
53 "(Press F8 to access the viewer menu)",
54 false);
55static StringParameter preferredEncoding("PreferredEncoding",
Peter Åstrand55855d52005-01-03 12:01:45 +000056 "Preferred encoding to use (Tight, ZRLE, Hextile or"
57 " Raw)", "Tight");
58static BoolParameter autoSelect("AutoSelect",
59 "Auto select pixel format and encoding. "
60 "Default if PreferredEncoding and FullColor are not specified.",
61 true);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000062static BoolParameter sharedConnection("Shared",
63 "Allow existing connections to the server to continue."
64 "(Default is to disconnect all other clients)",
65 false);
66
67static BoolParameter sendPtrEvents("SendPointerEvents",
68 "Send pointer (mouse) events to the server.", true);
69static BoolParameter sendKeyEvents("SendKeyEvents",
70 "Send key presses (and releases) to the server.", true);
Peter Åstrand57dcc452005-01-28 14:52:50 +000071static BoolParameter sendSysKeys("SendSysKeys",
72 "Send system keys (Alt combinations) to the server.", true);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000073
74static BoolParameter clientCutText("ClientCutText",
75 "Send clipboard changes to the server.", true);
76static BoolParameter serverCutText("ServerCutText",
77 "Accept clipboard changes from the server.", true);
78
Constantin Kaplinskyac306682006-05-16 08:48:31 +000079static BoolParameter disableWinKeys("DisableWinKeys",
80 "Pass special Windows keys directly to the server.", true);
81
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000082static BoolParameter protocol3_3("Protocol3.3",
83 "Only use protocol version 3.3", false);
84
85static IntParameter ptrEventInterval("PointerEventInterval",
86 "The interval to delay between sending one pointer event "
87 "and the next.", 0);
88static BoolParameter emulate3("Emulate3",
89 "Emulate middle mouse button when left and right buttons "
90 "are used simulatenously.", false);
91
92static BoolParameter acceptBell("AcceptBell",
93 "Produce a system beep when requested to by the server.",
94 true);
95
george82baa71192005-11-30 16:17:46 +000096static BoolParameter showToolbar("ShowToolbar", "Show toolbar by default.", true);
97
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000098static StringParameter monitor("Monitor", "The monitor to open the VNC Viewer window on, if available.", "");
99static StringParameter menuKey("MenuKey", "The key which brings up the popup menu", "F8");
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000100static BoolParameter autoReconnect("AutoReconnect", "Offer to reconnect to the remote server if the connection"
101 "is dropped because an error occurs.", true);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000102
Peter Åstrand365427a2004-12-29 10:59:03 +0000103static BoolParameter customCompressLevel("CustomCompressLevel",
Peter Åstrand55855d52005-01-03 12:01:45 +0000104 "Use custom compression level. "
105 "Default if CompressLevel is specified.", false);
Peter Åstrand365427a2004-12-29 10:59:03 +0000106
107static IntParameter compressLevel("CompressLevel",
108 "Use specified compression level"
109 "0 = Low, 9 = High",
110 6);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000111
Peter Åstrand0b870262004-12-28 15:55:46 +0000112static BoolParameter noJpeg("NoJPEG",
113 "Disable lossy JPEG compression in Tight encoding.",
114 false);
115
Peter Åstrand365427a2004-12-29 10:59:03 +0000116static IntParameter qualityLevel("QualityLevel",
117 "JPEG quality level. "
118 "0 = Low, 9 = High",
119 6);
120
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000121CConnOptions::CConnOptions()
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000122: useLocalCursor(::useLocalCursor), useDesktopResize(::useDesktopResize),
123autoSelect(::autoSelect), fullColour(::fullColour), fullScreen(::fullScreen),
Peter Åstrand57dcc452005-01-28 14:52:50 +0000124shared(::sharedConnection), sendPtrEvents(::sendPtrEvents), sendKeyEvents(::sendKeyEvents), sendSysKeys(::sendSysKeys),
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000125preferredEncoding(encodingZRLE), clientCutText(::clientCutText), serverCutText(::serverCutText),
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000126disableWinKeys(::disableWinKeys), protocol3_3(::protocol3_3), acceptBell(::acceptBell),
127lowColourLevel(::lowColourLevel), pointerEventInterval(ptrEventInterval),
128emulate3(::emulate3), monitor(::monitor.getData()), showToolbar(::showToolbar),
Peter Åstrand365427a2004-12-29 10:59:03 +0000129customCompressLevel(::customCompressLevel), compressLevel(::compressLevel),
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000130noJpeg(::noJpeg), qualityLevel(::qualityLevel), passwordFile(::passwordFile.getData()),
131autoReconnect(::autoReconnect)
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000132{
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000133 if (autoSelect) {
134 preferredEncoding = encodingZRLE;
135 } else {
136 CharArray encodingName(::preferredEncoding.getData());
137 preferredEncoding = encodingNum(encodingName.buf);
138 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000139 setMenuKey(CharArray(::menuKey.getData()).buf);
Peter Åstrand55855d52005-01-03 12:01:45 +0000140
141 if (!::autoSelect.hasBeenSet()) {
142 // Default to AutoSelect=0 if -PreferredEncoding or -FullColor is used
143 autoSelect = (!::preferredEncoding.hasBeenSet()
144 && !::fullColour.hasBeenSet()
145 && !::fullColourAlias.hasBeenSet());
146 }
147 if (!::customCompressLevel.hasBeenSet()) {
148 // Default to CustomCompressLevel=1 if CompressLevel is used.
149 customCompressLevel = ::compressLevel.hasBeenSet();
150 }
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000151}
152
153
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000154void CConnOptions::readFromFile(const char* filename) {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000155 FILE* f = fopen(filename, "r");
156 if (!f)
157 throw rdr::Exception("Failed to read configuration file");
158
159 try {
160 char line[4096];
161 CharArray section;
162
163 CharArray hostTmp;
164 int portTmp = 0;
165
166 while (!feof(f)) {
167 // Read the next line
168 if (!fgets(line, sizeof(line), f)) {
169 if (feof(f))
170 break;
171 throw rdr::SystemException("fgets", ferror(f));
172 }
173 int len=strlen(line);
174 if (line[len-1] == '\n') {
175 line[len-1] = 0;
176 len--;
177 }
178
179 // Process the line
180 if (line[0] == ';') {
181 // Comment
182 } else if (line[0] == '[') {
183 // Entering a new section
184 if (!strSplit(&line[1], ']', &section.buf, 0))
185 throw rdr::Exception("bad Section");
186 } else {
187 // Reading an option
188 CharArray name;
189 CharArray value;
190 if (!strSplit(line, '=', &name.buf, &value.buf))
191 throw rdr::Exception("bad Name/Value pair");
192
193 if (stricmp(section.buf, "Connection") == 0) {
194 if (stricmp(name.buf, "Host") == 0) {
195 hostTmp.replaceBuf(value.takeBuf());
196 } else if (stricmp(name.buf, "Port") == 0) {
197 portTmp = atoi(value.buf);
198 } else if (stricmp(name.buf, "UserName") == 0) {
199 userName.replaceBuf(value.takeBuf());
200 } else if (stricmp(name.buf, "Password") == 0) {
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000201 ObfuscatedPasswd obfPwd;
202 rdr::HexInStream::hexStrToBin(value.buf, (char**)&obfPwd.buf, &obfPwd.length);
203 PlainPasswd passwd(obfPwd);
204 password.replaceBuf(passwd.takeBuf());
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000205 }
206 } else if (stricmp(section.buf, "Options") == 0) {
207 // V4 options
208 if (stricmp(name.buf, "UseLocalCursor") == 0) {
209 useLocalCursor = atoi(value.buf);
210 } else if (stricmp(name.buf, "UseDesktopResize") == 0) {
211 useDesktopResize = atoi(value.buf);
212 } else if (stricmp(name.buf, "FullScreen") == 0) {
213 fullScreen = atoi(value.buf);
214 } else if (stricmp(name.buf, "FullColour") == 0) {
215 fullColour = atoi(value.buf);
216 } else if (stricmp(name.buf, "LowColourLevel") == 0) {
217 lowColourLevel = atoi(value.buf);
218 } else if (stricmp(name.buf, "PreferredEncoding") == 0) {
219 preferredEncoding = encodingNum(value.buf);
220 } else if ((stricmp(name.buf, "AutoDetect") == 0) ||
221 (stricmp(name.buf, "AutoSelect") == 0)) {
222 autoSelect = atoi(value.buf);
223 } else if (stricmp(name.buf, "Shared") == 0) {
224 shared = atoi(value.buf);
225 } else if (stricmp(name.buf, "SendPtrEvents") == 0) {
226 sendPtrEvents = atoi(value.buf);
227 } else if (stricmp(name.buf, "SendKeyEvents") == 0) {
228 sendKeyEvents = atoi(value.buf);
Peter Åstrand57dcc452005-01-28 14:52:50 +0000229 } else if (stricmp(name.buf, "SendSysKeys") == 0) {
230 sendSysKeys = atoi(value.buf);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000231 } else if (stricmp(name.buf, "SendCutText") == 0) {
232 clientCutText = atoi(value.buf);
233 } else if (stricmp(name.buf, "AcceptCutText") == 0) {
234 serverCutText = atoi(value.buf);
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000235 } else if (stricmp(name.buf, "DisableWinKeys") == 0) {
236 disableWinKeys = atoi(value.buf);
george82985da922005-12-03 06:08:30 +0000237 } else if (stricmp(name.buf, "AcceptBell") == 0) {
238 acceptBell = atoi(value.buf);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000239 } else if (stricmp(name.buf, "Emulate3") == 0) {
240 emulate3 = atoi(value.buf);
george82baa71192005-11-30 16:17:46 +0000241 } else if (stricmp(name.buf, "ShowToolbar") == 0) {
242 showToolbar = atoi(value.buf);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000243 } else if (stricmp(name.buf, "PointerEventInterval") == 0) {
244 pointerEventInterval = atoi(value.buf);
245 } else if (stricmp(name.buf, "Monitor") == 0) {
246 monitor.replaceBuf(value.takeBuf());
247 } else if (stricmp(name.buf, "MenuKey") == 0) {
248 setMenuKey(value.buf);
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000249 } else if (stricmp(name.buf, "AutoReconnect") == 0) {
250 autoReconnect = atoi(value.buf);
251
Peter Åstrand365427a2004-12-29 10:59:03 +0000252 } else if (stricmp(name.buf, "CustomCompressLevel") == 0) {
253 customCompressLevel = atoi(value.buf);
254 } else if (stricmp(name.buf, "CompressLevel") == 0) {
255 compressLevel = atoi(value.buf);
Peter Åstrand0b870262004-12-28 15:55:46 +0000256 } else if (stricmp(name.buf, "NoJPEG") == 0) {
257 noJpeg = atoi(value.buf);
Peter Åstrand365427a2004-12-29 10:59:03 +0000258 } else if (stricmp(name.buf, "QualityLevel") == 0) {
259 qualityLevel = atoi(value.buf);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000260 // Legacy options
261 } else if (stricmp(name.buf, "Preferred_Encoding") == 0) {
262 preferredEncoding = atoi(value.buf);
263 } else if (stricmp(name.buf, "8bit") == 0) {
264 fullColour = !atoi(value.buf);
265 } else if (stricmp(name.buf, "FullScreen") == 0) {
266 fullScreen = atoi(value.buf);
267 } else if (stricmp(name.buf, "ViewOnly") == 0) {
268 sendPtrEvents = sendKeyEvents = !atoi(value.buf);
269 } else if (stricmp(name.buf, "DisableClipboard") == 0) {
270 clientCutText = serverCutText = !atoi(value.buf);
271 }
272 }
273 }
274 }
275 fclose(f); f=0;
276
277 // Process the Host and Port
278 if (hostTmp.buf) {
279 int hostLen = strlen(hostTmp.buf) + 2 + 17;
280 host.replaceBuf(new char[hostLen]);
281 strCopy(host.buf, hostTmp.buf, hostLen);
282 if (portTmp) {
283 strncat(host.buf, "::", hostLen-1);
284 char tmp[16];
285 sprintf(tmp, "%d", portTmp);
286 strncat(host.buf, tmp, hostLen-1);
287 }
288 }
289
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000290 // If AutoSelect is enabled then override the preferred encoding
291 if (autoSelect)
292 preferredEncoding = encodingZRLE;
293
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000294 setConfigFileName(filename);
295 } catch (rdr::Exception&) {
296 if (f) fclose(f);
297 throw;
298 }
299}
300
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000301void CConnOptions::writeToFile(const char* filename) {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000302 FILE* f = fopen(filename, "w");
303 if (!f)
304 throw rdr::Exception("Failed to write configuration file");
305
306 try {
307 // - Split server into host and port and save
308 fprintf(f, "[Connection]\n");
309
310 fprintf(f, "Host=%s\n", host.buf);
311 if (userName.buf)
312 fprintf(f, "UserName=%s\n", userName.buf);
313 if (password.buf) {
314 // - Warn the user before saving the password
315 if (MsgBox(0, _T("Do you want to include the VNC Password in this configuration file?\n")
316 _T("Storing the password is more convenient but poses a security risk."),
317 MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING) == IDYES) {
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000318 ObfuscatedPasswd obfPwd(password);
319 CharArray obfuscatedHex = rdr::HexOutStream::binToHexStr(obfPwd.buf, obfPwd.length);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000320 fprintf(f, "Password=%s\n", obfuscatedHex.buf);
321 }
322 }
323
324 // - Save the other options
325 fprintf(f, "[Options]\n");
326
327 fprintf(f, "UseLocalCursor=%d\n", (int)useLocalCursor);
328 fprintf(f, "UseDesktopResize=%d\n", (int)useDesktopResize);
329 fprintf(f, "FullScreen=%d\n", (int)fullScreen);
330 fprintf(f, "FullColour=%d\n", (int)fullColour);
331 fprintf(f, "LowColourLevel=%d\n", lowColourLevel);
332 fprintf(f, "PreferredEncoding=%s\n", encodingName(preferredEncoding));
333 fprintf(f, "AutoSelect=%d\n", (int)autoSelect);
334 fprintf(f, "Shared=%d\n", (int)shared);
335 fprintf(f, "SendPtrEvents=%d\n", (int)sendPtrEvents);
336 fprintf(f, "SendKeyEvents=%d\n", (int)sendKeyEvents);
Peter Åstrand57dcc452005-01-28 14:52:50 +0000337 fprintf(f, "SendSysKeys=%d\n", (int)sendSysKeys);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000338 fprintf(f, "SendCutText=%d\n", (int)clientCutText);
339 fprintf(f, "AcceptCutText=%d\n", (int)serverCutText);
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000340 fprintf(f, "DisableWinKeys=%d\n", (int)disableWinKeys);
george82985da922005-12-03 06:08:30 +0000341 fprintf(f, "AcceptBell=%d\n", (int)acceptBell);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000342 fprintf(f, "Emulate3=%d\n", (int)emulate3);
george82baa71192005-11-30 16:17:46 +0000343 fprintf(f, "ShowToolbar=%d\n", (int)showToolbar);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000344 fprintf(f, "PointerEventInterval=%d\n", pointerEventInterval);
345 if (monitor.buf)
346 fprintf(f, "Monitor=%s\n", monitor.buf);
347 fprintf(f, "MenuKey=%s\n", CharArray(menuKeyName()).buf);
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000348 fprintf(f, "AutoReconnect=%d\n", (int)autoReconnect);
Peter Åstrand365427a2004-12-29 10:59:03 +0000349 fprintf(f, "CustomCompressLevel=%d\n", customCompressLevel);
350 fprintf(f, "CompressLevel=%d\n", compressLevel);
Peter Åstrand0b870262004-12-28 15:55:46 +0000351 fprintf(f, "NoJPEG=%d\n", noJpeg);
Peter Åstrand365427a2004-12-29 10:59:03 +0000352 fprintf(f, "QualityLevel=%d\n", qualityLevel);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000353 fclose(f); f=0;
354
355 setConfigFileName(filename);
356 } catch (rdr::Exception&) {
357 if (f) fclose(f);
358 throw;
359 }
360}
361
362
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000363void CConnOptions::writeDefaults() {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000364 RegKey key;
Peter Åstrand9fb4e0e2004-12-30 10:03:00 +0000365 key.createKey(HKEY_CURRENT_USER, _T("Software\\TightVNC\\VNCviewer4"));
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000366 key.setBool(_T("UseLocalCursor"), useLocalCursor);
367 key.setBool(_T("UseDesktopResize"), useDesktopResize);
368 key.setBool(_T("FullScreen"), fullScreen);
369 key.setBool(_T("FullColour"), fullColour);
370 key.setInt(_T("LowColourLevel"), lowColourLevel);
371 key.setString(_T("PreferredEncoding"), TStr(encodingName(preferredEncoding)));
372 key.setBool(_T("AutoSelect"), autoSelect);
373 key.setBool(_T("Shared"), shared);
374 key.setBool(_T("SendPointerEvents"), sendPtrEvents);
375 key.setBool(_T("SendKeyEvents"), sendKeyEvents);
Peter Åstrand57dcc452005-01-28 14:52:50 +0000376 key.setBool(_T("SendSysKeys"), sendSysKeys);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000377 key.setBool(_T("ClientCutText"), clientCutText);
378 key.setBool(_T("ServerCutText"), serverCutText);
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000379 key.setBool(_T("DisableWinKeys"), disableWinKeys);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000380 key.setBool(_T("Protocol3.3"), protocol3_3);
381 key.setBool(_T("AcceptBell"), acceptBell);
george82baa71192005-11-30 16:17:46 +0000382 key.setBool(_T("ShowToolbar"), showToolbar);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000383 key.setBool(_T("Emulate3"), emulate3);
384 key.setInt(_T("PointerEventInterval"), pointerEventInterval);
385 if (monitor.buf)
386 key.setString(_T("Monitor"), TStr(monitor.buf));
387 key.setString(_T("MenuKey"), TCharArray(menuKeyName()).buf);
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000388 key.setBool(_T("AutoReconnect"), autoReconnect);
Peter Åstrand365427a2004-12-29 10:59:03 +0000389 key.setInt(_T("CustomCompressLevel"), customCompressLevel);
390 key.setInt(_T("CompressLevel"), compressLevel);
Peter Åstrand0b870262004-12-28 15:55:46 +0000391 key.setInt(_T("NoJPEG"), noJpeg);
Peter Åstrand365427a2004-12-29 10:59:03 +0000392 key.setInt(_T("QualityLevel"), qualityLevel);
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000393}
394
395
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000396void CConnOptions::setUserName(const char* user) {userName.replaceBuf(strDup(user));}
397void CConnOptions::setPassword(const char* pwd) {password.replaceBuf(strDup(pwd));}
398void CConnOptions::setConfigFileName(const char* cfn) {configFileName.replaceBuf(strDup(cfn));}
399void CConnOptions::setHost(const char* h) {host.replaceBuf(strDup(h));}
400void CConnOptions::setMonitor(const char* m) {monitor.replaceBuf(strDup(m));}
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000401
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000402void CConnOptions::setMenuKey(const char* keyName) {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000403 if (!keyName[0]) {
404 menuKey = 0;
405 } else {
406 menuKey = VK_F8;
407 if (keyName[0] == 'F') {
408 UINT fKey = atoi(&keyName[1]);
409 if (fKey >= 1 && fKey <= 12)
410 menuKey = fKey-1 + VK_F1;
411 }
412 }
413}
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000414char* CConnOptions::menuKeyName() {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000415 int fNum = (menuKey-VK_F1)+1;
416 if (fNum<1 || fNum>12)
417 return strDup("");
418 CharArray menuKeyStr(4);
419 sprintf(menuKeyStr.buf, "F%d", fNum);
420 return menuKeyStr.takeBuf();
421}
422
423
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000424CConnOptions& CConnOptions::operator=(const CConnOptions& o) {
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000425 useLocalCursor = o.useLocalCursor;
426 useDesktopResize = o.useDesktopResize;
427 fullScreen = o.fullScreen;
428 fullColour = o.fullColour;
429 lowColourLevel = o.lowColourLevel;
430 preferredEncoding = o.preferredEncoding;
431 autoSelect = o.autoSelect;
432 shared = o.shared;
433 sendPtrEvents = o.sendPtrEvents;
434 sendKeyEvents = o.sendKeyEvents;
Peter Åstrand57dcc452005-01-28 14:52:50 +0000435 sendSysKeys = o.sendSysKeys;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000436 clientCutText = o.clientCutText;
437 serverCutText = o.serverCutText;
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000438 disableWinKeys = o.disableWinKeys;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000439 emulate3 = o.emulate3;
440 pointerEventInterval = o.pointerEventInterval;
441 protocol3_3 = o.protocol3_3;
442 acceptBell = o.acceptBell;
george82baa71192005-11-30 16:17:46 +0000443 showToolbar = o.showToolbar;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000444 setUserName(o.userName.buf);
445 setPassword(o.password.buf);
446 setConfigFileName(o.configFileName.buf);
447 setHost(o.host.buf);
448 setMonitor(o.monitor.buf);
449 menuKey = o.menuKey;
Constantin Kaplinskyac306682006-05-16 08:48:31 +0000450 autoReconnect = o.autoReconnect;
Peter Åstrand365427a2004-12-29 10:59:03 +0000451 customCompressLevel = o.customCompressLevel;
452 compressLevel = o.compressLevel;
Peter Åstrand0b870262004-12-28 15:55:46 +0000453 noJpeg = o.noJpeg;
Peter Åstrand365427a2004-12-29 10:59:03 +0000454 qualityLevel = o.qualityLevel;
455
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +0000456 return *this;
Peter Åstranded9d4ae2004-12-07 11:59:14 +0000457}