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

Diff of /trunk/Src/wptGPGPrefsDlg.cpp

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

revision 161 by twoaday, Thu Jan 19 16:10:37 2006 UTC revision 241 by twoaday, Thu Jun 29 11:15:55 2006 UTC
# Line 1  Line 1 
1  /* wptGPGPrefsDlg.cpp - GnuPG Preferences  /* wptGPGPrefsDlg.cpp - GnuPG Preferences
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 68  load_gpg4win_values (HWND dlg) Line 68  load_gpg4win_values (HWND dlg)
68          }          }
69          free_if_alloc (p);          free_if_alloc (p);
70      }      }
71        free_if_alloc (path);
72    
73      p = get_reg_entry_mo ();      p = get_reg_entry_mo ();
74      if (p) {      if (p) {
# Line 78  load_gpg4win_values (HWND dlg) Line 79  load_gpg4win_values (HWND dlg)
79          }          }
80          free_if_alloc (p);          free_if_alloc (p);
81      }      }
82        
83        path = get_reg_entry_gpg ("HomeDir");
84      p = multi_gnupg_path (1);      p = multi_gnupg_path (1);
85        if (path && dir_exist_check (path) == 0 && p && strcmp (path, p)) {
86            /* The 'HomeDir' has a higher priority so if the key exists and is
87               different from the multi user path, we force the use of it. */
88            free_if_alloc (p);
89            p = path;
90        }
91        else
92            free_if_alloc (path);
93      if (p) {      if (p) {
94          SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p);          SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p);
95          EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE);          EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), FALSE);
96          EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE);          EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), FALSE);
97          free_if_alloc (p);          free_if_alloc (p);
98      }      }
   
99      return true;      return true;
100  }  }
101    
# Line 100  load_registry_values (HWND dlg) Line 109  load_registry_values (HWND dlg)
109      p = get_reg_entry_gpg ("HomeDir");      p = get_reg_entry_gpg ("HomeDir");
110      if (p) {      if (p) {
111          SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p);          SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, p);
112          free_if_alloc (p);                free_if_alloc (p);
113      }      }
114      p = get_reg_entry_gpg ("gpgProgram");      p = get_reg_entry_gpg ("gpgProgram");
115      if (p) {      if (p) {
116          SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p);          SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, p);
117          free_if_alloc (p);                free_if_alloc (p);
118      }      }
119      p = get_reg_entry_mo ();      p = get_reg_entry_mo ();
120      if (p) {      if (p) {
121          SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p);          SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, p);
122          free_if_alloc (p);                  free_if_alloc (p);
123      }      }
124      if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) {      if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) {
125          p = multi_gnupg_path (0);          p = multi_gnupg_path (0);
# Line 146  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 155  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
155          SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF,          SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF,
156                          _("Locale directory (to access the translation files)"));                          _("Locale directory (to access the translation files)"));
157          SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign"));          SetDlgItemText (dlg, IDC_GPGPREFS_ASKLEVEL, _("Ask for the signature class during key sign"));
158            SetDlgItemText (dlg, IDC_GPGPREFS_ASKEXPIRE, _("Allow to set an expiration date for signatures"));
159          SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files"));          SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files"));
160          SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key"));          SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key"));
161          SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options"));          SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options"));
# Line 153  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 163  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
163          SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse..."));          SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse..."));
164          SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse..."));          SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse..."));
165          SetDlgItemText (dlg, IDC_GPGPREFS_OVRDEFAULT, _("&Overwrite default settings"));          SetDlgItemText (dlg, IDC_GPGPREFS_OVRDEFAULT, _("&Overwrite default settings"));
166            SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
167    
168          gpg4win = load_gpg4win_values (dlg);          gpg4win = load_gpg4win_values (dlg);
169          if (!gpg4win) {          if (!gpg4win) {
# Line 165  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 176  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
176              parse_gpg_options (p, &opt);              parse_gpg_options (p, &opt);
177              free_if_alloc (p);              free_if_alloc (p);
178              if (opt) {              if (opt) {
179                    if (find_option (opt, "ask-cert-expire"))
180                        CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED);
181                  if (find_option (opt, "ask-cert-level"))                  if (find_option (opt, "ask-cert-level"))
182                      CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED);                      CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED);
183                  if ((e=find_option (opt, "comment")))                  e = find_option (opt, "comment");
184                  SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);                  if (e != NULL)
185                  if ((e=find_option (opt, "encrypt-to")))                      SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);
186                    e = find_option (opt, "encrypt-to");
187                    if (e != NULL)
188                      SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val);                      SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val);
189                  release_gpg_options (opt);                  release_gpg_options (opt);
190              }              }
# Line 182  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 197  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
197      case WM_DESTROY:      case WM_DESTROY:
198          gpg4win = false;          gpg4win = false;
199          break;          break;
   
     case WM_SYSCOMMAND:  
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog (dlg, TRUE);  
         return FALSE;  
