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

Annotation of /trunk/Src/wptGPGOptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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


1 werner 36 /* wptGPGOptDlg.cpp - WinPT GnuPG GPG Config
2 twoaday 273 * Copyright (C) 2001-2003, 2005, 2006 Timo Schulz
3 werner 36 *
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 werner 47 #include "resource.h"
29 werner 36
30    
31 twoaday 256 /* Dialog box procedure for manipulating the GPG config file. */
32 werner 36 BOOL CALLBACK
33     gpgopt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
34 twoaday 256 {
35 twoaday 273 int nbytes;
36     char *optbuf;
37 werner 36
38     switch (msg) {
39 twoaday 273 case WM_INITDIALOG:
40 werner 36 optbuf = get_gnupg_config ();
41 twoaday 225 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 werner 36 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 twoaday 248 SetDlgItemText (dlg, IDCANCEL, _("&Exit"));
52 twoaday 225 free_if_alloc (optbuf);
53     SetForegroundWindow (dlg);
54 werner 36 return TRUE;
55    
56     case WM_COMMAND:
57 twoaday 273 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 twoaday 225 if (!optbuf)
67     BUG (0);
68 twoaday 273 memset (optbuf, 0, nbytes + 2);
69     nbytes = GetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf, nbytes+1);
70 twoaday 256 if (check_gnupg_options (optbuf, 1)) {
71 twoaday 273 msg_box (dlg, _("Config contains invalid GnuPG keywords."),
72     _("GPG Config"), MB_ERR);
73 twoaday 256 free_if_alloc (optbuf);
74 twoaday 273 return TRUE;
75 werner 36 }
76 twoaday 256 if (set_gnupg_options (optbuf, strlen (optbuf))) {
77 twoaday 273 msg_box (dlg, _("Could not save GnuPG config file."),
78     _("GPG Config"), MB_ERR);
79 twoaday 256 free_if_alloc (optbuf);
80 twoaday 273 return TRUE;
81 werner 36 }
82 twoaday 273 /* 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 twoaday 256 free_if_alloc (optbuf);
90 werner 36 return TRUE;
91    
92 twoaday 273 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 werner 36 return TRUE;
98     }
99     optbuf = get_gnupg_config ();
100     if (!optbuf)
101 twoaday 273 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 werner 36 return TRUE;
108    
109     case IDCANCEL:
110 twoaday 256 EndDialog (dlg, FALSE);
111 twoaday 273 return TRUE;
112 werner 36 }
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