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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26