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

Annotation of /trunk/Src/wptGPGOptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 255 - (hide annotations)
Tue Aug 1 16:37:23 2006 UTC (18 years, 7 months ago) by twoaday
File size: 3810 byte(s)


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     /* 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 twoaday 225 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 werner 36 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 twoaday 248 SetDlgItemText (dlg, IDCANCEL, _("&Exit"));
58 twoaday 225 free_if_alloc (optbuf);
59     SetForegroundWindow (dlg);
60 werner 36 return TRUE;
61    
62     case WM_COMMAND:
63     switch( LOWORD( wparam ) ) {
64     case IDC_GPGOPT_SAVE:
65     optbuf = new char[nbytes + 1];
66 twoaday 225 if (!optbuf)
67     BUG (0);
68     nbytes = GetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf, nbytes);
69     if (!nbytes) {
70     msg_box (dlg, _("The 'gpg.conf' file is not loaded."), _("GPG Config"), MB_ERR);
71     free_if_alloc (optbuf);
72 werner 36 return FALSE;
73     }
74     optbuf[nbytes] = '\0';
75 twoaday 255 if( check_gnupg_options( optbuf, 1 ) ) {
76 werner 36 msg_box( dlg, _("File contains invalid GnuPG keywords!"), _("GPG Config"), MB_ERR );
77     free_if_alloc( optbuf );
78     return FALSE;
79     }
80     if( set_gnupg_options( optbuf, strlen( optbuf ) ) ) {
81     msg_box( dlg, _("Could not save GnuPG config file."), _("GPG Config"), MB_ERR );
82     free_if_alloc( optbuf );
83     return FALSE;
84     }
85     msg_box( dlg, _("Successfully saved."), _("GPG Config"), MB_OK );
86     free_if_alloc( optbuf );
87     return TRUE;
88    
89     case IDC_GPGOPT_LOAD:
90     if( GetDlgItemText(dlg, IDC_GPGOPT_FILE, t, sizeof t - 1 ) ) {
91     id = msg_box( dlg, _("Current data will be lost!\n"
92     "Are you sure?"), _("GPG Config"), MB_INFO|MB_YESNO );
93     if (id == IDNO)
94     return TRUE;
95     }
96     optbuf = get_gnupg_config ();
97     if (!optbuf)
98     msg_box (dlg, _("Could not load GnuPG config file!"), _("GPG Config"), MB_ERR);
99     SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);
100     free_if_alloc (optbuf);
101     return TRUE;
102    
103     case IDCANCEL:
104     EndDialog( dlg, FALSE );
105     return FALSE;
106     }
107     break;
108     }
109    
110     return 0;
111     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26