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

Annotation of /trunk/Src/wptPreferencesDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26