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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 150 - (hide annotations)
Wed Jan 18 11:52:45 2006 UTC (19 years, 1 month ago) by twoaday
File size: 9517 byte(s)
2006-01-18  Timo Schulz  <ts@g10code.com>
 
        * wptListview.cpp (listview_del_sel_items): Fixed index
        calculation. This fixed a lot of problems with the KM listview
        update.
        (listview_del_all): Renamed to...
        (listview_del_all_items): ..this. Changed all callers.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Just refresh
        list when file import contained new/updated keys.
        * wptKeyManager.cpp (km_file_import): Indicate if the
        import contained any new/update keys.
        * wptClipImportDlg.cpp (print_import_status): Just mark
        keys which actually changed.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26