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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 147 - (hide annotations)
Fri Jan 13 14:21:16 2006 UTC (19 years, 1 month ago) by twoaday
File size: 9344 byte(s)
2006-11-13  Timo Schulz  <ts@g10code.com>
 
        * wptPreferencesDlg.cpp (prefs_dlg_proc): Changed translation.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Likewise.
        * wptAboutDlgs.cpp (about_dlg_proc): Make sure GPG about
        dialog isn't shown twice.
        * wptKeyCache.cpp (gpg_keycache_next_updated_key): New.
        (gpg_keycache_update_key): Set update flag.
        * wptKeyManagerDlg.cpp (refresh_keylist): New.
        (keymanager_dlg_proc): Use new refresh system for keyservers.
        * wptKeyserverSearchDlg.cpp (kserver_search_dlg_proc):
        Update keycache.
        * wptKeyserverDlg.cpp (hkp_dlg_proc): Likewise.
        * wptKeyserver.cpp (socket_read_ext): New.
        (kserver_recv_key_ext): New.
        (kserver_read_config, kserver_write_config): Removed.
         


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 128 /* 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 twoaday 139 EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCDLG), FALSE);
65 twoaday 128 }
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 twoaday 41 /* Dialog box procedure for the GPG preferences. */
112 werner 36 BOOL CALLBACK
113     gpgprefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
114     {
115 twoaday 128 static int gpg4win = false;
116     char exedir[512];
117     char homedir[512];
118 twoaday 41 char locale_dir[512];
119     char *p = NULL, t[256];
120     const char *s;
121 twoaday 128 const char *folder;
122 werner 36 gpg_optfile_t opt = NULL;
123     gpg_option_t e;
124     UINT n;
125    
126 twoaday 41 switch (msg) {
127 werner 36 case WM_INITDIALOG:
128 twoaday 41 SetWindowText (dlg, _("GnuPG Preferences"));
129 twoaday 117 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 twoaday 41 SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign"));
136 twoaday 117 SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files"));
137 twoaday 78 SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key"));
138 twoaday 88 SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options"));
139 twoaday 147 SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDLG, _("Browse..."));
140     SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse..."));
141     SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse..."));
142 twoaday 117
143 twoaday 128 gpg4win = load_gpg4win_values (dlg);
144     if (!gpg4win)
145     load_registry_values (dlg);
146    
147 twoaday 41 p = get_gnupg_cfgfile ();
148     if (p) {
149     parse_gpg_options (p, &opt);
150     free_if_alloc (p);
151 twoaday 128 if (opt) {
152     if (find_option (opt, "ask-cert-level"))
153     CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED);
154     if ((e=find_option (opt, "comment")))
155 twoaday 41 SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);
156 twoaday 128 if ((e=find_option (opt, "encrypt-to")))
157     SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val);
158 twoaday 41 release_gpg_options (opt);
159 twoaday 128 }
160 werner 36 }
161 twoaday 117
162 twoaday 41 center_window (dlg, NULL);
163     SetForegroundWindow (dlg);
164 werner 36 return TRUE;
165 twoaday 128
166     case WM_DESTROY:
167     gpg4win = false;
168     break;
169    
170 werner 36 case WM_SYSCOMMAND:
171 twoaday 128 if (LOWORD (wparam) == SC_CLOSE)
172     EndDialog (dlg, TRUE);
173 werner 36 return FALSE;
174    
175     case WM_COMMAND:
176 twoaday 128 switch (LOWORD (wparam)) {
177 werner 36 case IDC_GPGPREFS_SAVE:
178 twoaday 128 if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR,
179     homedir, sizeof (homedir) -1)) {
180     msg_box (dlg, _("Please enter the GnuPG home directory."),
181     _("Preferences"), MB_ERR);
182 werner 36 return FALSE;
183     }
184 twoaday 117 if (dir_exist_check (homedir)) {
185     _snprintf (t, sizeof (t) - 1, "%s: %s", homedir,
186     winpt_strerror (WPTERR_DIR_OPEN));
187     msg_box (dlg, t, _("Preferences"), MB_ERR);
188 werner 36 return FALSE;
189     }
190    
191 twoaday 128 if (!gpg4win && set_reg_entry_gpg ("HomeDir", homedir)) {
192     msg_box (dlg, _("Could not save 'HomeDir' in the registry."),
193     _("Preferences"), MB_ERR);
194 werner 36 return FALSE;
195     }
196 twoaday 128 if( !GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR,
197     exedir, sizeof (exedir) -1)) {
198     msg_box (dlg, _("Please enter where GPG.exe is located."),
199     _("Preferences"), MB_ERR);
200 werner 36 return FALSE;
201     }
202 twoaday 128 if (file_exist_check (exedir)) {
203     msg_box (dlg, _("Could not find the GPG program in this directory."),
204     _("Preferences"), MB_ERR);
205 werner 36 return FALSE;
206     }
207 twoaday 128 if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) {
208     msg_box (dlg, _("Could not save 'gpgProgram' in the registry"),
209     _("Preferences"), MB_ERR);
210 werner 36 return FALSE;
211     }
212 twoaday 128 if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1)) {
213 werner 36 if (dir_exist_check (locale_dir)) {
214 twoaday 128 log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir,
215     winpt_strerror (WPTERR_DIR_OPEN));
216 werner 36 return FALSE;
217     }
218 twoaday 128 if (!gpg4win)
219     set_reg_entry_mo (locale_dir);
220 werner 36 set_gettext_file ("winpt", locale_dir);
221     }
222 twoaday 128 else if (!gpg4win)
223 werner 36 set_reg_entry_mo ("");
224    
225     p = get_gnupg_cfgfile ();
226 twoaday 128 if (!p) {
227     msg_box (dlg, _("Could not get GPG config file"),
228     _("Preferences"), MB_ERR);
229     EndDialog (dlg, FALSE);
230 werner 36 }
231 twoaday 128 parse_gpg_options (p, &opt);
232 werner 36
233 twoaday 41 if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_ASKLEVEL ) ) {
234     modify_entry( opt, ENTRY_SINGLE, "ask-cert-level", NULL );
235     reg_prefs.gpg.ask_cert_level = 1;
236     }
237     else {
238 twoaday 128 delete_option (opt, "ask-cert-level");
239 twoaday 41 reg_prefs.gpg.ask_cert_level = 0;
240     }
241 werner 36
242     if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))
243     modify_entry( opt, ENTRY_MULTI, "comment", t );
244     else if( n == 0 )
245     modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );
246     else
247     delete_option( opt, "comment" );
248    
249     if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )
250     modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );
251     else
252     delete_option( opt, "encrypt-to" );
253    
254 twoaday 128 commit_gpg_options (p, opt);
255 twoaday 41 release_gpg_options (opt);
256 twoaday 128 EndDialog (dlg, TRUE);
257 werner 36 return TRUE;
258    
259     case IDC_GPGPREFS_HOMEDLG:
260 twoaday 128 folder = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);
261     if (folder) {
262     char *name;
263    
264     SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder);
265 werner 36 if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0)
266     break;
267 twoaday 128 name = make_filename (folder, "gpg", "exe");
268 werner 36 if (file_exist_check (name) == 0)
269     SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);
270     free_if_alloc (name);
271 twoaday 128 name = make_filename (folder, "gpg", "conf");
272 werner 36 if (file_exist_check (name) == 0)
273     SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name);
274     free_if_alloc (name);
275     }
276 twoaday 128 return TRUE;
277 werner 36
278 twoaday 128 case IDC_GPGPREFS_LOCDLG:
279     folder = get_folder_dlg (dlg, _("Choose locale directory"), NULL);
280     if (folder)
281     SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder);
282     return TRUE;
283    
284 werner 36 case IDC_GPGREFS_EXEDLG:
285 twoaday 128 s = get_fileopen_dlg (dlg, _("Choose GPG binary"),
286     _("Executable Files (*.exe)\0*.exe\0\0"),
287     NULL);
288     if (s)
289     SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s);
290 werner 36 return TRUE;
291 twoaday 130
292     case IDCANCEL:
293     EndDialog (dlg, FALSE);
294     return TRUE;
295 werner 36 }
296     break;
297     }
298    
299     return FALSE;
300 twoaday 41 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26