1 |
/* wptPreferencesDlg.cpp - Dialog for the preferences |
/* wptPreferencesDlg.cpp - Dialog for the preferences |
2 |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
* Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
43 |
static int hotkeys[] = { |
static int hotkeys[] = { |
44 |
IDC_PREFS_CLIP_ENCRYPT, |
IDC_PREFS_CLIP_ENCRYPT, |
45 |
IDC_PREFS_CLIP_DECRYPT_VERIFY, |
IDC_PREFS_CLIP_DECRYPT_VERIFY, |
|
IDC_PREFS_CLIP_SIGN, |
|
46 |
IDC_PREFS_CLIP_SIGNENC, |
IDC_PREFS_CLIP_SIGNENC, |
47 |
|
IDC_PREFS_CLIP_SIGN, |
48 |
IDC_PREFS_CWS_ENCRYPT, |
IDC_PREFS_CWS_ENCRYPT, |
49 |
IDC_PREFS_CWS_DECRYPT_VERIFY, |
IDC_PREFS_CWS_DECRYPT_VERIFY, |
50 |
IDC_PREFS_CWS_SIGN, |
IDC_PREFS_CWS_SIGN, |
55 |
|
|
56 |
/* Check that the given hotkey is in A..Z or a..z. */ |
/* Check that the given hotkey is in A..Z or a..z. */ |
57 |
static int |
static int |
58 |
check_hotkey (char * key) |
check_hotkey (char *key) |
59 |
{ |
{ |
60 |
if (*key >= 'A' && *key <= 'Z') |
if (*key >= 'A' && *key <= 'Z') |
61 |
return 1; |
return 1; |
122 |
{IDC_PREFS_KEYLISTINF, _("Select &key list mode")}, |
{IDC_PREFS_KEYLISTINF, _("Select &key list mode")}, |
123 |
{IDC_PREFS_WIPEINF, _("Select &wipe mode")}, |
{IDC_PREFS_WIPEINF, _("Select &wipe mode")}, |
124 |
{IDC_PREFS_KSINF, _("Keyserver &config")}, |
{IDC_PREFS_KSINF, _("Keyserver &config")}, |
125 |
{IDC_PREFS_CACHEINF, _("Cache &passphrases for 'n' seconds")}, |
{IDC_PREFS_CACHEINF, _("Cache &passphrases for 'n' minutes")}, |
126 |
{IDC_PREFS_CACHEHINT, _("(CTRL+ALT+F to clear the cache)")}, |
{IDC_PREFS_CACHEHINT, _("(CTRL+ALT+F to clear the cache)")}, |
127 |
{IDC_PREFS_ALLOPTINF, _("General options")}, |
{IDC_PREFS_ALLOPTINF, _("General options")}, |
128 |
{IDC_PREFS_CLIPINF, _("Clipboard hotkeys")}, |
{IDC_PREFS_CLIPINF, _("Clipboard hotkeys")}, |
129 |
{IDC_PREFS_CURRINF, _("Current window hotkeys")}, |
{IDC_PREFS_CURRINF, _("Current window hotkeys")}, |
130 |
{IDC_PREFS_KSELFILE, _("Browse...")}, |
{IDC_PREFS_KSELFILE, _("Browse...")}, |
131 |
{IDC_PREFS_BAKSELECT, _("Browse...")}, |
{IDC_PREFS_BAKSELECT, _("Browse...")}, |
132 |
|
{IDC_PREFS_EXTINF, _("Default extension for encrypted files")}, |
133 |
|
{IDC_PREFS_BAKSECRING, _("&Backup includes secret keyring")}, |
134 |
{IDCANCEL, _("&Cancel")}, |
{IDCANCEL, _("&Cancel")}, |
135 |
{0, NULL}}; |
{0, NULL}}; |
136 |
int i; |
int i; |
137 |
|
HWND cb; |
138 |
|
|
139 |
gettext_localize_dialog (dlg, prefs, _("WinPT Preferences")); |
gettext_localize_dialog (dlg, prefs, _("WinPT Preferences")); |
140 |
SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, reg_prefs.cache_time, TRUE); |
|
141 |
|
SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, reg_prefs.cache_time/60, TRUE); |
142 |
SetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, reg_prefs.word_wrap, TRUE); |
SetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, reg_prefs.word_wrap, TRUE); |
143 |
if (reg_prefs.backup.path) |
if (reg_prefs.backup.path) |
144 |
SetDlgItemText (dlg, IDC_PREFS_BAKPATH, reg_prefs.backup.path); |
SetDlgItemText (dlg, IDC_PREFS_BAKPATH, reg_prefs.backup.path); |
|
|
|
145 |
|
|
146 |
for (i=0; hotkeys[i]; i++) |
for (i=0; hotkeys[i]; i++) { |
147 |
SetDlgItemText (dlg, hotkeys[i], reg_hotkeys[i].key); |
if (!wpt_hotkeys[i].enabled) |
148 |
|
continue; |
149 |
|
char key[2]; |
150 |
|
key[0] = wpt_hotkeys[i].key; |
151 |
|
key[1] = 0; |
152 |
|
SetDlgItemText (dlg, hotkeys[i], key); |
153 |
|
} |
154 |
|
cb = GetDlgItem (dlg, IDC_PREFS_DEFEXT); |
155 |
|
combox_add_string (cb, "GnuPG (.gpg)"); |
156 |
|
combox_add_string (cb, "PGP (.pgp)"); |
157 |
|
SendMessage (cb, CB_SETCURSEL, 0, 0); |
158 |
|
|
159 |
CheckDlgButton (dlg, IDC_PREFS_DISABLE_HOTKEYS, |
CheckDlgButton (dlg, IDC_PREFS_DISABLE_HOTKEYS, |
160 |
reg_prefs.no_hotkeys ? BST_CHECKED : BST_UNCHECKED); |
reg_prefs.no_hotkeys ? BST_CHECKED : BST_UNCHECKED); |
|
CheckDlgButton (dlg, IDC_PREFS_SECMODE, |
|
|
reg_prefs.use_tmpfiles ? BST_UNCHECKED : BST_CHECKED); |
|
161 |
CheckDlgButton (dlg, IDC_PREFS_VIEWER, |
CheckDlgButton (dlg, IDC_PREFS_VIEWER, |
162 |
reg_prefs.use_viewer ? BST_CHECKED: BST_UNCHECKED); |
reg_prefs.use_viewer ? BST_CHECKED: BST_UNCHECKED); |
163 |
CheckDlgButton (dlg, IDC_PREFS_TRUST, |
CheckDlgButton (dlg, IDC_PREFS_TRUST, |
168 |
reg_prefs.backup.mode==1? BST_CHECKED : BST_UNCHECKED); |
reg_prefs.backup.mode==1? BST_CHECKED : BST_UNCHECKED); |
169 |
CheckDlgButton (dlg, IDC_PREFS_BAKUSER, |
CheckDlgButton (dlg, IDC_PREFS_BAKUSER, |
170 |
reg_prefs.backup.mode==2? BST_CHECKED : BST_UNCHECKED); |
reg_prefs.backup.mode==2? BST_CHECKED : BST_UNCHECKED); |
171 |
|
CheckDlgButton (dlg, IDC_PREFS_BAKSECRING, |
172 |
|
reg_prefs.backup.include_secr? BST_CHECKED :BST_UNCHECKED); |
173 |
|
SendDlgItemMessage (dlg, IDC_PREFS_DEFEXT, CB_SETCURSEL, |
174 |
|
reg_prefs.default_ext, 0); |
175 |
if (reg_prefs.no_hotkeys) |
if (reg_prefs.no_hotkeys) |
176 |
disable_hotkey_items (dlg, 1); |
disable_hotkey_items (dlg, 1); |
177 |
if (!reg_prefs.auto_backup) |
if (!reg_prefs.auto_backup) |
192 |
{ |
{ |
193 |
int rc; |
int rc; |
194 |
int i; |
int i; |
195 |
char t[2]; |
char t[3]; |
196 |
char path[256], *p; |
char path[256], *p; |
197 |
HWND cb; |
HWND cb; |
198 |
|
|
207 |
return FALSE; |
return FALSE; |
208 |
|
|
209 |
case WM_COMMAND: |
case WM_COMMAND: |
210 |
switch( HIWORD(wparam) ) { |
switch (HIWORD (wparam)) { |
211 |
case BN_CLICKED: |
case BN_CLICKED: |
212 |
switch( (int)LOWORD( wparam ) ) { |
switch ((int)LOWORD (wparam)) { |
213 |
case IDC_PREFS_DISABLE_HOTKEYS: |
case IDC_PREFS_DISABLE_HOTKEYS: |
214 |
reg_prefs.no_hotkeys ^= 1; |
reg_prefs.no_hotkeys ^= 1; |
215 |
disable_hotkey_items (dlg, reg_prefs.no_hotkeys); |
disable_hotkey_items (dlg, reg_prefs.no_hotkeys); |
220 |
if (reg_prefs.always_trust) { |
if (reg_prefs.always_trust) { |
221 |
msg_box (dlg, |
msg_box (dlg, |
222 |
_("In most cases it is not a good idea to enable this setting.\n" |
_("In most cases it is not a good idea to enable this setting.\n" |
223 |
"If you know what you are doing let this flag enabled, otherwise\n" |
"If you know what you are doing, you can enable this flag, otherwise\n" |
224 |
"it is safe to leave this flag untouched."), |
"it is safe to leave this flag untouched."), |
225 |
_("Preferences"), MB_ICONWARNING|MB_OK); |
_("Preferences"), MB_ICONWARNING|MB_OK); |
226 |
} |
} |
250 |
} |
} |
251 |
break; |
break; |
252 |
} |
} |
253 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
254 |
case IDC_PREFS_BAKSELECT: |
case IDC_PREFS_BAKSELECT: |
255 |
const char *bpath; |
const char *bpath; |
256 |
bpath = get_folder_dlg (dlg, _("Select GPG backup path"), NULL); |
bpath = get_folder_dlg (dlg, _("Select GPG backup path"), NULL); |
259 |
break; |
break; |
260 |
|
|
261 |
case IDOK: |
case IDOK: |
262 |
rc = GetDlgItemInt( dlg, IDC_PREFS_CACHETIME, NULL, FALSE ); |
rc = GetDlgItemInt (dlg, IDC_PREFS_CACHETIME, NULL, FALSE); |
263 |
if (!rc) |
if (rc <= 0) { |
264 |
reg_prefs.cache_time = 0; |
reg_prefs.cache_time = 0; |
265 |
else if (rc > 3600) { |
agent_flush_cache (); |
266 |
msg_box( dlg, _("Please enter a value that is between 1-3600.\nIt is not " |
} |
267 |
"a good idea to cache the passphrase more than one hour."), |
else if (rc > 720) { |
268 |
|
msg_box( dlg, _("Please enter a value that is between 1-720.\nIt is not " |
269 |
|
"a good idea to cache the passphrase more than 12 hours."), |
270 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
271 |
SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, 0, FALSE); |
SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, 0, FALSE); |
272 |
return TRUE; |
return TRUE; |
273 |
} |
} |
274 |
if (reg_prefs.cache_time != rc) |
if (reg_prefs.cache_time != rc) |
275 |
agent_flush_cache (); |
agent_flush_cache (); |
276 |
reg_prefs.cache_time = rc; |
reg_prefs.cache_time = rc*60; |
277 |
rc = GetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, NULL, FALSE); |
rc = GetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, NULL, FALSE); |
278 |
if (!rc) |
if (rc <= 0) |
279 |
reg_prefs.word_wrap = 0; |
reg_prefs.word_wrap = 0; |
280 |
else if (rc > 80) { |
else if (rc > 80) { |
281 |
msg_box (dlg, _("Please enter a value between 1-80."), |
msg_box (dlg, _("Please enter a value between 1-80."), |
282 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
283 |
return TRUE; |
return TRUE; |
284 |
} |
} |
285 |
|
reg_prefs.default_ext = SendDlgItemMessage (dlg, IDC_PREFS_DEFEXT, CB_GETCURSEL, 0, 0); |
286 |
reg_prefs.word_wrap = rc; |
reg_prefs.word_wrap = rc; |
287 |
reg_prefs.use_tmpfiles = IsDlgButtonChecked( dlg, IDC_PREFS_SECMODE )? 0 : 1; |
reg_prefs.use_viewer = IsDlgButtonChecked (dlg, IDC_PREFS_VIEWER)? 1 : 0; |
288 |
reg_prefs.use_viewer = IsDlgButtonChecked( dlg, IDC_PREFS_VIEWER )? 1 : 0; |
reg_prefs.backup.mode = IsDlgButtonChecked (dlg, IDC_PREFS_BAKHOME ) ? 1 : |
289 |
reg_prefs.backup.mode = IsDlgButtonChecked( dlg, IDC_PREFS_BAKHOME ) ? 1 : |
IsDlgButtonChecked (dlg, IDC_PREFS_BAKUSER)? 2 : 0; |
290 |
IsDlgButtonChecked( dlg, IDC_PREFS_BAKUSER )? 2 : 0; |
reg_prefs.backup.include_secr = IsDlgButtonChecked (dlg, IDC_PREFS_BAKSECRING)? 1 : 0; |
291 |
if( reg_prefs.backup.mode == 2 ) { |
if (reg_prefs.backup.mode == 2) { |
292 |
if( !GetDlgItemText( dlg, IDC_PREFS_BAKPATH, path, sizeof (path)-1 ) |
if (!GetDlgItemText (dlg, IDC_PREFS_BAKPATH, path, sizeof (path)-1) |
293 |
|| dir_exist_check( path ) ) { |
|| dir_exist_check (path)) { |
294 |
msg_box( dlg, _("The specified backup folder is invalid."), |
msg_box (dlg, _("The specified backup folder is invalid."), |
295 |
_("Preferences"), MB_ERR ); |
_("Preferences"), MB_ERR); |
296 |
return TRUE; |
return TRUE; |
297 |
} |
} |
298 |
free_if_alloc (reg_prefs.backup.path); |
free_if_alloc (reg_prefs.backup.path); |
301 |
BUG (0); |
BUG (0); |
302 |
} |
} |
303 |
|
|
304 |
cb = GetDlgItem( dlg, IDC_PREFS_WIPEMODE ); |
cb = GetDlgItem (dlg, IDC_PREFS_WIPEMODE); |
305 |
reg_prefs.wipe_mode = SendMessage( cb, CB_GETCURSEL, 0, 0 ); |
reg_prefs.wipe_mode = SendMessage (cb, CB_GETCURSEL, 0, 0); |
306 |
|
|
307 |
if (IsDlgButtonChecked (dlg, IDC_PREFS_DISABLE_HOTKEYS)) { |
if (IsDlgButtonChecked (dlg, IDC_PREFS_DISABLE_HOTKEYS)) { |
308 |
hotkeys_unregister (glob_hwnd); |
hotkeys_unregister (glob_hwnd); |
310 |
} |
} |
311 |
else { |
else { |
312 |
reg_prefs.no_hotkeys = 0; |
reg_prefs.no_hotkeys = 0; |
313 |
for( i = 0; hotkeys[i]; i++ ) { |
for (i = 0; hotkeys[i]; i++) { |
314 |
rc = GetDlgItemText (dlg, hotkeys[i], t, 2); |
rc = GetDlgItemText (dlg, hotkeys[i], t, sizeof (t)-1); |
315 |
if( rc && check_hotkey( &t[0] ) ) |
if (rc > 0 && check_hotkey (&t[0])) |
316 |
hotkey_enable( ®_hotkeys[i], t ); |
hotkey_enable (&wpt_hotkeys[i], t); |
317 |
else |
else |
318 |
hotkey_disable( ®_hotkeys[i] ); |
hotkey_disable (&wpt_hotkeys[i]); |
319 |
} |
} |
320 |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "DisableHotkeys", "0"); |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "DisableHotkeys", "0"); |
321 |
reg_prefs.no_hotkeys = 0; |
reg_prefs.no_hotkeys = 0; |
322 |
} |
} |
323 |
|
|
324 |
if ((rc = set_reg_winpt_prefs (®_prefs))) |
rc = set_reg_winpt_prefs (®_prefs); |
325 |
|
if (rc) |
326 |
msg_box (dlg, winpt_strerror (rc), _("Preferences"), MB_ERR); |
msg_box (dlg, winpt_strerror (rc), _("Preferences"), MB_ERR); |
327 |
|
|
328 |
if (reg_prefs.no_hotkeys == 0) { |
if (reg_prefs.no_hotkeys == 0) { |
329 |
hotkeys_unregister (glob_hwnd); |
hotkeys_unregister (glob_hwnd); |
330 |
hotkeys_modify (); |
rc = hotkeys_register (glob_hwnd); |
331 |
if ((rc = hotkeys_register (glob_hwnd))) |
if (rc) |
332 |
msg_box (NULL, winpt_strerror (rc), _("Hotkeys"), MB_ERR); |
msg_box (NULL, winpt_strerror (rc), _("Hotkeys"), MB_ERR); |
333 |
} |
} |
334 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |