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

Contents of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 139 - (show annotations)
Wed Jan 11 12:19:41 2006 UTC (19 years, 1 month ago) by twoaday
File size: 9164 byte(s)
2006-01-10  Timo Schulz  <ts@g10code.com>
 
        * wptMainProc.cpp (winpt_main_proc): Restore iconic
        File/Key Manager windows if needed.
        * wptGPGPrefsDlg.cpp (gpg_prefs_dlg_proc): Disable button.
        * wptSiglist.cpp (init_cmp): New.
        (siglist_sort): New.
        (siglist_cmp_cb): New.
        (siglist_add_key): Force NOKEY status when key was not found.
        * wptKeysigDlg.cpp (recv_single_key): New.
        (recv_missing_keys): Reload entire key when more than one key
        was fetched.
        (keysig_dlg_proc): Support sorting the listview items.
         

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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26