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

Contents of /trunk/Src/wptGPGPrefsDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (show annotations)
Wed Aug 10 11:33:35 2005 UTC (19 years, 6 months ago) by twoaday
File size: 9259 byte(s)
2005-08-06  Timo Schulz  <twoaday@freakmail.de>
 
        * wptGPGME.cpp (keycache_update): Reload OpenPGP parts
        of the secret key.
        (keycache_init): cache name of secret keyring.
        * wptKeyList.cpp (keylist_upd_key): Do not add long keyid.
        (get_key_type): Do not assume 'ultimate' means key pair.
        * wptKeyEditDlgs.cpp (diff_time): New.
        (keyedit_addsubkey_dlg_proc): Changed design and use
        diff_time. Drop checks for invalid keylength (< 1024, > 4096)
        because the combo box automatically handles this.
        * wptKeyManager.cpp (km_set_implicit_trust): Return error code.
        * wptGPG.cpp (get_backup_name): New.
        (gnupg_backup_keyrings): Rotate backup names, from 0..3.
        * wptClipImportDialog.cpp (clip_import_dlg_proc): Free memory.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Use 0x short keyid and
        not the long keyid.


1 /* 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 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 free_if_alloc (t);
150 }
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 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 return FALSE;
171 }
172 set_reg_entry_mo (locale_dir);
173 set_gettext_file ("winpt", locale_dir);
174 }
175 else
176 set_reg_entry_mo ("");
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 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 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