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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (hide annotations)
Thu Dec 8 09:26:32 2005 UTC (19 years, 2 months ago) by twoaday
File size: 9479 byte(s)
2005-12-07  Timo Schulz  <ts@g10code.com>
 
        * wptOwnertrustDlg.cpp (ownertrust_dlg_proc):
        Use 'Close' instead of 'Exit'.
        * wptKeyEditDlgs.cpp (keyedit_dlg_proc): Likewise.
        * wptGPG.cpp (gnupg_backup_keyrings): Use $APPDATA
        as the destination dir. Thanks to Werner.
        * wptRegistry.cpp (is_gpgee_installed): New.
        (regist_inst_winpt): Do not register file extensions
        if GPGee is available.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Limit
        use of local vars.
        * wptPreferencesDlg.cpp (prefs_dlg_proc): Make sure
        no illegal backup mode is saved.
        * wptKeyserverDlg.cpp (show_imported_key): New.
        (hkp_recv_key2): Show imported keys if the blob
        contained more than one.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26