1 |
werner |
36 |
/* wptKeysigDlg.cpp - Key signature listing |
2 |
twoaday |
139 |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
werner |
36 |
* |
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 |
werner |
42 |
#ifdef HAVE_CONFIG_H |
21 |
|
|
#include <config.h> |
22 |
|
|
#endif |
23 |
|
|
|
24 |
werner |
36 |
#include <windows.h> |
25 |
|
|
#include <commctrl.h> |
26 |
|
|
#include <time.h> |
27 |
|
|
|
28 |
werner |
47 |
#include "resource.h" |
29 |
werner |
36 |
#include "wptGPG.h" |
30 |
|
|
#include "wptCommonCtl.h" |
31 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
32 |
|
|
#include "wptDlgs.h" |
33 |
|
|
#include "wptW32API.h" |
34 |
|
|
#include "wptNLS.h" |
35 |
werner |
47 |
#include "wptKeylist.h" |
36 |
werner |
36 |
#include "wptKeyserver.h" |
37 |
|
|
#include "wptUTF8.h" |
38 |
|
|
#include "wptTypes.h" |
39 |
|
|
#include "wptVersion.h" |
40 |
|
|
#include "wptErrors.h" |
41 |
|
|
#include "wptKeyEdit.h" |
42 |
|
|
|
43 |
|
|
static subclass_s siglist_proc; |
44 |
|
|
|
45 |
|
|
|
46 |
twoaday |
225 |
/* Return -1 if the selected item is a signature. */ |
47 |
werner |
36 |
static int |
48 |
|
|
is_sig (listview_ctrl_t lv, int pos) |
49 |
|
|
{ |
50 |
twoaday |
128 |
char tmpbuf[200]; |
51 |
werner |
36 |
|
52 |
|
|
if (pos == -1) |
53 |
|
|
pos = listview_get_curr_pos (lv); |
54 |
|
|
if (pos == -1) |
55 |
|
|
return 0; |
56 |
twoaday |
139 |
listview_get_item_text (lv, pos, SL_COL_UID, tmpbuf, sizeof (tmpbuf)-1); |
57 |
werner |
36 |
if (*tmpbuf == ' ') |
58 |
|
|
return -1; |
59 |
|
|
return 0; |
60 |
twoaday |
32 |
} |
61 |
werner |
36 |
|
62 |
|
|
|
63 |
|
|
/* Delete the selected signature from list view @lv. The |
64 |
|
|
key is given in @key. */ |
65 |
|
|
static int |
66 |
|
|
do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key) |
67 |
|
|
{ |
68 |
twoaday |
150 |
gpgme_error_t err; |
69 |
|
|
GpgKeyEdit *ke; |
70 |
|
|
char keyid[32]; |
71 |
|
|
int pos, npos, id, is_selfsig=0; |
72 |
werner |
36 |
int signo=0, uidno=0; |
73 |
|
|
|
74 |
|
|
npos = pos = listview_get_curr_pos (lv); |
75 |
|
|
if (!is_sig (lv, -1)) |
76 |
|
|
return -1; |
77 |
twoaday |
150 |
listview_get_item_text (lv, pos, SL_COL_KEYID, keyid, sizeof (keyid)-1); |
78 |
|
|
if (!strncmp (key->keyid, keyid+2, 8)) |
79 |
|
|
is_selfsig = 1; |
80 |
|
|
|
81 |
werner |
36 |
while (pos > 0 && is_sig (lv, pos)) { |
82 |
|
|
signo++; |
83 |
|
|
pos--; |
84 |
|
|
} |
85 |
|
|
pos = npos; |
86 |
|
|
while (npos > 0) { |
87 |
|
|
if (!is_sig (lv, npos)) |
88 |
|
|
uidno++; |
89 |
|
|
npos--; |
90 |
|
|
} |
91 |
|
|
uidno++; |
92 |
|
|
|
93 |
|
|
/* XXX: do not allow to delete the self signature */ |
94 |
twoaday |
150 |
id = log_box (_("Key Manager"), is_selfsig? MB_WARN_ASK : MB_QUEST_ASK, |
95 |
|
|
_("Are you really sure you want to delete this %s from\n\n" |
96 |
|
|
" \"%s\""), is_selfsig? _("self signature") : _("signature"), |
97 |
|
|
key->uid); |
98 |
werner |
36 |
if (id == IDNO) |
99 |
|
|
return 0; |
100 |
|
|
|
101 |
|
|
ke = new GpgKeyEdit (key->keyid); |
102 |
|
|
if (!ke) |
103 |
|
|
BUG (NULL); |
104 |
|
|
err = ke->delUseridSignature (uidno, signo); |
105 |
|
|
if (err) |
106 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
107 |
|
|
else |
108 |
|
|
listview_del_item (lv, pos); |
109 |
|
|
delete ke; |
110 |
twoaday |
150 |
if (!err) |
111 |
|
|
key->update = 1; |
112 |
werner |
36 |
return err? -1 : 0; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
|
116 |
twoaday |
255 |
/* Initialize a datepicker control with the time given in @t. */ |
117 |
|
|
static void |
118 |
|
|
init_datepicker_from_time (HWND picker, time_t t) |
119 |
|
|
{ |
120 |
|
|
SYSTEMTIME st; |
121 |
|
|
struct tm *tm; |
122 |
|
|
|
123 |
|
|
tm = localtime (&t); |
124 |
|
|
memset (&st, 0, sizeof st); |
125 |
|
|
st.wYear = tm->tm_year+1900; |
126 |
|
|
st.wMonth = tm->tm_mon+1; |
127 |
|
|
st.wDay = tm->tm_mday; |
128 |
|
|
DateTime_SetSystemtime (picker, GDT_VALID, &st); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
|
132 |
werner |
36 |
/* Dialog box procedure to display the signature properties. */ |
133 |
twoaday |
176 |
BOOL CALLBACK |
134 |
werner |
36 |
sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
135 |
|
|
{ |
136 |
twoaday |
207 |
gpgme_key_sig_t ks; |
137 |
twoaday |
208 |
winpt_key_s issuer; |
138 |
werner |
36 |
char tmpbuf[256]; |
139 |
twoaday |
208 |
static struct { |
140 |
werner |
36 |
unsigned int exportable:1; |
141 |
|
|
unsigned int expired:1; |
142 |
|
|
unsigned int nrev:1; |
143 |
|
|
unsigned int rev:1; |
144 |
twoaday |
176 |
const char *alg; |
145 |
werner |
36 |
int _class; |
146 |
|
|
} ctx; |
147 |
|
|
const char *fmt_templ = _("%s %s signature"); |
148 |
twoaday |
208 |
const char *s; |
149 |
werner |
36 |
|
150 |
|
|
switch (msg) { |
151 |
|
|
case WM_INITDIALOG: |
152 |
twoaday |
225 |
ks = (gpgme_key_sig_t)lparam; |
153 |
|
|
if (!ks) |
154 |
|
|
BUG (0); |
155 |
twoaday |
88 |
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
156 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
157 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
158 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
159 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_CLASSINF, _("Class")); |
160 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_EXPSTR, _("Expire date")); |
161 |
twoaday |
255 |
SetDlgItemText (dlg, IDC_SIGPROPS_CREATSTR, _("Creation date")); |
162 |
twoaday |
88 |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYINF, _("Issuer key")); |
163 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_KEYIDINF, _("Issuer key ID")); |
164 |
twoaday |
207 |
SetDlgItemText (dlg, IDC_SIGPROPS_POLICINF, _("Policy URL")); |
165 |
twoaday |
225 |
SetWindowText (dlg, _("Signature Properties")); |
166 |
|
|
|
167 |
werner |
36 |
memset (&ctx, 0, sizeof ctx); |
168 |
twoaday |
176 |
ctx._class = ks->sig_class; |
169 |
werner |
36 |
if (ctx._class == 0) |
170 |
twoaday |
176 |
ctx._class = 16; |
171 |
|
|
ctx._class -= 6; |
172 |
|
|
if (ks->pubkey_algo == GPGME_PK_DSA) |
173 |
werner |
36 |
ctx.alg = "DSA"; |
174 |
twoaday |
176 |
else if (ks->pubkey_algo == GPGME_PK_RSA) |
175 |
werner |
36 |
ctx.alg = "RSA"; |
176 |
|
|
else |
177 |
|
|
ctx.alg = "ELG"; |
178 |
twoaday |
176 |
ctx.exportable = ks->exportable; |
179 |
werner |
36 |
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ, |
180 |
twoaday |
225 |
ctx.exportable? _("Exportable") : _("Non-exportable"), |
181 |
|
|
ctx.alg); |
182 |
werner |
36 |
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf); |
183 |
twoaday |
176 |
|
184 |
twoaday |
208 |
_snprintf (tmpbuf, DIM (tmpbuf)-1, "0x%s", ks->keyid+8); |
185 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf); |
186 |
werner |
36 |
SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE); |
187 |
|
|
if (ctx.exportable) |
188 |
|
|
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED); |
189 |
twoaday |
208 |
memset (&issuer, 0, sizeof (issuer)); |
190 |
|
|
if (!winpt_get_pubkey (ks->keyid+8, &issuer)) |
191 |
|
|
s = issuer.ext->uids->uid; |
192 |
twoaday |
176 |
else |
193 |
twoaday |
208 |
s = _(" user ID not found"); |
194 |
twoaday |
205 |
SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, s); |
195 |
twoaday |
255 |
|
196 |
|
|
init_datepicker_from_time (GetDlgItem (dlg, IDC_SIGPROPS_CREATDATE), |
197 |
|
|
ks->timestamp); |
198 |
twoaday |
176 |
if (ks->expires == 0) { |
199 |
werner |
36 |
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE); |
200 |
|
|
ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE); |
201 |
|
|
} |
202 |
|
|
else { |
203 |
twoaday |
255 |
init_datepicker_from_time (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), |
204 |
|
|
ks->expires); |
205 |
|
|
if (time (NULL) > ks->expires) |
206 |
werner |
36 |
ctx.expired = 1; |
207 |
|
|
if (ctx.expired) |
208 |
|
|
CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED); |
209 |
|
|
} |
210 |
twoaday |
208 |
/* XXX (gpgme): \r at the end of the notation value. */ |
211 |
twoaday |
207 |
if (ks->notations && !ks->notations->name && ks->notations->value) |
212 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_POLIC, ks->notations->value); |
213 |
|
|
|
214 |
werner |
36 |
SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable")); |
215 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
216 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
217 |
|
|
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
218 |
|
|
SetWindowText (dlg, _("Signature Properties")); |
219 |
|
|
SetForegroundWindow (dlg); |
220 |
|
|
center_window (dlg, NULL); |
221 |
|
|
return TRUE; |
222 |
|
|
|
223 |
|
|
case WM_COMMAND: |
224 |
twoaday |
208 |
if (HIWORD (wparam) == BN_CLICKED) { |
225 |
twoaday |
225 |
/* Code to prevent the user changes the check buttons. */ |
226 |
twoaday |
208 |
switch (LOWORD (wparam)) { |
227 |
|
|
case IDC_SIGPROPS_EXP: |
228 |
|
|
CheckDlgButton (dlg, IDC_SIGPROPS_EXP, |
229 |
|
|
ctx.exportable? BST_CHECKED : BST_UNCHECKED); |
230 |
|
|
return TRUE; |
231 |
|
|
|
232 |
|
|
case IDC_SIGPROPS_EXPIRED: |
233 |
|
|
CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, |
234 |
|
|
ctx.expired? BST_CHECKED : BST_UNCHECKED); |
235 |
|
|
return TRUE; |
236 |
|
|
|
237 |
|
|
case IDC_SIGPROPS_REV: |
238 |
|
|
CheckDlgButton (dlg, IDC_SIGPROPS_REV, |
239 |
|
|
ctx.rev? BST_CHECKED : BST_UNCHECKED); |
240 |
|
|
return TRUE; |
241 |
|
|
|
242 |
|
|
case IDC_SIGPROPS_NREV: |
243 |
|
|
CheckDlgButton (dlg, IDC_SIGPROPS_NREV, |
244 |
|
|
ctx.nrev? BST_CHECKED : BST_UNCHECKED); |
245 |
|
|
return TRUE; |
246 |
|
|
} |
247 |
|
|
} |
248 |
|
|
|
249 |
werner |
36 |
switch (LOWORD (wparam)) { |
250 |
|
|
case IDOK: |
251 |
|
|
EndDialog (dlg, TRUE); |
252 |
|
|
break; |
253 |
twoaday |
176 |
|
254 |
|
|
case IDCANCEL: |
255 |
|
|
EndDialog (dlg, FALSE); |
256 |
|
|
break; |
257 |
werner |
36 |
} |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
return FALSE; |
261 |
|
|
} |
262 |
|
|
|
263 |
|
|
|
264 |
twoaday |
225 |
/* Subclass window procedure for the list view. */ |
265 |
werner |
36 |
static BOOL CALLBACK |
266 |
|
|
subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
267 |
|
|
{ |
268 |
|
|
listview_ctrl_t lv; |
269 |
|
|
winpt_key_t key; |
270 |
twoaday |
176 |
gpgme_key_sig_t ks; |
271 |
werner |
36 |
|
272 |
|
|
switch (msg) { |
273 |
|
|
case WM_KEYUP: |
274 |
|
|
int virt_key = (int)wparam; |
275 |
|
|
key = (winpt_key_t)siglist_proc.opaque; |
276 |
|
|
lv = key->callback.ctl; |
277 |
|
|
if (virt_key == VK_SPACE) { |
278 |
twoaday |
176 |
if (is_sig (lv, -1)) { |
279 |
|
|
ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv)); |
280 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
281 |
twoaday |
176 |
sigprops_dlg_proc, (LPARAM)ks); |
282 |
|
|
} |
283 |
werner |
36 |
} |
284 |
|
|
else if (virt_key == VK_DELETE) |
285 |
|
|
do_delsig (dlg, lv, key); |
286 |
|
|
break; |
287 |
|
|
} |
288 |
|
|
return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam); |
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
|
292 |
|
|
/* Return 1 if the list view @lv contains non-available keys. */ |
293 |
|
|
static int |
294 |
|
|
check_for_missing_keys (listview_ctrl_t lv) |
295 |
|
|
{ |
296 |
|
|
int i, n; |
297 |
|
|
char id[128]; |
298 |
|
|
|
299 |
twoaday |
225 |
n = listview_count_items (lv, 0); |
300 |
|
|
for (i = 0; i < n; i++) { |
301 |
twoaday |
139 |
listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1); |
302 |
|
|
if (!strncmp (id, "NOKEY", 5)) |
303 |
werner |
36 |
return 1; |
304 |
|
|
} |
305 |
|
|
|
306 |
|
|
return 0; |
307 |
|
|
} |
308 |
|
|
|
309 |
|
|
|
310 |
|
|
/* Receive all missing keys marked in the list @lv. */ |
311 |
twoaday |
150 |
static int |
312 |
werner |
36 |
recv_missing_keys (HWND dlg, listview_ctrl_t lv) |
313 |
|
|
{ |
314 |
twoaday |
150 |
char id[128], keyid[18+1]; |
315 |
twoaday |
139 |
int i, n, cnt=0; |
316 |
|
|
|
317 |
|
|
i = msg_box (dlg, _("Really receive all missing keys?"), |
318 |
|
|
_("Key Manager"), MB_YESNO|MB_INFO); |
319 |
|
|
if (i == IDNO) |
320 |
twoaday |
150 |
return 0; |
321 |
werner |
36 |
|
322 |
|
|
n = listview_count_items (lv, 0); |
323 |
twoaday |
139 |
for (i = 0; i < n; i++) { |
324 |
|
|
listview_get_item_text (lv, i, SL_COL_VALID, id, sizeof (id) - 1); |
325 |
|
|
if (!strncmp (id, "NOKEY", 5)) { |
326 |
twoaday |
225 |
listview_get_item_text (lv, i, SL_COL_KEYID, |
327 |
twoaday |
139 |
keyid, sizeof (keyid) -1); |
328 |
|
|
if (!hkp_recv_key (dlg, default_keyserver, |
329 |
twoaday |
150 |
default_keyserver_port, keyid, 0, 0)) { |
330 |
|
|
keycache_update (0, keyid); |
331 |
twoaday |
139 |
cnt++; |
332 |
twoaday |
150 |
} |
333 |
twoaday |
139 |
else |
334 |
werner |
36 |
break; |
335 |
|
|
} |
336 |
|
|
} |
337 |
twoaday |
150 |
return cnt; |
338 |
werner |
36 |
} |
339 |
|
|
|
340 |
|
|
|
341 |
|
|
/* Create a mini popup with available choices. */ |
342 |
|
|
static void |
343 |
|
|
do_create_popup (HWND dlg) |
344 |
|
|
{ |
345 |
|
|
HMENU hm, sm; |
346 |
|
|
POINT p; |
347 |
|
|
|
348 |
|
|
GetCursorPos (&p); |
349 |
|
|
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX)); |
350 |
|
|
sm = GetSubMenu (hm, 0); |
351 |
|
|
set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties")); |
352 |
|
|
set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties")); |
353 |
|
|
TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
354 |
|
|
DestroyMenu (hm); |
355 |
|
|
DestroyMenu (sm); |
356 |
|
|
} |
357 |
|
|
|
358 |
|
|
|
359 |
twoaday |
139 |
/* Fetch a single key and extract the keyid from the listview |
360 |
|
|
entry at the pos @idx. */ |
361 |
|
|
static int |
362 |
|
|
recv_single_key (HWND dlg, listview_ctrl_t lv, int idx) |
363 |
|
|
{ |
364 |
|
|
char keyid[32]; |
365 |
|
|
int rc; |
366 |
|
|
|
367 |
|
|
listview_get_item_text (lv, idx, SL_COL_KEYID, keyid, DIM (keyid)-1); |
368 |
|
|
rc = hkp_recv_key (dlg, default_keyserver, |
369 |
|
|
default_keyserver_port, keyid, 0, 0); |
370 |
|
|
if (!rc) |
371 |
|
|
keycache_update (0, keyid); |
372 |
|
|
return rc; |
373 |
|
|
} |
374 |
|
|
|
375 |
|
|
|
376 |
werner |
36 |
/* Load the key property dialog with the selected key from @lv. */ |
377 |
|
|
static void |
378 |
|
|
do_load_keyprops (HWND dlg, listview_ctrl_t lv) |
379 |
|
|
{ |
380 |
|
|
winpt_key_s k; |
381 |
|
|
char keyid[32] = {0}; |
382 |
|
|
char status[64] = {0}, creation[64] = {0}; |
383 |
|
|
int n = listview_get_curr_pos (lv); |
384 |
|
|
|
385 |
twoaday |
139 |
listview_get_item_text (lv, n, SL_COL_VALID, status, DIM (status)-1); |
386 |
|
|
listview_get_item_text (lv, n, SL_COL_CREATE, creation, DIM (creation)-1); |
387 |
|
|
listview_get_item_text (lv, n, SL_COL_KEYID, keyid, DIM (keyid)-1); |
388 |
werner |
36 |
if (!strcmp (status, "NOKEY")) { |
389 |
twoaday |
139 |
int id = msg_box (dlg, _("Key not found in keyring, do you want to fetch it from the keyserver?"), |
390 |
twoaday |
150 |
_("Key Manager"), MB_QUEST_ASK); |
391 |
twoaday |
139 |
if (id == IDNO) |
392 |
|
|
return; |
393 |
|
|
if (recv_single_key (dlg, lv, n)) |
394 |
|
|
return; |
395 |
werner |
36 |
} |
396 |
|
|
|
397 |
twoaday |
212 |
memset (&k, 0, sizeof k); |
398 |
|
|
if ((strlen (keyid) < 3 || winpt_get_pubkey (keyid, &k))) { |
399 |
werner |
36 |
if (strlen (creation) > 0) |
400 |
|
|
msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO); |
401 |
|
|
return; |
402 |
|
|
} |
403 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg, |
404 |
|
|
keyprops_dlg_proc, (LPARAM)&k); |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
|
408 |
|
|
/* Dialog box procedure to list signatures. */ |
409 |
|
|
BOOL CALLBACK |
410 |
|
|
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
411 |
|
|
{ |
412 |
|
|
static listview_ctrl_t lv = NULL; |
413 |
|
|
static struct winpt_key_s *k; |
414 |
twoaday |
176 |
gpgme_key_sig_t ks; |
415 |
|
|
HWND sl; |
416 |
twoaday |
204 |
char inf[384]; |
417 |
twoaday |
176 |
int idx = 0; |
418 |
werner |
36 |
|
419 |
twoaday |
139 |
switch (msg) { |
420 |
werner |
36 |
case WM_INITDIALOG: |
421 |
|
|
k = (winpt_key_t) lparam; |
422 |
|
|
if (!k) |
423 |
|
|
BUG (0); |
424 |
twoaday |
208 |
if (k->uid) |
425 |
|
|
_snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid); |
426 |
twoaday |
205 |
SetWindowText (dlg, inf); |
427 |
werner |
36 |
SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key")); |
428 |
|
|
SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties")); |
429 |
twoaday |
128 |
|
430 |
werner |
36 |
lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid); |
431 |
|
|
if (!check_for_missing_keys (lv)) |
432 |
twoaday |
41 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), FALSE); |
433 |
twoaday |
129 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), FALSE); |
434 |
werner |
36 |
k->callback.ctl = lv; |
435 |
|
|
sl = GetDlgItem (dlg, IDC_KEYSIG_LIST); |
436 |
|
|
siglist_proc.dlg = dlg; |
437 |
|
|
siglist_proc.opaque = k; |
438 |
|
|
siglist_proc.current = (WNDPROC)subclass_dlg_proc; |
439 |
|
|
siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC); |
440 |
|
|
if (siglist_proc.old) { |
441 |
|
|
if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) { |
442 |
twoaday |
141 |
msg_box (dlg, "Could not set keylist window procedure.", |
443 |
werner |
36 |
_("Key Manager"), MB_ERR); |
444 |
|
|
BUG (0); |
445 |
|
|
} |
446 |
|
|
} |
447 |
|
|
SetForegroundWindow (dlg); |
448 |
|
|
center_window (dlg, NULL); |
449 |
|
|
return TRUE; |
450 |
|
|
|
451 |
|
|
case WM_DESTROY: |
452 |
twoaday |
139 |
if (lv) { |
453 |
|
|
siglist_delete (lv); |
454 |
werner |
36 |
lv = NULL; |
455 |
|
|
} |
456 |
|
|
return FALSE; |
457 |
|
|
|
458 |
|
|
case WM_NOTIFY: |
459 |
twoaday |
41 |
NMHDR *notify; |
460 |
werner |
36 |
|
461 |
|
|
notify = (NMHDR *)lparam; |
462 |
twoaday |
139 |
if (!notify) |
463 |
|
|
return FALSE; |
464 |
twoaday |
225 |
if (notify->code == NM_DBLCLK && |
465 |
|
|
notify->idFrom == IDC_KEYSIG_LIST) |
466 |
werner |
36 |
do_load_keyprops (dlg, lv); |
467 |
twoaday |
139 |
if (notify->code == NM_RCLICK && |
468 |
twoaday |
128 |
notify->idFrom == IDC_KEYSIG_LIST && |
469 |
|
|
is_sig (lv, -1)) |
470 |
werner |
36 |
do_create_popup (dlg); |
471 |
twoaday |
139 |
if (notify->code == LVN_ITEMCHANGED && |
472 |
twoaday |
41 |
((LPNMLISTVIEW)lparam)->uNewState) { |
473 |
|
|
idx = listview_get_curr_pos (lv); |
474 |
twoaday |
139 |
listview_get_item_text (lv, idx, SL_COL_VALID, inf, DIM (inf)-1); |
475 |
twoaday |
41 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_RECVKEY), |
476 |
|
|
strcmp (inf, "NOKEY") == 0? TRUE: FALSE); |
477 |
twoaday |
128 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIG_SIGPROPS), |
478 |
|
|
is_sig (lv, -1)? TRUE : FALSE); |
479 |
twoaday |
41 |
} |
480 |
twoaday |
139 |
if (notify->code == LVN_COLUMNCLICK) { |
481 |
|
|
NMLISTVIEW *nft = (LPNMLISTVIEW) lparam; |
482 |
|
|
int sortby = 0; |
483 |
|
|
switch (nft->iSubItem) { |
484 |
|
|
//case 0: sortby = KEY_SORT_USERID; break; |
485 |
|
|
case 1: sortby = KEY_SORT_VALIDITY; break; |
486 |
|
|
case 2: sortby = SIG_SORT_CLASS; break; |
487 |
|
|
case 3: sortby = KEY_SORT_CREATED; break; |
488 |
|
|
case 4: sortby = KEY_SORT_KEYID; break; |
489 |
|
|
case 5: sortby = SIG_SORT_EXPIRE; break; |
490 |
|
|
case 6: sortby = KEY_SORT_ALGO; break; |
491 |
|
|
default: return TRUE; |
492 |
|
|
} |
493 |
|
|
siglist_sort (lv, sortby); |
494 |
|
|
} |
495 |
werner |
36 |
break; |
496 |
|
|
|
497 |
|
|
case WM_COMMAND: |
498 |
twoaday |
139 |
switch (LOWORD (wparam)) { |
499 |
werner |
36 |
case ID_SIGCTX_KEYPROPS: |
500 |
|
|
do_load_keyprops (dlg, lv); |
501 |
|
|
break; |
502 |
|
|
|
503 |
|
|
case ID_SIGCTX_PROPS: |
504 |
twoaday |
176 |
if (is_sig (lv, -1)) { |
505 |
|
|
ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv)); |
506 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
507 |
twoaday |
176 |
sigprops_dlg_proc, (LPARAM)ks); |
508 |
|
|
} |
509 |
werner |
36 |
break; |
510 |
|
|
|
511 |
|
|
case IDC_KEYSIG_RECVKEY: |
512 |
|
|
idx = listview_get_curr_pos (lv); |
513 |
twoaday |
139 |
if (idx == -1) |
514 |
|
|
recv_missing_keys (dlg, lv); |
515 |
|
|
else |
516 |
|
|
recv_single_key (dlg, lv, idx); |
517 |
werner |
36 |
return TRUE; |
518 |
|
|
|
519 |
|
|
case IDC_KEYSIG_SIGPROPS: |
520 |
twoaday |
176 |
if (is_sig (lv, -1)) { |
521 |
|
|
ks = ks = (gpgme_key_sig_t)listview_get_item2 (lv, listview_get_curr_pos (lv)); |
522 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
523 |
twoaday |
176 |
sigprops_dlg_proc, (LPARAM)ks); |
524 |
|
|
} |
525 |
werner |
36 |
return TRUE; |
526 |
|
|
|
527 |
twoaday |
212 |
case IDCANCEL: |
528 |
|
|
EndDialog (dlg, FALSE); |
529 |
|
|
return TRUE; |
530 |
|
|
|
531 |
werner |
36 |
case IDOK: |
532 |
|
|
EndDialog (dlg, TRUE); |
533 |
|
|
return TRUE; |
534 |
|
|
} |
535 |
|
|
break; |
536 |
|
|
} |
537 |
|
|
return FALSE; |
538 |
|
|
} |