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

Annotation of /trunk/Src/wptClipImportDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (hide annotations)
Mon Apr 4 06:59:24 2005 UTC (19 years, 10 months ago) by twoaday
File size: 7262 byte(s)
2005-03-04  Timo Schulz  <twoaday@g10code.com>
 
        * GPG asks twice for the new PIN. Thanks to Achim.
        * wptCardDlg.cpp (card_changepin_dlg_proc): Reset the 'safety' pin also.        Only check the passphrase if the backup flag is enabled. Again thanks to        Achim.
 
2005-03-06  Timo Schulz  <twoaday@freakmail.de>
 
        * wptKeySignDlg.cpp (do_fill_seckeylist): Skip secret keys without
        a public key. Noted by Kurt Fitzner.
 
2005-03-22  Timo Schulz  <twoaday@freakmail.de>
 
        * WinPT.cpp (WinMain): --debug as an alias for --enable-debug.
        (enable_mobile_mode): New.
        * wptKeyEditDlg.cpp (keyedit_addsubkey_dlg_proc): Use new
        ID's for adding subkeys.
 


1 twoaday 2 /* wptClipImportDlg.cpp - WinPT key import dialog
2     * Copyright (C) 2001-2004 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #include <windows.h>
22    
23     #include "../resource.h"
24    
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    
36    
37     static HANDLE thread_hd = NULL;
38     static int dlg_init = 0;
39    
40     struct data_callback_s {
41     listview_ctrl_t lv;
42     int is_revcert;
43     int has_seckeys;
44     const char * filename;
45     HWND root_dlg, dlg;
46     };
47     typedef struct data_callback_s *data_callback_t;
48    
49    
50     BOOL CALLBACK
51     data_cb_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
52     {
53     static data_callback_t ctx;
54     int rc;
55    
56     switch( msg ) {
57     case WM_INITDIALOG:
58     ctx = (data_callback_t)lparam;
59     if (!ctx)
60     BUG (NULL);
61     SetForegroundWindow( dlg );
62     center_window( dlg );
63     dlg_init = 1;
64     ctx->dlg = dlg;
65     ShowWindow (ctx->root_dlg, SW_HIDE);
66     SetTimer (dlg, 0x123, 100, NULL);
67     break;
68    
69     case WM_TIMER:
70     /* if the procedure is done, we make the callback window invisible
71     and the root dialog is forced to the forceground again. */
72     rc = implist_load (ctx->lv, ctx->filename, &ctx->is_revcert, &ctx->has_seckeys);
73     if (rc) {
74     KillTimer (dlg, 0x123);
75     PostQuitMessage (0);
76     EndDialog (dlg, FALSE);
77     }
78     SetForegroundWindow( ctx->root_dlg );
79     ShowWindow( ctx->root_dlg, SW_SHOW );
80     ShowWindow( dlg, SW_HIDE );
81     KillTimer( dlg, 0x123 );
82     break;
83     }
84     return FALSE;
85     } /* data_cb_dlg_proc */
86    
87    
88     DWORD WINAPI
89     data_cb_thread (void * opaque)
90     {
91     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_DATACB, glob_hwnd,
92     data_cb_dlg_proc, (LPARAM)opaque);
93     ExitThread (0);
94     return 0;
95     } /* data_cb_thread */
96    
97    
98     int
99     data_cb_dlg_create (data_callback_t ctx)
100     {
101     DWORD tid;
102     SECURITY_ATTRIBUTES sec_attr;
103    
104     if (dlg_init)
105     return 0;
106    
107     memset (&sec_attr, 0, sizeof (sec_attr));
108     sec_attr.bInheritHandle = FALSE;
109     sec_attr.nLength = sizeof (sec_attr);
110     thread_hd = CreateThread( &sec_attr, 0, data_cb_thread, (void *)ctx, 0, &tid );
111     if( thread_hd == NULL ) {
112     msg_box( NULL, "Could not create data callback thread", _("WinPT"), MB_ERR );
113     return WPTERR_GENERAL;
114     }
115     return 0;
116     } /* data_cb_dlg_create */
117    
118    
119     void
120     data_cb_dlg_destroy( void )
121     {
122     if( dlg_init ) {
123     TerminateThread( thread_hd, 0 );
124     CloseHandle( thread_hd );
125     thread_hd = NULL;
126     dlg_init = 0;
127     }
128     } /* data_cb_dlg_destroy */
129    
130    
131     void
132     print_import_status( int *import_res, int is_revcert )
133     {
134     struct import_status_s res;
135     int i, rc = 0;
136    
137     memset (&res, 0, sizeof (res));
138     for (i = 0; i < 14; i++)
139     res.import_res[i] = import_res[i];
140     res.rev_cert = is_revcert? 1 : 0;
141     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT_STAT, glob_hwnd,
142     import_status_dlg_proc, (LPARAM)&res,
143     _("Key Import Statistics"), IDS_WINPT_IMPORT_STAT);
144     if (import_res[GPGME_IMPSTAT_IPKEYS] || import_res[GPGME_IMPSTAT_ISKEYS])
145     keycache_set_reload (1);
146     } /* print_import_status */
147    
148    
149     data_callback_t
150     data_cb_new( const char *filename, listview_ctrl_t lv, HWND dlg )
151     {
152     data_callback_t ctx;
153    
154     ctx = new struct data_callback_s;
155     if( !ctx )
156     BUG( NULL );
157     ctx->filename = filename;
158     ctx->is_revcert = 0;
159     ctx->lv = lv;
160     ctx->root_dlg = dlg;
161     return ctx;
162     } /* data_cb_new */
163    
164    
165    
166     BOOL CALLBACK
167     clip_import_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )
168     {
169     static listview_ctrl_t lv = NULL;
170     static data_callback_t ctx;
171     int rc = 0, id = 0, ctrl = 0, import_res[14];
172     int n;
173     char keyid[32];
174     gpgme_error_t err;
175     gpgme_recipients_t selkeys = NULL;
176    
177     switch( msg ) {
178     case WM_INITDIALOG:
179     #ifndef LANG_DE
180     SetWindowText( dlg, _("Key Import") );
181     SetDlgItemText( dlg, IDC_IMPORT_DOIT, _("&Import") );
182     #endif
183     rc = implist_build( &lv, GetDlgItem( dlg, IDC_IMPORT_KEYLIST ) );
184     if( rc )
185     BUG( NULL );
186     SetForegroundWindow( dlg );
187     center_window( dlg );
188     //ctx = data_cb_new( NULL, lv, dlg );
189     //data_cb_dlg_create( ctx );
190     ctx = new data_callback_s;
191     memset (ctx, 0, sizeof (data_callback_s));
192     rc = implist_load (lv, NULL, &ctx->is_revcert, &ctx->has_seckeys);
193     ctrl = 0;
194     return TRUE;
195    
196     case WM_DESTROY:
197     if( lv ) {
198     implist_delete( lv );
199     lv = NULL;
200     }
201     free_if_alloc (ctx);
202     return FALSE;
203    
204     case WM_SYSCOMMAND:
205     if( LOWORD (wparam) == SC_CLOSE )
206     EndDialog( dlg, TRUE );
207     return FALSE;
208    
209     case WM_COMMAND:
210     switch( LOWORD( wparam ) ) {
211     case IDCANCEL:
212     data_cb_dlg_destroy();
213     EndDialog( dlg, TRUE );
214     return TRUE;
215    
216     case IDC_IMPORT_DOIT:
217     ShowWindow( ctx->dlg, SW_SHOW );
218     if (ctx->has_seckeys) {
219     msg_box (dlg, _("Some of the imported keys are secret keys.\n\n"
220     "The ownertrust values of these keys must be\n"
221     "set manually via the Key Properties dialog."),
222     _("Import"), MB_INFO);
223     }
224     SetForegroundWindow( ctx->dlg );
225     center_window( ctx->dlg );
226     n = listview_count_items( lv, 0 );
227     if( n > 1 && listview_count_items( lv, 1 ) > 0 ) {
228     gpgme_recipients_new( &selkeys );
229     for( id = 0; id < n; id++ ) {
230     if( listview_get_item_state( lv, id ) ) {
231     listview_get_item_text( lv, id, 2, keyid, sizeof (keyid)-1 );
232     gpgme_recipients_add_name( selkeys, keyid+2 );
233     }
234     }
235     }
236    
237     err = gpgme_op_clip_import( ctrl, selkeys, import_res );
238     if( err ) {
239     ctrl = 0;
240 twoaday 6 if( err == GPGME_Internal_GPG_Problem )
241 twoaday 2 gnupg_display_error ();
242     else
243     msg_box( dlg, gpgme_strerror( err ), _("Import"), MB_ERR );
244     return FALSE;
245     }
246     print_import_status( import_res, ctx->is_revcert );
247     if( import_res[GPGME_IMPSTAT_NOSELFSIG] > 0 ) {
248     msg_box( dlg, _("Key without a self signature was dectected!\n"
249     "(This key is NOT usable for encryption, etc)\n"
250     "\n"
251     "Cannot import these key(s)."), _("Import"), MB_INFO );
252     }
253     EndDialog( dlg, TRUE );
254     return TRUE;
255     }
256     break;
257     }
258    
259     return FALSE;
260     } /* clip_import_dlg_proc */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26