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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 78 - (hide annotations)
Tue Nov 15 08:54:44 2005 UTC (19 years, 3 months ago) by twoaday
File size: 9446 byte(s)
2005-11-14  Timo Schulz  <ts@g10code.com>
 
        * wptGPG.cpp (check_gnupg_engine): Fix version check.
        * wptMainProc.cpp (winpt_main_proc): Check keyring
        file permissions always and do not use interative output
        when the windows session ends.
        * wptProxySettingsDlg.cpp (proxy_settings_dlg_proc):
        Localize all strings.
        * wptPassphraseDlg.cpp (passwd_dlg_proc): Likewise.
        * wptGPGPrefsDlg.cpp (gpg_prefs_dlg): Likewise.
        * wptKeyEditDlgs.cpp (do_init_keylist): Skip all
        non-valid keys.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26