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

Annotation of /trunk/Src/wptOwnertrustDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (hide annotations)
Thu Oct 27 15:25:13 2005 UTC (19 years, 4 months ago) by werner
File size: 4103 byte(s)
First set of changes to use autotools for building.
1 werner 36 /* 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 <windows.h>
28     #include <sys/stat.h>
29    
30     #include "../resource.h"
31     #include "wptTypes.h"
32     #include "wptGPG.h"
33     #include "wptErrors.h"
34     #include "wptNLS.h"
35     #include "wptW32API.h"
36    
37    
38     /* Export the ownertrust to the file @fname.
39     Return value: 0 on success. */
40     static gpgme_error_t
41     gpg_export_ownertrust (const char *fname)
42     {
43     gpgme_error_t err;
44     char *ot_data = NULL;
45     FILE *f;
46    
47     err = gpg_manage_ownertrust (&ot_data, 1);
48     if (err)
49     return err;
50     f = fopen (fname, "wb");
51     if (f) {
52     fwrite (ot_data, 1, strlen (ot_data), f);
53     fclose (f);
54     }
55     else
56     err = gpg_error (GPG_ERR_ENOENT);
57     free (ot_data);
58     return 0;
59     }
60    
61    
62     /* Import the ownertrust from file @fname.
63     Return value: 0 on success. */
64     static gpgme_error_t
65     gpg_import_ownertrust (const char *fname)
66     {
67     gpgme_error_t err;
68     FILE *f;
69     struct stat st;
70     char *ot_data;
71    
72     if (stat (fname, &st))
73     return gpg_error (GPG_ERR_ENOENT);
74     f = fopen (fname, "rb");
75     if (!f)
76     return gpg_error (GPG_ERR_ENOENT);
77     ot_data = (char*)calloc (1, st.st_size+1);
78     if (!ot_data)
79     BUG (NULL);
80     fread (ot_data, 1, st.st_size, f);
81     fclose (f);
82    
83     err = gpg_manage_ownertrust (&ot_data, 0);
84    
85     free (ot_data);
86     return 0;
87     }
88    
89    
90     /* Dialog procedure to manage the ownertrust. */
91     BOOL CALLBACK
92     ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
93     {
94     gpgme_error_t err;
95     const char *fname;
96    
97     switch( msg ) {
98     case WM_INITDIALOG:
99     #ifndef LANG_DE
100     SetWindowText( dlg, _("Ownertrust") );
101     SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") );
102     SetDlgItemText( dlg, IDC_OWNERTRUST_DESC,
103     _("Here it is possible to save or restore the ownertrust from the "
104     "'trustdb' file. This could be very useful because the values are NOT "
105     "stored in the keyring.") );
106     #endif
107     center_window( dlg, NULL );
108     SetForegroundWindow( dlg );
109     return TRUE;
110    
111     case WM_SYSCOMMAND:
112     if (LOWORD (wparam) == SC_CLOSE)
113     EndDialog (dlg, TRUE);
114     return TRUE;
115    
116     case WM_COMMAND:
117     switch (LOWORD (wparam)) {
118     case IDC_OWNERTRUST_EXPORT:
119     fname = get_filesave_dlg (dlg, _("Select file name for output"), NULL, NULL);
120     if (!fname)
121     return TRUE;
122     err = gpg_export_ownertrust (fname);
123     if (err) {
124     msg_box (dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );
125     return TRUE;
126     }
127     status_box (dlg, _("Ownertrust successfully exported."), _("GnuPG Status"));
128     return TRUE;
129    
130     case IDC_OWNERTRUST_IMPORT:
131     fname = get_fileopen_dlg (dlg, _("Select file name for input"), NULL, NULL);
132     if (!fname)
133     return TRUE;
134     err = gpg_import_ownertrust (fname);
135     if (err) {
136     msg_box (dlg, gpgme_strerror (err), _("Ownertrust"), MB_ERR);
137     return TRUE;
138     }
139     status_box (dlg, _("Ownertrust succefully imported."), _("GnuPG Status"));
140     return TRUE;
141    
142     case IDCANCEL:
143     EndDialog (dlg, FALSE);
144     return TRUE;
145     }
146     break;
147     }
148    
149     return FALSE;
150     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26