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

Contents of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations)
Mon Dec 19 13:05:59 2005 UTC (19 years, 2 months ago) by twoaday
File size: 9029 byte(s)
2005-12-17  Timo Schulz  <ts@g10code.com>
 
        * wptUTF8.cpp: Removed unused charset array.
        * wptSigList.cpp (siglist_build): Increase size for 'class'
        column.
        * wptGPG.cpp (get_gnupg_path): Simplified.
        * WinPT.cpp (load_gpg_env): New.
        (check_crypto_engine): Return type is now bool.
        * wptRegistry.cpp (is_gpg4win_installed): New.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): More consistent
        dialog design.
        * wptKeyManagerDlg.cpp (translate_menu_strings): New.
        (translate_popupmenu_strings): New.
        * wptKeyEditDlgs.cpp (is_jpg_file): New.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26