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

Contents of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (show annotations)
Mon Oct 31 21:14:11 2005 UTC (19 years, 4 months ago) by werner
File size: 9286 byte(s)
More changes.  Compiles again but there are at least gettext issues with
w32-gettext.c.  I can't get a gpg-error build with ENABLE_NLS.

1 /* wptGPGPrefsDlg.cpp - WinPT 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 "wptContext.h" /* for passphrase_s */
35 #include "wptDlgs.h"
36 #include "wptW32API.h"
37 #include "wptVersion.h"
38
39 static struct {
40 const char *name;
41 int id;
42 } opts[] = {
43 {"HomeDir", IDC_GPGPREFS_HOMEDIR},
44 {"gpgProgram", IDC_GPGPREFS_EXEDIR},
45 {"OptFile", IDC_GPGPREFS_OPTFILE},
46 {"", 0}
47 };
48
49 /* Dialog box procedure for the GPG preferences. */
50 BOOL CALLBACK
51 gpgprefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
52 {
53 char exedir[512], homedir[512], optfile[512];
54 char locale_dir[512];
55 char *p = NULL, t[256];
56 const char *s;
57 int have_optfile = 0;
58 gpg_optfile_t opt = NULL;
59 gpg_option_t e;
60 UINT n;
61
62 switch (msg) {
63 case WM_INITDIALOG:
64 SetWindowText (dlg, _("GnuPG Preferences"));
65 SetDlgItemText( dlg, IDC_GPGPREFS_HOMEINF,
66 _("GnuPG home directory (where both keyrings are located)") );
67 SetDlgItemText( dlg, IDC_GPGPREFS_OPTINF,
68 _("GnuPG config file (default: use gpg.conf)") );
69 SetDlgItemText( dlg, IDC_GPGPREFS_EXEINF,
70 _("GnuPG exe file location (full path with added gpg.exe)") );
71 SetDlgItemText( dlg, IDC_GPGPREFS_LOCALINF,
72 _("Locale directory (to access the translation files)") );
73 SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign"));
74
75 for( n=0; (s = opts[n].name); n++ ) {
76 p = get_reg_entry_gpg( s );
77 if( p ) {
78 SetDlgItemText( dlg, opts[n].id, p );
79 free_if_alloc( p );
80 }
81 }
82
83 p = get_reg_entry_mo ();
84 if (p) {
85 SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p);
86 free_if_alloc (p);
87 }
88 p = get_gnupg_cfgfile ();
89 if (p) {
90 parse_gpg_options (p, &opt);
91 free_if_alloc (p);
92 if (opt && find_option( opt, "ask-cert-level" ) )
93 CheckDlgButton( dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED );
94 if (opt && (e=find_option( opt, "comment" )) )
95 SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);
96 if (opt && (e=find_option( opt, "encrypt-to")))
97 SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val);
98 if (opt)
99 release_gpg_options (opt);
100 }
101 center_window (dlg, NULL);
102 SetForegroundWindow (dlg);
103 return TRUE;
104
105 case WM_SYSCOMMAND:
106 if( LOWORD( wparam ) == SC_CLOSE )
107 EndDialog( dlg, TRUE );
108 return FALSE;
109
110 case WM_COMMAND:
111 switch ( LOWORD( wparam ) ) {
112 case IDC_GPGPREFS_SAVE:
113 if( !GetDlgItemText( dlg, IDC_GPGPREFS_HOMEDIR, homedir, sizeof homedir -1 ) ) {
114 msg_box( dlg, _("Please enter the GnuPG home directory."), _("Preferences"), MB_ERR );
115 return FALSE;
116 }
117 if( dir_exist_check( homedir ) ) {
118 _snprintf( t, sizeof t - 1, "%s: %s", homedir, winpt_strerror(WPTERR_DIR_OPEN) );
119 msg_box( dlg, t, _("Preferences"), MB_ERR );
120 return FALSE;
121 }
122
123 if( GetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, optfile, sizeof optfile - 1 ) ) {
124 if ( file_exist_check( optfile ) ) {
125 n = msg_box(dlg, _("Could not find GPG config file.\n"
126 "Do you want to create a config file?"),
127 _("Preferences"), MB_INFO|MB_YESNO );
128 if( n == IDNO ) {
129 SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, "" );
130 return FALSE;
131 }
132 else if( n == IDYES ) {
133 FILE * fp = fopen( optfile, "wb" );
134 if( fp )
135 fclose( fp );
136 if( file_exist_check( optfile ) ) {
137 log_box( _("Preferences"), MB_ERR, "%s: %s", optfile, winpt_strerror( WPTERR_FILE_CREAT ) );
138 return FALSE;
139 }
140 have_optfile = 1;
141 }
142 }
143 else
144 have_optfile = 1;
145 if( have_optfile ) {
146 if( set_reg_entry_gpg( "OptFile", optfile ) ) {
147 msg_box( dlg, _("Could not save 'OptFile' in the registry."), _("Preferences"), MB_ERR );
148 return FALSE;
149 }
150 }
151 }
152 else {
153 char * t = get_gnupg_cfgfile ();
154 if (t && !file_exist_check (t))
155 set_reg_entry_gpg( "OptFile", t );
156 free_if_alloc (t);
157 }
158 if ( set_reg_entry_gpg( "HomeDir", homedir ) ) {
159 msg_box( dlg, _("Could not save 'HomeDir' in the registry."), _("Preferences"), MB_ERR );
160 return FALSE;
161 }
162 if( !GetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, exedir, sizeof exedir -1 ) ) {
163 msg_box( dlg, _("Please enter where GPG.exe is located."), _("Preferences"), MB_ERR );
164 return FALSE;
165 }
166 if( file_exist_check( exedir ) ) {
167 msg_box( dlg, _("Could not find the GPG program in this directory."), _("Preferences"), MB_ERR );
168 return FALSE;
169 }
170 if( set_reg_entry_gpg("gpgProgram", exedir ) ) {
171 msg_box( dlg, _("Could not save 'gpgProgram' in the registry"), _("Preferences"), MB_ERR );
172 return FALSE;
173 }
174 if( GetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1 ) ) {
175 if (dir_exist_check (locale_dir)) {
176 log_box( _("Preferences"), MB_ERR, "%s: %s", locale_dir, winpt_strerror (WPTERR_DIR_OPEN));
177 return FALSE;
178 }
179 set_reg_entry_mo (locale_dir);
180 set_gettext_file ("winpt", locale_dir);
181 }
182 else
183 set_reg_entry_mo ("");
184
185 p = get_gnupg_cfgfile ();
186 if( !p ) {
187 msg_box( dlg, _("Could not get GPG config file"), _("Preferences"), MB_ERR );
188 EndDialog( dlg, FALSE );
189 }
190 parse_gpg_options( p, &opt );
191
192 if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_ASKLEVEL ) ) {
193 modify_entry( opt, ENTRY_SINGLE, "ask-cert-level", NULL );
194 reg_prefs.gpg.ask_cert_level = 1;
195 }
196 else {
197 delete_option( opt, "ask-cert-level" );
198 reg_prefs.gpg.ask_cert_level = 0;
199 }
200
201 if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))
202 modify_entry( opt, ENTRY_MULTI, "comment", t );
203 else if( n == 0 )
204 modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );
205 else
206 delete_option( opt, "comment" );
207
208 if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )
209 modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );
210 else
211 delete_option( opt, "encrypt-to" );
212
213 commit_gpg_options( p, opt );
214 release_gpg_options (opt);
215 EndDialog( dlg, TRUE );
216 return TRUE;
217
218 case IDC_GPGPREFS_HOMEDLG:
219 const char * home;
220 home = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);
221 if (home) {
222 SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, home);
223 if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0)
224 break;
225 char *name = make_filename (home, "gpg", "exe");
226 if (file_exist_check (name) == 0)
227 SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);
228 free_if_alloc (name);
229 name = make_filename (home, "gpg", "conf");
230 if (file_exist_check (name) == 0)
231 SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name);
232 free_if_alloc (name);
233 }
234 break;
235
236 case IDC_GPGREFS_EXEDLG:
237 const char * bin;
238 bin = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG binary"), _("Executable Files (*.exe)\0*.exe\0\0"), NULL );
239 if( bin )
240 SetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, bin );
241 return TRUE;
242
243 case IDC_GPGPREFS_OPTDLG:
244 const char * opt;
245 opt = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG config file"), NULL, NULL );
246 if( opt )
247 SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, opt);
248 return TRUE;
249 }
250 break;
251 }
252
253 return FALSE;
254 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26