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

Legend:
Removed from v.35  
changed lines
  Added in v.36

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26