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

Annotation of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 9265 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


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 twoaday 23 center_window( dlg, NULL );
95 twoaday 2 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 twoaday 22 char * t = get_gnupg_cfgfile ();
147     if (t && !file_exist_check (t))
148 twoaday 2 set_reg_entry_gpg( "OptFile", t );
149 twoaday 22 free_if_alloc (t);
150 twoaday 2 }
151     if ( set_reg_entry_gpg( "HomeDir", homedir ) ) {
152     msg_box( dlg, _("Could not save 'HomeDir' in the registry."), _("Preferences"), MB_ERR );
153     return FALSE;
154     }
155     if( !GetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, exedir, sizeof exedir -1 ) ) {
156     msg_box( dlg, _("Please enter where GPG.exe is located."), _("Preferences"), MB_ERR );
157     return FALSE;
158     }
159     if( file_exist_check( exedir ) ) {
160     msg_box( dlg, _("Could not find the GPG program in this directory."), _("Preferences"), MB_ERR );
161     return FALSE;
162     }
163     if( set_reg_entry_gpg("gpgProgram", exedir ) ) {
164     msg_box( dlg, _("Could not save 'gpgProgram' in the registry"), _("Preferences"), MB_ERR );
165     return FALSE;
166     }
167 twoaday 4 if( GetDlgItemText( dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1 ) ) {
168     if (dir_exist_check (locale_dir)) {
169     log_box( _("Preferences"), MB_ERR, "%s: %s", locale_dir, winpt_strerror (WPTERR_DIR_OPEN));
170 twoaday 2 return FALSE;
171     }
172 twoaday 4 set_reg_entry_mo (locale_dir);
173     set_gettext_file ("winpt", locale_dir);
174 twoaday 2 }
175 twoaday 4 else
176     set_reg_entry_mo ("");
177 twoaday 2
178 twoaday 4 p = get_gnupg_cfgfile ();
179 twoaday 2 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 twoaday 22 home = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);
210     if (home) {
211     SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, home);
212     if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0)
213     break;
214     char *name = make_filename (home, "gpg", "exe");
215     if (file_exist_check (name) == 0)
216     SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);
217     free_if_alloc (name);
218     name = make_filename (home, "gpg", "conf");
219     if (file_exist_check (name) == 0)
220     SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name);
221     free_if_alloc (name);
222     }
223 twoaday 2 break;
224    
225     case IDC_GPGREFS_EXEDLG:
226     const char * bin;
227     bin = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG binary"), _("Executable Files (*.exe)\0*.exe\0\0"), NULL );
228     if( bin )
229     SetDlgItemText( dlg, IDC_GPGPREFS_EXEDIR, bin );
230     return TRUE;
231    
232     case IDC_GPGPREFS_OPTDLG:
233     const char * opt;
234     opt = get_filename_dlg( dlg, FILE_OPEN, _("Choose GPG config file"), NULL, NULL );
235     if( opt )
236     SetDlgItemText( dlg, IDC_GPGPREFS_OPTFILE, opt );
237     return TRUE;
238     }
239     break;
240     }
241    
242     return FALSE;
243     } /* gpgprefs_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26