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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26