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

Annotation of /trunk/Src/wptGPGOptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 256 - (hide 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 werner 36 /* 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 werner 47 #include "resource.h"
35 werner 36
36    
37 twoaday 256 #define DEF_CFGSIZE 2048
38    
39     /* Dialog box procedure for manipulating the GPG config file. */
40 werner 36 BOOL CALLBACK
41     gpgopt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
42 twoaday 256 {
43     int id, nbytes = DEF_CFGSIZE;
44 werner 36 char t[4], *optbuf = NULL;
45    
46     switch (msg) {
47     case WM_INITDIALOG:
48     optbuf = get_gnupg_config ();
49 twoaday 225 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 werner 36 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 twoaday 248 SetDlgItemText (dlg, IDCANCEL, _("&Exit"));
60 twoaday 225 free_if_alloc (optbuf);
61     SetForegroundWindow (dlg);
62 werner 36 return TRUE;
63    
64     case WM_COMMAND:
65     switch( LOWORD( wparam ) ) {
66     case IDC_GPGOPT_SAVE:
67     optbuf = new char[nbytes + 1];
68 twoaday 225 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 werner 36 return FALSE;
75     }
76     optbuf[nbytes] = '\0';
77 twoaday 256 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 werner 36 return FALSE;
81     }
82 twoaday 256 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 werner 36 return FALSE;
86     }
87 twoaday 256 msg_box (dlg, _("Successfully saved."), _("GPG Config"), MB_OK);
88     free_if_alloc (optbuf);
89 werner 36 return TRUE;
90    
91     case IDC_GPGOPT_LOAD:
92 twoaday 256 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 werner 36 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 twoaday 256 EndDialog (dlg, FALSE);
107 werner 36 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