/[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 181 by twoaday, Tue Mar 14 11:01:22 2006 UTC revision 271 by twoaday, Sun Nov 5 08:57:45 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 there is no 'HomeDir' registry value but an existing
125           GPG multipath, we use this as the home dir instead. */
126      if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) {      if (!item_get_text_length (dlg, IDC_GPGPREFS_HOMEDIR)) {
127          p = multi_gnupg_path (0);          p = multi_gnupg_path (0);
128          if (p && dir_exist_check (p) == 0)          if (p && dir_exist_check (p) == 0)
# Line 132  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 143  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
143      char *p = NULL, t[256];      char *p = NULL, t[256];
144      const char *s;      const char *s;
145      const char *folder;      const char *folder;
146      gpg_optfile_t opt = NULL;      config_file_t opt = NULL;
147      gpg_option_t e;      conf_option_t e;
148      UINT n;      UINT n;
149            
150      switch (msg) {      switch (msg) {
# Line 164  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 175  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
175    
176          p = get_gnupg_cfgfile ();          p = get_gnupg_cfgfile ();
177          if (p) {          if (p) {
178              parse_gpg_options (p, &opt);              parse_config (p, &opt);
179              free_if_alloc (p);              free_if_alloc (p);
180              if (opt) {              if (opt) {
181                  if (find_option (opt, "ask-cert-expire"))                  if (conf_find_option (opt, "ask-cert-expire"))
182                      CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED);                      CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED);
183                  if (find_option (opt, "ask-cert-level"))                  if (conf_find_option (opt, "ask-cert-level"))
184                      CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED);                      CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED);
185                  e = find_option (opt, "comment");                  e = conf_find_option (opt, "comment");
186                  if (e != NULL)                  if (e != NULL)
187                      SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);                      SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);
188                  e = find_option (opt, "encrypt-to");                  e = conf_find_option (opt, "encrypt-to");
189                  if (e != NULL)                  if (e != NULL)
190                      SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val);                      SetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, e->val);
191                  release_gpg_options (opt);                  release_config (opt);
192              }              }
193          }          }
194    
# Line 188  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 199  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
199      case WM_DESTROY:      case WM_DESTROY:
200          gpg4win = false;          gpg4win = false;
201          break;          break;
   
     case WM_SYSCOMMAND:  
         if (LOWORD (wparam) == SC_CLOSE)  
             EndDialog (dlg, FALSE);  
         return FALSE;  
