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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 88 - (hide annotations)
Mon Nov 21 12:06:59 2005 UTC (19 years, 3 months ago) by twoaday
File size: 9519 byte(s)
2005-11-21  Timo Schulz  <ts@g10code.com>
 
        * WinPT.cpp (WinMain): Implement --stop switch.
        * wptClipEditDlg.cpp (clip_edit_dlg_proc): Localize
        missing string.
        * wptPreferencesDlg.cpp (prefs_dlg_proc): Likewise.
        * wptKeygenDlg.cpp (keygen_dlg_proc): Verify valid context
        first. Thanks to Ralf.
        * wptFileManagerDlg.cpp (update_ui_items): New.
        * wptFileManager.cpp (fm_set_status): New sigmode param.
        Changed all callers.


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 twoaday 88 SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options"));
77 twoaday 78
78 werner 36 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     }
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 41 center_window (dlg, NULL);
105     SetForegroundWindow (dlg);
106 werner 36 return TRUE;
107    
108     case WM_SYSCOMMAND:
109     if( LOWORD( wparam ) == SC_CLOSE )
110     EndDialog( dlg, TRUE );
111     return FALSE;
112    
113     case WM_COMMAND:
114     switch ( LOWORD( wparam ) ) {
115     case IDC_GPGPREFS_SAVE:
116     if( !GetDlgItemText( dlg, IDC_GPGPREFS_HOMEDIR, homedir, sizeof homedir -1 ) ) {
117     msg_box( dlg, _("Please enter the GnuPG home directory."), _("Preferences"), MB_ERR );
118     return FALSE;
119     }
120     if( dir_exist_check( homedir ) ) {
121     _snprintf( t, sizeof t - 1, "%s: %s", homedir, winpt_strerror(WPTERR_DIR_OPEN) );
122     msg_box( dlg, t, _("Preferences"), MB_ERR );
123     return FALSE;
124     }
125    
126     if( GetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, optfile, sizeof optfile - 1 ) ) {
127     if ( file_exist_check( optfile ) ) {
128     n = msg_box(dlg, _("Could not find GPG config file.\n"
129     "Do you want to create a config file?"),
130     _("Preferences"), MB_INFO|MB_YESNO );
131     if( n == IDNO ) {
132     SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, "" );
133     return FALSE;
134     }
135     else if( n == IDYES ) {
136     FILE * fp = fopen( optfile, "wb" );
137     if( fp )
138     fclose( fp );
139     if( file_exist_check( optfile ) ) {
140     log_box( _("Preferences"), MB_ERR, "%s: %s", optfile, winpt_strerror( WPTERR_FILE_CREAT ) );
141     return FALSE;
142     }
143     have_optfile = 1;
144     }
145     }
146     else
147     have_optfile = 1;
148     if( have_optfile ) {
149     if( set_reg_entry_gpg( "OptFile", optfile ) ) {
150     msg_box( dlg, _("Could not save 'OptFile' in the registry."), _("Preferences"), MB_ERR );
151     return FALSE;
152     }
153     }
154     }
155     else {
156 twoaday 77 char *cfg = get_gnupg_cfgfile ();
157     if (cfg && !file_exist_check (cfg))
158     set_reg_entry_gpg( "OptFile", cfg);
159     free_if_alloc (cfg);
160 werner 36 }
161     if ( set_reg_entry_gpg( "HomeDir", homedir ) ) {
162     msg_box( dlg, _("Could not save 'HomeDir' in the registry."), _("Preferences"), MB_ERR );
163     return FALSE;
164     }
165     if( !GetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, exedir, sizeof exedir -1 ) ) {
166     msg_box( dlg, _("Please enter where GPG.exe is located."), _("Preferences"), MB_ERR );
167     return FALSE;
168     }
169     if( file_exist_check( exedir ) ) {
170     msg_box( dlg, _("Could not find the GPG program in this directory."), _("Preferences"), MB_ERR );
171     return FALSE;
172     }
173     if( set_reg_entry_gpg("gpgProgram", exedir ) ) {
174     msg_box( dlg, _("Could not save 'gpgProgram' in the registry"), _("Preferences"), MB_ERR );
175     return FALSE;
176     }
177     if( GetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1 ) ) {
178     if (dir_exist_check (locale_dir)) {
179     log_box( _("Preferences"), MB_ERR, "%s: %s", locale_dir, winpt_strerror (WPTERR_DIR_OPEN));
180     return FALSE;
181     }
182     set_reg_entry_mo (locale_dir);
183     set_gettext_file ("winpt", locale_dir);
184     }
185     else
186     set_reg_entry_mo ("");
187    
188     p = get_gnupg_cfgfile ();
189     if( !p ) {
190     msg_box( dlg, _("Could not get GPG config file"), _("Preferences"), MB_ERR );
191     EndDialog( dlg, FALSE );
192     }
193     parse_gpg_options( p, &opt );
194    
195 twoaday 41 if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_ASKLEVEL ) ) {
196     modify_entry( opt, ENTRY_SINGLE, "ask-cert-level", NULL );
197     reg_prefs.gpg.ask_cert_level = 1;
198     }
199     else {
200     delete_option( opt, "ask-cert-level" );
201     reg_prefs.gpg.ask_cert_level = 0;
202     }
203 werner 36
204     if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))
205     modify_entry( opt, ENTRY_MULTI, "comment", t );
206     else if( n == 0 )
207     modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );
208     else
209     delete_option( opt, "comment" );
210    
211     if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )
212     modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );
213     else
214     delete_option( opt, "encrypt-to" );
215    
216     commit_gpg_options( p, opt );
217 twoaday 41 release_gpg_options (opt);
218 werner 36 EndDialog( dlg, TRUE );
219     return TRUE;
220    
221     case IDC_GPGPREFS_HOMEDLG:
222     const char * home;
223     home = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);
224     if (home) {
225     SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, home);
226     if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0)
227     break;
228     char *name = make_filename (home, "gpg", "exe");
229     if (file_exist_check (name) == 0)
230     SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);
231     free_if_alloc (name);
232     name = make_filename (home, "gpg", "conf");
233     if (file_exist_check (name) == 0)
234     SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name);
235     free_if_alloc (name);
236     }
237     break;
238    
239     case IDC_GPGREFS_EXEDLG:
240 twoaday 77 const char *bin;
241     bin = get_fileopen_dlg (dlg, _("Choose GPG binary"),
242     _("Executable Files (*.exe)\0*.exe\0\0"),
243     NULL);
244     if (bin)
245     SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, bin);
246 werner 36 return TRUE;
247    
248     case IDC_GPGPREFS_OPTDLG:
249 twoaday 77 const char *optf;
250     optf = get_fileopen_dlg (dlg, _("Choose GPG config file"),
251     NULL, NULL);
252     if (optf)
253     SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, optf);
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