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")}, |
134 |
int i; |
int i; |
135 |
|
|
136 |
gettext_localize_dialog (dlg, prefs, _("WinPT Preferences")); |
gettext_localize_dialog (dlg, prefs, _("WinPT Preferences")); |
137 |
SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, reg_prefs.cache_time, TRUE); |
|
138 |
|
SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, reg_prefs.cache_time/60, TRUE); |
139 |
SetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, reg_prefs.word_wrap, TRUE); |
SetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, reg_prefs.word_wrap, TRUE); |
140 |
if (reg_prefs.backup.path) |
if (reg_prefs.backup.path) |
141 |
SetDlgItemText (dlg, IDC_PREFS_BAKPATH, reg_prefs.backup.path); |
SetDlgItemText (dlg, IDC_PREFS_BAKPATH, reg_prefs.backup.path); |
|
|
|
142 |
|
|
143 |
for (i=0; hotkeys[i]; i++) |
for (i=0; hotkeys[i]; i++) { |
144 |
SetDlgItemText (dlg, hotkeys[i], reg_hotkeys[i].key); |
if (!wpt_hotkeys[i].enabled) |
145 |
|
continue; |
146 |
|
char key[2]; |
147 |
|
key[0] = wpt_hotkeys[i].key; |
148 |
|
key[1] = 0; |
149 |
|
SetDlgItemText (dlg, hotkeys[i], key); |
150 |
|
} |
151 |
CheckDlgButton (dlg, IDC_PREFS_DISABLE_HOTKEYS, |
CheckDlgButton (dlg, IDC_PREFS_DISABLE_HOTKEYS, |
152 |
reg_prefs.no_hotkeys ? BST_CHECKED : BST_UNCHECKED); |
reg_prefs.no_hotkeys ? BST_CHECKED : BST_UNCHECKED); |
153 |
CheckDlgButton (dlg, IDC_PREFS_SECMODE, |
CheckDlgButton (dlg, IDC_PREFS_SECMODE, |
182 |
{ |
{ |
183 |
int rc; |
int rc; |
184 |
int i; |
int i; |
185 |
char t[2]; |
char t[3]; |
186 |
char path[256], *p; |
char path[256], *p; |
187 |
HWND cb; |
HWND cb; |
188 |
|
|
197 |
return FALSE; |
return FALSE; |
198 |
|
|
199 |
case WM_COMMAND: |
case WM_COMMAND: |
200 |
switch( HIWORD(wparam) ) { |
switch (HIWORD (wparam)) { |
201 |
case BN_CLICKED: |
case BN_CLICKED: |
202 |
switch( (int)LOWORD( wparam ) ) { |
switch ((int)LOWORD (wparam)) { |
203 |
case IDC_PREFS_DISABLE_HOTKEYS: |
case IDC_PREFS_DISABLE_HOTKEYS: |
204 |
reg_prefs.no_hotkeys ^= 1; |
reg_prefs.no_hotkeys ^= 1; |
205 |
disable_hotkey_items (dlg, reg_prefs.no_hotkeys); |
disable_hotkey_items (dlg, reg_prefs.no_hotkeys); |
240 |
} |
} |
241 |
break; |
break; |
242 |
} |
} |
243 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
244 |
case IDC_PREFS_BAKSELECT: |
case IDC_PREFS_BAKSELECT: |
245 |
const char *bpath; |
const char *bpath; |
246 |
bpath = get_folder_dlg (dlg, _("Select GPG backup path"), NULL); |
bpath = get_folder_dlg (dlg, _("Select GPG backup path"), NULL); |
249 |
break; |
break; |
250 |
|
|
251 |
case IDOK: |
case IDOK: |
252 |
rc = GetDlgItemInt( dlg, IDC_PREFS_CACHETIME, NULL, FALSE ); |
rc = GetDlgItemInt (dlg, IDC_PREFS_CACHETIME, NULL, FALSE); |
253 |
if (!rc) |
if (rc <= 0) { |
254 |
reg_prefs.cache_time = 0; |
reg_prefs.cache_time = 0; |
255 |
else if (rc > 3600) { |
agent_flush_cache (); |
256 |
msg_box( dlg, _("Please enter a value that is between 1-3600.\nIt is not " |
} |
257 |
"a good idea to cache the passphrase more than one hour."), |
else if (rc > 720) { |
258 |
|
msg_box( dlg, _("Please enter a value that is between 1-720.\nIt is not " |
259 |
|
"a good idea to cache the passphrase more than 12 hours."), |
260 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
261 |
SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, 0, FALSE); |
SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, 0, FALSE); |
262 |
return TRUE; |
return TRUE; |
263 |
} |
} |
264 |
if (reg_prefs.cache_time != rc) |
if (reg_prefs.cache_time != rc) |
265 |
agent_flush_cache (); |
agent_flush_cache (); |
266 |
reg_prefs.cache_time = rc; |
reg_prefs.cache_time = rc*60; |
267 |
rc = GetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, NULL, FALSE); |
rc = GetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, NULL, FALSE); |
268 |
if (!rc) |
if (rc <= 0) |
269 |
reg_prefs.word_wrap = 0; |
reg_prefs.word_wrap = 0; |
270 |
else if (rc > 80) { |
else if (rc > 80) { |
271 |
msg_box (dlg, _("Please enter a value between 1-80."), |
msg_box (dlg, _("Please enter a value between 1-80."), |
273 |
return TRUE; |
return TRUE; |
274 |
} |
} |
275 |
reg_prefs.word_wrap = rc; |
reg_prefs.word_wrap = rc; |
276 |
reg_prefs.use_tmpfiles = IsDlgButtonChecked( dlg, IDC_PREFS_SECMODE )? 0 : 1; |
reg_prefs.use_tmpfiles = IsDlgButtonChecked (dlg, IDC_PREFS_SECMODE)? 0 : 1; |
277 |
reg_prefs.use_viewer = IsDlgButtonChecked( dlg, IDC_PREFS_VIEWER )? 1 : 0; |
reg_prefs.use_viewer = IsDlgButtonChecked (dlg, IDC_PREFS_VIEWER)? 1 : 0; |
278 |
reg_prefs.backup.mode = IsDlgButtonChecked( dlg, IDC_PREFS_BAKHOME ) ? 1 : |
reg_prefs.backup.mode = IsDlgButtonChecked (dlg, IDC_PREFS_BAKHOME ) ? 1 : |
279 |
IsDlgButtonChecked( dlg, IDC_PREFS_BAKUSER )? 2 : 0; |
IsDlgButtonChecked (dlg, IDC_PREFS_BAKUSER)? 2 : 0; |
280 |
if( reg_prefs.backup.mode == 2 ) { |
if (reg_prefs.backup.mode == 2) { |
281 |
if( !GetDlgItemText( dlg, IDC_PREFS_BAKPATH, path, sizeof (path)-1 ) |
if (!GetDlgItemText (dlg, IDC_PREFS_BAKPATH, path, sizeof (path)-1) |
282 |
|| dir_exist_check( path ) ) { |
|| dir_exist_check (path)) { |
283 |
msg_box( dlg, _("The specified backup folder is invalid."), |
msg_box (dlg, _("The specified backup folder is invalid."), |
284 |
_("Preferences"), MB_ERR ); |
_("Preferences"), MB_ERR); |
285 |
return TRUE; |
return TRUE; |
286 |
} |
} |
287 |
free_if_alloc (reg_prefs.backup.path); |
free_if_alloc (reg_prefs.backup.path); |
290 |
BUG (0); |
BUG (0); |
291 |
} |
} |
292 |
|
|
293 |
cb = GetDlgItem( dlg, IDC_PREFS_WIPEMODE ); |
cb = GetDlgItem (dlg, IDC_PREFS_WIPEMODE); |
294 |
reg_prefs.wipe_mode = SendMessage( cb, CB_GETCURSEL, 0, 0 ); |
reg_prefs.wipe_mode = SendMessage (cb, CB_GETCURSEL, 0, 0); |
295 |
|
|
296 |
if (IsDlgButtonChecked (dlg, IDC_PREFS_DISABLE_HOTKEYS)) { |
if (IsDlgButtonChecked (dlg, IDC_PREFS_DISABLE_HOTKEYS)) { |
297 |
hotkeys_unregister (glob_hwnd); |
hotkeys_unregister (glob_hwnd); |
299 |
} |
} |
300 |
else { |
else { |
301 |
reg_prefs.no_hotkeys = 0; |
reg_prefs.no_hotkeys = 0; |
302 |
for( i = 0; hotkeys[i]; i++ ) { |
for (i = 0; hotkeys[i]; i++) { |
303 |
rc = GetDlgItemText (dlg, hotkeys[i], t, 2); |
rc = GetDlgItemText (dlg, hotkeys[i], t, sizeof (t)-1); |
304 |
if( rc && check_hotkey( &t[0] ) ) |
if (rc > 0 && check_hotkey (&t[0])) |
305 |
hotkey_enable( ®_hotkeys[i], t ); |
hotkey_enable (&wpt_hotkeys[i], t); |
306 |
else |
else |
307 |
hotkey_disable( ®_hotkeys[i] ); |
hotkey_disable (&wpt_hotkeys[i]); |
308 |
} |
} |
309 |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "DisableHotkeys", "0"); |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "DisableHotkeys", "0"); |
310 |
reg_prefs.no_hotkeys = 0; |
reg_prefs.no_hotkeys = 0; |
311 |
} |
} |
312 |
|
|
313 |
if ((rc = set_reg_winpt_prefs (®_prefs))) |
rc = set_reg_winpt_prefs (®_prefs); |
314 |
|
if (rc) |
315 |
msg_box (dlg, winpt_strerror (rc), _("Preferences"), MB_ERR); |
msg_box (dlg, winpt_strerror (rc), _("Preferences"), MB_ERR); |
316 |
|
|
317 |
if (reg_prefs.no_hotkeys == 0) { |
if (reg_prefs.no_hotkeys == 0) { |
318 |
hotkeys_unregister (glob_hwnd); |
hotkeys_unregister (glob_hwnd); |
319 |
hotkeys_modify (); |
rc = hotkeys_register (glob_hwnd); |
320 |
if ((rc = hotkeys_register (glob_hwnd))) |
if (rc) |
321 |
msg_box (NULL, winpt_strerror (rc), _("Hotkeys"), MB_ERR); |
msg_box (NULL, winpt_strerror (rc), _("Hotkeys"), MB_ERR); |
322 |
} |
} |
323 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |