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

Contents of /trunk/Src/wptGPGOptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 273 - (show annotations)
Fri Dec 8 10:22:17 2006 UTC (18 years, 2 months ago) by twoaday
File size: 3735 byte(s)


1 /* wptGPGOptDlg.cpp - WinPT GnuPG GPG Config
2 * Copyright (C) 2001-2003, 2005, 2006 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 #ifdef HAVE_CONFIG_H
17 #include <config.h>
18 #endif
19
20 #include <windows.h>
21
22 #include "wptTypes.h"
23 #include "wptNLS.h"
24 #include "wptGPG.h"
25 #include "wptCommonCtl.h"
26 #include "wptW32API.h"
27 #include "wptErrors.h"
28 #include "resource.h"
29
30
31 /* Dialog box procedure for manipulating the GPG config file. */
32 BOOL CALLBACK
33 gpgopt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
34 {
35 int nbytes;
36 char *optbuf;
37
38 switch (msg) {
39 case WM_INITDIALOG:
40 optbuf = get_gnupg_config ();
41 if (!optbuf) {
42 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);
48 SetWindowText (dlg, _("GnuPG Configuration File" ));
49 SetDlgItemText (dlg, IDC_GPGOPT_SAVE, _("&Save"));
50 SetDlgItemText (dlg, IDC_GPGOPT_LOAD, _("&Load"));
51 SetDlgItemText (dlg, IDCANCEL, _("&Exit"));
52 free_if_alloc (optbuf);
53 SetForegroundWindow (dlg);
54 return TRUE;
55
56 case WM_COMMAND:
57 switch (LOWORD (wparam)) {
58 case IDC_GPGOPT_SAVE:
59 nbytes = item_get_text_length (dlg, IDC_GPGOPT_FILE);
60 if (nbytes < 1) {
61 msg_box (dlg, _("The 'gpg.conf' file is not loaded."),
62 _("GPG Config"), MB_ERR);
63 return TRUE;
64 }
65 optbuf = new char[nbytes + 2];
66 if (!optbuf)
67 BUG (0);
68 memset (optbuf, 0, nbytes + 2);
69 nbytes = GetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf, nbytes+1);
70 if (check_gnupg_options (optbuf, 1)) {
71 msg_box (dlg, _("Config contains invalid GnuPG keywords."),
72 _("GPG Config"), MB_ERR);
73 free_if_alloc (optbuf);
74 return TRUE;
75 }
76 if (set_gnupg_options (optbuf, strlen (optbuf))) {
77 msg_box (dlg, _("Could not save GnuPG config file."),
78 _("GPG Config"), MB_ERR);
79 free_if_alloc (optbuf);
80 return TRUE;
81 }
82 /* We need to call gpg after the gpg.conf is stored, otherwise
83 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;
91
92 case IDC_GPGOPT_LOAD:
93 if (item_get_text_length (dlg, IDC_GPGOPT_FILE) > 2) {
94 if (msg_box (dlg, _("Current data will be lost!\n"
95 "Are you sure?"), _("GPG Config"),
96 MB_WARN|MB_YESNO) == IDNO)
97 return TRUE;
98 }
99 optbuf = get_gnupg_config ();
100 if (!optbuf)
101 msg_box (dlg, _("Could not load GnuPG config file."),
102 _("GPG Config"), MB_ERR);
103 else {
104 SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);
105 free_if_alloc (optbuf);
106 }
107 return TRUE;
108
109 case IDCANCEL:
110 EndDialog (dlg, FALSE);
111 return TRUE;
112 }
113 break;
114 }
115
116 return 0;
117 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26