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

Contents of /trunk/Src/wptGPGOptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 256 - (show annotations)
Sat Aug 5 10:31:06 2006 UTC (18 years, 6 months ago) by twoaday
File size: 3839 byte(s)
1.0.0pre3 release.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26