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

Diff of /trunk/Src/wptGPGOptDlg.cpp

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

revision 256 by twoaday, Sat Aug 5 10:31:06 2006 UTC revision 273 by twoaday, Fri Dec 8 10:22:17 2006 UTC
# Line 1  Line 1 
1  /* wptGPGOptDlg.cpp - WinPT GnuPG GPG Config  /* wptGPGOptDlg.cpp - WinPT GnuPG GPG Config
2   *      Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz   *      Copyright (C) 2001-2003, 2005, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 12  Line 12 
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.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  
15   */   */
16  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
17  #include <config.h>  #include <config.h>
# Line 27  Line 23 
23  #include "wptNLS.h"  #include "wptNLS.h"
24  #include "wptGPG.h"  #include "wptGPG.h"
25  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
 #include "wptContext.h" /* for passphrase_s */  
 #include "wptDlgs.h"  
26  #include "wptW32API.h"  #include "wptW32API.h"
27  #include "wptErrors.h"  #include "wptErrors.h"
28  #include "resource.h"  #include "resource.h"
29    
30    
 #define DEF_CFGSIZE 2048  
   
31  /* Dialog box procedure for manipulating the GPG config file. */  /* Dialog box procedure for manipulating the GPG config file. */
32  BOOL CALLBACK  BOOL CALLBACK
33  gpgopt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  gpgopt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
34  {  {
35      int id, nbytes = DEF_CFGSIZE;      int nbytes;
36      char t[4], *optbuf = NULL;      char *optbuf;
37            
38      switch (msg)  {      switch (msg)  {
39      case WM_INITDIALOG:        case WM_INITDIALOG:
40          optbuf = get_gnupg_config ();          optbuf = get_gnupg_config ();
41          if (!optbuf) {          if (!optbuf) {
42              msg_box (dlg,  _("Could not load GnuPG config file!"),              msg_box (dlg,  _("Could not load GnuPG config file!"),
# Line 62  gpgopt_dlg_proc (HWND dlg, UINT msg, WPA Line 54  gpgopt_dlg_proc (HWND dlg, UINT msg, WPA
54          return TRUE;          return TRUE;
55                    
56      case WM_COMMAND:      case WM_COMMAND:
57          switch( LOWORD( wparam ) ) {          switch (LOWORD (wparam)) {
58          case IDC_GPGOPT_SAVE:                        case IDC_GPGOPT_SAVE:
59              optbuf = new char[nbytes + 1];              nbytes = item_get_text_length (dlg, IDC_GPGOPT_FILE);
60                if (nbytes < 1) {
61                    msg_box (dlg, _("The 'gpg.conf' file is not loaded."),
62                             _("GPG Config"), MB_ERR);
63                    return TRUE;
64                }
65                optbuf = new char[nbytes + 2];
66              if (!optbuf)              if (!optbuf)
67                  BUG (0);                  BUG (0);
68              nbytes = GetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf, nbytes);              memset (optbuf, 0, nbytes + 2);
69              if (!nbytes) {              nbytes = GetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf, nbytes+1);
                 msg_box (dlg, _("The 'gpg.conf' file is not loaded."), _("GPG Config"), MB_ERR);  
                 free_if_alloc (optbuf);  
                 return FALSE;            
             }  
             optbuf[nbytes] = '\0';  
70              if (check_gnupg_options (optbuf, 1)) {              if (check_gnupg_options (optbuf, 1)) {
71                  msg_box (dlg, _("File contains invalid GnuPG keywords!"), _("GPG Config"), MB_ERR);                  msg_box (dlg, _("Config contains invalid GnuPG keywords."),
72                             _("GPG Config"), MB_ERR);
73                  free_if_alloc (optbuf);                  free_if_alloc (optbuf);
74                  return FALSE;                  return TRUE;
75              }              }
76              if (set_gnupg_options (optbuf, strlen (optbuf))) {              if (set_gnupg_options (optbuf, strlen (optbuf))) {
77                  msg_box (dlg, _("Could not save GnuPG config file."), _("GPG Config"), MB_ERR);                  msg_box (dlg, _("Could not save GnuPG config file."),
78                             _("GPG Config"), MB_ERR);
79                  free_if_alloc (optbuf);                  free_if_alloc (optbuf);
80                  return FALSE;                  return TRUE;
81              }              }
82              msg_box (dlg, _("Successfully saved."), _("GPG Config"), MB_OK);              /* We need to call gpg after the gpg.conf is stored, otherwise
83                   it would still check the old content. */
84                if (!gpg_check_return_code ("--gpgconf-list"))
85                    msg_box (dlg, _("Successfully saved."), _("GPG Config"), MB_OK);
86                else
87                    msg_box (dlg, _("GnuPG returned an error while parsing the config file."),
88                             _("GPG Config"), MB_ERR);
89              free_if_alloc (optbuf);              free_if_alloc (optbuf);
90              return TRUE;              return TRUE;
91                            
92          case IDC_GPGOPT_LOAD:                            case IDC_GPGOPT_LOAD:
93              if (GetDlgItemText(dlg, IDC_GPGOPT_FILE, t, sizeof (t) - 1)) {              if (item_get_text_length (dlg, IDC_GPGOPT_FILE) > 2) {
94                  id = msg_box (dlg, _("Current data will be lost!\n"                  if (msg_box (dlg, _("Current data will be lost!\n"
95                                       "Are you sure?"), _("GPG Config"), MB_INFO|MB_YESNO);                                      "Are you sure?"), _("GPG Config"),
96                  if (id == IDNO)                                      MB_WARN|MB_YESNO) == IDNO)
97                      return TRUE;                      return TRUE;
98              }              }
99              optbuf = get_gnupg_config ();              optbuf = get_gnupg_config ();
100              if (!optbuf)              if (!optbuf)
101                  msg_box (dlg, _("Could not load GnuPG config file!"), _("GPG Config"), MB_ERR);                  msg_box (dlg, _("Could not load GnuPG config file."),
102              SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);                           _("GPG Config"), MB_ERR);
103              free_if_alloc (optbuf);              else {
104                    SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);
105                    free_if_alloc (optbuf);
106                }
107              return TRUE;              return TRUE;
108                            
109          case IDCANCEL:          case IDCANCEL:
110              EndDialog (dlg, FALSE);              EndDialog (dlg, FALSE);
111              return FALSE;              return TRUE;
112          }          }
113          break;          break;
114      }      }

Legend:
Removed from v.256  
changed lines
  Added in v.273

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26