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

Contents of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (show annotations)
Thu Oct 27 15:25:13 2005 UTC (19 years, 4 months ago) by werner
File size: 9092 byte(s)
First set of changes to use autotools for building.
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
51 BOOL CALLBACK
52 gpgprefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
53 {
54 char exedir[1024], homedir[1024], optfile[1024];
55 char locale_dir[1024];
56 char * p = NULL, t[512];
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 #ifndef LANG_DE
66 SetWindowText( dlg, _("GnuPG Preferences") );
67 SetDlgItemText( dlg, IDC_GPGPREFS_HOMEINF,
68 _("GnuPG home directory (where both keyrings are located)") );
69 SetDlgItemText( dlg, IDC_GPGPREFS_OPTINF,
70 _("GnuPG config file (default: use gpg.conf)") );
71 SetDlgItemText( dlg, IDC_GPGPREFS_EXEINF,
72 _("GnuPG exe file location (full path with added gpg.exe)") );
73 SetDlgItemText( dlg, IDC_GPGPREFS_LOCALINF,
74 _("Locale directory (to access the translation files)") );
75 #endif
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 if( (p = get_reg_entry_mo( )) ) {
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, "force-v3-sigs" ) )
93 CheckDlgButton( dlg, IDC_GPGPREFS_V3SIGS, 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 }
99 center_window( dlg, NULL );
100 SetForegroundWindow( dlg );
101 return TRUE;
102
103 case WM_SYSCOMMAND:
104 if( LOWORD( wparam ) == SC_CLOSE )
105 EndDialog( dlg, TRUE );
106 return FALSE;
107
108 case WM_COMMAND:
109 switch ( LOWORD( wparam ) ) {
110 case IDC_GPGPREFS_SAVE:
111 if( !GetDlgItemText( dlg, IDC_GPGPREFS_HOMEDIR, homedir, sizeof homedir -1 ) ) {
112 msg_box( dlg, _("Please enter the GnuPG home directory."), _("Preferences"), MB_ERR );
113 return FALSE;
114 }
115 if( dir_exist_check( homedir ) ) {
116 _snprintf( t, sizeof t - 1, "%s: %s", homedir, winpt_strerror(WPTERR_DIR_OPEN) );
117 msg_box( dlg, t, _("Preferences"), MB_ERR );
118 return FALSE;
119 }
120
121 if( GetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, optfile, sizeof optfile - 1 ) ) {
122 if ( file_exist_check( optfile ) ) {
123 n = msg_box(dlg, _("Could not find GPG config file.\n"
124 "Do you want to create a config file?"),
125 _("Preferences"), MB_INFO|MB_YESNO );
126 if( n == IDNO ) {
127 SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, "" );
128 return FALSE;
129 }
130 else if( n == IDYES ) {
131 FILE * fp = fopen( optfile, "wb" );
132 if( fp )
133 fclose( fp );
134 if( file_exist_check( optfile ) ) {
135 log_box( _("Preferences"), MB_ERR, "%s: %s", optfile, winpt_strerror( WPTERR_FILE_CREAT ) );
136 return FALSE;
137 }
138 have_optfile = 1;
139 }
140 }
141 else
142 have_optfile = 1;
143 if( have_optfile ) {
144 if( set_reg_entry_gpg( "OptFile", optfile ) ) {
145 msg_box( dlg, _("Could not save 'OptFile' in the registry."), _("Preferences"), MB_ERR );
146 return FALSE;
147 }
148 }
149 }
150 else {
151 char * t = get_gnupg_cfgfile ();
152 if (t && !file_exist_check (t))
153 set_reg_entry_gpg( "OptFile", t );
154 free_if_alloc (t);
155 }
156 if ( set_reg_entry_gpg( "HomeDir", homedir ) ) {
157 msg_box( dlg, _("Could not save 'HomeDir' in the registry."), _("Preferences"), MB_ERR );
158 return FALSE;
159 }
160 if( !GetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, exedir, sizeof exedir -1 ) ) {
161 msg_box( dlg, _("Please enter where GPG.exe is located."), _("Preferences"), MB_ERR );
162 return FALSE;
163 }
164 if( file_exist_check( exedir ) ) {
165 msg_box( dlg, _("Could not find the GPG program in this directory."), _("Preferences"), MB_ERR );
166 return FALSE;
167 }
168 if( set_reg_entry_gpg("gpgProgram", exedir ) ) {
169 msg_box( dlg, _("Could not save 'gpgProgram' in the registry"), _("Preferences"), MB_ERR );
170 return FALSE;
171 }
172 if( GetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1 ) ) {
173 if (dir_exist_check (locale_dir)) {
174 log_box( _("Preferences"), MB_ERR, "%s: %s", locale_dir, winpt_strerror (WPTERR_DIR_OPEN));
175 return FALSE;
176 }
177 set_reg_entry_mo (locale_dir);
178 set_gettext_file ("winpt", locale_dir);
179 }
180 else
181 set_reg_entry_mo ("");
182
183 p = get_gnupg_cfgfile ();
184 if( !p ) {
185 msg_box( dlg, _("Could not get GPG config file"), _("Preferences"), MB_ERR );
186 EndDialog( dlg, FALSE );
187 }
188 parse_gpg_options( p, &opt );
189
190 if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_V3SIGS ) )
191 modify_entry( opt, ENTRY_SINGLE, "force-v3-sigs", NULL );
192 else
193 delete_option( opt, "force-v3-sigs" );
194
195 if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))
196 modify_entry( opt, ENTRY_MULTI, "comment", t );
197 else if( n == 0 )
198 modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );
199 else
200 delete_option( opt, "comment" );
201
202 if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )
203 modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );
204 else
205 delete_option( opt, "encrypt-to" );
206
207 commit_gpg_options( p, opt );
208 release_gpg_options( opt );
209 EndDialog( dlg, TRUE );
210 return TRUE;
211
212 case IDC_GPGPREFS_HOMEDLG:
213 const char * home;
214 home = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);
215 if (home) {
216 SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, home);
217 if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0)
218 break;
219 char *name = make_filename (home, "gpg", "exe");
220 if (file_exist_check (name) == 0)
221 SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);
222 free_if_alloc (name);
223 name = make_filename (home, "gpg", "conf");
224 if (file_exist_check (name) == 0)
225 SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name);
226 free_if_alloc (name);
227 }
228 break;
229
230 case IDC_GPGREFS_EXEDLG:
231 const char * bin;
232 bin = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG binary"), _("Executable Files (*.exe)\0*.exe\0\0"), NULL );
233 if( bin )
234 SetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, bin );
235 return TRUE;
236
237 case IDC_GPGPREFS_OPTDLG:
238 const char * opt;
239 opt = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG config file"), NULL, NULL );
240 if( opt )
241 SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, opt );
242 return TRUE;
243 }
244 break;
245 }
246
247 return FALSE;
248 } /* gpgprefs_dlg_proc */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26