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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26