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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sun Feb 6 11:11:40 2005 UTC (20 years ago) by twoaday
File size: 8906 byte(s)
2005-02-02  Timo Schulz  <twoaday@freakmail.de>
                                                                                                                            
        * wptPassphraseDlg.cpp (passwd_dlg_proc): use center_window2, otherwise
        it is invisible.
        * wptPassphraseCB.cpp (passphrase_callback_proc): Do not cache symmetric
        passphrases.
        * Enable the progress dialog for symmetric encryption.
        * wptFileManager.cpp (fm_check_file_type): Also check for 'SYMKEYENC' in
        FM_ENCRYPT mode.
        * WinPT.cpp (WinMain): SETUP_EXISTING implemented.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Reset 'Locale directory' when
        no value is entered.
                                                                                                                            
2005-02-04  Timo Schulz  <twoaday@freakmail.de>
                                                                                                                            
        * wptProgressDlg.cpp (progress_cb_thread): Set root window if available.
        If the progress window survives by accident, it will be closed when the
        File Manager (root window) is closed.
                                                                                                                            


1 twoaday 2 /* wptGPGPrefsDlg.cpp - WinPT GnuPG Preferences
2 twoaday 4 * Copyright (C) 2001-2005 Timo Schulz
3 twoaday 2 *
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 twoaday 4 gpgprefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
48 twoaday 2 {
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 twoaday 4 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 twoaday 2 return FALSE;
173     }
174 twoaday 4 set_reg_entry_mo (locale_dir);
175     set_gettext_file ("winpt", locale_dir);
176 twoaday 2 }
177 twoaday 4 else
178     set_reg_entry_mo ("");
179 twoaday 2
180 twoaday 4 p = get_gnupg_cfgfile ();
181 twoaday 2 if( !p ) {
182     msg_box( dlg, _("Could not get GPG config file"), _("Preferences"), MB_ERR );
183     EndDialog( dlg, FALSE );
184     }
185     parse_gpg_options( p, &opt );
186    
187     if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_V3SIGS ) )
188     modify_entry( opt, ENTRY_SINGLE, "force-v3-sigs", NULL );
189     else
190     delete_option( opt, "force-v3-sigs" );
191    
192     if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))
193     modify_entry( opt, ENTRY_MULTI, "comment", t );
194     else if( n == 0 )
195     modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );
196     else
197     delete_option( opt, "comment" );
198    
199     if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )
200     modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );
201     else
202     delete_option( opt, "encrypt-to" );
203    
204     commit_gpg_options( p, opt );
205     release_gpg_options( opt );
206     EndDialog( dlg, TRUE );
207     return TRUE;
208    
209     case IDC_GPGPREFS_HOMEDLG:
210     const char * home;
211    
212     home = get_folder_dlg( dlg, _("Choose GPG home directory"), NULL );
213     if( home )
214     SetDlgItemText( dlg, IDC_GPGPREFS_HOMEDIR, home );
215     break;
216    
217     case IDC_GPGREFS_EXEDLG:
218     const char * bin;
219     bin = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG binary"), _("Executable Files (*.exe)\0*.exe\0\0"), NULL );
220     if( bin )
221     SetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, bin );
222     return TRUE;
223    
224     case IDC_GPGPREFS_OPTDLG:
225     const char * opt;
226     opt = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG config file"), NULL, NULL );
227     if( opt )
228     SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, opt );
229     return TRUE;
230     }
231     break;
232     }
233    
234     return FALSE;
235     } /* gpgprefs_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26