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

Contents of /trunk/Src/wptOwnertrustDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (show annotations)
Mon Oct 31 21:14:11 2005 UTC (19 years, 4 months ago) by werner
File size: 4079 byte(s)
More changes.  Compiles again but there are at least gettext issues with
w32-gettext.c.  I can't get a gpg-error build with ENABLE_NLS.

1 /* wptOwnertrust.cpp - Ownertrust im- and export
2 * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3 * Copyright (C) 2005 g10 Code GmbH
4 *
5 * This file is part of WinPT.
6 *
7 * WinPT is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * WinPT is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with WinPT; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <windows.h>
27 #include <sys/stat.h>
28
29 #include "resource.h"
30 #include "wptTypes.h"
31 #include "wptGPG.h"
32 #include "wptErrors.h"
33 #include "wptNLS.h"
34 #include "wptW32API.h"
35
36
37 /* Export the ownertrust to the file @fname.
38 Return value: 0 on success. */
39 static gpgme_error_t
40 gpg_export_ownertrust (const char *fname)
41 {
42 gpgme_error_t err;
43 char *ot_data = NULL;
44 FILE *f;
45
46 err = gpg_manage_ownertrust (&ot_data, 1);
47 if (err)
48 return err;
49 f = fopen (fname, "wb");
50 if (f) {
51 fwrite (ot_data, 1, strlen (ot_data), f);
52 fclose (f);
53 }
54 else
55 err = gpg_error (GPG_ERR_ENOENT);
56 free (ot_data);
57 return 0;
58 }
59
60
61 /* Import the ownertrust from file @fname.
62 Return value: 0 on success. */
63 static gpgme_error_t
64 gpg_import_ownertrust (const char *fname)
65 {
66 gpgme_error_t err;
67 FILE *f;
68 struct stat st;
69 char *ot_data;
70
71 if (stat (fname, &st))
72 return gpg_error (GPG_ERR_ENOENT);
73 f = fopen (fname, "rb");
74 if (!f)
75 return gpg_error (GPG_ERR_ENOENT);
76 ot_data = (char*)calloc (1, st.st_size+1);
77 if (!ot_data)
78 BUG (NULL);
79 fread (ot_data, 1, st.st_size, f);
80 fclose (f);
81
82 err = gpg_manage_ownertrust (&ot_data, 0);
83
84 free (ot_data);
85 return 0;
86 }
87
88
89 /* Dialog procedure to manage the ownertrust. */
90 BOOL CALLBACK
91 ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
92 {
93 gpgme_error_t err;
94 const char *fname;
95
96 switch( msg ) {
97 case WM_INITDIALOG:
98 #ifndef LANG_DE
99 SetWindowText( dlg, _("Ownertrust") );
100 SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") );
101 SetDlgItemText( dlg, IDC_OWNERTRUST_DESC,
102 _("Here it is possible to save or restore the ownertrust from the "
103 "'trustdb' file. This could be very useful because the values are NOT "
104 "stored in the keyring.") );
105 #endif
106 center_window( dlg, NULL );
107 SetForegroundWindow( dlg );
108 return TRUE;
109
110 case WM_SYSCOMMAND:
111 if (LOWORD (wparam) == SC_CLOSE)
112 EndDialog (dlg, TRUE);
113 return TRUE;
114
115 case WM_COMMAND:
116 switch (LOWORD (wparam)) {
117 case IDC_OWNERTRUST_EXPORT:
118 fname = get_filesave_dlg (dlg, _("Select file name for output"), NULL, NULL);
119 if (!fname)
120 return TRUE;
121 err = gpg_export_ownertrust (fname);
122 if (err) {
123 msg_box (dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );
124 return TRUE;
125 }
126 status_box (dlg, _("Ownertrust successfully exported."), _("GnuPG Status"));
127 return TRUE;
128
129 case IDC_OWNERTRUST_IMPORT:
130 fname = get_fileopen_dlg (dlg, _("Select file name for input"), NULL, NULL);
131 if (!fname)
132 return TRUE;
133 err = gpg_import_ownertrust (fname);
134 if (err) {
135 msg_box (dlg, gpgme_strerror (err), _("Ownertrust"), MB_ERR);
136 return TRUE;
137 }
138 status_box (dlg, _("Ownertrust succefully imported."), _("GnuPG Status"));
139 return TRUE;
140
141 case IDCANCEL:
142 EndDialog (dlg, FALSE);
143 return TRUE;
144 }
145 break;
146 }
147
148 return FALSE;
149 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26