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

Diff of /trunk/Src/wptPreferencesDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.32  
changed lines
  Added in v.88

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26