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

Annotation of /trunk/Src/wptOwnertrustDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 112 - (hide annotations)
Fri Dec 2 10:02:17 2005 UTC (19 years, 3 months ago) by twoaday
File size: 4089 byte(s)
Updated the translation.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26