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

Contents of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (show annotations)
Mon Oct 31 14:04:59 2005 UTC (19 years, 4 months ago) by werner
File size: 9307 byte(s)
Minor changes; compiles now but gettext is still missing.

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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26