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

Contents of /trunk/Src/wptKeygenCBDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 3119 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 /* wptKeygenDlg.cpp - Key callback generation dialog
2 * Copyright (C) 2001, 2002, 2003, 2005 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 #include "wptTypes.h"
25 #include "wptW32API.h"
26 #include "wptVersion.h"
27 #include "wptNLS.h"
28 #include "wptErrors.h"
29
30 /* Handle to the progress dialog. */
31 static HWND dlg_hwnd = NULL;
32
33
34 /* Dialog box param for the keygen progress. */
35 static BOOL CALLBACK
36 keygen_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
37 {
38 switch (msg) {
39 case WM_INITDIALOG:
40 SetDlgItemText( dlg, IDC_KEYPROG_CB, "" );
41 SetForegroundWindow( dlg );
42 center_window( dlg, NULL );
43 dlg_hwnd = dlg;
44 return TRUE;
45
46 case WM_DESTROY:
47 dlg_hwnd = NULL;
48 }
49
50 return FALSE;
51 }
52
53
54 /* Thread to start the progress dialog (async). */
55 static DWORD WINAPI
56 keygen_cb_thread (void *opaque)
57 {
58 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROG, GetActiveWindow (),
59 keygen_cb_dlg_proc, NULL);
60 ExitThread (0);
61 return 0;
62 }
63
64
65 /* Create the progress thread. */
66 int
67 keygen_cb_dlg_create (void)
68 {
69 DWORD tid;
70 HANDLE thread_hd;
71 SECURITY_ATTRIBUTES sec_attr;
72
73 memset (&sec_attr, 0, sizeof sec_attr);
74 sec_attr.bInheritHandle = FALSE;
75 sec_attr.lpSecurityDescriptor = NULL;
76 sec_attr.nLength = sizeof sec_attr;
77 thread_hd = CreateThread (&sec_attr, 0, keygen_cb_thread, NULL, 0, &tid);
78 if (!thread_hd) {
79 msg_box (NULL, _("Could not create key generation thread"), _("Key Generation"), MB_ERR);
80 return WPTERR_GENERAL;
81 }
82
83 return 0;
84 }
85
86 /* Destroy the progress dialog and cleanup. */
87 void
88 keygen_cb_dlg_destroy (void)
89 {
90 if (dlg_hwnd) {
91 EndDialog (dlg_hwnd, TRUE);
92 dlg_hwnd = NULL;
93 }
94 }
95
96
97 /* GPGME progress callback function. */
98 void
99 keygen_cb (void * opaque, const char * what, int type, int curretn, int total)
100 {
101 static char cb[8192] = {0};
102 static int cb_pos = 0;
103
104 if (!opaque && !what && !type && !curretn && !total) {
105 memset (cb, 0, sizeof cb);
106 cb_pos = 0;
107 return;
108 }
109
110 if (cb_pos >= (DIM (cb)-1))
111 cb_pos = 0;
112 cb[cb_pos] = (char)type;
113 cb_pos++;
114 cb[cb_pos] = '\0';
115
116 SetDlgItemText (dlg_hwnd, IDC_KEYPROG_CB, cb);
117 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26