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

Annotation of /trunk/Src/wptClipImportDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 164 - (hide annotations)
Fri Jan 20 09:19:15 2006 UTC (19 years, 1 month ago) by twoaday
File size: 4637 byte(s)
2006-01-20  Timo Schulz  <ts@g10code.com>
 
        * wptKeyCache.cpp (w32_tmpfile): New.
        (parse_attr_data): Use it here.
        * wptGPGUtil.cpp (gpg_get_photoid_data): Reset @ndata var.
         
2006-01-19  Timo Schulz  <ts@g10code.com>
 
        * wptClipVerifyDlg.cpp (clip_verify_dlg_proc): Do not
        reload the entire cache, just update the key.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Likewise.
        * wptKeyPropsDlg.cpp (keyprops_dlg_proc): Set update flag.
        * wptKeyRevokersDlg.cpp (key_revokers_dlg_proc): Likewise.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Update key
        if need after showing the properties.
        * wptGPGMEData.cpp (gpg_data_putc): Fix off-by-one bug.
        * wptKeyManager.cpp (km_import_file): New param. Changed
        all callers.
        (km_import_clip): Likewise.
        (delete_keys_from_cache): Delete secret part if available.
        * wptClipImportDlg.cpp (print_import_status): If there
        are too many new keys, use reload code.
         


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     #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25     #include <windows.h>
26    
27 werner 47 #include "resource.h"
28 werner 36 #include "wptCrypto.h"
29     #include "wptGPG.h"
30     #include "wptCommonCtl.h"
31     #include "wptKeylist.h"
32     #include "wptNLS.h"
33     #include "wptErrors.h"
34     #include "wptTypes.h"
35     #include "wptContext.h" /* for passphrase_s */
36     #include "wptDlgs.h"
37     #include "wptW32API.h"
38     #include "wptVersion.h"
39     #include "wptImport.h"
40 twoaday 164 #include "wptKeyManager.h"
41 werner 36
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 twoaday 150 int
62 werner 36 print_import_status (gpgme_import_result_t res)
63     {
64 twoaday 150 gpgme_import_status_t st;
65     const char *keyid;
66 twoaday 164 int new_keys = res->considered - res->unchanged;
67 twoaday 150
68 werner 36 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT_STAT, glob_hwnd,
69     import_status_dlg_proc, (LPARAM)res,
70     _("Key Import Statistics"), IDS_WINPT_IMPORT_STAT);
71 twoaday 164 if (new_keys > 0 && new_keys < KM_PRELOAD_KEYS) {
72 twoaday 150 for (st=res->imports; st; st=st->next) {
73     if (st->status == 0) /* nothing changed */
74     continue;
75     keyid = st->fpr;
76     keyid += (strlen (st->fpr) == 32)? 24 : 32;
77     keycache_update (0, keyid);
78     }
79     }
80     return !(res->unchanged == res->considered);
81 werner 36 }
82    
83    
84     /* Dialog procedure for importing key clipboard data. */
85     BOOL CALLBACK
86     clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
87     {
88     static listview_ctrl_t lv = NULL;
89     static int is_revcert;
90     static int has_seckeys;
91 twoaday 150 int rc = 0, upd = 0;
92 werner 36 gpgme_error_t err;
93     gpgme_ctx_t ctx;
94     gpgme_import_result_t res;
95    
96 twoaday 150 switch (msg) {
97 werner 36 case WM_INITDIALOG:
98     SetWindowText (dlg, _("Key Import"));
99     SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import"));
100    
101     rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST));
102     if (rc)
103     BUG (NULL);
104     SetForegroundWindow (dlg);
105     center_window (dlg, NULL);
106     rc = implist_load (lv, NULL, &is_revcert, &has_seckeys);
107     return TRUE;
108    
109     case WM_DESTROY:
110     if( lv ) {
111     implist_delete(lv);
112     lv = NULL;
113     }
114     return FALSE;
115    
116     case WM_SYSCOMMAND:
117 twoaday 150 if (LOWORD (wparam) == SC_CLOSE)
118     EndDialog (dlg, FALSE);
119 werner 36 return FALSE;
120    
121     case WM_COMMAND:
122 twoaday 150 switch (LOWORD(wparam)) {
123 werner 36 case IDCANCEL:
124 twoaday 150 EndDialog (dlg, FALSE);
125 werner 36 return TRUE;
126    
127     case IDC_IMPORT_DOIT:
128     if (has_seckeys > 0) {
129     msg_box (dlg, _("Some of the imported keys are secret keys.\n\n"
130     "The ownertrust values of these keys must be\n"
131     "set manually via the Key Properties dialog."),
132     _("Import"), MB_INFO);
133     }
134     SetForegroundWindow (dlg);
135     center_window (dlg, NULL);
136    
137     err = gpgme_new (&ctx);
138     if (err)
139     BUG (NULL);
140     err = gpgme_op_clip_import (ctx);
141     if (err) {
142     msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR);
143     gpgme_release (ctx);
144     return FALSE;
145     }
146     res = gpgme_op_import_result (ctx);
147 twoaday 164 print_import_status (res);
148     upd = res->considered - res->unchanged;
149 werner 36 if (res->no_user_id > 0) {
150     msg_box (dlg, _("Key without a self signature was dectected!\n"
151     "(This key is NOT usable for encryption, etc)\n"
152     "\n"
153     "Cannot import these key(s)."), _("Import"), MB_INFO);
154     }
155     gpgme_release (ctx);
156 twoaday 150 EndDialog (dlg, upd);
157 werner 36 return TRUE;
158     }
159     break;
160     }
161    
162     return FALSE;
163     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26