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 |
* |
* |
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> |
18 |
#endif |
#endif |
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 |
|
|
31 |
/* Dialog box procedure for 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 = 8192; |
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 |
dlg_fatal_error (dlg, _("Could not load GnuPG config file!")); |
msg_box (dlg, _("Could not load GnuPG config file!"), |
43 |
|
_("GPG Config"), MB_ERR); |
44 |
|
EndDialog (dlg, FALSE); |
45 |
|
return TRUE; |
46 |
|
} |
47 |
SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf); |
SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf); |
|
#ifndef LANG_DE |
|
48 |
SetWindowText (dlg, _("GnuPG Configuration File" )); |
SetWindowText (dlg, _("GnuPG Configuration File" )); |
49 |
SetDlgItemText (dlg, IDC_GPGOPT_SAVE, _("&Save")); |
SetDlgItemText (dlg, IDC_GPGOPT_SAVE, _("&Save")); |
50 |
SetDlgItemText (dlg, IDC_GPGOPT_LOAD, _("&Load")); |
SetDlgItemText (dlg, IDC_GPGOPT_LOAD, _("&Load")); |
51 |
#endif |
SetDlgItemText (dlg, IDCANCEL, _("&Exit")); |
52 |
free_if_alloc( optbuf ); |
free_if_alloc (optbuf); |
53 |
SetForegroundWindow( dlg ); |
SetForegroundWindow (dlg); |
54 |
return TRUE; |
return TRUE; |
55 |
|
|
|
case WM_SYSCOMMAND: |
|
|
if( LOWORD (wparam) == SC_CLOSE ) |
|
|
EndDialog(dlg, TRUE); |
|
|
return FALSE; |
|
|
|
|
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( !optbuf ) |
if (nbytes < 1) { |
61 |
BUG( dlg); |
msg_box (dlg, _("The 'gpg.conf' file is not loaded."), |
62 |
nbytes = GetDlgItemText( dlg, IDC_GPGOPT_FILE, optbuf, nbytes ); |
_("GPG Config"), MB_ERR); |
63 |
if( !nbytes ) { |
return TRUE; |
64 |
msg_box( dlg, _("The 'gpg.conf' file is not loaded."), _("GPG Config"), MB_ERR ); |
} |
65 |
free_if_alloc( optbuf ); |
optbuf = new char[nbytes + 2]; |
66 |
return FALSE; |
if (!optbuf) |
67 |
} |
BUG (0); |
68 |
optbuf[nbytes] = '\0'; |
memset (optbuf, 0, nbytes + 2); |
69 |
if( check_gnupg_options( optbuf ) ) { |
nbytes = GetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf, nbytes+1); |
70 |
msg_box( dlg, _("File contains invalid GnuPG keywords!"), _("GPG Config"), MB_ERR ); |
if (check_gnupg_options (optbuf, 1)) { |
71 |
free_if_alloc( optbuf ); |
msg_box (dlg, _("Config contains invalid GnuPG keywords."), |
72 |
return FALSE; |
_("GPG Config"), MB_ERR); |
73 |
|
free_if_alloc (optbuf); |
74 |
|
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 |
free_if_alloc( optbuf ); |
_("GPG Config"), MB_ERR); |
79 |
return FALSE; |
free_if_alloc (optbuf); |
80 |
|
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 |
free_if_alloc( optbuf ); |
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); |
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 |
} |
} |