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

Annotation of /trunk/Src/wptPreferencesDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (hide annotations)
Thu Jan 12 16:28:06 2006 UTC (19 years, 1 month ago) by twoaday
File size: 12693 byte(s)
2006-01-12  Timo Schulz  <ts@g10code.com>
 
        * wptListView.cpp (listview_set_image_list): Make icons
        always transparent.
        * wptImageList.cpp (imagelist_load): New icons.
        * wptGPGMEData.cpp (gpg_data_putc): New.
        * wptKeyManagerDlg.cpp (load_toolbar): Include new icons.
        (keymanager_dlg_proc): Add tooltips.
        * wptKeyserverDlg.cpp (keyserver_list_build): Use icons.
        * wptKeyserver.cpp (URL_encode): New.
        (URL_must_encode): New.
        (kserver_search_init): Properly encode pattern.
        (parse_iso_date): New.
        (keyserver_search): Be more strict to prevent buffer overflows.
         
2006-01-11  Timo Schulz  <ts@g10code.com>
 
        * wptKeyManagerDlg.cpp (load_toolbar): 2 new icons.
        (keymanager_dlg_proc): Adjust tooltips.
        (update_ui_items): Handle new icons.
        * wptImageList.cpp (imagelist_load): New icons.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26