/[winpt]/trunk/Src/wptGPGPrefsDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 315 - (hide annotations)
Fri May 25 14:45:06 2007 UTC (17 years, 9 months ago) by twoaday
File size: 11964 byte(s)


1 twoaday 128 /* wptGPGPrefsDlg.cpp - GnuPG Preferences
2 twoaday 241 * Copyright (C) 2001-2006 Timo Schulz
3 werner 36 *
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 twoaday 278 activate_items (HWND dlg, BOOL val)
40 twoaday 161 {
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 twoaday 241 free_if_alloc (path);
72 twoaday 128
73     p = get_reg_entry_mo ();
74     if (p) {
75     if (dir_exist_check (p) == 0) {
76     SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p);
77     EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCALE), FALSE);
78 twoaday 139 EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCDLG), FALSE);
79 twoaday 128 }
80     free_if_alloc (p);
81     }
82 twoaday 241
83     path = get_reg_entry_gpg ("HomeDir");
84 twoaday 128 p = multi_gnupg_path (1);
85 twoaday 241 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 twoaday 128 if (p) {
94     SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p);
95     EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE);
96     EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE);
97     free_if_alloc (p);
98     }
99     return true;
100     }
101    
102    
103     /* Load the GPG values direct from the registry. */
104     static void
105     load_registry_values (HWND dlg)
106     {
107     char *p;
108    
109     p = get_reg_entry_gpg ("HomeDir");
110     if (p) {
111     SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p);
112 twoaday 225 free_if_alloc (p);
113 twoaday 128 }
114     p = get_reg_entry_gpg ("gpgProgram");
115     if (p) {
116     SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p);
117 twoaday 225 free_if_alloc (p);
118 twoaday 128 }
119     p = get_reg_entry_mo ();
120     if (p) {
121     SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p);
122 twoaday 225 free_if_alloc (p);
123 twoaday 128 }
124 twoaday 256 /* if there is no 'HomeDir' registry value but an existing
125     GPG multipath, we use this as the home dir instead. */
126 twoaday 128 if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) {
127     p = multi_gnupg_path (0);
128     if (p && dir_exist_check (p) == 0)
129     SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p);
130     free_if_alloc (p);
131     }
132     }
133    
134    
135 twoaday 41 /* Dialog box procedure for the GPG preferences. */
136 werner 36 BOOL CALLBACK
137     gpgprefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
138     {
139 twoaday 128 static int gpg4win = false;
140     char exedir[512];
141     char homedir[512];
142 twoaday 41 char locale_dir[512];
143     char *p = NULL, t[256];
144     const char *s;
145 twoaday 128 const char *folder;
146 twoaday 271 config_file_t opt = NULL;
147     conf_option_t e;
148 werner 36 UINT n;
149    
150 twoaday 41 switch (msg) {
151 werner 36 case WM_INITDIALOG:
152 twoaday 41 SetWindowText (dlg, _("GnuPG Preferences"));
153 twoaday 117 SetDlgItemText (dlg, IDC_GPGPREFS_HOMEINF,
154     _("GnuPG home directory (where both keyrings are located)"));
155     SetDlgItemText ( dlg, IDC_GPGPREFS_EXEINF,
156     _("GnuPG exe file location (full path with added gpg.exe)"));
157     SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF,
158     _("Locale directory (to access the translation files)"));
159 twoaday 41 SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign"));
160 twoaday 181 SetDlgItemText (dlg, IDC_GPGPREFS_ASKEXPIRE, _("Allow to set an expiration date for signatures"));
161 twoaday 117 SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files"));
162 twoaday 78 SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key"));
163 twoaday 88 SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options"));
164 twoaday 147 SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDLG, _("Browse..."));
165     SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse..."));
166     SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse..."));
167 twoaday 150 SetDlgItemText (dlg, IDC_GPGPREFS_OVRDEFAULT, _("&Overwrite default settings"));
168 twoaday 177 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
169 twoaday 117
170 twoaday 128 gpg4win = load_gpg4win_values (dlg);
171 twoaday 161 if (!gpg4win) {
172 twoaday 128 load_registry_values (dlg);
173 twoaday 161 CheckDlgButton (dlg, IDC_GPGPREFS_OVRDEFAULT, BST_CHECKED);
174     }
175 twoaday 128
176 twoaday 41 p = get_gnupg_cfgfile ();
177     if (p) {
178 twoaday 270 parse_config (p, &opt);
179 twoaday 41 free_if_alloc (p);
180 twoaday 128 if (opt) {
181 twoaday 271 if (conf_find_option (opt, "ask-cert-expire"))
182 twoaday 181 CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED);
183 twoaday 271 if (conf_find_option (opt, "ask-cert-level"))
184 twoaday 128 CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED);
185 twoaday 271 e = conf_find_option (opt, "comment");
186 twoaday 177 if (e != NULL)
187     SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);
188 twoaday 271 e = conf_find_option (opt, "encrypt-to");
189 twoaday 177 if (e != NULL)
190 twoaday 128 SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val);
191 twoaday 270 release_config (opt);
192 twoaday 128 }
193 werner 36 }
194 twoaday 117
195 twoaday 278 #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 twoaday 41 center_window (dlg, NULL);
204     SetForegroundWindow (dlg);
205 werner 36 return TRUE;
206 twoaday 128
207     case WM_DESTROY:
208     gpg4win = false;
209     break;
210 werner 36
211     case WM_COMMAND:
212 twoaday 161 if (HIWORD (wparam) == BN_CLICKED &&
213     LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) {
214 twoaday 165 if (IsDlgButtonChecked (dlg, LOWORD (wparam))) {
215 twoaday 278 activate_items (dlg, TRUE);
216 twoaday 165 gpg4win = false;
217     }
218     else {
219 twoaday 278 activate_items (dlg, FALSE);
220 twoaday 165 gpg4win = true;
221     }
222 twoaday 161 break;
223     }
224    
225 twoaday 128 switch (LOWORD (wparam)) {
226 werner 36 case IDC_GPGPREFS_SAVE:
227 twoaday 128 if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR,
228 twoaday 315 homedir, DIM (homedir) -1)) {
229 twoaday 165 msg_box (dlg, _("Please enter the GnuPG home directory."),
230 twoaday 128 _("Preferences"), MB_ERR);
231 werner 36 return FALSE;
232     }
233 twoaday 117 if (dir_exist_check (homedir)) {
234 twoaday 315 _snprintf (t, DIM (t) - 1, "%s: %s", homedir,
235 twoaday 117 winpt_strerror (WPTERR_DIR_OPEN));
236     msg_box (dlg, t, _("Preferences"), MB_ERR);
237 werner 36 return FALSE;
238     }
239    
240 twoaday 128 if (!gpg4win && set_reg_entry_gpg ("HomeDir", homedir)) {
241     msg_box (dlg, _("Could not save 'HomeDir' in the registry."),
242     _("Preferences"), MB_ERR);
243 werner 36 return FALSE;
244     }
245 twoaday 256 if (!GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR,
246 twoaday 315 exedir, DIM (exedir) -1)) {
247 twoaday 256 msg_box (dlg, _("Please enter where GPG.exe is located."),
248 twoaday 128 _("Preferences"), MB_ERR);
249 werner 36 return FALSE;
250     }
251 twoaday 128 if (file_exist_check (exedir)) {
252 twoaday 165 msg_box (dlg, _("Could not find the GPG program in this directory."),
253 twoaday 128 _("Preferences"), MB_ERR);
254 werner 36 return FALSE;
255     }
256 twoaday 128 if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) {
257 twoaday 165 msg_box (dlg, _("Could not save 'gpgProgram' in the registry"),
258 twoaday 128 _("Preferences"), MB_ERR);
259 werner 36 return FALSE;
260     }
261 twoaday 256 if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE,
262 twoaday 315 locale_dir, DIM (locale_dir) -1) > 0) {
263 werner 36 if (dir_exist_check (locale_dir)) {
264 twoaday 128 log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir,
265     winpt_strerror (WPTERR_DIR_OPEN));
266 werner 36 return FALSE;
267     }
268 twoaday 128 if (!gpg4win)
269     set_reg_entry_mo (locale_dir);
270 twoaday 278 gettext_set_file ("winpt", locale_dir);
271 werner 36 }
272 twoaday 128 else if (!gpg4win)
273 werner 36 set_reg_entry_mo ("");
274    
275     p = get_gnupg_cfgfile ();
276 twoaday 128 if (!p) {
277     msg_box (dlg, _("Could not get GPG config file"),
278     _("Preferences"), MB_ERR);
279     EndDialog (dlg, FALSE);
280 twoaday 225 return TRUE;
281 werner 36 }
282 twoaday 270 parse_config (p, &opt);
283 werner 36
284 twoaday 165 if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKLEVEL)) {
285 twoaday 271 conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-level", NULL);
286 twoaday 41 reg_prefs.gpg.ask_cert_level = 1;
287     }
288     else {
289 twoaday 271 conf_delete_option (opt, "ask-cert-level");
290 twoaday 41 reg_prefs.gpg.ask_cert_level = 0;
291     }
292 twoaday 181 if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKEXPIRE)) {
293 twoaday 271 conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL);
294 twoaday 181 reg_prefs.gpg.ask_cert_expire = 1;
295     }
296     else {
297 twoaday 271 conf_delete_option (opt, "ask-cert-expire");
298 twoaday 181 reg_prefs.gpg.ask_cert_expire = 0;
299     }
300    
301 twoaday 225 n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, DIM (t)-1);
302 twoaday 165 if (n > 0)
303 twoaday 271 conf_modify_entry (opt, ENTRY_MULTI, "comment", t);
304 twoaday 165 else if (n == 0)
305 twoaday 271 conf_modify_entry (opt, ENTRY_MULTI, "comment", "\"\"");
306 werner 36 else
307 twoaday 271 conf_delete_option (opt, "comment");
308 werner 36
309 twoaday 225 n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, DIM (t)-1);
310 twoaday 165 if (n > 0)
311 twoaday 271 conf_modify_entry (opt, ENTRY_MULTI, "encrypt-to", t);
312 werner 36 else
313 twoaday 271 conf_delete_option (opt, "encrypt-to");
314 werner 36
315 twoaday 270 commit_config (p, opt);
316     release_config (opt);
317 twoaday 197 /* only return TRUE if the home dir has been changed. */
318     if (SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR, EM_GETMODIFY, 0, 0)) {
319     set_gnupg_default_key (NULL);
320     EndDialog (dlg, TRUE);
321     }
322     else
323     EndDialog (dlg, FALSE);
324 werner 36 return TRUE;
325    
326     case IDC_GPGPREFS_HOMEDLG:
327 twoaday 197 folder = get_folder_dlg (dlg, _("Choose GPG Home Directory"), NULL);
328 twoaday 128 if (folder) {
329     char *name;
330    
331     SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder);
332 twoaday 197 SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR,
333     EM_SETMODIFY, (WPARAM)(UINT)TRUE, 0);
334 twoaday 256 if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR,
335 twoaday 165 exedir, DIM (exedir)-1) > 0)
336 werner 36 break;
337 twoaday 128 name = make_filename (folder, "gpg", "exe");
338 werner 36 if (file_exist_check (name) == 0)
339     SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);
340     free_if_alloc (name);
341     }
342 twoaday 128 return TRUE;
343 werner 36
344 twoaday 128 case IDC_GPGPREFS_LOCDLG:
345 twoaday 193 folder = get_folder_dlg (dlg, _("Choose Locale Directory"), NULL);
346 twoaday 128 if (folder)
347     SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder);
348     return TRUE;
349    
350 werner 36 case IDC_GPGREFS_EXEDLG:
351 twoaday 315 n = msg_box (dlg, _("Please be aware that the modifcation of "
352     "the value will affect all installed "
353     "programs which use GPG via the "
354     "GPGME interface library\n\n"
355     "Do you really want to continue?"),
356     _("GPG Warning"), MB_WARN_ASK);
357     if (n != IDYES)
358     return TRUE;
359    
360 twoaday 197 s = get_fileopen_dlg (dlg, _("Choose GPG Binary"),
361 twoaday 167 "Executable Files (*.exe)\0*.exe\0\0",
362 twoaday 128 NULL);
363     if (s)
364     SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s);
365 werner 36 return TRUE;
366 twoaday 130
367     case IDCANCEL:
368     EndDialog (dlg, FALSE);
369     return TRUE;
370 werner 36 }
371     break;
372     }
373    
374     return FALSE;
375 twoaday 41 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26