1 |
/* wptVerifyFileDlg.cpp - (File Manager) Verify file |
2 |
* Copyright (C) 2001, 2002, 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 |
#ifdef HAVE_CONFIG_H |
22 |
#include <config.h> |
23 |
#endif |
24 |
|
25 |
#include <windows.h> |
26 |
#include <windows.h> |
27 |
|
28 |
#include "../resource.h" |
29 |
#include "wptGPG.h" |
30 |
#include "wptW32API.h" |
31 |
#include "wptTypes.h" |
32 |
#include "wptNLS.h" |
33 |
#include "wptVersion.h" |
34 |
#include "wptCommonCtl.h" |
35 |
#include "wptKeylist.h" |
36 |
#include "wptTypes.h" |
37 |
#include "wptKeyserver.h" |
38 |
|
39 |
static listview_ctrl_t dlg_lv = NULL; |
40 |
static HWND dlg_wnd = NULL; /* handle to the dialog box window */ |
41 |
static HANDLE dlg_event = NULL; /* event for the dialog. */ |
42 |
|
43 |
|
44 |
/* Dialog box procedure to show the verify results of a file. */ |
45 |
static BOOL CALLBACK |
46 |
file_verify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
47 |
{ |
48 |
static listview_ctrl_t lv = NULL; |
49 |
int rc = 0; |
50 |
|
51 |
switch( msg ) { |
52 |
case WM_INITDIALOG: |
53 |
#ifndef LANG_DE |
54 |
SetWindowText (dlg, _("File Verify")); |
55 |
SetDlgItemText (dlg, IDC_VERIFY_SAVE, _("&Save")); |
56 |
#endif |
57 |
rc = verlist_build (&lv, GetDlgItem (dlg, IDC_VERIFY_SIGLIST), 1); |
58 |
if (rc) |
59 |
BUG (dlg); |
60 |
EnableWindow (GetDlgItem (dlg, IDC_VERIFY_SAVE), FALSE); |
61 |
SetForegroundWindow (dlg); |
62 |
dlg_lv = lv; |
63 |
dlg_wnd = dlg; |
64 |
return TRUE; |
65 |
|
66 |
case WM_DESTROY: |
67 |
if (lv) { |
68 |
listview_release (lv); |
69 |
lv = NULL; |
70 |
} |
71 |
dlg_lv = NULL; |
72 |
dlg_wnd = NULL; |
73 |
return FALSE; |
74 |
|
75 |
case WM_NOTIFY: |
76 |
NMHDR *notify; |
77 |
|
78 |
notify = (NMHDR *)lparam; |
79 |
if (notify && notify->code == NM_DBLCLK && |
80 |
notify->idFrom == IDC_VERIFY_SIGLIST) { |
81 |
char buf[64]; |
82 |
listview_get_item_text (lv, listview_get_curr_pos (lv), 4, buf, 63); |
83 |
if (strlen (buf) == 10 && buf[0] == '0' && buf[1] == 'x') { |
84 |
rc = msg_box (dlg, _("Do you want to retrieve the key?"), |
85 |
_("Verify"), MB_QUEST_ASK); |
86 |
if (rc == IDYES) { |
87 |
if (!hkp_recv_key (dlg, default_keyserver, |
88 |
default_keyserver_port, buf, 0, 0)) |
89 |
keycache_reload (dlg); |
90 |
} |
91 |
} |
92 |
|
93 |
} |
94 |
break; |
95 |
|
96 |
case WM_SYSCOMMAND: |
97 |
if (LOWORD (wparam) == SC_CLOSE) |
98 |
EndDialog (dlg, TRUE); |
99 |
return FALSE; |
100 |
|
101 |
case WM_COMMAND: |
102 |
switch (LOWORD (wparam)) { |
103 |
case IDOK: |
104 |
if (dlg_event) |
105 |
SetEvent (dlg_event); |
106 |
EndDialog (dlg, TRUE); |
107 |
return TRUE; |
108 |
} |
109 |
break; |
110 |
} |
111 |
|
112 |
return FALSE; |
113 |
} |
114 |
|
115 |
|
116 |
/* Thread which spawns the verify dialog. */ |
117 |
static DWORD CALLBACK |
118 |
file_verify_dlg_thread (void *opaque) |
119 |
{ |
120 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_VERIFY, GetActiveWindow(), |
121 |
file_verify_dlg_proc, NULL); |
122 |
if (dlg_event) { |
123 |
CloseHandle (dlg_event); |
124 |
dlg_event = NULL; |
125 |
} |
126 |
|
127 |
ExitThread (0); |
128 |
return 0; |
129 |
} |
130 |
|
131 |
|
132 |
/* Create the verify dialog asynchronly. */ |
133 |
int |
134 |
file_verify_create_dlg (void) |
135 |
{ |
136 |
DWORD tid; |
137 |
HANDLE thread_hd; |
138 |
SECURITY_ATTRIBUTES sec_attr; |
139 |
|
140 |
if (dlg_wnd) |
141 |
return 0; |
142 |
|
143 |
memset (&sec_attr, 0, sizeof (sec_attr)); |
144 |
sec_attr.bInheritHandle = FALSE; |
145 |
sec_attr.lpSecurityDescriptor = NULL; |
146 |
sec_attr.nLength = sizeof (sec_attr); |
147 |
thread_hd = CreateThread (&sec_attr, 0, file_verify_dlg_thread, NULL, 0, &tid); |
148 |
if (thread_hd == NULL) { |
149 |
msg_box (NULL, "Could not create verify thread.", _("Verify"), MB_ERR); |
150 |
return -1; |
151 |
} |
152 |
|
153 |
return 0; |
154 |
} |
155 |
|
156 |
|
157 |
/* Add the signature + information in @c to the verify dialog. */ |
158 |
void |
159 |
file_verify_add_state (file_sig_ctx_t c) |
160 |
{ |
161 |
if (dlg_lv) |
162 |
verlist_add_sig_log (dlg_lv, c); |
163 |
} |
164 |
|
165 |
|
166 |
/* Create an event for the verify dialog. */ |
167 |
void |
168 |
file_verify_use_event (void) |
169 |
{ |
170 |
SECURITY_ATTRIBUTES sec_attr; |
171 |
|
172 |
memset (&sec_attr, 0, sizeof (sec_attr)); |
173 |
sec_attr.bInheritHandle = FALSE; |
174 |
sec_attr.nLength = sizeof (sec_attr); |
175 |
dlg_event = CreateEvent (&sec_attr, TRUE, FALSE, NULL); |
176 |
} |
177 |
|
178 |
|
179 |
/* Wait until the verify event is signaled. */ |
180 |
void |
181 |
file_verify_wait (void) |
182 |
{ |
183 |
WaitForSingleObject (dlg_event, INFINITE); |
184 |
} |