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

Annotation of /trunk/Src/wptClipImportDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 4963 byte(s)
2005-10-23  Timo Schulz  <twoaday@g10code.com>
 
        * wptFileManager.cpp (fm_get_file_type): Detect detached sigs.
        * wptKeyList.cpp (keylist_cmp_cb): Take care of expired/revoked keys.
        (get_ext_validity): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Several cleanups.
        * wptClipEditDlg.cpp (load_clipboard): Factored out some code into
        this function.
        (load_clipboard_from_file): Likewise.
        (save_clipboard_to_file): New.
        * wptKeyManagerDlg.cpp (keyprops_dlg_proc): Fix stack overflow.

For complete details, see the ChangeLog files.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26