/[winpt]/trunk/Src/wptGPGOptDlg.cpp
ViewVC logotype

Contents of /trunk/Src/wptGPGOptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (show annotations)
Tue Jun 6 13:37:59 2006 UTC (18 years, 8 months ago) by twoaday
File size: 3762 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26