/[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 147 by twoaday, Fri Jan 13 14:21:16 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 34  Line 34 
34  #include "wptW32API.h"  #include "wptW32API.h"
35    
36    
37    /* Enable all edit items if @val is TRUE, disable them otherwise. */
38    static void
39    enable_disable_items (HWND dlg, BOOL val)
40    {
41        EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_EXEDIR), val);
42        EnableWindow (GetDlgItem (dlg, IDC_GPGREFS_EXEDLG), val);
43        EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCALE), val);
44        EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_LOCDLG), val);
45        EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDIR), val);
46        EnableWindow (GetDlgItem (dlg, IDC_GPGPREFS_HOMEDLG), val);
47    }
48    
49    
50  /* Load the GPG4WIN default values and disabled the  /* Load the GPG4WIN default values and disabled the
51     dialog items to indicate these are fixed values.     dialog items to indicate these are fixed values.
52     Return value: true if GPG4win was found. */     Return value: true if GPG4win was found. */
# Line 55  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 65  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 87  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 119  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 133  gpgprefs_dlg_proc (HWND dlg, UINT msg, W Line 157  gpgprefs_dlg_proc (HWND dlg, UINT msg, W
157          SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF,          SetDlgItemText ( dlg, IDC_GPGPREFS_LOCALINF,
158                          _("Locale directory (to access the translation files)"));                          _("Locale directory (to access the translation files)"));
159          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"));
160            SetDlgItemText (dlg, IDC_GPGPREFS_ASKEXPIRE, _("Allow to set an expiration date for signatures"));
161          SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files"));          SetDlgItemText (dlg, IDC_GPGPREFS_CMTINF, _("Comment in armored files"));
162          SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key"));          SetDlgItemText (dlg, IDC_GPGPREFS_ENCINF, _("Encrypt to this key"));
163          SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options"));          SetDlgItemText (dlg, IDC_GPGPREFS_ALLOPTINF, _("General GPG options"));
164          SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDLG, _("Browse..."));          SetDlgItemText (dlg, IDC_GPGPREFS_HOMEDLG, _("Browse..."));
165          SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse..."));          SetDlgItemText (dlg, IDC_GPGREFS_EXEDLG, _("Browse..."));
166          SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse..."));          SetDlgItemText (dlg, IDC_GPGPREFS_LOCDLG, _("Browse..."));
167            SetDlgItemText (dlg, IDC_GPGPREFS_OVRDEFAULT, _("&Overwrite default settings"));
168            SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
169    
170          gpg4win = load_gpg4win_values (dlg);          gpg4win = load_gpg4win_values (dlg);
171          if (!gpg4win)          if (!gpg4win) {
172              load_registry_values (dlg);              load_registry_values (dlg);
173                CheckDlgButton (dlg, IDC_GPGPREFS_OVRDEFAULT, BST_CHECKED);
174            }
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-level"))                  if (conf_find_option (opt, "ask-cert-expire"))
182                        CheckDlgButton (dlg, IDC_GPGPREFS_ASKEXPIRE, BST_CHECKED);
183                    if (conf_find_option (opt, "ask-cert-level"))
184                      CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED);                      CheckDlgButton (dlg, IDC_GPGPREFS_ASKLEVEL, BST_CHECKED);
185                  if ((e=find_option (opt, "comment")))                  e = conf_find_option (opt, "comment");
186                  SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);                  if (e != NULL)
187                  if ((e=find_option (opt, "encrypt-to")))                      SetDlgItemText (dlg, IDC_GPGPREFS_COMMENT, e->val);
188                    e = conf_find_option (opt, "encrypt-to");
189                    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 166  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, TRUE);  
         return FALSE;  
