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

Annotation of /trunk/Src/wptPreferencesDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 180 - (hide annotations)
Mon Mar 6 14:41:58 2006 UTC (18 years, 11 months ago) by twoaday
File size: 10991 byte(s)
2006-02-27  Timo Schulz  <twoaday@freakmail.de>
 
        * wptSOCKS.cpp (socks_handshake): New.
        * wptMainProc.cpp (winpt_main_proc): A dbl-click forces
        the key manager in teh foreground if possible.
        * wptHotkey.cpp (hotkey_unregister): Unregister all hotkeys.
        * wptRegistry.cpp (get_reg_proxy_prefs,
        set_reg_proxy_prefs): Use directly the proxy context.
        Changed all callers.
        * wptProxySettingsDlg.cpp (init_proxy_protocols): New.
        (keyserver_proxy_dlg_proc): Use directly the proxy context.
        * wptKeyserver.cpp (kserver_connect): Better proxy support.
        (kserver_send_request, kserver_recvkey_request): Likewise.
        * wptKeyserverDlg.cpp (name_from_proto): New.
        (set_proxy): Adjusted for the new code.


1 werner 36 /* wptPreferencesDlg.cpp - Dialog for the preferences
2 twoaday 180 * Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz
3 werner 36 *
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_SIGNENC,
47 twoaday 180 IDC_PREFS_CLIP_SIGN,
48 werner 36 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 twoaday 180 check_hotkey (char *key)
59 werner 36 {
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 combobox in the dialog @dlg with the valid wipe modes. */
98     static void
99     init_wipe_modes (HWND dlg)
100     {
101     HWND cb = GetDlgItem (dlg, IDC_PREFS_WIPEMODE);
102     combox_add_string (cb, (char *)"Simple");
103     combox_add_string (cb, (char *)"DoD");
104     combox_add_string (cb, (char *)"Gutmann");
105     SendMessage (cb, CB_SETCURSEL, (WPARAM)reg_prefs.wipe_mode, 0);
106     }
107    
108    
109 twoaday 176 /* Helper function to prepare dialog. */
110     static void
111     on_init_dialog (HWND dlg)
112     {
113     struct gettext_tab_s prefs[] = {
114     {IDC_PREFS_SECMODE, _("Do not use any &temporary files")},
115     {IDC_PREFS_VIEWER, _("Use clipboard &viewer to display the plaintext")},
116     {IDC_PREFS_WWINFO, _("Word wrap cleartext &signatures at column")},
117     {IDC_PREFS_DISABLE_HOTKEYS, _("&Disable hotkeys (Not recommended!)")},
118     {IDC_PREFS_TRUST, _("Skip key validation and assume that keys are always fully trusted")},
119     {IDC_PREFS_AUTOBACKUP, _("&Automatic keyring backup when WinPT closes")},
120     {IDC_PREFS_BAKHOME, _("Backup to &keyring folder")},
121     {IDC_PREFS_BAKUSER, _("Backup to:")},
122     {IDC_PREFS_KEYLISTINF, _("Select &key list mode")},
123     {IDC_PREFS_WIPEINF, _("Select &wipe mode")},
124     {IDC_PREFS_KSINF, _("Keyserver &config")},
125 twoaday 180 {IDC_PREFS_CACHEINF, _("Cache &passphrases for 'n' minutes")},
126 twoaday 176 {IDC_PREFS_CACHEHINT, _("(CTRL+ALT+F to clear the cache)")},
127     {IDC_PREFS_ALLOPTINF, _("General options")},
128     {IDC_PREFS_CLIPINF, _("Clipboard hotkeys")},
129     {IDC_PREFS_CURRINF, _("Current window hotkeys")},
130     {IDC_PREFS_KSELFILE, _("Browse...")},
131     {IDC_PREFS_BAKSELECT, _("Browse...")},
132     {IDCANCEL, _("&Cancel")},
133     {0, NULL}};
134     int i;
135    
136     gettext_localize_dialog (dlg, prefs, _("WinPT Preferences"));
137 twoaday 180
138     SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, reg_prefs.cache_time/60, TRUE);
139 twoaday 176 SetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, reg_prefs.word_wrap, TRUE);
140     if (reg_prefs.backup.path)
141     SetDlgItemText (dlg, IDC_PREFS_BAKPATH, reg_prefs.backup.path);
142    
143 twoaday 180 for (i=0; hotkeys[i]; i++) {
144     if (!wpt_hotkeys[i].enabled)
145     continue;
146     char key[2];
147     key[0] = wpt_hotkeys[i].key;
148     key[1] = 0;
149     SetDlgItemText (dlg, hotkeys[i], key);
150     }
151 twoaday 176 CheckDlgButton (dlg, IDC_PREFS_DISABLE_HOTKEYS,
152     reg_prefs.no_hotkeys ? BST_CHECKED : BST_UNCHECKED);
153     CheckDlgButton (dlg, IDC_PREFS_SECMODE,
154     reg_prefs.use_tmpfiles ? BST_UNCHECKED : BST_CHECKED);
155     CheckDlgButton (dlg, IDC_PREFS_VIEWER,
156     reg_prefs.use_viewer ? BST_CHECKED: BST_UNCHECKED);
157     CheckDlgButton (dlg, IDC_PREFS_TRUST,
158     reg_prefs.always_trust? BST_CHECKED : BST_UNCHECKED);
159     CheckDlgButton (dlg, IDC_PREFS_AUTOBACKUP,
160     reg_prefs.auto_backup? BST_CHECKED : BST_UNCHECKED);
161     CheckDlgButton (dlg, IDC_PREFS_BAKHOME,
162     reg_prefs.backup.mode==1? BST_CHECKED : BST_UNCHECKED);
163     CheckDlgButton (dlg, IDC_PREFS_BAKUSER,
164     reg_prefs.backup.mode==2? BST_CHECKED : BST_UNCHECKED);
165     if (reg_prefs.no_hotkeys)
166     disable_hotkey_items (dlg, 1);
167     if (!reg_prefs.auto_backup)
168     enable_backup_items (dlg, 0);
169     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKPATH),
170     reg_prefs.backup.mode==1?FALSE : TRUE);
171     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKSELECT),
172     reg_prefs.backup.mode==1? FALSE : TRUE);
173     init_wipe_modes (dlg);
174     center_window (dlg, NULL);
175     SetForegroundWindow (dlg);
176     }
177    
178    
179 werner 36 /* Dialog box procedure for the WinPT preferences. */
180     BOOL CALLBACK
181     prefs_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
182     {
183     int rc;
184 twoaday 176 int i;
185 twoaday 180 char t[3];
186 twoaday 176 char path[256], *p;
187 werner 36 HWND cb;
188    
189 twoaday 88 switch (msg) {
190 werner 36 case WM_INITDIALOG:
191 twoaday 176 on_init_dialog (dlg);
192 werner 36 return TRUE;
193    
194     case WM_SYSCOMMAND:
195     if (LOWORD (wparam) == SC_CLOSE)
196 twoaday 176 EndDialog (dlg, FALSE);
197 werner 36 return FALSE;
198    
199     case WM_COMMAND:
200 twoaday 180 switch (HIWORD (wparam)) {
201 werner 36 case BN_CLICKED:
202 twoaday 180 switch ((int)LOWORD (wparam)) {
203 werner 36 case IDC_PREFS_DISABLE_HOTKEYS:
204     reg_prefs.no_hotkeys ^= 1;
205 twoaday 117 disable_hotkey_items (dlg, reg_prefs.no_hotkeys);
206 werner 36 break;
207    
208     case IDC_PREFS_TRUST:
209     reg_prefs.always_trust ^= 1;
210 twoaday 117 if (reg_prefs.always_trust) {
211 werner 36 msg_box (dlg,
212     _("In most cases it is not a good idea to enable this setting.\n"
213     "If you know what you are doing let this flag enabled, otherwise\n"
214     "it is safe to leave this flag untouched."),
215 twoaday 117 _("Preferences"), MB_ICONWARNING|MB_OK);
216 werner 36 }
217     break;
218    
219     case IDC_PREFS_AUTOBACKUP:
220     reg_prefs.auto_backup ^= 1;
221     enable_backup_items (dlg, reg_prefs.auto_backup);
222     if (reg_prefs.auto_backup == 1) {
223     if (!IsDlgButtonChecked (dlg, IDC_PREFS_BAKHOME) &&
224     !IsDlgButtonChecked (dlg, IDC_PREFS_BAKUSER))
225     CheckDlgButton (dlg, IDC_PREFS_BAKHOME, BST_CHECKED);
226     }
227 twoaday 130 if (IsDlgButtonChecked (dlg, IDC_PREFS_BAKHOME))
228     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKPATH), FALSE);
229 werner 36 break;
230    
231     case IDC_PREFS_BAKHOME:
232     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKSELECT), FALSE);
233     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKPATH), FALSE);
234     break;
235    
236     case IDC_PREFS_BAKUSER:
237     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKSELECT), TRUE);
238     EnableWindow (GetDlgItem (dlg, IDC_PREFS_BAKPATH), TRUE);
239     break;
240     }
241     break;
242     }
243 twoaday 180 switch (LOWORD (wparam)) {
244 werner 36 case IDC_PREFS_BAKSELECT:
245     const char *bpath;
246     bpath = get_folder_dlg (dlg, _("Select GPG backup path"), NULL);
247     if (bpath)
248     SetDlgItemText (dlg, IDC_PREFS_BAKPATH, bpath);
249     break;
250    
251     case IDOK:
252 twoaday 180 rc = GetDlgItemInt (dlg, IDC_PREFS_CACHETIME, NULL, FALSE);
253     if (rc <= 0)
254 werner 36 reg_prefs.cache_time = 0;
255 twoaday 180 else if (rc > 720) {
256     msg_box( dlg, _("Please enter a value that is between 1-720.\nIt is not "
257     "a good idea to cache the passphrase more than 12 hours."),
258 twoaday 117 _("Preferences"), MB_ERR);
259     SetDlgItemInt (dlg, IDC_PREFS_CACHETIME, 0, FALSE);
260 werner 36 return TRUE;
261     }
262     if (reg_prefs.cache_time != rc)
263     agent_flush_cache ();
264 twoaday 180 reg_prefs.cache_time = rc*60;
265 twoaday 117 rc = GetDlgItemInt (dlg, IDC_PREFS_WORDWRAP, NULL, FALSE);
266 twoaday 180 if (rc <= 0)
267 werner 36 reg_prefs.word_wrap = 0;
268 twoaday 117 else if (rc > 80) {
269 twoaday 176 msg_box (dlg, _("Please enter a value between 1-80."),
270     _("Preferences"), MB_ERR);
271 werner 36 return TRUE;
272     }
273     reg_prefs.word_wrap = rc;
274 twoaday 180 reg_prefs.use_tmpfiles = IsDlgButtonChecked (dlg, IDC_PREFS_SECMODE)? 0 : 1;
275     reg_prefs.use_viewer = IsDlgButtonChecked (dlg, IDC_PREFS_VIEWER)? 1 : 0;
276     reg_prefs.backup.mode = IsDlgButtonChecked (dlg, IDC_PREFS_BAKHOME ) ? 1 :
277     IsDlgButtonChecked (dlg, IDC_PREFS_BAKUSER)? 2 : 0;
278     if (reg_prefs.backup.mode == 2) {
279     if (!GetDlgItemText (dlg, IDC_PREFS_BAKPATH, path, sizeof (path)-1)
280     || dir_exist_check (path)) {
281     msg_box (dlg, _("The specified backup folder is invalid."),
282     _("Preferences"), MB_ERR);
283 werner 36 return TRUE;
284     }
285     free_if_alloc (reg_prefs.backup.path);
286     p = reg_prefs.backup.path = m_strdup (path);
287     if (!p)
288     BUG (0);
289     }
290    
291 twoaday 180 cb = GetDlgItem (dlg, IDC_PREFS_WIPEMODE);
292     reg_prefs.wipe_mode = SendMessage (cb, CB_GETCURSEL, 0, 0);
293 werner 36
294     if (IsDlgButtonChecked (dlg, IDC_PREFS_DISABLE_HOTKEYS)) {
295     hotkeys_unregister (glob_hwnd);
296     reg_prefs.no_hotkeys = 1;
297     }
298     else {
299     reg_prefs.no_hotkeys = 0;
300 twoaday 180 for (i = 0; hotkeys[i]; i++) {
301     rc = GetDlgItemText (dlg, hotkeys[i], t, sizeof (t)-1);
302     if (rc > 0 && check_hotkey (&t[0]))
303     hotkey_enable (&wpt_hotkeys[i], t);
304 werner 36 else
305 twoaday 180 hotkey_disable (&wpt_hotkeys[i]);
306 werner 36 }
307     set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "DisableHotkeys", "0");
308     reg_prefs.no_hotkeys = 0;
309     }
310    
311 twoaday 180 rc = set_reg_winpt_prefs (&reg_prefs);
312     if (rc)
313 werner 36 msg_box (dlg, winpt_strerror (rc), _("Preferences"), MB_ERR);
314    
315     if (reg_prefs.no_hotkeys == 0) {
316     hotkeys_unregister (glob_hwnd);
317 twoaday 180 rc = hotkeys_register (glob_hwnd);
318     if (rc)
319 werner 36 msg_box (NULL, winpt_strerror (rc), _("Hotkeys"), MB_ERR);
320     }
321     EndDialog (dlg, TRUE);
322     return TRUE;
323    
324     case IDCANCEL:
325 twoaday 117 /* Reset backup mode if no mode was chosen. */
326     if (reg_prefs.auto_backup == 1 &&
327     !IsDlgButtonChecked (dlg, IDC_PREFS_BAKHOME) &&
328     !IsDlgButtonChecked (dlg, IDC_PREFS_BAKUSER))
329     reg_prefs.auto_backup = 0;
330     EndDialog (dlg, FALSE);
331 werner 36 return FALSE;
332     }
333     break;
334     }
335    
336     return FALSE;
337     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26