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

Annotation of /trunk/Src/wptClipImportDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 68 - (hide annotations)
Sat Nov 5 12:00:55 2005 UTC (19 years, 3 months ago) by twoaday
File size: 4803 byte(s)
More minor changes to avoid GCC warnings.


1 werner 36 /* wptClipImportDlg.cpp - WinPT key import dialog
2     * Copyright (C) 2001-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    
28 werner 47 #include "resource.h"
29 werner 36 #include "wptCrypto.h"
30     #include "wptGPG.h"
31     #include "wptCommonCtl.h"
32     #include "wptKeylist.h"
33     #include "wptNLS.h"
34     #include "wptErrors.h"
35     #include "wptTypes.h"
36     #include "wptContext.h" /* for passphrase_s */
37     #include "wptDlgs.h"
38     #include "wptW32API.h"
39     #include "wptVersion.h"
40     #include "wptImport.h"
41    
42    
43     /* Import the PGP key data from the clipboard.
44     Return value: 0 on success. */
45     gpgme_error_t
46     gpgme_op_clip_import (gpgme_ctx_t ctx)
47     {
48     gpgme_error_t err = 0;
49     gpgme_data_t keydata = NULL;
50    
51     err = gpg_data_new_from_clipboard (&keydata, 0);
52     if (!err)
53     err = gpgme_op_import (ctx, keydata);
54    
55     gpgme_data_release (keydata);
56     return err;
57     }
58    
59    
60     /* Load the import statistics dialog with the results from @res. */
61     void
62     print_import_status (gpgme_import_result_t res)
63     {
64     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT_STAT, glob_hwnd,
65     import_status_dlg_proc, (LPARAM)res,
66     _("Key Import Statistics"), IDS_WINPT_IMPORT_STAT);
67     if (res->imported || res->secret_imported)
68     keycache_set_reload (1); /* XXX: update flag */
69     }
70    
71    
72     /* Dialog procedure for importing key clipboard data. */
73     BOOL CALLBACK
74     clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
75     {
76     static listview_ctrl_t lv = NULL;
77     static int is_revcert;
78     static int has_seckeys;
79 twoaday 68 int rc = 0;
80     /*int id=0;*/
81 werner 36 gpgme_error_t err;
82     gpgme_ctx_t ctx;
83     gpgme_import_result_t res;
84 twoaday 68 /*gpgme_key_t *selkeys = NULL;*/
85 werner 36
86     switch( msg ) {
87     case WM_INITDIALOG:
88     SetWindowText (dlg, _("Key Import"));
89     SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import"));
90    
91     rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST));
92     if (rc)
93     BUG (NULL);
94     SetForegroundWindow (dlg);
95     center_window (dlg, NULL);
96     rc = implist_load (lv, NULL, &is_revcert, &has_seckeys);
97     return TRUE;
98    
99     case WM_DESTROY:
100     if( lv ) {
101     implist_delete(lv);
102     lv = NULL;
103     }
104     return FALSE;
105    
106     case WM_SYSCOMMAND:
107     if( LOWORD (wparam) == SC_CLOSE )
108     EndDialog( dlg, TRUE );
109     return FALSE;
110    
111     case WM_COMMAND:
112     switch( LOWORD( wparam ) ) {
113     case IDCANCEL:
114     EndDialog (dlg, TRUE);
115     return TRUE;
116    
117     case IDC_IMPORT_DOIT:
118     if (has_seckeys > 0) {
119     msg_box (dlg, _("Some of the imported keys are secret keys.\n\n"
120     "The ownertrust values of these keys must be\n"
121     "set manually via the Key Properties dialog."),
122     _("Import"), MB_INFO);
123     }
124     SetForegroundWindow (dlg);
125     center_window (dlg, NULL);
126    
127     /* XXX: support interactive and only import some keys. */
128     /*
129     int n;
130     char keyid[32];
131     n = listview_count_items (lv, 0);
132     if( n > 1 && listview_count_items( lv, 1 ) > 0 ) {
133     selkeys = calloc (n+1, sizeof (gpgme_key_t));
134     if (!selkeys)
135     BUG (NULL);
136     for (id = 0; id < n; id++) {
137     if (listview_get_item_state (lv, id)) {
138     listview_get_item_text (lv, id, 2, keyid, DIM (keyid)-1);
139     // XXX: set the keyid??
140     // ( selkeys, keyid+2 );
141     }
142     }
143     }
144     */
145    
146     err = gpgme_new (&ctx);
147     if (err)
148     BUG (NULL);
149     err = gpgme_op_clip_import (ctx);
150     if (err) {
151     msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR);
152     gpgme_release (ctx);
153     return FALSE;
154     }
155     res = gpgme_op_import_result (ctx);
156     print_import_status (res);
157     if (res->no_user_id > 0) {
158     msg_box (dlg, _("Key without a self signature was dectected!\n"
159     "(This key is NOT usable for encryption, etc)\n"
160     "\n"
161     "Cannot import these key(s)."), _("Import"), MB_INFO);
162     }
163     gpgme_release (ctx);
164     EndDialog (dlg, TRUE);
165     return TRUE;
166     }
167     break;
168     }
169    
170     return FALSE;
171     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26