1 |
/* wptGPGPrefsDlg.cpp - GnuPG Preferences |
/* wptGPGPrefsDlg.cpp - GnuPG Preferences |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
34 |
#include "wptW32API.h" |
#include "wptW32API.h" |
35 |
|
|
36 |
|
|
37 |
|
/* Enable all edit items if @val is TRUE, disable them otherwise. */ |
38 |
|
static void |
39 |
|
activate_items (HWND dlg, BOOL val) |
40 |
|
{ |
41 |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_EXEDIR), val); |
42 |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGREFS_EXEDLG), val); |
43 |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCALE), val); |
44 |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCDLG), val); |
45 |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), val); |
46 |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), val); |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
/* Load the GPG4WIN default values and disabled the |
/* Load the GPG4WIN default values and disabled the |
51 |
dialog items to indicate these are fixed values. |
dialog items to indicate these are fixed values. |
52 |
Return value: true if GPG4win was found. */ |
Return value: true if GPG4win was found. */ |
68 |
} |
} |
69 |
free_if_alloc (p); |
free_if_alloc (p); |
70 |
} |
} |
71 |
|
free_if_alloc (path); |
72 |
|
|
73 |
p = get_reg_entry_mo (); |
p = get_reg_entry_mo (); |
74 |
if (p) { |
if (p) { |
79 |
} |
} |
80 |
free_if_alloc (p); |
free_if_alloc (p); |
81 |
} |
} |
82 |
|
|
83 |
|
path = get_reg_entry_gpg ("HomeDir"); |
84 |
p = multi_gnupg_path (1); |
p = multi_gnupg_path (1); |
85 |
|
if (path && dir_exist_check (path) == 0 && p && strcmp (path, p)) { |
86 |
|
/* The 'HomeDir' has a higher priority so if the key exists and is |
87 |
|
different from the multi user path, we force the use of it. */ |
88 |
|
free_if_alloc (p); |
89 |
|
p = path; |
90 |
|
} |
91 |
|
else |
92 |
|
free_if_alloc (path); |
93 |
if (p) { |
if (p) { |
94 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
95 |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE); |
96 |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE); |
97 |
free_if_alloc (p); |
free_if_alloc (p); |
98 |
} |
} |
|
|
|
99 |
return true; |
return true; |
100 |
} |
} |
101 |
|
|
109 |
p = get_reg_entry_gpg ("HomeDir"); |
p = get_reg_entry_gpg ("HomeDir"); |
110 |
if (p) { |
if (p) { |
111 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
112 |
free_if_alloc (p); |
free_if_alloc (p); |
113 |
} |
} |
114 |
p = get_reg_entry_gpg ("gpgProgram"); |
p = get_reg_entry_gpg ("gpgProgram"); |
115 |
if (p) { |
if (p) { |
116 |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p); |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p); |
117 |
free_if_alloc (p); |
free_if_alloc (p); |
118 |
} |
} |
119 |
p = get_reg_entry_mo (); |
p = get_reg_entry_mo (); |
120 |
if (p) { |
if (p) { |
121 |
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p); |
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p); |
122 |
free_if_alloc (p); |
free_if_alloc (p); |
123 |
} |
} |
124 |
|
/* if there is no 'HomeDir' registry value but an existing |
125 |
|
GPG multipath, we use this as the home dir instead. */ |
126 |
if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) { |
if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) { |
127 |
p = multi_gnupg_path (0); |
p = multi_gnupg_path (0); |
128 |
if (p && dir_exist_check (p) == 0) |
if (p && dir_exist_check (p) == 0) |
143 |
char *p = NULL, t[256]; |
char *p = NULL, t[256]; |
144 |
const char *s; |
const char *s; |
145 |
const char *folder; |
const char *folder; |
146 |
gpg_optfile_t opt = NULL; |
config_file_t opt = NULL; |
147 |
gpg_option_t e; |
conf_option_t e; |
148 |
UINT n; |
UINT n; |
149 |
|
|
150 |
switch (msg) { |
switch (msg) { |
157 |
SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF, |
SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF, |
158 |
_("Locale directory (to access the translation files)")); |
_("Locale directory (to access the translation files)")); |
159 |
SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign")); |
SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign")); |
160 |
|
SetDlgItemText (dlg, IDC_GPGPREFS_ASKEXPIRE, _("Allow to set an expiration date for signatures")); |
161 |
SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files")); |
SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files")); |
162 |
SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key")); |
SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key")); |
163 |
SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options")); |
SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options")); |
164 |
|
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDLG, _("Browse...")); |
165 |
|
SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse...")); |
166 |
|
SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse...")); |
167 |
|
SetDlgItemText (dlg, IDC_GPGPREFS_OVRDEFAULT, _("&Overwrite default settings")); |
168 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
169 |
|
|
170 |
gpg4win = load_gpg4win_values (dlg); |
gpg4win = load_gpg4win_values (dlg); |
171 |
if (!gpg4win) |
if (!gpg4win) { |
172 |
load_registry_values (dlg); |
load_registry_values (dlg); |
173 |
|
CheckDlgButton (dlg, IDC_GPGPREFS_OVRDEFAULT, BST_CHECKED); |
174 |
|
} |
175 |
|
|
176 |
p = get_gnupg_cfgfile (); |
p = get_gnupg_cfgfile (); |
177 |
if (p) { |
if (p) { |
178 |
parse_gpg_options (p, &opt); |
parse_config (p, &opt); |
179 |
free_if_alloc (p); |
free_if_alloc (p); |
180 |
if (opt) { |
if (opt) { |
181 |
if (find_option (opt, "ask-cert-level")) |
if (conf_find_option (opt, "ask-cert-expire")) |
182 |
|
CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED); |
183 |
|
if (conf_find_option (opt, "ask-cert-level")) |
184 |
CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED); |
CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED); |
185 |
if ((e=find_option (opt, "comment"))) |
e = conf_find_option (opt, "comment"); |
186 |
SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val); |
if (e != NULL) |
187 |
if ((e=find_option (opt, "encrypt-to"))) |
SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val); |
188 |
|
e = conf_find_option (opt, "encrypt-to"); |
189 |
|
if (e != NULL) |
190 |
SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val); |
SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val); |
191 |
release_gpg_options (opt); |
release_config (opt); |
192 |
} |
} |
193 |
} |
} |
194 |
|
|
195 |
|
#ifdef WINPT_MOBILE |
196 |
|
/* In mobile mode we do not allow to change the default settings |
197 |
|
because this would not make any sense. */ |
198 |
|
CheckDlgButton (dlg, IDC_GPGPREFS_OVRDEFAULT, BST_UNCHECKED); |
199 |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_OVRDEFAULT), FALSE); |
200 |
|
activate_items (dlg, FALSE); |
201 |
|
#endif |
202 |
|
|
203 |
|
|
204 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
205 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
206 |
return TRUE; |
return TRUE; |
208 |
case WM_DESTROY: |
case WM_DESTROY: |
209 |
gpg4win = false; |
gpg4win = false; |
210 |
break; |
break; |
|
|
|
|
case WM_SYSCOMMAND: |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
|
|
EndDialog (dlg, TRUE); |
|
|
return FALSE; |
|
211 |
|
|
212 |
case WM_COMMAND: |
case WM_COMMAND: |
213 |
|
if (HIWORD (wparam) == BN_CLICKED && |
214 |
|
LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) { |
215 |
|
if (IsDlgButtonChecked (dlg, LOWORD (wparam))) { |
216 |
|
activate_items (dlg, TRUE); |
217 |
|
gpg4win = false; |
218 |
|
} |
219 |
|
else { |
220 |
|
activate_items (dlg, FALSE); |
221 |
|
gpg4win = true; |
222 |
|
} |
223 |
|
break; |
224 |
|
} |
225 |
|
|
226 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
227 |
case IDC_GPGPREFS_SAVE: |
case IDC_GPGPREFS_SAVE: |
228 |
if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, |
if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, |
229 |
homedir, sizeof (homedir) -1)) { |
homedir, sizeof (homedir) -1)) { |
230 |
msg_box (dlg, _("Please enter the GnuPG home directory."), |
msg_box (dlg, _("Please enter the GnuPG home directory."), |
231 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
232 |
return FALSE; |
return FALSE; |
233 |
} |
} |
234 |
if (dir_exist_check (homedir)) { |
if (dir_exist_check (homedir)) { |
235 |
_snprintf (t, sizeof (t) - 1, "%s: %s", homedir, |
_snprintf (t, sizeof (t) - 1, "%s: %s", homedir, |
236 |
winpt_strerror (WPTERR_DIR_OPEN)); |
winpt_strerror (WPTERR_DIR_OPEN)); |
237 |
msg_box (dlg, t, _("Preferences"), MB_ERR); |
msg_box (dlg, t, _("Preferences"), MB_ERR); |
238 |
return FALSE; |
return FALSE; |
243 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
244 |
return FALSE; |
return FALSE; |
245 |
} |
} |
246 |
if( !GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
if (!GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
247 |
exedir, sizeof (exedir) -1)) { |
exedir, sizeof (exedir) -1)) { |
248 |
msg_box (dlg, _("Please enter where GPG.exe is located."), |
msg_box (dlg, _("Please enter where GPG.exe is located."), |
249 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
250 |
return FALSE; |
return FALSE; |
251 |
} |
} |
252 |
if (file_exist_check (exedir)) { |
if (file_exist_check (exedir)) { |
253 |
msg_box (dlg, _("Could not find the GPG program in this directory."), |
msg_box (dlg, _("Could not find the GPG program in this directory."), |
254 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
255 |
return FALSE; |
return FALSE; |
256 |
} |
} |
257 |
if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) { |
if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) { |
258 |
msg_box (dlg, _("Could not save 'gpgProgram' in the registry"), |
msg_box (dlg, _("Could not save 'gpgProgram' in the registry"), |
259 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
260 |
return FALSE; |
return FALSE; |
261 |
} |
} |
262 |
if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1)) { |
if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, |
263 |
|
locale_dir, sizeof (locale_dir) -1) > 0) { |
264 |
if (dir_exist_check (locale_dir)) { |
if (dir_exist_check (locale_dir)) { |
265 |
log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir, |
log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir, |
266 |
winpt_strerror (WPTERR_DIR_OPEN)); |
winpt_strerror (WPTERR_DIR_OPEN)); |
268 |
} |
} |
269 |
if (!gpg4win) |
if (!gpg4win) |
270 |
set_reg_entry_mo (locale_dir); |
set_reg_entry_mo (locale_dir); |
271 |
set_gettext_file ("winpt", locale_dir); |
gettext_set_file ("winpt", locale_dir); |
272 |
} |
} |
273 |
else if (!gpg4win) |
else if (!gpg4win) |
274 |
set_reg_entry_mo (""); |
set_reg_entry_mo (""); |
278 |
msg_box (dlg, _("Could not get GPG config file"), |
msg_box (dlg, _("Could not get GPG config file"), |
279 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
280 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
281 |
|
return TRUE; |
282 |
} |
} |
283 |
parse_gpg_options (p, &opt); |
parse_config (p, &opt); |
284 |
|
|
285 |
if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_ASKLEVEL ) ) { |
if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKLEVEL)) { |
286 |
modify_entry( opt, ENTRY_SINGLE, "ask-cert-level", NULL ); |
conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-level", NULL); |
287 |
reg_prefs.gpg.ask_cert_level = 1; |
reg_prefs.gpg.ask_cert_level = 1; |
288 |
} |
} |
289 |
else { |
else { |
290 |
delete_option (opt, "ask-cert-level"); |
conf_delete_option (opt, "ask-cert-level"); |
291 |
reg_prefs.gpg.ask_cert_level = 0; |
reg_prefs.gpg.ask_cert_level = 0; |
292 |
} |
} |
293 |
|
if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKEXPIRE)) { |
294 |
|
conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL); |
295 |
|
reg_prefs.gpg.ask_cert_expire = 1; |
296 |
|
} |
297 |
|
else { |
298 |
|
conf_delete_option (opt, "ask-cert-expire"); |
299 |
|
reg_prefs.gpg.ask_cert_expire = 0; |
300 |
|
} |
301 |
|
|
302 |
if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) )) |
n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, DIM (t)-1); |
303 |
modify_entry( opt, ENTRY_MULTI, "comment", t ); |
if (n > 0) |
304 |
else if( n == 0 ) |
conf_modify_entry (opt, ENTRY_MULTI, "comment", t); |
305 |
modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" ); |
else if (n == 0) |
306 |
|
conf_modify_entry (opt, ENTRY_MULTI, "comment", "\"\""); |
307 |
else |
else |
308 |
delete_option( opt, "comment" ); |
conf_delete_option (opt, "comment"); |
309 |
|
|
310 |
if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) ) |
n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, DIM (t)-1); |
311 |
modify_entry( opt, ENTRY_MULTI, "encrypt-to", t ); |
if (n > 0) |
312 |
|
conf_modify_entry (opt, ENTRY_MULTI, "encrypt-to", t); |
313 |
else |
else |
314 |
delete_option( opt, "encrypt-to" ); |
conf_delete_option (opt, "encrypt-to"); |
315 |
|
|
316 |
commit_gpg_options (p, opt); |
commit_config (p, opt); |
317 |
release_gpg_options (opt); |
release_config (opt); |
318 |
EndDialog (dlg, TRUE); |
/* only return TRUE if the home dir has been changed. */ |
319 |
|
if (SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR, EM_GETMODIFY, 0, 0)) { |
320 |
|
set_gnupg_default_key (NULL); |
321 |
|
EndDialog (dlg, TRUE); |
322 |
|
} |
323 |
|
else |
324 |
|
EndDialog (dlg, FALSE); |
325 |
return TRUE; |
return TRUE; |
326 |
|
|
327 |
case IDC_GPGPREFS_HOMEDLG: |
case IDC_GPGPREFS_HOMEDLG: |
328 |
folder = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL); |
folder = get_folder_dlg (dlg, _("Choose GPG Home Directory"), NULL); |
329 |
if (folder) { |
if (folder) { |
330 |
char *name; |
char *name; |
331 |
|
|
332 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder); |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder); |
333 |
if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0) |
SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR, |
334 |
|
EM_SETMODIFY, (WPARAM)(UINT)TRUE, 0); |
335 |
|
if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
336 |
|
exedir, DIM (exedir)-1) > 0) |
337 |
break; |
break; |
338 |
name = make_filename (folder, "gpg", "exe"); |
name = make_filename (folder, "gpg", "exe"); |
339 |
if (file_exist_check (name) == 0) |
if (file_exist_check (name) == 0) |
340 |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name); |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name); |
341 |
free_if_alloc (name); |
free_if_alloc (name); |
|
name = make_filename (folder, "gpg", "conf"); |
|
|
if (file_exist_check (name) == 0) |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name); |
|
|
free_if_alloc (name); |
|
342 |
} |
} |
343 |
return TRUE; |
return TRUE; |
344 |
|
|
345 |
case IDC_GPGPREFS_LOCDLG: |
case IDC_GPGPREFS_LOCDLG: |
346 |
folder = get_folder_dlg (dlg, _("Choose locale directory"), NULL); |
folder = get_folder_dlg (dlg, _("Choose Locale Directory"), NULL); |
347 |
if (folder) |
if (folder) |
348 |
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder); |
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder); |
349 |
return TRUE; |
return TRUE; |
350 |
|
|
351 |
case IDC_GPGREFS_EXEDLG: |
case IDC_GPGREFS_EXEDLG: |
352 |
s = get_fileopen_dlg (dlg, _("Choose GPG binary"), |
s = get_fileopen_dlg (dlg, _("Choose GPG Binary"), |
353 |
_("Executable Files (*.exe)\0*.exe\0\0"), |
"Executable Files (*.exe)\0*.exe\0\0", |
354 |
NULL); |
NULL); |
355 |
if (s) |
if (s) |
356 |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s); |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s); |