/[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 32 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  /* wptGPGOptDlg.cpp - WinPT GnuPG GPG Config  /* wptGPGOptDlg.cpp - WinPT GnuPG GPG Config
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 <config.h>
23  #include "wptTypes.h"  #endif
24  #include "wptNLS.h"  
25  #include "wptGPG.h"  #include <windows.h>
26  #include "wptCommonCtl.h"  #include <windows.h>
27  #include "wptContext.h" /* for passphrase_s */  
28  #include "wptDlgs.h"  #include "wptTypes.h"
29  #include "wptW32API.h"  #include "wptNLS.h"
30  #include "wptErrors.h"  #include "wptGPG.h"
31  #include "../resource.h"  #include "wptCommonCtl.h"
32    #include "wptContext.h" /* for passphrase_s */
33    #include "wptDlgs.h"
34  /* Dialog box procedure for the GPG config file. */  #include "wptW32API.h"
35  BOOL CALLBACK  #include "wptErrors.h"
36  gpgopt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  #include "../resource.h"
37  {        
38      int id, nbytes = 8192;  
39      char t[4], *optbuf = NULL;  /* Dialog box procedure for the GPG config file. */
40        BOOL CALLBACK
41      switch (msg)  {  gpgopt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
42      case WM_INITDIALOG:    {      
43          optbuf = get_gnupg_config ();      int id, nbytes = 8192;
44          if (!optbuf)      char t[4], *optbuf = NULL;
45              dlg_fatal_error (dlg,  _("Could not load GnuPG config file!"));      
46          SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);      switch (msg)  {
47          #ifndef LANG_DE      case WM_INITDIALOG:  
48          SetWindowText (dlg, _("GnuPG Configuration File" ));          optbuf = get_gnupg_config ();
49          SetDlgItemText (dlg, IDC_GPGOPT_SAVE, _("&Save"));          if (!optbuf)
50          SetDlgItemText (dlg, IDC_GPGOPT_LOAD, _("&Load"));              dlg_fatal_error (dlg,  _("Could not load GnuPG config file!"));
51          #endif          SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);
52          free_if_alloc( optbuf );          #ifndef LANG_DE
53          SetForegroundWindow( dlg );          SetWindowText (dlg, _("GnuPG Configuration File" ));
54          return TRUE;          SetDlgItemText (dlg, IDC_GPGOPT_SAVE, _("&Save"));
55                    SetDlgItemText (dlg, IDC_GPGOPT_LOAD, _("&Load"));
56      case WM_SYSCOMMAND:          #endif
57          if( LOWORD (wparam) == SC_CLOSE )          free_if_alloc( optbuf );
58              EndDialog(dlg, TRUE);          SetForegroundWindow( dlg );
59          return FALSE;          return TRUE;
60                    
61      case WM_COMMAND:      case WM_SYSCOMMAND:
62          switch( LOWORD( wparam ) ) {          if( LOWORD (wparam) == SC_CLOSE )
63          case IDC_GPGOPT_SAVE:                            EndDialog(dlg, TRUE);
64              optbuf = new char[nbytes + 1];          return FALSE;
65              if( !optbuf )          
66                  BUG( dlg);      case WM_COMMAND:
67              nbytes = GetDlgItemText( dlg, IDC_GPGOPT_FILE, optbuf, nbytes );          switch( LOWORD( wparam ) ) {
68              if( !nbytes ) {          case IDC_GPGOPT_SAVE:              
69                  msg_box( dlg, _("The 'gpg.conf' file is not loaded."), _("GPG Config"), MB_ERR );              optbuf = new char[nbytes + 1];
70                  free_if_alloc( optbuf );              if( !optbuf )
71                  return FALSE;                            BUG( dlg);
72              }              nbytes = GetDlgItemText( dlg, IDC_GPGOPT_FILE, optbuf, nbytes );
73              optbuf[nbytes] = '\0';              if( !nbytes ) {
74              if( check_gnupg_options( optbuf ) ) {                  msg_box( dlg, _("The 'gpg.conf' file is not loaded."), _("GPG Config"), MB_ERR );
75                  msg_box( dlg, _("File contains invalid GnuPG keywords!"), _("GPG Config"), MB_ERR );                  free_if_alloc( optbuf );
76                  free_if_alloc( optbuf );                  return FALSE;          
77                  return FALSE;              }
78              }              optbuf[nbytes] = '\0';
79              if( set_gnupg_options( optbuf, strlen( optbuf ) ) ) {              if( check_gnupg_options( optbuf ) ) {
80                  msg_box( dlg, _("Could not save GnuPG config file."), _("GPG Config"), MB_ERR );                  msg_box( dlg, _("File contains invalid GnuPG keywords!"), _("GPG Config"), MB_ERR );
81                  free_if_alloc( optbuf );                  free_if_alloc( optbuf );
82                  return FALSE;                  return FALSE;
83              }              }
84              msg_box( dlg, _("Successfully saved."), _("GPG Config"), MB_OK );              if( set_gnupg_options( optbuf, strlen( optbuf ) ) ) {
85              free_if_alloc( optbuf );                  msg_box( dlg, _("Could not save GnuPG config file."), _("GPG Config"), MB_ERR );
86              return TRUE;                  free_if_alloc( optbuf );
87                                return FALSE;
88          case IDC_GPGOPT_LOAD:                                }
89              if( GetDlgItemText(dlg, IDC_GPGOPT_FILE, t, sizeof t - 1 ) ) {              msg_box( dlg, _("Successfully saved."), _("GPG Config"), MB_OK );
90                  id = msg_box( dlg, _("Current data will be lost!\n"              free_if_alloc( optbuf );
91                                       "Are you sure?"), _("GPG Config"), MB_INFO|MB_YESNO );                                  return TRUE;
92                  if (id == IDNO)              
93                      return TRUE;          case IDC_GPGOPT_LOAD:                  
94              }              if( GetDlgItemText(dlg, IDC_GPGOPT_FILE, t, sizeof t - 1 ) ) {
95              optbuf = get_gnupg_config ();                  id = msg_box( dlg, _("Current data will be lost!\n"
96              if (!optbuf)                                       "Are you sure?"), _("GPG Config"), MB_INFO|MB_YESNO );                    
97                  msg_box (dlg, _("Could not load GnuPG config file!"), _("GPG Config"), MB_ERR);                  if (id == IDNO)
98              SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);                      return TRUE;
99              free_if_alloc (optbuf);              }
100              return TRUE;              optbuf = get_gnupg_config ();
101                            if (!optbuf)
102          case IDCANCEL:                  msg_box (dlg, _("Could not load GnuPG config file!"), _("GPG Config"), MB_ERR);
103              EndDialog( dlg, FALSE );              SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);
104              return FALSE;              free_if_alloc (optbuf);
105          }              return TRUE;
106          break;              
107      }          case IDCANCEL:
108                    EndDialog( dlg, FALSE );
109      return 0;              return FALSE;
110  }          }
111            break;
112        }
113        
114        return 0;
115    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26