202                    
203      case WM_COMMAND:      case WM_COMMAND:
204            if (HIWORD (wparam) == BN_CLICKED &&
205                LOWORD (wparam) == IDC_GPGPREFS_OVRDEFAULT) {
206                if (IsDlgButtonChecked (dlg, LOWORD (wparam))) {
207                    enable_disable_items (dlg, TRUE);
208                    gpg4win = false;
209                }
210                else {
211                    enable_disable_items (dlg, FALSE);
212                    gpg4win = true;
213                }
214                break;
215            }
216    
217          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
218          case IDC_GPGPREFS_SAVE:          case IDC_GPGPREFS_SAVE:
219              if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR,              if (!GetDlgItemText (dlg, IDC_GPGPREFS_HOMEDIR,
220                                   homedir, sizeof (homedir) -1)) {                                   homedir, sizeof (homedir) -1)) {
221                  msg_box (dlg, _("Please enter the GnuPG home directory."),                  msg_box (dlg, _("Please enter the GnuPG home directory."),
222                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
223                  return FALSE;                  return FALSE;
224              }              }
225              if (dir_exist_check (homedir)) {              if (dir_exist_check (homedir)) {
226                  _snprintf (t, sizeof (t) - 1, "%s: %s", homedir,                  _snprintf (t, sizeof (t) - 1, "%s: %s", homedir,
227                             winpt_strerror (WPTERR_DIR_OPEN));                             winpt_strerror (WPTERR_DIR_OPEN));
228                  msg_box (dlg, t, _("Preferences"), MB_ERR);                  msg_box (dlg, t, _("Preferences"), MB_ERR);
229                  return FALSE;                  return FALSE;
# Line 193  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              }              }
243              if (file_exist_check (exedir)) {              if (file_exist_check (exedir)) {
244                  msg_box (dlg, _("Could not find the GPG program in this directory."),                  msg_box (dlg, _("Could not find the GPG program in this directory."),
245                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
246                  return FALSE;                  return FALSE;
247              }              }
248              if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) {              if (!gpg4win && set_reg_entry_gpg ("gpgProgram", exedir)) {
249                  msg_box (dlg, _("Could not save 'gpgProgram' in the registry"),                  msg_box (dlg, _("Could not save 'gpgProgram' in the registry"),
250                           _("Preferences"), MB_ERR);                           _("Preferences"), MB_ERR);
251                  return FALSE;                  return FALSE;
252              }              }
253              if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE, locale_dir, sizeof (locale_dir) -1)) {              if (GetDlgItemText (dlg, IDC_GPGPREFS_LOCALE,
254                                    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,
257                               winpt_strerror (WPTERR_DIR_OPEN));                               winpt_strerror (WPTERR_DIR_OPEN));
# Line 227  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)) {
285                    conf_modify_entry (opt, ENTRY_SINGLE, "ask-cert-expire", NULL);
286                    reg_prefs.gpg.ask_cert_expire = 1;
287                }
288                else {
289                    conf_delete_option (opt, "ask-cert-expire");
290                    reg_prefs.gpg.ask_cert_expire = 0;
291                }
292    
293              if( (n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, sizeof t - 1 ) ))              n = GetDlgItemText(dlg, IDC_GPGPREFS_COMMENT, t, DIM (t)-1);
294                  modify_entry( opt, ENTRY_MULTI, "comment", t );              if (n > 0)
295              else if( n == 0 )                  conf_modify_entry (opt, ENTRY_MULTI, "comment", t);
296                  modify_entry( opt, ENTRY_MULTI, "comment", "\"\"" );              else if (n == 0)
297                    conf_modify_entry (opt, ENTRY_MULTI, "comment", "\"\"");
298              else              else
299                  delete_option( opt, "comment" );                  conf_delete_option (opt, "comment");
300    
301              if( (n=GetDlgItemText( dlg, IDC_GPGPREFS_ENCTO, t, sizeof t -1 ) ) )              n = GetDlgItemText (dlg, IDC_GPGPREFS_ENCTO, t, DIM (t)-1);
302                  modify_entry( opt, ENTRY_MULTI, "encrypt-to", t );              if (n > 0)
303                    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, exedir, DIM (exedir)-1) > 0)                  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)
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)
347                  SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s);                  SetDlgItemText (dlg, IDC_GPGPREFS_EXEDIR, s);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26