200                    
201      case WM_COMMAND:      case WM_COMMAND:
202          if (HIWORD (wparam) == BN_CLICKED &&          if (HIWORD (wparam) == BN_CLICKED &&
203              LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) {              LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) {
204              if (IsDlgButtonChecked (dlg, LOWORD (wparam)))              if (IsDlgButtonChecked (dlg, LOWORD (wparam))) {
205                  enable_disable_items (dlg, TRUE);                  enable_disable_items (dlg, TRUE);
206              else                  gpg4win = false;
207                }
208                else {
209                  enable_disable_items (dlg, FALSE);                  enable_disable_items (dlg, FALSE);
210                    gpg4win = true;
211                }
212              break;              break;
213          }          }
214    
# Line 202  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 216  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
216          case IDC_GPGPREFS_SAVE:          case IDC_GPGPREFS_SAVE:
217              if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR,              if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR,
218                                   homedir, sizeof (homedir) -1)) {                                   homedir, sizeof (homedir) -1)) {
219                  msg_box (dlg, _("Please enter the GnuPG home directory."),                  msg_box (dlg, _("Please enter the GnuPG home directory."),
220                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
221                  return FALSE;                  return FALSE;
222              }              }
223              if (dir_exist_check (homedir)) {              if (dir_exist_check (homedir)) {
224                  _snprintf (t, sizeof (t) - 1, "%s: %s", homedir,                  _snprintf (t, sizeof (t) - 1, "%s: %s", homedir,
225                             winpt_strerror (WPTERR_DIR_OPEN));                             winpt_strerror (WPTERR_DIR_OPEN));
226                  msg_box (dlg, t, _("Preferences"), MB_ERR);                  msg_box (dlg, t, _("Preferences"), MB_ERR);
227                  return FALSE;                  return FALSE;
# Line 225  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 239  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
239                  return FALSE;                  return FALSE;
240              }              }
241              if (file_exist_check (exedir)) {              if (file_exist_check (exedir)) {
242                  msg_box (dlg, _("Could not find the GPG program in this directory."),                  msg_box (dlg, _("Could not find the GPG program in this directory."),
243                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
244                  return FALSE;                  return FALSE;
245              }              }
246              if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) {              if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) {
247                  msg_box (dlg, _("Could not save 'gpgProgram' in the registry"),                  msg_box (dlg, _("Could not save 'gpgProgram' in the registry"),
248                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
249                  return FALSE;                  return FALSE;
250              }              }
251              if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1)) {              if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE,
252                                    locale_dir, sizeof (locale_dir) -1) > 0) {
253                  if (dir_exist_check (locale_dir)) {                  if (dir_exist_check (locale_dir)) {
254                      log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir,                      log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir,
255                               winpt_strerror (WPTERR_DIR_OPEN));                               winpt_strerror (WPTERR_DIR_OPEN));
# Line 252  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 267  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
267                  msg_box (dlg, _("Could not get GPG config file"),                  msg_box (dlg, _("Could not get GPG config file"),
268                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
269                  EndDialog (dlg, FALSE);                  EndDialog (dlg, FALSE);
270                    return TRUE;
271              }              }
272              parse_gpg_options (p, &opt);              parse_gpg_options (p, &opt);
273    
274              if( IsDlgButtonChecked( dlg, IDC_GPGPREFS_ASKLEVEL ) ) {              if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKLEVEL)) {
275                  modify_entry( opt, ENTRY_SINGLE, "ask-cert-level", NULL );                  modify_entry (opt, ENTRY_SINGLE, "ask-cert-level", NULL);
276                  reg_prefs.gpg.ask_cert_level = 1;                  reg_prefs.gpg.ask_cert_level = 1;
277              }              }
278              else {              else {
279                  delete_option (opt, "ask-cert-level");                  delete_option (opt, "ask-cert-level");
280                  reg_prefs.gpg.ask_cert_level = 0;                  reg_prefs.gpg.ask_cert_level = 0;
281              }              }
282                if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKEXPIRE)) {
283                    modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL);
284                    reg_prefs.gpg.ask_cert_expire = 1;
285                }
286                else {
287                    delete_option (opt, "ask-cert-expire");
288                    reg_prefs.gpg.ask_cert_expire = 0;
289                }
290    
291              if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))              n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, DIM (t)-1);
292                  modify_entry( opt, ENTRY_MULTI, "comment", t );              if (n > 0)
293              else if( n == 0 )                  modify_entry (opt, ENTRY_MULTI, "comment", t);
294                  modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );              else if (n == 0)
295                    modify_entry (opt, ENTRY_MULTI, "comment", "\"\"");
296              else              else
297                  delete_option( opt, "comment" );                  delete_option (opt, "comment");
298    
299              if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )              n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, DIM (t)-1);
300                  modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );              if (n > 0)
301                    modify_entry (opt, ENTRY_MULTI, "encrypt-to", t);
302              else              else
303                  delete_option( opt, "encrypt-to" );                  delete_option (opt, "encrypt-to");
304    
305              commit_gpg_options (p, opt);              commit_gpg_options (p, opt);
306              release_gpg_options (opt);              release_gpg_options (opt);
307              EndDialog (dlg, TRUE);              /* only return TRUE if the home dir has been changed. */
308                if (SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR, EM_GETMODIFY, 0, 0)) {
309                    set_gnupg_default_key (NULL);
310                    EndDialog (dlg, TRUE);          
311                }
312                else
313                    EndDialog (dlg, FALSE);
314              return TRUE;              return TRUE;
315                            
316          case IDC_GPGPREFS_HOMEDLG:          case IDC_GPGPREFS_HOMEDLG:
317              folder = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);              folder = get_folder_dlg (dlg, _("Choose GPG Home Directory"), NULL);
318              if (folder) {              if (folder) {
319                  char *name;                  char *name;
320    
321                  SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder);                  SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder);
322                  if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, exedir, DIM (exedir)-1) > 0)                  SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR,
323                                        EM_SETMODIFY, (WPARAM)(UINT)TRUE, 0);
324                    if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR,
325                                        exedir, DIM (exedir)-1) > 0)
326                      break;                      break;
327                  name = make_filename (folder, "gpg", "exe");                  name = make_filename (folder, "gpg", "exe");
328                  if (file_exist_check (name) == 0)                  if (file_exist_check (name) == 0)
# Line 301  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 336  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
336              return TRUE;              return TRUE;
337    
338          case IDC_GPGPREFS_LOCDLG:          case IDC_GPGPREFS_LOCDLG:
339              folder = get_folder_dlg (dlg, _("Choose locale directory"), NULL);              folder = get_folder_dlg (dlg, _("Choose Locale Directory"), NULL);
340              if (folder)              if (folder)
341                  SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder);                  SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder);
342              return TRUE;              return TRUE;
343                            
344          case IDC_GPGREFS_EXEDLG:          case IDC_GPGREFS_EXEDLG:
345              s = get_fileopen_dlg (dlg, _("Choose GPG binary"),              s = get_fileopen_dlg (dlg, _("Choose GPG Binary"),
346                                    _("Executable Files (*.exe)\0*.exe\0\0"),                                    "Executable Files (*.exe)\0*.exe\0\0",
347                                    NULL);                                    NULL);
348              if (s)              if (s)
349                  SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s);                  SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s);

Legend:
Removed from v.161  
changed lines
  Added in v.241

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26