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

Annotation of /trunk/Src/wptGPGOptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 3871 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 22 /* wptGPGOptDlg.cpp - WinPT GnuPG GPG Config
2     * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3 twoaday 2 *
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    
21     #include <windows.h>
22    
23     #include "wptTypes.h"
24     #include "wptNLS.h"
25     #include "wptGPG.h"
26     #include "wptCommonCtl.h"
27     #include "wptContext.h" /* for passphrase_s */
28     #include "wptDlgs.h"
29     #include "wptW32API.h"
30     #include "wptErrors.h"
31     #include "../resource.h"
32    
33    
34     BOOL CALLBACK
35     gpgopt_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
36     {
37     int id, nbytes = 8192;
38     char t[4], *optbuf = NULL;
39    
40     switch( msg ) {
41     case WM_INITDIALOG:
42     optbuf = get_gnupg_config ();
43 twoaday 22 if (!optbuf)
44 twoaday 2 dlg_fatal_error( dlg, _("Could not load GnuPG config file!") );
45 twoaday 22 SetDlgItemText( dlg, IDC_GPGOPT_FILE, optbuf);
46 twoaday 2 #ifndef LANG_DE
47 twoaday 23 SetWindowText( dlg, _("GnuPG Configuration File" ) );
48 twoaday 2 SetDlgItemText( dlg, IDC_GPGOPT_SAVE, _("&Save") );
49     SetDlgItemText( dlg, IDC_GPGOPT_LOAD, _("&Load") );
50     #endif
51     free_if_alloc( optbuf );
52     SetForegroundWindow( dlg );
53     return TRUE;
54    
55     case WM_SYSCOMMAND:
56     if( LOWORD (wparam) == SC_CLOSE )
57     EndDialog(dlg, TRUE);
58     return FALSE;
59    
60     case WM_COMMAND:
61     switch( LOWORD( wparam ) ) {
62     case IDC_GPGOPT_SAVE:
63     optbuf = new char[nbytes + 1];
64     if( !optbuf )
65     BUG( dlg);
66     nbytes = GetDlgItemText( dlg, IDC_GPGOPT_FILE, optbuf, nbytes );
67     if( !nbytes ) {
68 twoaday 22 msg_box( dlg, _("The 'gpg.conf' file is not loaded."), _("GPG Config"), MB_ERR );
69 twoaday 2 free_if_alloc( optbuf );
70     return FALSE;
71     }
72     optbuf[nbytes] = '\0';
73     if( check_gnupg_options( optbuf ) ) {
74 twoaday 22 msg_box( dlg, _("File contains invalid GnuPG keywords!"), _("GPG Config"), MB_ERR );
75 twoaday 2 free_if_alloc( optbuf );
76     return FALSE;
77     }
78     if( set_gnupg_options( optbuf, strlen( optbuf ) ) ) {
79 twoaday 22 msg_box( dlg, _("Could not save GnuPG config file."), _("GPG Config"), MB_ERR );
80 twoaday 2 free_if_alloc( optbuf );
81     return FALSE;
82     }
83 twoaday 22 msg_box( dlg, _("Successfully saved."), _("GPG Config"), MB_OK );
84 twoaday 2 free_if_alloc( optbuf );
85     return TRUE;
86    
87     case IDC_GPGOPT_LOAD:
88     if( GetDlgItemText(dlg, IDC_GPGOPT_FILE, t, sizeof t - 1 ) ) {
89     id = msg_box( dlg, _("Current data will be lost!\n"
90 twoaday 22 "Are you sure?"), _("GPG Config"), MB_INFO|MB_YESNO );
91     if (id == IDNO)
92 twoaday 2 return TRUE;
93     }
94     optbuf = get_gnupg_config ();
95 twoaday 22 if (!optbuf)
96     msg_box (dlg, _("Could not load GnuPG config file!"), _("GPG Config"), MB_ERR);
97     SetDlgItemText (dlg, IDC_GPGOPT_FILE, optbuf);
98     free_if_alloc (optbuf);
99 twoaday 2 return TRUE;
100    
101     case IDCANCEL:
102     EndDialog( dlg, FALSE );
103     return FALSE;
104     }
105     break;
106     }
107    
108     return 0;
109     } /* gpgopt_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26