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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (hide annotations)
Fri Oct 28 07:15:26 2005 UTC (19 years, 4 months ago) by twoaday
File size: 9240 byte(s)
A lot of bug fixes. See ChangeLog.

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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26