1 |
/* wptGPGOptDlg.cpp - WinPT GnuPG GPG Config |
2 |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
3 |
* |
4 |
* This file is part of WinPT. |
5 |
* |
6 |
* 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 |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
20 |
|
21 |
#ifdef HAVE_CONFIG_H |
22 |
#include <config.h> |
23 |
#endif |
24 |
|
25 |
#include <windows.h> |
26 |
#include <windows.h> |
27 |
|
28 |
#include "wptTypes.h" |
29 |
#include "wptNLS.h" |
30 |
#include "wptGPG.h" |
31 |
#include "wptCommonCtl.h" |
32 |
#include "wptContext.h" /* for passphrase_s */ |
33 |
#include "wptDlgs.h" |
34 |
#include "wptW32API.h" |
35 |
#include "wptErrors.h" |
36 |
#include "../resource.h" |
37 |
|
38 |
|
39 |
/* Dialog box procedure for the GPG config file. */ |
40 |
BOOL CALLBACK |
41 |
gpgopt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
42 |
{ |
43 |
int id, nbytes = 8192; |
44 |
char t[4], *optbuf = NULL; |
45 |
|
46 |
switch (msg) { |
47 |
case WM_INITDIALOG: |
48 |
optbuf = get_gnupg_config (); |
49 |
if (!optbuf) |
50 |
dlg_fatal_error (dlg, _("Could not load GnuPG config file!")); |
51 |
SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf); |
52 |
#ifndef LANG_DE |
53 |
SetWindowText (dlg, _("GnuPG Configuration File" )); |
54 |
SetDlgItemText (dlg, IDC_GPGOPT_SAVE, _("&Save")); |
55 |
SetDlgItemText (dlg, IDC_GPGOPT_LOAD, _("&Load")); |
56 |
#endif |
57 |
free_if_alloc( optbuf ); |
58 |
SetForegroundWindow( dlg ); |
59 |
return TRUE; |
60 |
|
61 |
case WM_SYSCOMMAND: |
62 |
if( LOWORD (wparam) == SC_CLOSE ) |
63 |
EndDialog(dlg, TRUE); |
64 |
return FALSE; |
65 |
|
66 |
case WM_COMMAND: |
67 |
switch( LOWORD( wparam ) ) { |
68 |
case IDC_GPGOPT_SAVE: |
69 |
optbuf = new char[nbytes + 1]; |
70 |
if( !optbuf ) |
71 |
BUG( dlg); |
72 |
nbytes = GetDlgItemText( dlg, IDC_GPGOPT_FILE, optbuf, nbytes ); |
73 |
if( !nbytes ) { |
74 |
msg_box( dlg, _("The 'gpg.conf' file is not loaded."), _("GPG Config"), MB_ERR ); |
75 |
free_if_alloc( optbuf ); |
76 |
return FALSE; |
77 |
} |
78 |
optbuf[nbytes] = '\0'; |
79 |
if( check_gnupg_options( optbuf ) ) { |
80 |
msg_box( dlg, _("File contains invalid GnuPG keywords!"), _("GPG Config"), MB_ERR ); |
81 |
free_if_alloc( optbuf ); |
82 |
return FALSE; |
83 |
} |
84 |
if( set_gnupg_options( optbuf, strlen( optbuf ) ) ) { |
85 |
msg_box( dlg, _("Could not save GnuPG config file."), _("GPG Config"), MB_ERR ); |
86 |
free_if_alloc( optbuf ); |
87 |
return FALSE; |
88 |
} |
89 |
msg_box( dlg, _("Successfully saved."), _("GPG Config"), MB_OK ); |
90 |
free_if_alloc( optbuf ); |
91 |
return TRUE; |
92 |
|
93 |
case IDC_GPGOPT_LOAD: |
94 |
if( GetDlgItemText(dlg, IDC_GPGOPT_FILE, t, sizeof t - 1 ) ) { |
95 |
id = msg_box( dlg, _("Current data will be lost!\n" |
96 |
"Are you sure?"), _("GPG Config"), MB_INFO|MB_YESNO ); |
97 |
if (id == IDNO) |
98 |
return TRUE; |
99 |
} |
100 |
optbuf = get_gnupg_config (); |
101 |
if (!optbuf) |
102 |
msg_box (dlg, _("Could not load GnuPG config file!"), _("GPG Config"), MB_ERR); |
103 |
SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf); |
104 |
free_if_alloc (optbuf); |
105 |
return TRUE; |
106 |
|
107 |
case IDCANCEL: |
108 |
EndDialog( dlg, FALSE ); |
109 |
return FALSE; |
110 |
} |
111 |
break; |
112 |
} |
113 |
|
114 |
return 0; |
115 |
} |