1 |
twoaday |
128 |
/* wptGPGPrefsDlg.cpp - GnuPG Preferences |
2 |
werner |
36 |
* Copyright (C) 2001-2005 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 |
twoaday |
128 |
|
21 |
werner |
42 |
#ifdef HAVE_CONFIG_H |
22 |
|
|
#include <config.h> |
23 |
|
|
#endif |
24 |
|
|
|
25 |
werner |
36 |
#include <windows.h> |
26 |
|
|
|
27 |
werner |
47 |
#include "resource.h" |
28 |
werner |
36 |
#include "wptNLS.h" |
29 |
|
|
#include "wptTypes.h" |
30 |
|
|
#include "wptErrors.h" |
31 |
|
|
#include "wptGPG.h" |
32 |
|
|
#include "wptRegistry.h" |
33 |
|
|
#include "wptCommonCtl.h" |
34 |
|
|
#include "wptW32API.h" |
35 |
|
|
|
36 |
|
|
|
37 |
twoaday |
161 |
/* Enable all edit items if @val is TRUE, disable them otherwise. */ |
38 |
|
|
static void |
39 |
|
|
enable_disable_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 |
twoaday |
128 |
/* Load the GPG4WIN default values and disabled the |
51 |
|
|
dialog items to indicate these are fixed values. |
52 |
|
|
Return value: true if GPG4win was found. */ |
53 |
|
|
static bool |
54 |
|
|
load_gpg4win_values (HWND dlg) |
55 |
|
|
{ |
56 |
|
|
char *path; |
57 |
|
|
char *p; |
58 |
|
|
|
59 |
|
|
path = get_reg_entry_gpg4win (NULL); |
60 |
|
|
if (!path) |
61 |
|
|
return false; |
62 |
|
|
p = make_filename (path, "gpg", "exe"); |
63 |
|
|
if (p) { |
64 |
|
|
if (file_exist_check (p) == 0) { |
65 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p); |
66 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_EXEDIR), FALSE); |
67 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_GPGREFS_EXEDLG), FALSE); |
68 |
|
|
} |
69 |
|
|
free_if_alloc (p); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
p = get_reg_entry_mo (); |
73 |
|
|
if (p) { |
74 |
|
|
if (dir_exist_check (p) == 0) { |
75 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p); |
76 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCALE), FALSE); |
77 |
twoaday |
139 |
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCDLG), FALSE); |
78 |
twoaday |
128 |
} |
79 |
|
|
free_if_alloc (p); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
p = multi_gnupg_path (1); |
83 |
|
|
if (p) { |
84 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
85 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE); |
86 |
|
|
EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE); |
87 |
|
|
free_if_alloc (p); |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
return true; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
/* Load the GPG values direct from the registry. */ |
95 |
|
|
static void |
96 |
|
|
load_registry_values (HWND dlg) |
97 |
|
|
{ |
98 |
|
|
char *p; |
99 |
|
|
|
100 |
|
|
p = get_reg_entry_gpg ("HomeDir"); |
101 |
|
|
if (p) { |
102 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
103 |
|
|
free_if_alloc (p); |
104 |
|
|
} |
105 |
|
|
p = get_reg_entry_gpg ("gpgProgram"); |
106 |
|
|
if (p) { |
107 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p); |
108 |
|
|
free_if_alloc (p); |
109 |
|
|
} |
110 |
|
|
p = get_reg_entry_mo (); |
111 |
|
|
if (p) { |
112 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p); |
113 |
|
|
free_if_alloc (p); |
114 |
|
|
} |
115 |
|
|
if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) { |
116 |
|
|
p = multi_gnupg_path (0); |
117 |
|
|
if (p && dir_exist_check (p) == 0) |
118 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p); |
119 |
|
|
free_if_alloc (p); |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
|
124 |
twoaday |
41 |
/* Dialog box procedure for the GPG preferences. */ |
125 |
werner |
36 |
BOOL CALLBACK |
126 |
|
|
gpgprefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
127 |
|
|
{ |
128 |
twoaday |
128 |
static int gpg4win = false; |
129 |
|
|
char exedir[512]; |
130 |
|
|
char homedir[512]; |
131 |
twoaday |
41 |
char locale_dir[512]; |
132 |
|
|
char *p = NULL, t[256]; |
133 |
|
|
const char *s; |
134 |
twoaday |
128 |
const char *folder; |
135 |
werner |
36 |
gpg_optfile_t opt = NULL; |
136 |
|
|
gpg_option_t e; |
137 |
|
|
UINT n; |
138 |
|
|
|
139 |
twoaday |
41 |
switch (msg) { |
140 |
werner |
36 |
case WM_INITDIALOG: |
141 |
twoaday |
41 |
SetWindowText (dlg, _("GnuPG Preferences")); |
142 |
twoaday |
117 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEINF, |
143 |
|
|
_("GnuPG home directory (where both keyrings are located)")); |
144 |
|
|
SetDlgItemText ( dlg, IDC_GPGPREFS_EXEINF, |
145 |
|
|
_("GnuPG exe file location (full path with added gpg.exe)")); |
146 |
|
|
SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF, |
147 |
|
|
_("Locale directory (to access the translation files)")); |
148 |
twoaday |
41 |
SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign")); |
149 |
twoaday |
181 |
SetDlgItemText (dlg, IDC_GPGPREFS_ASKEXPIRE, _("Allow to set an expiration date for signatures")); |
150 |
twoaday |
117 |
SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files")); |
151 |
twoaday |
78 |
SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key")); |
152 |
twoaday |
88 |
SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options")); |
153 |
twoaday |
147 |
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDLG, _("Browse...")); |
154 |
|
|
SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse...")); |
155 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse...")); |
156 |
twoaday |
150 |
SetDlgItemText (dlg, IDC_GPGPREFS_OVRDEFAULT, _("&Overwrite default settings")); |
157 |
twoaday |
177 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
158 |
twoaday |
117 |
|
159 |
twoaday |
128 |
gpg4win = load_gpg4win_values (dlg); |
160 |
twoaday |
161 |
if (!gpg4win) { |
161 |
twoaday |
128 |
load_registry_values (dlg); |
162 |
twoaday |
161 |
CheckDlgButton (dlg, IDC_GPGPREFS_OVRDEFAULT, BST_CHECKED); |
163 |
|
|
} |
164 |
twoaday |
128 |
|
165 |
twoaday |
41 |
p = get_gnupg_cfgfile (); |
166 |
|
|
if (p) { |
167 |
|
|
parse_gpg_options (p, &opt); |
168 |
|
|
free_if_alloc (p); |
169 |
twoaday |
128 |
if (opt) { |
170 |
twoaday |
181 |
if (find_option (opt, "ask-cert-expire")) |
171 |
|
|
CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED); |
172 |
twoaday |
128 |
if (find_option (opt, "ask-cert-level")) |
173 |
|
|
CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED); |
174 |
twoaday |
177 |
e = find_option (opt, "comment"); |
175 |
|
|
if (e != NULL) |
176 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val); |
177 |
|
|
e = find_option (opt, "encrypt-to"); |
178 |
|
|
if (e != NULL) |
179 |
twoaday |
128 |
SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val); |
180 |
twoaday |
41 |
release_gpg_options (opt); |
181 |
twoaday |
128 |
} |
182 |
werner |
36 |
} |
183 |
twoaday |
117 |
|
184 |
twoaday |
41 |
center_window (dlg, NULL); |
185 |
|
|
SetForegroundWindow (dlg); |
186 |
werner |
36 |
return TRUE; |
187 |
twoaday |
128 |
|
188 |
|
|
case WM_DESTROY: |
189 |
|
|
gpg4win = false; |
190 |
|
|
break; |
191 |
|
|
|
192 |
werner |
36 |
case WM_SYSCOMMAND: |
193 |
twoaday |
128 |
if (LOWORD (wparam) == SC_CLOSE) |
194 |
twoaday |
165 |
EndDialog (dlg, FALSE); |
195 |
werner |
36 |
return FALSE; |
196 |
|
|
|
197 |
|
|
case WM_COMMAND: |
198 |
twoaday |
161 |
if (HIWORD (wparam) == BN_CLICKED && |
199 |
|
|
LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) { |
200 |
twoaday |
165 |
if (IsDlgButtonChecked (dlg, LOWORD (wparam))) { |
201 |
twoaday |
161 |
enable_disable_items (dlg, TRUE); |
202 |
twoaday |
165 |
gpg4win = false; |
203 |
|
|
} |
204 |
|
|
else { |
205 |
twoaday |
161 |
enable_disable_items (dlg, FALSE); |
206 |
twoaday |
165 |
gpg4win = true; |
207 |
|
|
} |
208 |
twoaday |
161 |
break; |
209 |
|
|
} |
210 |
|
|
|
211 |
twoaday |
128 |
switch (LOWORD (wparam)) { |
212 |
werner |
36 |
case IDC_GPGPREFS_SAVE: |
213 |
twoaday |
128 |
if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, |
214 |
|
|
homedir, sizeof (homedir) -1)) { |
215 |
twoaday |
165 |
msg_box (dlg, _("Please enter the GnuPG home directory."), |
216 |
twoaday |
128 |
_("Preferences"), MB_ERR); |
217 |
werner |
36 |
return FALSE; |
218 |
|
|
} |
219 |
twoaday |
117 |
if (dir_exist_check (homedir)) { |
220 |
twoaday |
165 |
_snprintf (t, sizeof (t) - 1, "%s: %s", homedir, |
221 |
twoaday |
117 |
winpt_strerror (WPTERR_DIR_OPEN)); |
222 |
|
|
msg_box (dlg, t, _("Preferences"), MB_ERR); |
223 |
werner |
36 |
return FALSE; |
224 |
|
|
} |
225 |
|
|
|
226 |
twoaday |
128 |
if (!gpg4win && set_reg_entry_gpg ("HomeDir", homedir)) { |
227 |
|
|
msg_box (dlg, _("Could not save 'HomeDir' in the registry."), |
228 |
|
|
_("Preferences"), MB_ERR); |
229 |
werner |
36 |
return FALSE; |
230 |
|
|
} |
231 |
twoaday |
128 |
if( !GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
232 |
|
|
exedir, sizeof (exedir) -1)) { |
233 |
|
|
msg_box (dlg, _("Please enter where GPG.exe is located."), |
234 |
|
|
_("Preferences"), MB_ERR); |
235 |
werner |
36 |
return FALSE; |
236 |
|
|
} |
237 |
twoaday |
128 |
if (file_exist_check (exedir)) { |
238 |
twoaday |
165 |
msg_box (dlg, _("Could not find the GPG program in this directory."), |
239 |
twoaday |
128 |
_("Preferences"), MB_ERR); |
240 |
werner |
36 |
return FALSE; |
241 |
|
|
} |
242 |
twoaday |
128 |
if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) { |
243 |
twoaday |
165 |
msg_box (dlg, _("Could not save 'gpgProgram' in the registry"), |
244 |
twoaday |
128 |
_("Preferences"), MB_ERR); |
245 |
werner |
36 |
return FALSE; |
246 |
|
|
} |
247 |
twoaday |
165 |
if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, |
248 |
|
|
locale_dir, sizeof (locale_dir) -1) > 0) { |
249 |
werner |
36 |
if (dir_exist_check (locale_dir)) { |
250 |
twoaday |
128 |
log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir, |
251 |
|
|
winpt_strerror (WPTERR_DIR_OPEN)); |
252 |
werner |
36 |
return FALSE; |
253 |
|
|
} |
254 |
twoaday |
128 |
if (!gpg4win) |
255 |
|
|
set_reg_entry_mo (locale_dir); |
256 |
werner |
36 |
set_gettext_file ("winpt", locale_dir); |
257 |
|
|
} |
258 |
twoaday |
128 |
else if (!gpg4win) |
259 |
werner |
36 |
set_reg_entry_mo (""); |
260 |
|
|
|
261 |
|
|
p = get_gnupg_cfgfile (); |
262 |
twoaday |
128 |
if (!p) { |
263 |
|
|
msg_box (dlg, _("Could not get GPG config file"), |
264 |
|
|
_("Preferences"), MB_ERR); |
265 |
|
|
EndDialog (dlg, FALSE); |
266 |
werner |
36 |
} |
267 |
twoaday |
128 |
parse_gpg_options (p, &opt); |
268 |
werner |
36 |
|
269 |
twoaday |
165 |
if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKLEVEL)) { |
270 |
|
|
modify_entry (opt, ENTRY_SINGLE, "ask-cert-level", NULL); |
271 |
twoaday |
41 |
reg_prefs.gpg.ask_cert_level = 1; |
272 |
|
|
} |
273 |
|
|
else { |
274 |
twoaday |
128 |
delete_option (opt, "ask-cert-level"); |
275 |
twoaday |
41 |
reg_prefs.gpg.ask_cert_level = 0; |
276 |
|
|
} |
277 |
twoaday |
181 |
if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKEXPIRE)) { |
278 |
|
|
modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL); |
279 |
|
|
reg_prefs.gpg.ask_cert_expire = 1; |
280 |
|
|
} |
281 |
|
|
else { |
282 |
|
|
delete_option (opt, "ask-cert-expire"); |
283 |
|
|
reg_prefs.gpg.ask_cert_expire = 0; |
284 |
|
|
} |
285 |
|
|
|
286 |
twoaday |
165 |
n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1); |
287 |
|
|
if (n > 0) |
288 |
|
|
modify_entry (opt, ENTRY_MULTI, "comment", t); |
289 |
|
|
else if (n == 0) |
290 |
|
|
modify_entry (opt, ENTRY_MULTI, "comment", "\"\""); |
291 |
werner |
36 |
else |
292 |
twoaday |
165 |
delete_option (opt, "comment"); |
293 |
werner |
36 |
|
294 |
twoaday |
165 |
n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1); |
295 |
|
|
if (n > 0) |
296 |
|
|
modify_entry (opt, ENTRY_MULTI, "encrypt-to", t); |
297 |
werner |
36 |
else |
298 |
twoaday |
165 |
delete_option (opt, "encrypt-to"); |
299 |
werner |
36 |
|
300 |
twoaday |
128 |
commit_gpg_options (p, opt); |
301 |
twoaday |
41 |
release_gpg_options (opt); |
302 |
twoaday |
128 |
EndDialog (dlg, TRUE); |
303 |
werner |
36 |
return TRUE; |
304 |
|
|
|
305 |
|
|
case IDC_GPGPREFS_HOMEDLG: |
306 |
twoaday |
128 |
folder = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL); |
307 |
|
|
if (folder) { |
308 |
|
|
char *name; |
309 |
|
|
|
310 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder); |
311 |
twoaday |
165 |
if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, |
312 |
|
|
exedir, DIM (exedir)-1) > 0) |
313 |
werner |
36 |
break; |
314 |
twoaday |
128 |
name = make_filename (folder, "gpg", "exe"); |
315 |
werner |
36 |
if (file_exist_check (name) == 0) |
316 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name); |
317 |
|
|
free_if_alloc (name); |
318 |
twoaday |
128 |
name = make_filename (folder, "gpg", "conf"); |
319 |
werner |
36 |
if (file_exist_check (name) == 0) |
320 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name); |
321 |
|
|
free_if_alloc (name); |
322 |
|
|
} |
323 |
twoaday |
128 |
return TRUE; |
324 |
werner |
36 |
|
325 |
twoaday |
128 |
case IDC_GPGPREFS_LOCDLG: |
326 |
twoaday |
193 |
folder = get_folder_dlg (dlg, _("Choose Locale Directory"), NULL); |
327 |
twoaday |
128 |
if (folder) |
328 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder); |
329 |
|
|
return TRUE; |
330 |
|
|
|
331 |
werner |
36 |
case IDC_GPGREFS_EXEDLG: |
332 |
twoaday |
128 |
s = get_fileopen_dlg (dlg, _("Choose GPG binary"), |
333 |
twoaday |
167 |
"Executable Files (*.exe)\0*.exe\0\0", |
334 |
twoaday |
128 |
NULL); |
335 |
|
|
if (s) |
336 |
|
|
SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s); |
337 |
werner |
36 |
return TRUE; |
338 |
twoaday |
130 |
|
339 |
|
|
case IDCANCEL: |
340 |
|
|
EndDialog (dlg, FALSE); |
341 |
|
|
return TRUE; |
342 |
werner |
36 |
} |
343 |
|
|
break; |
344 |
|
|
} |
345 |
|
|
|
346 |
|
|
return FALSE; |
347 |
twoaday |
41 |
} |