1 |
twoaday |
2 |
/* wptPreferencesDlg.cpp - Dialog for the preferences |
2 |
|
|
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include <windows.h> |
22 |
|
|
#include <shlobj.h> |
23 |
|
|
|
24 |
|
|
#include "wptNLS.h" |
25 |
|
|
#include "wptGPG.h" |
26 |
|
|
#include "wptCommonCtl.h" |
27 |
|
|
#include "wptDlgs.h" |
28 |
|
|
#include "wptTypes.h" |
29 |
|
|
#include "wptErrors.h" |
30 |
|
|
#include "wptRegistry.h" |
31 |
|
|
#include "wptHotkey.h" |
32 |
|
|
#include "wptW32API.h" |
33 |
|
|
#include "wptVersion.h" |
34 |
|
|
#include "wptAgent.h" |
35 |
|
|
#include "wptKeyserver.h" |
36 |
|
|
#include "../resource.h" |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
static int hotkeys[] = { |
40 |
|
|
IDC_PREFS_CLIP_ENCRYPT, |
41 |
|
|
IDC_PREFS_CLIP_DECRYPT_VERIFY, |
42 |
|
|
IDC_PREFS_CLIP_SIGN, |
43 |
|
|
IDC_PREFS_CLIP_SIGNENC, |
44 |
|
|
IDC_PREFS_CWS_ENCRYPT, |
45 |
|
|
IDC_PREFS_CWS_DECRYPT_VERIFY, |
46 |
|
|
IDC_PREFS_CWS_SIGN, |
47 |
|
|
IDC_PREFS_CWS_SIGNENC, |
48 |
|
|
0 |
49 |
|
|
}; |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
static int |
53 |
|
|
check_hotkey( char * key ) |
54 |
|
|
{ |
55 |
|
|
if( *key >= 'A' && *key <= 'Z' ) |
56 |
|
|
return 1; |
57 |
|
|
else if( *key >= 'a' && *key <= 'z' ) { |
58 |
|
|
*key = *key - 32; |
59 |
|
|
return 1; |
60 |
|
|
} |
61 |
|
|
return 0; |
62 |
|
|
} /* check_hotkey */ |
63 |
|
|
|
64 |
|
|
|
65 |
|
|
static void |
66 |
|
|
disable_hotkey_items( HWND dlg, int yes ) |
67 |
|
|
{ |
68 |
|
|
int mode = yes ? FALSE : TRUE; |
69 |
|
|
int i, id; |
70 |
|
|
|
71 |
|
|
for( i=0; (id = hotkeys[i]); i++ ) |
72 |
|
|
EnableWindow( GetDlgItem( dlg, id ), mode ); |
73 |
|
|
} /* disable_hotkey_items */ |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
static void |
77 |
|
|
enable_backup_items( HWND dlg, int yes ) |
78 |
|
|
{ |
79 |
|
|
int mode = yes ? TRUE : FALSE; |
80 |
|
|
|
81 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKHOME ), mode ); |
82 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKUSER ), mode ); |
83 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKSELECT ), mode ); |
84 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKPATH ), mode ); |
85 |
|
|
} /* enable_backup_items */ |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
static void |
89 |
|
|
set_keylist_mode( HWND dlg ) |
90 |
|
|
{ |
91 |
|
|
HWND cb = GetDlgItem( dlg, IDC_PREFS_LISTMODE ); |
92 |
|
|
combox_add_string( cb, (char *)"NORMAL" ); |
93 |
|
|
combox_add_string( cb, (char *)"MINIMAL" ); |
94 |
|
|
SendMessage( cb, CB_SETCURSEL, (WPARAM)reg_prefs.keylist_mode, 0 ); |
95 |
|
|
} /* set_keylist_mode */ |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
static void |
99 |
|
|
set_wipe_mode( HWND dlg ) |
100 |
|
|
{ |
101 |
|
|
HWND cb = GetDlgItem( dlg, IDC_PREFS_WIPEMODE ); |
102 |
|
|
combox_add_string( cb, (char *)"Simple" ); |
103 |
|
|
combox_add_string( cb, (char *)"DoD" ); |
104 |
|
|
combox_add_string( cb, (char *)"Gutmann" ); |
105 |
|
|
SendMessage( cb, CB_SETCURSEL, (WPARAM)reg_prefs.wipe_mode, 0 ); |
106 |
|
|
} /* set_wipe_mode */ |
107 |
|
|
|
108 |
|
|
|
109 |
|
|
BOOL CALLBACK |
110 |
|
|
prefs_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
111 |
|
|
{ |
112 |
|
|
int rc; |
113 |
|
|
int i, id; |
114 |
|
|
char t[2]; |
115 |
|
|
char path[256], * p; |
116 |
|
|
HWND cb; |
117 |
|
|
|
118 |
|
|
switch ( msg ) { |
119 |
|
|
case WM_INITDIALOG: |
120 |
|
|
#ifndef LANG_DE |
121 |
|
|
SetWindowText( dlg, _("WinPT Preferences") ); |
122 |
|
|
SetDlgItemText( dlg, IDC_PREFS_SECMODE, _("Do not use any &temporary files") ); |
123 |
|
|
SetDlgItemText( dlg, IDC_PREFS_VIEWER, _("Use clipboard &viewer to display the plaintext") ); |
124 |
|
|
SetDlgItemText( dlg, IDC_PREFS_WWINFO, _("Word wrap cleartext &signatures at column") ); |
125 |
|
|
SetDlgItemText( dlg, IDC_PREFS_DISABLE_HOTKEYS, _("&Disable hotkeys (Not recommended!)") ); |
126 |
|
|
#endif |
127 |
|
|
SetDlgItemInt( dlg, IDC_PREFS_CACHETIME, reg_prefs.cache_time, TRUE ); |
128 |
|
|
SetDlgItemInt( dlg, IDC_PREFS_WORDWRAP, reg_prefs.word_wrap, TRUE ); |
129 |
|
|
if (reg_prefs.backup.path) |
130 |
|
|
SetDlgItemText (dlg, IDC_PREFS_BAKPATH, reg_prefs.backup.path); |
131 |
|
|
if (reg_prefs.kserv_conf) |
132 |
|
|
SetDlgItemText (dlg, IDC_PREFS_KSERVER, reg_prefs.kserv_conf); |
133 |
|
|
|
134 |
|
|
for( i=0; (id=hotkeys[i]); i++ ) |
135 |
|
|
SetDlgItemText( dlg, id, reg_hotkeys[i].key ); |
136 |
|
|
CheckDlgButton( dlg, IDC_PREFS_DISABLE_HOTKEYS, |
137 |
|
|
reg_prefs.no_hotkeys ? BST_CHECKED : BST_UNCHECKED ); |
138 |
|
|
CheckDlgButton( dlg, IDC_PREFS_SECMODE, |
139 |
|
|
reg_prefs.use_tmpfiles ? BST_UNCHECKED : BST_CHECKED ); |
140 |
|
|
CheckDlgButton( dlg, IDC_PREFS_VIEWER, |
141 |
|
|
reg_prefs.use_viewer ? BST_CHECKED: BST_UNCHECKED ); |
142 |
|
|
CheckDlgButton( dlg, IDC_PREFS_TRUST, |
143 |
|
|
reg_prefs.always_trust? BST_CHECKED : BST_UNCHECKED ); |
144 |
|
|
CheckDlgButton( dlg, IDC_PREFS_AUTOBACKUP, |
145 |
|
|
reg_prefs.auto_backup? BST_CHECKED : BST_UNCHECKED ); |
146 |
|
|
CheckDlgButton( dlg, IDC_PREFS_BAKHOME, |
147 |
|
|
reg_prefs.backup.mode==1? BST_CHECKED : BST_UNCHECKED ); |
148 |
|
|
CheckDlgButton( dlg, IDC_PREFS_BAKUSER, |
149 |
|
|
reg_prefs.backup.mode==2? BST_CHECKED : BST_UNCHECKED ); |
150 |
|
|
if( reg_prefs.no_hotkeys ) |
151 |
|
|
disable_hotkey_items( dlg, 1 ); |
152 |
|
|
if( !reg_prefs.auto_backup ) |
153 |
|
|
enable_backup_items( dlg, 0 ); |
154 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKPATH ), |
155 |
|
|
reg_prefs.backup.mode==1?FALSE : TRUE ); |
156 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKSELECT ), |
157 |
|
|
reg_prefs.backup.mode==1? FALSE : TRUE ); |
158 |
|
|
set_keylist_mode( dlg ); |
159 |
|
|
set_wipe_mode( dlg ); |
160 |
|
|
center_window( dlg ); |
161 |
|
|
SetForegroundWindow( dlg ); |
162 |
|
|
return TRUE; |
163 |
|
|
|
164 |
|
|
case WM_SYSCOMMAND: |
165 |
|
|
if( LOWORD( wparam ) == SC_CLOSE ) |
166 |
|
|
EndDialog( dlg, TRUE ); |
167 |
|
|
return FALSE; |
168 |
|
|
|
169 |
|
|
case WM_COMMAND: |
170 |
|
|
switch( HIWORD(wparam) ) { |
171 |
|
|
case BN_CLICKED: |
172 |
|
|
switch( (int)LOWORD( wparam ) ) { |
173 |
|
|
case IDC_PREFS_DISABLE_HOTKEYS: |
174 |
|
|
reg_prefs.no_hotkeys ^= 1; |
175 |
|
|
disable_hotkey_items( dlg, reg_prefs.no_hotkeys ); |
176 |
|
|
break; |
177 |
|
|
|
178 |
|
|
case IDC_PREFS_TRUST: |
179 |
|
|
reg_prefs.always_trust ^= 1; |
180 |
|
|
if( reg_prefs.always_trust ) { |
181 |
|
|
msg_box( NULL, |
182 |
|
|
_("In most cases it is not a good idea to enable this setting.\n" |
183 |
|
|
"If you know what you are doing let this flag enabled, otherwise\n" |
184 |
|
|
"it is safe to leave this flag untouched."), |
185 |
|
|
_("Preferences"), MB_ICONWARNING|MB_OK ); |
186 |
|
|
} |
187 |
|
|
break; |
188 |
|
|
|
189 |
|
|
case IDC_PREFS_AUTOBACKUP: |
190 |
|
|
reg_prefs.auto_backup ^= 1; |
191 |
|
|
enable_backup_items( dlg, reg_prefs.auto_backup ); |
192 |
|
|
break; |
193 |
|
|
|
194 |
|
|
case IDC_PREFS_BAKHOME: |
195 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKSELECT ), FALSE ); |
196 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKPATH ), FALSE ); |
197 |
|
|
break; |
198 |
|
|
|
199 |
|
|
case IDC_PREFS_BAKUSER: |
200 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKSELECT ), TRUE ); |
201 |
|
|
EnableWindow( GetDlgItem( dlg, IDC_PREFS_BAKPATH ), TRUE ); |
202 |
|
|
break; |
203 |
|
|
} |
204 |
|
|
break; |
205 |
|
|
} |
206 |
|
|
switch( LOWORD( wparam ) ) { |
207 |
|
|
case IDC_PREFS_BAKSELECT: |
208 |
|
|
BROWSEINFO bi; |
209 |
|
|
ITEMIDLIST * item; |
210 |
|
|
|
211 |
|
|
memset( &bi, 0, sizeof (bi) ); |
212 |
|
|
item = SHBrowseForFolder( &bi ); |
213 |
|
|
if( item ) { |
214 |
|
|
SHGetPathFromIDList( item, path ); |
215 |
|
|
SetDlgItemText( dlg, IDC_PREFS_BAKPATH, path ); |
216 |
|
|
} |
217 |
|
|
break; |
218 |
|
|
|
219 |
|
|
case IDC_PREFS_KSELFILE: { |
220 |
|
|
const char * name; |
221 |
|
|
name = get_filename_dlg (dlg, 0, _("Please select a keyserver.conf file"), |
222 |
|
|
NULL, NULL); |
223 |
|
|
if (name && file_exist_check (name) == 0) |
224 |
|
|
SetDlgItemText (dlg, IDC_PREFS_KSERVER, name); |
225 |
|
|
break; } |
226 |
|
|
|
227 |
|
|
case IDOK: |
228 |
|
|
rc = GetDlgItemInt( dlg, IDC_PREFS_CACHETIME, NULL, FALSE ); |
229 |
|
|
if( !rc ) |
230 |
|
|
reg_prefs.cache_time = 0; |
231 |
|
|
else if( rc > 3600 ) { |
232 |
|
|
msg_box( dlg, _("Please enter a value that is between 1-3600.\nIt is not " |
233 |
|
|
"a good idea to cache the passphrase more than one hour."), |
234 |
|
|
_("Preferences"), MB_ERR ); |
235 |
|
|
SetDlgItemInt( dlg, IDC_PREFS_CACHETIME, 0, FALSE ); |
236 |
|
|
return FALSE; |
237 |
|
|
} |
238 |
|
|
if (reg_prefs.cache_time != rc) |
239 |
|
|
agent_flush_cache (); |
240 |
|
|
reg_prefs.cache_time = rc; |
241 |
|
|
rc = GetDlgItemInt( dlg, IDC_PREFS_WORDWRAP, NULL, FALSE ); |
242 |
|
|
if( !rc ) |
243 |
|
|
reg_prefs.word_wrap = 0; |
244 |
|
|
else if( rc > 80 ) { |
245 |
|
|
msg_box( dlg, _("Please enter a value between 1-80."), _("Preferences"), MB_ERR ); |
246 |
|
|
return FALSE; |
247 |
|
|
} |
248 |
|
|
reg_prefs.word_wrap = rc; |
249 |
|
|
reg_prefs.use_tmpfiles = IsDlgButtonChecked( dlg, IDC_PREFS_SECMODE )? 0 : 1; |
250 |
|
|
reg_prefs.use_viewer = IsDlgButtonChecked( dlg, IDC_PREFS_VIEWER )? 1 : 0; |
251 |
|
|
reg_prefs.backup.mode = IsDlgButtonChecked( dlg, IDC_PREFS_BAKHOME ) ? 1 : |
252 |
|
|
IsDlgButtonChecked( dlg, IDC_PREFS_BAKUSER )? 2 : 0; |
253 |
|
|
if( reg_prefs.backup.mode == 2 ) { |
254 |
|
|
if( !GetDlgItemText( dlg, IDC_PREFS_BAKPATH, path, sizeof (path)-1 ) |
255 |
|
|
|| dir_exist_check( path ) ) { |
256 |
|
|
msg_box( dlg, _("The specified backup folder is invalid."), |
257 |
|
|
_("Preferences"), MB_ERR ); |
258 |
|
|
return FALSE; |
259 |
|
|
} |
260 |
|
|
free_if_alloc (reg_prefs.backup.path); |
261 |
|
|
p = reg_prefs.backup.path = m_strdup (path); |
262 |
|
|
if (!p) |
263 |
|
|
BUG (0); |
264 |
|
|
} |
265 |
|
|
free_if_alloc (reg_prefs.kserv_conf); |
266 |
|
|
if (!GetDlgItemText (dlg, IDC_PREFS_KSERVER, path, sizeof (path)-1) |
267 |
|
|
|| file_exist_check (path)) { |
268 |
|
|
rc = msg_box (dlg, _("The specified keyserver config file is invalid.\n\n" |
269 |
|
|
"Create new default config file?"), |
270 |
|
|
_("Preferences"), MB_ERR|MB_YESNO); |
271 |
|
|
if (rc == IDNO) |
272 |
|
|
return FALSE; |
273 |
|
|
else |
274 |
|
|
{ |
275 |
|
|
char cwd[256], * fn; |
276 |
|
|
FILE * fp = fopen ("keyserver.conf", "wb"); |
277 |
|
|
if (fp) |
278 |
|
|
{ |
279 |
|
|
fprintf (fp, "%s\r\n", DEF_HKP_KEYSERVER); |
280 |
|
|
fclose (fp); |
281 |
|
|
} |
282 |
|
|
GetCurrentDirectory (DIM (cwd)-1, cwd); |
283 |
|
|
fn = make_filename (cwd, "keyserver", "conf"); |
284 |
|
|
memset (path, 0, sizeof( path)); |
285 |
|
|
strncpy (path, fn, DIM (path)-1); |
286 |
|
|
free_if_alloc (fn); |
287 |
|
|
} |
288 |
|
|
} |
289 |
|
|
p = reg_prefs.kserv_conf = m_strdup (path); |
290 |
|
|
if (!p) |
291 |
|
|
BUG (0); |
292 |
|
|
|
293 |
|
|
cb = GetDlgItem( dlg, IDC_PREFS_LISTMODE ); |
294 |
|
|
reg_prefs.keylist_mode = SendMessage( cb, CB_GETCURSEL, 0, 0 ); |
295 |
|
|
|
296 |
|
|
cb = GetDlgItem( dlg, IDC_PREFS_WIPEMODE ); |
297 |
|
|
reg_prefs.wipe_mode = SendMessage( cb, CB_GETCURSEL, 0, 0 ); |
298 |
|
|
|
299 |
|
|
if (IsDlgButtonChecked (dlg, IDC_PREFS_DISABLE_HOTKEYS)) { |
300 |
|
|
hotkeys_unregister (glob_hwnd); |
301 |
|
|
reg_prefs.no_hotkeys = 1; |
302 |
|
|
} |
303 |
|
|
else { |
304 |
|
|
reg_prefs.no_hotkeys = 0; |
305 |
|
|
for( i = 0; (id = hotkeys[i]); i++ ) { |
306 |
|
|
rc = GetDlgItemText( dlg, id, t, 2 ); |
307 |
|
|
if( rc && check_hotkey( &t[0] ) ) |
308 |
|
|
hotkey_enable( ®_hotkeys[i], t ); |
309 |
|
|
else |
310 |
|
|
hotkey_disable( ®_hotkeys[i] ); |
311 |
|
|
} |
312 |
|
|
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "DisableHotkeys", "0"); |
313 |
|
|
reg_prefs.no_hotkeys = 0; |
314 |
|
|
} |
315 |
|
|
|
316 |
|
|
if ((rc = set_reg_winpt_prefs (®_prefs))) |
317 |
|
|
msg_box (dlg, winpt_strerror (rc), _("Preferences"), MB_ERR); |
318 |
|
|
|
319 |
|
|
if (reg_prefs.no_hotkeys == 0) { |
320 |
|
|
hotkeys_unregister (glob_hwnd); |
321 |
|
|
hotkeys_modify (); |
322 |
|
|
if ((rc = hotkeys_register (glob_hwnd))) |
323 |
|
|
msg_box (NULL, winpt_strerror (rc), _("Hotkeys"), MB_ERR); |
324 |
|
|
} |
325 |
|
|
EndDialog (dlg, TRUE); |
326 |
|
|
return TRUE; |
327 |
|
|
|
328 |
|
|
case IDCANCEL: |
329 |
|
|
EndDialog( dlg, FALSE ); |
330 |
|
|
return FALSE; |
331 |
|
|
} |
332 |
|
|
break; |
333 |
|
|
} |
334 |
|
|
|
335 |
|
|
return FALSE; |
336 |
|
|
} /* prefs_dlg_proc */ |