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

Legend:
Removed from v.22  
changed lines
  Added in v.176

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26