1 |
/* wptGPGPrefsDlg.cpp - GnuPG Preferences |
/* wptGPGPrefsDlg.cpp - GnuPG Preferences |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2006, 2007 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
36 |
|
|
37 |
/* Enable all edit items if @val is TRUE, disable them otherwise. */ |
/* Enable all edit items if @val is TRUE, disable them otherwise. */ |
38 |
static void |
static void |
39 |
enable_disable_items (HWND dlg, BOOL val) |
activate_items (HWND dlg, BOOL val) |
40 |
{ |
{ |
41 |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_EXEDIR), val); |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_EXEDIR), val); |
42 |
EnableWindow (GetDlgItem (dlg, IDC_GPGREFS_EXEDLG), val); |
EnableWindow (GetDlgItem (dlg, IDC_GPGREFS_EXEDLG), val); |
68 |
} |
} |
69 |
free_if_alloc (p); |
free_if_alloc (p); |
70 |
} |
} |
71 |
|
free_if_alloc (path); |
72 |
|
|
73 |
p = get_reg_entry_mo (); |
path = get_reg_entry_gpg ("HomeDir"); |
74 |
if (p) { |
p = multi_gnupg_path (1); |
75 |
if (dir_exist_check (p) == 0) { |
if (path && dir_exist_check (path) == 0 && p && strcmp (path, p)) { |
76 |
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p); |
/* The 'HomeDir' has a higher priority so if the key exists and is |
77 |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCALE), FALSE); |
different from the multi user path, we force the use of it. */ |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCDLG), FALSE); |
|
|
} |
|
78 |
free_if_alloc (p); |
free_if_alloc (p); |
79 |
|
p = path; |
80 |
} |
} |
81 |
|
else |
82 |
p = multi_gnupg_path (1); |
free_if_alloc (path); |
83 |
if (p) { |
if (p) { |
84 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
85 |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE); |
86 |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE); |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE); |
87 |
free_if_alloc (p); |
free_if_alloc (p); |
88 |
} |
} |
|
|
|
89 |
return true; |
return true; |
90 |
} |
} |
91 |
|
|
99 |
p = get_reg_entry_gpg ("HomeDir"); |
p = get_reg_entry_gpg ("HomeDir"); |
100 |
if (p) { |
if (p) { |
101 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
102 |
free_if_alloc (p); |
free_if_alloc (p); |
103 |
} |
} |
104 |
p = get_reg_entry_gpg ("gpgProgram"); |
p = get_reg_entry_gpg ("gpgProgram"); |
105 |
if (p) { |
if (p) { |
106 |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p); |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p); |
107 |
free_if_alloc (p); |
free_if_alloc (p); |
|
} |
|
|
p = get_reg_entry_mo (); |
|
|
if (p) { |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p); |
|
|
free_if_alloc (p); |
|
108 |
} |
} |
109 |
|
|
110 |
|
/* if there is no 'HomeDir' registry value but an existing |
111 |
|
GPG multipath, we use this as the home dir instead. */ |
112 |
if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) { |
if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) { |
113 |
p = multi_gnupg_path (0); |
p = multi_gnupg_path (0); |
114 |
if (p && dir_exist_check (p) == 0) |
if (p && dir_exist_check (p) == 0) |
125 |
static int gpg4win = false; |
static int gpg4win = false; |
126 |
char exedir[512]; |
char exedir[512]; |
127 |
char homedir[512]; |
char homedir[512]; |
|
char locale_dir[512]; |
|
128 |
char *p = NULL, t[256]; |
char *p = NULL, t[256]; |
129 |
const char *s; |
const char *s; |
130 |
const char *folder; |
const char *folder; |
131 |
gpg_optfile_t opt = NULL; |
config_file_t opt = NULL; |
132 |
gpg_option_t e; |
conf_option_t e; |
133 |
UINT n; |
UINT n; |
134 |
|
|
135 |
switch (msg) { |
switch (msg) { |
139 |
_("GnuPG home directory (where both keyrings are located)")); |
_("GnuPG home directory (where both keyrings are located)")); |
140 |
SetDlgItemText ( dlg, IDC_GPGPREFS_EXEINF, |
SetDlgItemText ( dlg, IDC_GPGPREFS_EXEINF, |
141 |
_("GnuPG exe file location (full path with added gpg.exe)")); |
_("GnuPG exe file location (full path with added gpg.exe)")); |
|
SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF, |
|
|
_("Locale directory (to access the translation files)")); |
|
142 |
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")); |
143 |
SetDlgItemText (dlg, IDC_GPGPREFS_ASKEXPIRE, _("Allow to set an expiration date for signatures")); |
SetDlgItemText (dlg, IDC_GPGPREFS_ASKEXPIRE, _("Allow to set an expiration date for signatures")); |
144 |
SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files")); |
SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files")); |
146 |
SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options")); |
SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options")); |
147 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDLG, _("Browse...")); |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDLG, _("Browse...")); |
148 |
SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse...")); |
SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse...")); |
|
SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse...")); |
|
149 |
SetDlgItemText (dlg, IDC_GPGPREFS_OVRDEFAULT, _("&Overwrite default settings")); |
SetDlgItemText (dlg, IDC_GPGPREFS_OVRDEFAULT, _("&Overwrite default settings")); |
150 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
151 |
|
|
157 |
|
|
158 |
p = get_gnupg_cfgfile (); |
p = get_gnupg_cfgfile (); |
159 |
if (p) { |
if (p) { |
160 |
parse_gpg_options (p, &opt); |
parse_config (p, &opt); |
161 |
free_if_alloc (p); |
free_if_alloc (p); |
162 |
if (opt) { |
if (opt) { |
163 |
if (find_option (opt, "ask-cert-expire")) |
if (conf_find_option (opt, "ask-cert-expire")) |
164 |
CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED); |
CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED); |
165 |
if (find_option (opt, "ask-cert-level")) |
if (conf_find_option (opt, "ask-cert-level")) |
166 |
CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED); |
CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED); |
167 |
e = find_option (opt, "comment"); |
e = conf_find_option (opt, "comment"); |
168 |
if (e != NULL) |
if (e != NULL) |
169 |
SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val); |
SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val); |
170 |
e = find_option (opt, "encrypt-to"); |
e = conf_find_option (opt, "encrypt-to"); |
171 |
if (e != NULL) |
if (e != NULL) |
172 |
SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val); |
SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val); |
173 |
release_gpg_options (opt); |
release_config (opt); |
174 |
} |
} |
175 |
} |
} |
176 |
|
|
177 |
|
#ifdef WINPT_MOBILE |
178 |
|
/* In mobile mode we do not allow to change the default settings |
179 |
|
because this would not make any sense. */ |
180 |
|
CheckDlgButton (dlg, IDC_GPGPREFS_OVRDEFAULT, BST_UNCHECKED); |
181 |
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_OVRDEFAULT), FALSE); |
182 |
|
activate_items (dlg, FALSE); |
183 |
|
#endif |
184 |
|
|
185 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
186 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
187 |
return TRUE; |
return TRUE; |
189 |
case WM_DESTROY: |
case WM_DESTROY: |
190 |
gpg4win = false; |
gpg4win = false; |
191 |
break; |
break; |
|
|
|
|
case WM_SYSCOMMAND: |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
|
|
EndDialog (dlg, FALSE); |
|
|
return FALSE; |
|
192 |
|
|
193 |
case WM_COMMAND: |
case WM_COMMAND: |
194 |
if (HIWORD (wparam) == BN_CLICKED && |
if (HIWORD (wparam) == BN_CLICKED && |
195 |
LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) { |
LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) { |
196 |
if (IsDlgButtonChecked (dlg, LOWORD (wparam))) { |
if (IsDlgButtonChecked (dlg, LOWORD (wparam))) { |
197 |
enable_disable_items (dlg, TRUE); |
activate_items (dlg, TRUE); |
198 |
gpg4win = false; |
gpg4win = false; |
199 |
} |
} |
200 |
else { |
else { |
201 |
enable_disable_items (dlg, FALSE); |
activate_items (dlg, FALSE); |
202 |
gpg4win = true; |
gpg4win = true; |
203 |
} |
} |
204 |
break; |
break; |
207 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
208 |
case IDC_GPGPREFS_SAVE: |
case IDC_GPGPREFS_SAVE: |
209 |
if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, |
if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, |
210 |
homedir, sizeof (homedir) -1)) { |
homedir, DIM (homedir) -1)) { |
211 |
msg_box (dlg, _("Please enter the GnuPG home directory."), |
msg_box (dlg, _("Please enter the GnuPG home directory."), |
212 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
213 |
return FALSE; |
return FALSE; |
214 |
} |
} |
215 |
if (dir_exist_check (homedir)) { |
if (dir_exist_check (homedir)) { |
216 |
_snprintf (t, sizeof (t) - 1, "%s: %s", homedir, |
_snprintf (t, DIM (t) - 1, "%s: %s", homedir, |
217 |
winpt_strerror (WPTERR_DIR_OPEN)); |
winpt_strerror (WPTERR_DIR_OPEN)); |
218 |
msg_box (dlg, t, _("Preferences"), MB_ERR); |
msg_box (dlg, t, _("Preferences"), MB_ERR); |
219 |
return FALSE; |
return FALSE; |
224 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
225 |
return FALSE; |
return FALSE; |
226 |
} |
} |
227 |
if( !GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
if (!GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
228 |
exedir, sizeof (exedir) -1)) { |
exedir, DIM (exedir) -1)) { |
229 |
msg_box (dlg, _("Please enter where GPG.exe is located."), |
msg_box (dlg, _("Please enter where GPG.exe is located."), |
230 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
231 |
return FALSE; |
return FALSE; |
232 |
} |
} |
240 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
241 |
return FALSE; |
return FALSE; |
242 |
} |
} |
243 |
if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, |
|
|
locale_dir, sizeof (locale_dir) -1) > 0) { |
|
|
if (dir_exist_check (locale_dir)) { |
|
|
log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir, |
|
|
winpt_strerror (WPTERR_DIR_OPEN)); |
|
|
return FALSE; |
|
|
} |
|
|
if (!gpg4win) |
|
|
set_reg_entry_mo (locale_dir); |
|
|
set_gettext_file ("winpt", locale_dir); |
|
|
} |
|
|
else if (!gpg4win) |
|
|
set_reg_entry_mo (""); |
|
|
|
|
244 |
p = get_gnupg_cfgfile (); |
p = get_gnupg_cfgfile (); |
245 |
if (!p) { |
if (!p) { |
246 |
msg_box (dlg, _("Could not get GPG config file"), |
msg_box (dlg, _("Could not get GPG config file"), |
247 |
_("Preferences"), MB_ERR); |
_("Preferences"), MB_ERR); |
248 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
249 |
|
return TRUE; |
250 |
} |
} |
251 |
parse_gpg_options (p, &opt); |
parse_config (p, &opt); |
252 |
|
|
253 |
if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKLEVEL)) { |
if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKLEVEL)) { |
254 |
modify_entry (opt, ENTRY_SINGLE, "ask-cert-level", NULL); |
conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-level", NULL); |
255 |
reg_prefs.gpg.ask_cert_level = 1; |
reg_prefs.gpg.ask_cert_level = 1; |
256 |
} |
} |
257 |
else { |
else { |
258 |
delete_option (opt, "ask-cert-level"); |
conf_delete_option (opt, "ask-cert-level"); |
259 |
reg_prefs.gpg.ask_cert_level = 0; |
reg_prefs.gpg.ask_cert_level = 0; |
260 |
} |
} |
261 |
if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKEXPIRE)) { |
if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKEXPIRE)) { |
262 |
modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL); |
conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL); |
263 |
reg_prefs.gpg.ask_cert_expire = 1; |
reg_prefs.gpg.ask_cert_expire = 1; |
264 |
} |
} |
265 |
else { |
else { |
266 |
delete_option (opt, "ask-cert-expire"); |
conf_delete_option (opt, "ask-cert-expire"); |
267 |
reg_prefs.gpg.ask_cert_expire = 0; |
reg_prefs.gpg.ask_cert_expire = 0; |
268 |
} |
} |
269 |
|
|
270 |
n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1); |
n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, DIM (t)-1); |
271 |
if (n > 0) |
if (n > 0) |
272 |
modify_entry (opt, ENTRY_MULTI, "comment", t); |
conf_modify_entry (opt, ENTRY_MULTI, "comment", t); |
273 |
else if (n == 0) |
else if (n == 0) |
274 |
modify_entry (opt, ENTRY_MULTI, "comment", "\"\""); |
conf_modify_entry (opt, ENTRY_MULTI, "comment", "\"\""); |
275 |
else |
else |
276 |
delete_option (opt, "comment"); |
conf_delete_option (opt, "comment"); |
277 |
|
|
278 |
n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1); |
n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, DIM (t)-1); |
279 |
if (n > 0) |
if (n > 0) |
280 |
modify_entry (opt, ENTRY_MULTI, "encrypt-to", t); |
conf_modify_entry (opt, ENTRY_MULTI, "encrypt-to", t); |
281 |
else |
else |
282 |
delete_option (opt, "encrypt-to"); |
conf_delete_option (opt, "encrypt-to"); |
283 |
|
|
284 |
commit_gpg_options (p, opt); |
commit_config (p, opt); |
285 |
release_gpg_options (opt); |
release_config (opt); |
286 |
EndDialog (dlg, TRUE); |
/* only return TRUE if the home dir has been changed. */ |
287 |
|
if (SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR, EM_GETMODIFY, 0, 0)) { |
288 |
|
set_gnupg_default_key (NULL); |
289 |
|
EndDialog (dlg, TRUE); |
290 |
|
} |
291 |
|
else |
292 |
|
EndDialog (dlg, FALSE); |
293 |
return TRUE; |
return TRUE; |
294 |
|
|
295 |
case IDC_GPGPREFS_HOMEDLG: |
case IDC_GPGPREFS_HOMEDLG: |
296 |
folder = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL); |
folder = get_folder_dlg (dlg, _("Choose GPG Home Directory"), NULL); |
297 |
if (folder) { |
if (folder) { |
298 |
char *name; |
char *name; |
299 |
|
|
300 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder); |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder); |
301 |
if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR, |
302 |
|
EM_SETMODIFY, (WPARAM)(UINT)TRUE, 0); |
303 |
|
if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
304 |
exedir, DIM (exedir)-1) > 0) |
exedir, DIM (exedir)-1) > 0) |
305 |
break; |
break; |
306 |
name = make_filename (folder, "gpg", "exe"); |
name = make_filename (folder, "gpg", "exe"); |
307 |
if (file_exist_check (name) == 0) |
if (file_exist_check (name) == 0) |
308 |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name); |
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name); |
309 |
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); |
|
310 |
} |
} |
311 |
return TRUE; |
return TRUE; |
|
|
|
|
case IDC_GPGPREFS_LOCDLG: |
|
|
folder = get_folder_dlg (dlg, _("Choose locale directory"), NULL); |
|
|
if (folder) |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder); |
|
|
return TRUE; |
|
312 |
|
|
313 |
case IDC_GPGREFS_EXEDLG: |
case IDC_GPGREFS_EXEDLG: |
314 |
s = get_fileopen_dlg (dlg, _("Choose GPG binary"), |
// TODO: use gpgme_ctx_set_engine_info instead. |
315 |
|
n = msg_box (dlg, _("Please be aware that the modifcation of " |
316 |
|
"the value will affect all installed " |
317 |
|
"programs which use GPG via the " |
318 |
|
"GPGME interface library\n\n" |
319 |
|
"Do you really want to continue?"), |
320 |
|
_("GPG WARNING"), MB_WARN_ASK); |
321 |
|
if (n != IDYES) |
322 |
|
return TRUE; |
323 |
|
|
324 |
|
s = get_fileopen_dlg (dlg, _("Choose GPG Binary"), |
325 |
"Executable Files (*.exe)\0*.exe\0\0", |
"Executable Files (*.exe)\0*.exe\0\0", |
326 |
NULL); |
NULL); |
327 |
if (s) |
if (s) |