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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 8882 byte(s)
WinPT initial checkin.


1 twoaday 2 /* wptGPGPrefsDlg.cpp - WinPT GnuPG Preferences
2     * Copyright (C) 2001, 2002, 2003 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     const char * name;
37     int id;
38     } opts[] = {
39     {"HomeDir", IDC_GPGPREFS_HOMEDIR},
40     {"gpgProgram", IDC_GPGPREFS_EXEDIR},
41     {"OptFile", IDC_GPGPREFS_OPTFILE},
42     {0}
43     };
44    
45    
46     BOOL CALLBACK
47     gpgprefs_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
48     {
49     char exedir[1024], homedir[1024], optfile[1024];
50     char locale_dir[1024];
51     char * p = NULL, t[512];
52     const char * s;
53     int have_optfile = 0;
54     gpg_optfile_t opt = NULL;
55     gpg_option_t e;
56     UINT n;
57    
58     switch ( msg ) {
59     case WM_INITDIALOG:
60     #ifndef LANG_DE
61     SetWindowText( dlg, _("GnuPG Preferences") );
62     SetDlgItemText( dlg, IDC_GPGPREFS_HOMEINF,
63     _("GnuPG home directory (where both keyrings are located)") );
64     SetDlgItemText( dlg, IDC_GPGPREFS_OPTINF,
65     _("GnuPG config file (default: use gpg.conf)") );
66     SetDlgItemText( dlg, IDC_GPGPREFS_EXEINF,
67     _("GnuPG exe file location (full path with added gpg.exe)") );
68     SetDlgItemText( dlg, IDC_GPGPREFS_LOCALINF,
69     _("Locale directory (to access the translation files)") );
70     #endif
71     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     if( (p = get_reg_entry_mo( )) ) {
80     SetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, p );
81     free_if_alloc( p );
82     }
83     p = get_gnupg_cfgfile( );
84     if( p ) {
85     parse_gpg_options( p, &opt );
86     free_if_alloc( p );
87     if( opt && find_option( opt, "force-v3-sigs" ) )
88     CheckDlgButton( dlg, IDC_GPGPREFS_V3SIGS, BST_CHECKED );
89     if( opt && (e=find_option( opt, "comment" )) )
90     SetDlgItemText( dlg, IDC_GPGPREFS_COMMENT, e->val );
91     if( opt && (e=find_option( opt, "encrypt-to" )) )
92     SetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, e->val );
93     }
94     center_window( dlg );
95     SetForegroundWindow( dlg );
96     return TRUE;
97    
98     case WM_SYSCOMMAND:
99     if( LOWORD( wparam ) == SC_CLOSE )
100     EndDialog( dlg, TRUE );
101     return FALSE;
102    
103     case WM_COMMAND:
104     switch ( LOWORD( wparam ) ) {
105     case IDC_GPGPREFS_SAVE:
106     if( !GetDlgItemText( dlg, IDC_GPGPREFS_HOMEDIR, homedir, sizeof homedir -1 ) ) {
107     msg_box( dlg, _("Please enter the GnuPG home directory."), _("Preferences"), MB_ERR );
108     return FALSE;
109     }
110     if( dir_exist_check( homedir ) ) {
111     _snprintf( t, sizeof t - 1, "%s: %s", homedir, winpt_strerror(WPTERR_DIR_OPEN) );
112     msg_box( dlg, t, _("Preferences"), MB_ERR );
113     return FALSE;
114     }
115    
116     if( GetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, optfile, sizeof optfile - 1 ) ) {
117     if ( file_exist_check( optfile ) ) {
118     n = msg_box(dlg, _("Could not find GPG config file.\n"
119     "Do you want to create a config file?"),
120     _("Preferences"), MB_INFO|MB_YESNO );
121     if( n == IDNO ) {
122     SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, "" );
123     return FALSE;
124     }
125     else if( n == IDYES ) {
126     FILE * fp = fopen( optfile, "wb" );
127     if( fp )
128     fclose( fp );
129     if( file_exist_check( optfile ) ) {
130     log_box( _("Preferences"), MB_ERR, "%s: %s", optfile, winpt_strerror( WPTERR_FILE_CREAT ) );
131     return FALSE;
132     }
133     have_optfile = 1;
134     }
135     }
136     else
137     have_optfile = 1;
138     if( have_optfile ) {
139     if( set_reg_entry_gpg( "OptFile", optfile ) ) {
140     msg_box( dlg, _("Could not save 'OptFile' in the registry."), _("Preferences"), MB_ERR );
141     return FALSE;
142     }
143     }
144     }
145     else {
146     char * t = get_gnupg_cfgfile( );
147     if( t && !file_exist_check(t) )
148     set_reg_entry_gpg( "OptFile", t );
149     else
150     set_reg_entry_gpg( "OptFile", "" );
151     free_if_alloc( t );
152     }
153     if ( set_reg_entry_gpg( "HomeDir", homedir ) ) {
154     msg_box( dlg, _("Could not save 'HomeDir' in the registry."), _("Preferences"), MB_ERR );
155     return FALSE;
156     }
157     if( !GetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, exedir, sizeof exedir -1 ) ) {
158     msg_box( dlg, _("Please enter where GPG.exe is located."), _("Preferences"), MB_ERR );
159     return FALSE;
160     }
161     if( file_exist_check( exedir ) ) {
162     msg_box( dlg, _("Could not find the GPG program in this directory."), _("Preferences"), MB_ERR );
163     return FALSE;
164     }
165     if( set_reg_entry_gpg("gpgProgram", exedir ) ) {
166     msg_box( dlg, _("Could not save 'gpgProgram' in the registry"), _("Preferences"), MB_ERR );
167     return FALSE;
168     }
169     if( GetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof locale_dir -1 ) ) {
170     if ( dir_exist_check( locale_dir ) ) {
171     log_box( _("Preferences"), MB_ERR, "%s: %s", locale_dir, winpt_strerror( WPTERR_DIR_OPEN ) );
172     return FALSE;
173     }
174     set_reg_entry_mo( locale_dir );
175     set_gettext_file( "winpt", locale_dir );
176     }
177    
178     p = get_gnupg_cfgfile( );
179     if( !p ) {
180     msg_box( dlg, _("Could not get GPG config file"), _("Preferences"), MB_ERR );
181     EndDialog( dlg, FALSE );
182     }
183     parse_gpg_options( p, &opt );
184    
185     if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_V3SIGS ) )
186     modify_entry( opt, ENTRY_SINGLE, "force-v3-sigs", NULL );
187     else
188     delete_option( opt, "force-v3-sigs" );
189    
190     if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))
191     modify_entry( opt, ENTRY_MULTI, "comment", t );
192     else if( n == 0 )
193     modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );
194     else
195     delete_option( opt, "comment" );
196    
197     if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )
198     modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );
199     else
200     delete_option( opt, "encrypt-to" );
201    
202     commit_gpg_options( p, opt );
203     release_gpg_options( opt );
204     EndDialog( dlg, TRUE );
205     return TRUE;
206    
207     case IDC_GPGPREFS_HOMEDLG:
208     const char * home;
209    
210     home = get_folder_dlg( dlg, _("Choose GPG home directory"), NULL );
211     if( home )
212     SetDlgItemText( dlg, IDC_GPGPREFS_HOMEDIR, home );
213     break;
214    
215     case IDC_GPGREFS_EXEDLG:
216     const char * bin;
217     bin = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG binary"), _("Executable Files (*.exe)\0*.exe\0\0"), NULL );
218     if( bin )
219     SetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, bin );
220     return TRUE;
221    
222     case IDC_GPGPREFS_OPTDLG:
223     const char * opt;
224     opt = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG config file"), NULL, NULL );
225     if( opt )
226     SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, opt );
227     return TRUE;
228     }
229     break;
230     }
231    
232     return FALSE;
233     } /* gpgprefs_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26