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

Annotation of /trunk/Src/wptClipImportDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30 - (hide annotations)
Sat Oct 22 10:17:59 2005 UTC (19 years, 4 months ago) by twoaday
File size: 4939 byte(s)
Sync with old SVN repository.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26