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

Annotation of /trunk/Src/wptPreferencesDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 12102 byte(s)
2005-10-23  Timo Schulz  <twoaday@g10code.com>
 
        * wptFileManager.cpp (fm_get_file_type): Detect detached sigs.
        * wptKeyList.cpp (keylist_cmp_cb): Take care of expired/revoked keys.
        (get_ext_validity): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Several cleanups.
        * wptClipEditDlg.cpp (load_clipboard): Factored out some code into
        this function.
        (load_clipboard_from_file): Likewise.
        (save_clipboard_to_file): New.
        * wptKeyManagerDlg.cpp (keyprops_dlg_proc): Fix stack overflow.

For complete details, see the ChangeLog files.

1 twoaday 2 /* wptPreferencesDlg.cpp - Dialog for the preferences
2 twoaday 22 * Copyright (C) 2001, 2002, 2003, 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     #include <shlobj.h>
23    
24     #include "wptNLS.h"
25     #include "wptGPG.h"
26     #include "wptCommonCtl.h"
27     #include "wptDlgs.h"
28     #include "wptTypes.h"
29     #include "wptErrors.h"
30     #include "wptRegistry.h"
31     #include "wptHotkey.h"
32     #include "wptW32API.h"
33     #include "wptVersion.h"
34     #include "wptAgent.h"
35     #include "wptKeyserver.h"
36     #include "../resource.h"
37    
38    
39 twoaday 32 /* Dialog IDs of all hotkeys. */
40 twoaday 2 static int hotkeys[] = {
41     IDC_PREFS_CLIP_ENCRYPT,
42     IDC_PREFS_CLIP_DECRYPT_VERIFY,
43     IDC_PREFS_CLIP_SIGN,
44     IDC_PREFS_CLIP_SIGNENC,
45     IDC_PREFS_CWS_ENCRYPT,
46     IDC_PREFS_CWS_DECRYPT_VERIFY,
47     IDC_PREFS_CWS_SIGN,
48     IDC_PREFS_CWS_SIGNENC,
49     0
50     };
51    
52    
53 twoaday 32 /* Check that the given hotkey is in A..Z or a..z. */
54 twoaday 2 static int
55 twoaday 22 check_hotkey (char * key)
56 twoaday 2 {
57 twoaday 22 if (*key >= 'A' && *key <= 'Z')
58 twoaday 2 return 1;
59 twoaday 22 else if (*key >= 'a' && *key <= 'z') {
60 twoaday 2 *key = *key - 32;
61     return 1;
62 twoaday 22 }
63 twoaday 2 return 0;
64 twoaday 32 }
65 twoaday 2
66    
67 twoaday 32 /* Disable all hotkey controls in the dialog @dlg if val is 1. */
68 twoaday 2 static void
69 twoaday 22 disable_hotkey_items (HWND dlg, int val)
70 twoaday 2 {
71 twoaday 22 int mode = val? FALSE : TRUE;
72 twoaday 2 int i, id;
73    
74 twoaday 22 for (i=0; (id = hotkeys[i]); i++)
75 twoaday 32 EnableWindow (GetDlgItem (dlg, id), mode);
76     }
77 twoaday 2
78    
79 twoaday 32
80     /* En- or disable the backup items in the dialog @dlg.
81     If val != 0 activate them, disable them otherwise. */
82 twoaday 2 static void
83 twoaday 22 enable_backup_items (HWND dlg, int val)
84 twoaday 2 {
85 twoaday 22 int mode = val? TRUE : FALSE;
86 twoaday 2
87 twoaday 22 EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKHOME), mode);
88     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKUSER), mode);
89     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKSELECT), mode);
90     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKPATH), mode);
91 twoaday 32 }
92 twoaday 2
93    
94 twoaday 32 /* Initialize the combox in the dialog @dlg with the valid list modes. */
95 twoaday 2 static void
96 twoaday 32 init_keylist_modes (HWND dlg)
97 twoaday 2 {
98 twoaday 22 HWND cb = GetDlgItem (dlg, IDC_PREFS_LISTMODE);
99     combox_add_string (cb, (char *)"NORMAL");
100     combox_add_string (cb, (char *)"MINIMAL");
101     SendMessage (cb, CB_SETCURSEL, (WPARAM)reg_prefs.keylist_mode, 0);
102 twoaday 32 }
103 twoaday 2
104    
105 twoaday 32 /* Initialize the combobox in the dialog @dlg with the valid wipe modes. */
106 twoaday 2 static void
107 twoaday 32 init_wipe_modes (HWND dlg)
108 twoaday 2 {
109 twoaday 22 HWND cb = GetDlgItem (dlg, IDC_PREFS_WIPEMODE);
110     combox_add_string (cb, (char *)"Simple");
111     combox_add_string (cb, (char *)"DoD");
112     combox_add_string (cb, (char *)"Gutmann");
113     SendMessage (cb, CB_SETCURSEL, (WPARAM)reg_prefs.wipe_mode, 0);
114 twoaday 32 }
115 twoaday 2
116    
117 twoaday 32 /* Dialog box procedure for the WinPT preferences. */
118 twoaday 2 BOOL CALLBACK
119 twoaday 22 prefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
120 twoaday 2 {
121     int rc;
122     int i, id;
123     char t[2];
124     char path[256], * p;
125     HWND cb;
126    
127     switch ( msg ) {
128     case WM_INITDIALOG:
129 twoaday 32 #ifndef LANG_DE
130     SetWindowText (dlg, _("WinPT Preferences"));
131     SetDlgItemText (dlg, IDC_PREFS_SECMODE, _("Do not use any &temporary files"));
132     SetDlgItemText (dlg, IDC_PREFS_VIEWER, _("Use clipboard &viewer to display the plaintext"));
133     SetDlgItemText (dlg, IDC_PREFS_WWINFO, _("Word wrap cleartext &signatures at column"));
134     SetDlgItemText (dlg, IDC_PREFS_DISABLE_HOTKEYS, _("&Disable hotkeys (Not recommended!)"));
135     SetDlgItemText (dlg, IDC_PREFS_TRUST, _("Skip key validation and assume that keys are always fully trusted"));
136     SetDlgItemText (dlg, IDC_PREFS_AUTOBACKUP, _("&Automatic keyring backup when WinPT closes"));
137     SetDlgItemText (dlg, IDC_PREFS_BAKHOME, _("Backup to GPG &home folder"));
138     SetDlgItemText (dlg, IDC_PREFS_BAKUSER, _("Backup to:"));
139     #endif
140 twoaday 2 SetDlgItemInt( dlg, IDC_PREFS_CACHETIME, reg_prefs.cache_time, TRUE );
141     SetDlgItemInt( dlg, IDC_PREFS_WORDWRAP, reg_prefs.word_wrap, TRUE );
142     if (reg_prefs.backup.path)
143     SetDlgItemText (dlg, IDC_PREFS_BAKPATH, reg_prefs.backup.path);
144     if (reg_prefs.kserv_conf)
145     SetDlgItemText (dlg, IDC_PREFS_KSERVER, reg_prefs.kserv_conf);
146    
147 twoaday 22 for (i=0; (id=hotkeys[i]); i++)
148     SetDlgItemText (dlg, id, reg_hotkeys[i].key);
149 twoaday 2 CheckDlgButton( dlg, IDC_PREFS_DISABLE_HOTKEYS,
150     reg_prefs.no_hotkeys ? BST_CHECKED : BST_UNCHECKED );
151     CheckDlgButton( dlg, IDC_PREFS_SECMODE,
152     reg_prefs.use_tmpfiles ? BST_UNCHECKED : BST_CHECKED );
153     CheckDlgButton( dlg, IDC_PREFS_VIEWER,
154     reg_prefs.use_viewer ? BST_CHECKED: BST_UNCHECKED );
155     CheckDlgButton( dlg, IDC_PREFS_TRUST,
156     reg_prefs.always_trust? BST_CHECKED : BST_UNCHECKED );
157     CheckDlgButton( dlg, IDC_PREFS_AUTOBACKUP,
158     reg_prefs.auto_backup? BST_CHECKED : BST_UNCHECKED );
159     CheckDlgButton( dlg, IDC_PREFS_BAKHOME,
160     reg_prefs.backup.mode==1? BST_CHECKED : BST_UNCHECKED );
161     CheckDlgButton( dlg, IDC_PREFS_BAKUSER,
162     reg_prefs.backup.mode==2? BST_CHECKED : BST_UNCHECKED );
163     if( reg_prefs.no_hotkeys )
164     disable_hotkey_items( dlg, 1 );
165 twoaday 32 if (!reg_prefs.auto_backup)
166     enable_backup_items (dlg, 0);
167     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKPATH),
168     reg_prefs.backup.mode==1?FALSE : TRUE);
169     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKSELECT),
170     reg_prefs.backup.mode==1? FALSE : TRUE);
171     init_keylist_modes (dlg);
172     init_wipe_modes (dlg);
173     center_window (dlg, NULL);
174     SetForegroundWindow (dlg);
175 twoaday 2 return TRUE;
176    
177     case WM_SYSCOMMAND:
178 twoaday 32 if (LOWORD (wparam) == SC_CLOSE)
179     EndDialog (dlg, TRUE);
180 twoaday 2 return FALSE;
181    
182     case WM_COMMAND:
183     switch( HIWORD(wparam) ) {
184     case BN_CLICKED:
185     switch( (int)LOWORD( wparam ) ) {
186     case IDC_PREFS_DISABLE_HOTKEYS:
187     reg_prefs.no_hotkeys ^= 1;
188     disable_hotkey_items( dlg, reg_prefs.no_hotkeys );
189     break;
190    
191 twoaday 22 case IDC_PREFS_TRUST:
192 twoaday 2 reg_prefs.always_trust ^= 1;
193     if( reg_prefs.always_trust ) {
194 twoaday 22 msg_box (dlg,
195 twoaday 2 _("In most cases it is not a good idea to enable this setting.\n"
196     "If you know what you are doing let this flag enabled, otherwise\n"
197     "it is safe to leave this flag untouched."),
198     _("Preferences"), MB_ICONWARNING|MB_OK );
199     }
200     break;
201    
202     case IDC_PREFS_AUTOBACKUP:
203     reg_prefs.auto_backup ^= 1;
204 twoaday 22 enable_backup_items (dlg, reg_prefs.auto_backup);
205     if (reg_prefs.auto_backup == 1) {
206     if (!IsDlgButtonChecked (dlg, IDC_PREFS_BAKHOME) &&
207     !IsDlgButtonChecked (dlg, IDC_PREFS_BAKUSER))
208     CheckDlgButton (dlg, IDC_PREFS_BAKHOME, BST_CHECKED);
209     }
210 twoaday 2 break;
211    
212     case IDC_PREFS_BAKHOME:
213 twoaday 22 EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKSELECT), FALSE);
214     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKPATH), FALSE);
215 twoaday 2 break;
216    
217     case IDC_PREFS_BAKUSER:
218 twoaday 22 EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKSELECT), TRUE);
219     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKPATH), TRUE);
220 twoaday 2 break;
221     }
222     break;
223     }
224     switch( LOWORD( wparam ) ) {
225     case IDC_PREFS_BAKSELECT:
226 twoaday 22 const char *bpath;
227     bpath = get_folder_dlg (dlg, _("Select GPG backup path"), NULL);
228     if (bpath)
229     SetDlgItemText (dlg, IDC_PREFS_BAKPATH, bpath);
230 twoaday 2 break;
231    
232     case IDC_PREFS_KSELFILE: {
233     const char * name;
234 twoaday 23 name = get_filename_dlg (dlg, FILE_OPEN, _("Please select a keyserver.conf file"),
235 twoaday 2 NULL, NULL);
236 twoaday 23 if (name != NULL)
237 twoaday 2 SetDlgItemText (dlg, IDC_PREFS_KSERVER, name);
238     break; }
239    
240     case IDOK:
241     rc = GetDlgItemInt( dlg, IDC_PREFS_CACHETIME, NULL, FALSE );
242     if( !rc )
243     reg_prefs.cache_time = 0;
244     else if( rc > 3600 ) {
245     msg_box( dlg, _("Please enter a value that is between 1-3600.\nIt is not "
246     "a good idea to cache the passphrase more than one hour."),
247     _("Preferences"), MB_ERR );
248     SetDlgItemInt( dlg, IDC_PREFS_CACHETIME, 0, FALSE );
249 twoaday 32 return TRUE;
250 twoaday 2 }
251     if (reg_prefs.cache_time != rc)
252     agent_flush_cache ();
253     reg_prefs.cache_time = rc;
254     rc = GetDlgItemInt( dlg, IDC_PREFS_WORDWRAP, NULL, FALSE );
255     if( !rc )
256     reg_prefs.word_wrap = 0;
257     else if( rc > 80 ) {
258     msg_box( dlg, _("Please enter a value between 1-80."), _("Preferences"), MB_ERR );
259 twoaday 32 return TRUE;
260 twoaday 2 }
261     reg_prefs.word_wrap = rc;
262     reg_prefs.use_tmpfiles = IsDlgButtonChecked( dlg, IDC_PREFS_SECMODE )? 0 : 1;
263     reg_prefs.use_viewer = IsDlgButtonChecked( dlg, IDC_PREFS_VIEWER )? 1 : 0;
264     reg_prefs.backup.mode = IsDlgButtonChecked( dlg, IDC_PREFS_BAKHOME ) ? 1 :
265     IsDlgButtonChecked( dlg, IDC_PREFS_BAKUSER )? 2 : 0;
266     if( reg_prefs.backup.mode == 2 ) {
267     if( !GetDlgItemText( dlg, IDC_PREFS_BAKPATH, path, sizeof (path)-1 )
268     || dir_exist_check( path ) ) {
269     msg_box( dlg, _("The specified backup folder is invalid."),
270     _("Preferences"), MB_ERR );
271 twoaday 32 return TRUE;
272 twoaday 2 }
273     free_if_alloc (reg_prefs.backup.path);
274     p = reg_prefs.backup.path = m_strdup (path);
275     if (!p)
276     BUG (0);
277     }
278     free_if_alloc (reg_prefs.kserv_conf);
279     if (!GetDlgItemText (dlg, IDC_PREFS_KSERVER, path, sizeof (path)-1)
280     || file_exist_check (path)) {
281     rc = msg_box (dlg, _("The specified keyserver config file is invalid.\n\n"
282     "Create new default config file?"),
283     _("Preferences"), MB_ERR|MB_YESNO);
284     if (rc == IDNO)
285 twoaday 32 return TRUE;
286 twoaday 2 else
287     {
288     char cwd[256], * fn;
289     FILE * fp = fopen ("keyserver.conf", "wb");
290 twoaday 22 if (fp) {
291 twoaday 2 fprintf (fp, "%s\r\n", DEF_HKP_KEYSERVER);
292     fclose (fp);
293     }
294     GetCurrentDirectory (DIM (cwd)-1, cwd);
295     fn = make_filename (cwd, "keyserver", "conf");
296     memset (path, 0, sizeof( path));
297     strncpy (path, fn, DIM (path)-1);
298     free_if_alloc (fn);
299     }
300     }
301     p = reg_prefs.kserv_conf = m_strdup (path);
302     if (!p)
303     BUG (0);
304    
305     cb = GetDlgItem( dlg, IDC_PREFS_LISTMODE );
306     reg_prefs.keylist_mode = SendMessage( cb, CB_GETCURSEL, 0, 0 );
307    
308     cb = GetDlgItem( dlg, IDC_PREFS_WIPEMODE );
309     reg_prefs.wipe_mode = SendMessage( cb, CB_GETCURSEL, 0, 0 );
310    
311     if (IsDlgButtonChecked (dlg, IDC_PREFS_DISABLE_HOTKEYS)) {
312     hotkeys_unregister (glob_hwnd);
313     reg_prefs.no_hotkeys = 1;
314     }
315     else {
316     reg_prefs.no_hotkeys = 0;
317     for( i = 0; (id = hotkeys[i]); i++ ) {
318     rc = GetDlgItemText( dlg, id, t, 2 );
319     if( rc && check_hotkey( &t[0] ) )
320     hotkey_enable( &reg_hotkeys[i], t );
321     else
322     hotkey_disable( &reg_hotkeys[i] );
323     }
324     set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "DisableHotkeys", "0");
325     reg_prefs.no_hotkeys = 0;
326     }
327    
328     if ((rc = set_reg_winpt_prefs (&reg_prefs)))
329     msg_box (dlg, winpt_strerror (rc), _("Preferences"), MB_ERR);
330    
331     if (reg_prefs.no_hotkeys == 0) {
332     hotkeys_unregister (glob_hwnd);
333     hotkeys_modify ();
334     if ((rc = hotkeys_register (glob_hwnd)))
335     msg_box (NULL, winpt_strerror (rc), _("Hotkeys"), MB_ERR);
336     }
337     EndDialog (dlg, TRUE);
338     return TRUE;
339    
340     case IDCANCEL:
341     EndDialog( dlg, FALSE );
342     return FALSE;
343     }
344     break;
345     }
346    
347     return FALSE;
348 twoaday 32 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26