202                    
203      case WM_COMMAND:      case WM_COMMAND:
204          if (HIWORD (wparam) == BN_CLICKED &&          if (HIWORD (wparam) == BN_CLICKED &&
# Line 228  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 234  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
234                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
235                  return FALSE;                  return FALSE;
236              }              }
237              if( !GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR,              if (!GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR,
238                                   exedir, sizeof (exedir) -1)) {                                   exedir, sizeof (exedir) -1)) {
239                  msg_box (dlg, _("Please enter where GPG.exe is located."),                  msg_box (dlg, _("Please enter where GPG.exe is located."),
240                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
241                  return FALSE;                  return FALSE;
242              }              }
# Line 244  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 250  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
250                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
251                  return FALSE;                  return FALSE;
252              }              }
253              if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE,              if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE,
254                                  locale_dir, sizeof (locale_dir) -1) > 0) {                                  locale_dir, sizeof (locale_dir) -1) > 0) {
255                  if (dir_exist_check (locale_dir)) {                  if (dir_exist_check (locale_dir)) {
256                      log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir,                      log_box ( _("Preferences"), MB_ERR, "%s: %s", locale_dir,
# Line 263  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 269  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
269                  msg_box (dlg, _("Could not get GPG config file"),                  msg_box (dlg, _("Could not get GPG config file"),
270                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
271                  EndDialog (dlg, FALSE);                  EndDialog (dlg, FALSE);
272                    return TRUE;
273              }              }
274              parse_gpg_options (p, &opt);              parse_config (p, &opt);
275    
276              if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKLEVEL)) {              if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKLEVEL)) {
277                  modify_entry (opt, ENTRY_SINGLE, "ask-cert-level", NULL);                  conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-level", NULL);
278                  reg_prefs.gpg.ask_cert_level = 1;                  reg_prefs.gpg.ask_cert_level = 1;
279              }              }
280              else {              else {
281                  delete_option (opt, "ask-cert-level");                  conf_delete_option (opt, "ask-cert-level");
282                  reg_prefs.gpg.ask_cert_level = 0;                  reg_prefs.gpg.ask_cert_level = 0;
283              }              }
284              if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKEXPIRE)) {              if (IsDlgButtonChecked (dlg, IDC_GPGPREFS_ASKEXPIRE)) {
285                  modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL);                  conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL);
286                  reg_prefs.gpg.ask_cert_expire = 1;                  reg_prefs.gpg.ask_cert_expire = 1;
287              }              }
288              else {              else {
289                  delete_option (opt, "ask-cert-expire");                  conf_delete_option (opt, "ask-cert-expire");
290                  reg_prefs.gpg.ask_cert_expire = 0;                  reg_prefs.gpg.ask_cert_expire = 0;
291              }              }
292    
293              n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1);              n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, DIM (t)-1);
294              if (n > 0)              if (n > 0)
295                  modify_entry (opt, ENTRY_MULTI, "comment", t);                  conf_modify_entry (opt, ENTRY_MULTI, "comment", t);
296              else if (n == 0)              else if (n == 0)
297                  modify_entry (opt, ENTRY_MULTI, "comment", "\"\"");                  conf_modify_entry (opt, ENTRY_MULTI, "comment", "\"\"");
298              else              else
299                  delete_option (opt, "comment");                  conf_delete_option (opt, "comment");
300    
301              n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1);              n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, DIM (t)-1);
302              if (n > 0)              if (n > 0)
303                  modify_entry (opt, ENTRY_MULTI, "encrypt-to", t);                  conf_modify_entry (opt, ENTRY_MULTI, "encrypt-to", t);
304              else              else
305                  delete_option (opt, "encrypt-to");                  conf_delete_option (opt, "encrypt-to");
306    
307              commit_gpg_options (p, opt);              commit_config (p, opt);
308              release_gpg_options (opt);              release_config (opt);
309              EndDialog (dlg, TRUE);              /* only return TRUE if the home dir has been changed. */
310                if (SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR, EM_GETMODIFY, 0, 0)) {
311                    set_gnupg_default_key (NULL);
312                    EndDialog (dlg, TRUE);          
313                }
314                else
315                    EndDialog (dlg, FALSE);
316              return TRUE;              return TRUE;
317                            
318          case IDC_GPGPREFS_HOMEDLG:          case IDC_GPGPREFS_HOMEDLG:
319              folder = get_folder_dlg (dlg, _("Choose GPG home directory"), NULL);              folder = get_folder_dlg (dlg, _("Choose GPG Home Directory"), NULL);
320              if (folder) {              if (folder) {
321                  char *name;                  char *name;
322    
323                  SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder);                  SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR, folder);
324                  if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR,                  SendDlgItemMessage (dlg, IDC_GPGPREFS_HOMEDIR,
325                                        EM_SETMODIFY, (WPARAM)(UINT)TRUE, 0);
326                    if (GetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR,
327                                      exedir, DIM (exedir)-1) > 0)                                      exedir, DIM (exedir)-1) > 0)
328                      break;                      break;
329                  name = make_filename (folder, "gpg", "exe");                  name = make_filename (folder, "gpg", "exe");
330                  if (file_exist_check (name) == 0)                  if (file_exist_check (name) == 0)
331                      SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);                      SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, name);
332                  free_if_alloc (name);                  free_if_alloc (name);
                 name = make_filename (folder, "gpg", "conf");  
                 if (file_exist_check (name) == 0)  
                     SetDlgItemText (dlg, IDC_GPGPREFS_OPTFILE, name);  
                 free_if_alloc (name);  
333              }              }
334              return TRUE;              return TRUE;
335    
336          case IDC_GPGPREFS_LOCDLG:          case IDC_GPGPREFS_LOCDLG:
337              folder = get_folder_dlg (dlg, _("Choose locale directory"), NULL);              folder = get_folder_dlg (dlg, _("Choose Locale Directory"), NULL);
338              if (folder)              if (folder)
339                  SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder);                  SetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, folder);
340              return TRUE;              return TRUE;
341                            
342          case IDC_GPGREFS_EXEDLG:          case IDC_GPGREFS_EXEDLG:
343              s = get_fileopen_dlg (dlg, _("Choose GPG binary"),              s = get_fileopen_dlg (dlg, _("Choose GPG Binary"),
344                                    "Executable Files (*.exe)\0*.exe\0\0",                                    "Executable Files (*.exe)\0*.exe\0\0",
345                                    NULL);                                    NULL);
346              if (s)              if (s)

Legend:
Removed from v.181  
changed lines
  Added in v.271

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26