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

Contents of /trunk/Src/wptKeyManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 161 - (show annotations)
Thu Jan 19 16:10:37 2006 UTC (19 years, 1 month ago) by twoaday
File size: 61878 byte(s)
2006-01-19  Timo Schulz  <ts@g10code.com>
 
        * wptClipVerifyDlg.cpp (clip_verify_dlg_proc): Do not
        reload the entire cache, just update the key.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Likewise.
        * wptKeyPropsDlg.cpp (keyprops_dlg_proc): Set update flag.
        * wptKeyRevokersDlg.cpp (key_revokers_dlg_proc): Likewise.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Update key
        if need after showing the properties.
         

1 /* wptKeyManagerDlg.cpp - WinPT Key Manager
2 * Copyright (C) 2000-2006 Timo Schulz
3 * Copyright (C) 2004 Andreas Jobs
4 *
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 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26 #include <commctrl.h>
27
28 #include "resource.h"
29 #include "wptTypes.h"
30 #include "wptGPG.h"
31 #include "wptCommonCtl.h"
32 #include "wptContext.h" /* for passphrase_s */
33 #include "wptDlgs.h"
34 #include "wptW32API.h"
35 #include "wptVersion.h"
36 #include "wptKeylist.h"
37 #include "wptNLS.h"
38 #include "wptErrors.h"
39 #include "wptHotkey.h"
40 #include "wptKeyManager.h"
41 #include "wptKeyserver.h"
42 #include "wptKeyEdit.h"
43 #include "wptRegistry.h"
44 #include "wptUTF8.h"
45
46 /* Name and ID of the separator window. */
47 #define KM_SEPARATOR_ID 10000
48 #define WINDOWCLASS_SEPARATOR_CHILD "WINPT_SEP_CHILD"
49
50 /* Virtual key codes. */
51 #ifndef VK_F
52 #define VK_F 70
53 #endif
54 #ifndef VK_A
55 #define VK_A 65
56 #endif
57 #ifndef VK_C
58 #define VK_C 67
59 #endif
60 #ifndef VK_P
61 #define VK_P 80
62 #endif
63
64 static subclass_s keylist_proc;
65
66 HIMAGELIST glob_imagelist;
67
68 struct km_info_s {
69 /* Window positions */
70 int pos_x, pos_y;
71 int ypos_sep;
72 int ypercent_sep;
73
74 HWND hwnd_sep;
75 HWND toolbar;
76 HWND statbar;
77
78 listview_ctrl_t lv;
79 int lv_idx;
80 int keylist_sortby;
81 };
82
83 /* Toolbar button structure. */
84 struct mybuttons {
85 long icon;
86 long command;
87 char *text;
88 };
89
90 struct mybuttons myb[] = {
91 {IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"},
92 {IMI_KEY_PROPS, ID_KEYMISC_PROPS, "Properties"},
93 {IMI_KEY_SIGN, ID_KEYMISC_SIGN, "Sign"},
94 {IMI_KEY_IMPORT, ID_KEYMISC_IMPORT, "Import"},
95 {IMI_KEY_EXPORT, ID_KEYMISC_EXPORT, "Export"},
96 };
97
98
99 /* Subclass the keylist listview control to allow extended commands. */
100 static BOOL CALLBACK
101 keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
102 {
103 struct listview_ctrl_s lv;
104
105 switch (msg) {
106 case WM_LBUTTONDBLCLK:
107 send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);
108 break;
109
110 case WM_KEYUP:
111 int virt_key = (int)wparam;
112 switch (virt_key) {
113 case VK_SPACE:
114 send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);
115 break;
116
117 case VK_DELETE:
118 send_cmd_id (keylist_proc.dlg, ID_KEYMISC_DELETE);
119 break;
120
121 case VK_INSERT:
122 send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);
123 break;
124
125 case VK_A:
126 if (GetAsyncKeyState (VK_CONTROL)) {
127 lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
128 listview_select_all (&lv);
129 }
130 break;
131
132 case VK_C:
133 if (GetAsyncKeyState (VK_CONTROL)) {
134 lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
135 km_clip_export (keylist_proc.dlg, &lv);
136 }
137 break;
138
139 case VK_P:
140 if (GetAsyncKeyState (VK_CONTROL))
141 send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);
142 break;
143
144 case VK_F:
145 if (GetAsyncKeyState (VK_CONTROL)) {
146 lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
147 km_find_key (dlg, &lv);
148 }
149 break;
150 }
151 break;
152 }
153
154 return CallWindowProc (keylist_proc.old, dlg, msg, wparam, lparam);
155 }
156
157
158 #define ico2idx(ico) imagelist_getindex((ico))
159
160 static HWND
161 load_toolbar (HWND dlg, struct km_info_s *kmi)
162 {
163 HWND tbwnd;
164 TBSAVEPARAMS tbsp;
165 TBBUTTON tb_buttons[] = {
166 {ico2idx (IMI_KEY_NEW), ID_KEYMISC_KEYWIZARD, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L},
167 {ico2idx (IMI_KEY_DELETE), ID_KEYMISC_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
168 {ico2idx (IMI_KEY_PROPS), ID_KEYMISC_PROPS, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
169 {ico2idx (IMI_KEY_SIGN), ID_KEYMISC_SIGN, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
170 {ico2idx (IMI_KEY_SEARCH), ID_KEYMISC_SENDRECV, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
171 {0, 0, 0, TBSTYLE_SEP, {0}, 0L, 0},
172 {ico2idx (IMI_KEY_FILE_IMPORT), ID_KEYMISC_IMPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
173 {ico2idx (IMI_KEY_FILE_EXPORT), ID_KEYMISC_EXPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
174 {ico2idx (IMI_KEY_IMPORT), ID_KEYCTX_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
175 {ico2idx (IMI_KEY_EXPORT), ID_KEYCTX_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
176 };
177
178 tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL,
179 WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE,
180 0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL);
181 if (tbwnd) {
182 SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
183 SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist);
184 SendMessage (tbwnd, TB_AUTOSIZE, 0, 0);
185 ShowWindow (tbwnd, SW_SHOW);
186
187 /* Restore toolbar */
188 tbsp.hkr = HKEY_CURRENT_USER;
189 tbsp.pszSubKey = "Software\\WinPT";
190 tbsp.pszValueName = "KM_toolbar";
191 if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0)
192 SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]),
193 (LONG)&tb_buttons[0]);
194 }
195 return tbwnd;
196 }
197
198
199 /* Restore the width of the columns from the registry.
200 If no bitstring was found, the default size is used. */
201 int
202 restore_column_info (listview_ctrl_t hd)
203 {
204 WORD *buf;
205 HKEY root;
206 DWORD type;
207 DWORD size = hd->cols*sizeof (WORD), i;
208 LONG ec;
209
210 ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0,
211 KEY_ALL_ACCESS, &root);
212 if (ec != ERROR_SUCCESS)
213 return -1;
214
215 buf = new WORD[size/2];
216 if (!buf)
217 BUG (NULL);
218 ec = RegQueryValueEx (root, "KMColumnSize", NULL, &type,
219 (BYTE*)buf, &size);
220 RegCloseKey (root);
221 if (ec != ERROR_SUCCESS) {
222 free_if_alloc (buf);
223 return -1;
224 }
225
226 /* check for garbled values. */
227 for (i=0; i < size/2; i++) {
228 if (buf[i] == 0 || buf[i] > 512) {
229 free_if_alloc (buf);
230 return -1;
231 }
232 }
233 for (i=0; i < size/2; i++) {
234 LVCOLUMN lvc;
235
236 memset (&lvc, 0, sizeof (lvc));
237 lvc.mask = LVCF_WIDTH;
238 lvc.cx = buf[i];
239 ListView_SetColumn (hd->ctrl, i, &lvc);
240 }
241 free_if_alloc (buf);
242 return 0;
243 }
244
245
246 /* Save the current column width to the registry. */
247 int
248 save_column_info (listview_ctrl_t hd)
249 {
250 WORD *buf;
251 HKEY root;
252 LONG ec;
253 int i;
254
255 buf = new WORD[hd->cols];
256 if (!buf)
257 BUG (NULL);
258 for (i=0; i < hd->cols; i++) {
259 LVCOLUMN lvc;
260
261 memset (&lvc, 0, sizeof (lvc));
262 lvc.mask = LVCF_WIDTH;
263 ListView_GetColumn (hd->ctrl, i, &lvc);
264 buf[i] = lvc.cx;
265 }
266
267 ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0,
268 KEY_ALL_ACCESS, &root);
269 if (ec != ERROR_SUCCESS) {
270 free_if_alloc (buf);
271 return -1;
272 }
273
274 ec = RegSetValueEx (root, "KMColumnSize", 0, REG_BINARY,
275 (const BYTE*)buf, 2*hd->cols);
276 RegCloseKey (root);
277 free_if_alloc (buf);
278 return ec == ERROR_SUCCESS? 0 : -1;
279 }
280
281
282 /* Center window @dlg. */
283 static void
284 do_center_window (HWND dlg, struct km_info_s *kmi)
285 {
286 RECT rect;
287 char *p;
288 int pos_x = 0;
289 int pos_y = 0;
290
291 /* Find bottom of keylist */
292 GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect);
293 MapWindowPoints (NULL, dlg, (POINT*)&rect, 2);
294
295 kmi->ypos_sep = rect.bottom;
296
297 p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X");
298 if (p && !strcmp (p, " ")) {
299 free_if_alloc (p);
300 center_window (dlg, NULL);
301 return;
302 }
303 else if (p)
304 pos_x = atol (p);
305
306 p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y");
307 if (p && !strcmp (p, " ")) {
308 free_if_alloc (p);
309 center_window (dlg, NULL);
310 return;
311 }
312 else if (p)
313 pos_y = atol (p);
314
315 if (!pos_y && !pos_x) {
316 center_window (dlg, NULL);
317 return;
318 }
319
320 if (pos_x < 0 || pos_y < 0)
321 pos_x = pos_y = 0;
322 if (pos_x > GetSystemMetrics (SM_CXSCREEN)
323 || pos_y > GetSystemMetrics (SM_CYSCREEN)) {
324 pos_x = pos_y = 0;
325 }
326 GetClientRect (dlg, &rect);
327 MoveWindow (dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE);
328 }
329
330
331 /* Resize the key manager window with the information from @kmi. */
332 static void
333 do_resize_window (HWND dlg, struct km_info_s *kmi)
334 {
335 HWND h;
336 RECT rclient, rect;
337 BOOL bRepaint = FALSE;
338
339 /* Get rect of client area and make life easier */
340 GetClientRect (dlg, &rclient);
341
342 /* Move toolbar to the top of the window */
343 if (kmi->toolbar) {
344 GetWindowRect (kmi->toolbar, &rect);
345 ScreenToClient (dlg, (POINT*)&rect);
346 ScreenToClient (dlg, (POINT*)&(rect.right));
347
348 rclient.top += rect.bottom - rect.top;
349 MoveWindow (kmi->toolbar, 0, 0, rclient.right - rclient.left,
350 rect.bottom - rect.top, bRepaint);
351 }
352
353 /* Move statusbar to the bottom of the window */
354 if (kmi->statbar) {
355 GetWindowRect (kmi->statbar, &rect);
356 ScreenToClient (dlg, (POINT*)&rect);
357 ScreenToClient (dlg, (POINT*)&(rect.right));
358
359 rclient.bottom -= rect.bottom - rect.top;
360 MoveWindow (kmi->statbar, 0, rclient.bottom,
361 rclient.right - rclient.left,
362 rect.bottom - rect.top, bRepaint);
363 }
364
365 /* Obtain separator information and move it to the desired posistion */
366 if (kmi->ypercent_sep)
367 kmi->ypos_sep = (rclient.bottom - rclient.top) * kmi->ypercent_sep / 100;
368 else
369 kmi->ypercent_sep = kmi->ypos_sep * 100 / (rclient.bottom - rclient.top);
370
371 /* Don't move away */
372 if (kmi->ypos_sep+5 > rclient.bottom)
373 kmi->ypos_sep = rclient.bottom - 5;
374 if (kmi->ypos_sep < rclient.top)
375 kmi->ypos_sep = rclient.top;
376 MoveWindow (kmi->hwnd_sep, 0, kmi->ypos_sep,
377 (rclient.right - rclient.left), 5, bRepaint);
378
379 /* Place the keylist above the separator */
380 h = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);
381 MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,
382 kmi->ypos_sep - rclient.top, bRepaint);
383 rclient.top = kmi->ypos_sep + 5 + 8;
384
385 #if 0 /* Disable the code until we support groups again. */
386 /* Place the group text and the group box below the separator */
387 h = GetDlgItem (dlg, IDC_KEYMISC_GTEXT);
388 MoveWindow (h, rclient.left, rclient.top, 100, 14, bRepaint);
389 rclient.top += 18;
390
391 h = GetDlgItem (dlg, IDC_KEYMISC_GROUP);
392 MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,
393 (rclient.bottom < rclient.top) ?
394 0 : rclient.bottom - rclient.top, bRepaint);
395 #endif
396
397 /* Repaint the whole thing */
398 InvalidateRect (dlg, NULL, TRUE);
399 }
400
401
402 /* Return true if the clipboard contains an OpenPGP key. */
403 static bool
404 clip_contains_pgpkey (void)
405 {
406 char *ctxt;
407 bool val = false;
408
409 ctxt = get_clip_text (NULL);
410 if (!ctxt || strlen (ctxt) < 512)
411 val = false;
412 else if (strstr (ctxt, "BEGIN PGP") && strstr (ctxt, "KEY BLOCK") &&
413 strstr (ctxt, "END PGP"))
414 val = true;
415 free_if_alloc (ctxt);
416 return val;
417 }
418
419
420 /* Show a mini popup menu to import keys. */
421 static void
422 do_create_minpopup (HWND dlg)
423 {
424 HMENU hm;
425 MENUITEMINFO mi;
426 char * s;
427 POINT p;
428
429 if (gpg_read_only || !clip_contains_pgpkey ())
430 return;
431 hm = CreatePopupMenu ();
432 if (!hm)
433 BUG( NULL );
434 memset (&mi, 0, sizeof mi);
435 mi.cbSize = sizeof mi;
436 s = (char *)_("Paste Key from Clipboard");
437 mi.fType = MF_STRING;
438 mi.dwTypeData = s;
439 mi.cch = strlen (s);
440 mi.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
441 mi.wID = ID_KEYCTX_PASTE;
442 InsertMenuItem (hm, 0, FALSE, &mi);
443 GetCursorPos (&p);
444 TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);
445 DestroyMenu (hm);
446 }
447
448
449 /* Update the default key entry in the status bar for dialog @dlg. */
450 void
451 update_default_key_str (HWND dlg)
452 {
453 const char *fmt;
454 char *keyid;
455 char defkeyinf[128];
456
457 /* XXX: also show the name? */
458 keyid = get_gnupg_default_key ();
459 if (!keyid)
460 return;
461 if ((keyid[0] >= 'A' && keyid[0] <= 'Z') ||
462 (keyid[0] >= 'a' && keyid[0] <= 'z') ||
463 (keyid[0] == '0' && keyid[1] == 'x'))
464 fmt = _("Default Key: %s");
465 else
466 fmt = _("Default Key: 0x%s");
467 _snprintf (defkeyinf, sizeof (defkeyinf) - 1, fmt, keyid);
468 SendMessage (dlg, SB_SETTEXT, 0, (LPARAM)defkeyinf);
469 free_if_alloc (keyid);
470 }
471
472
473 /* Count all keys and show from @lv results in the status bar @sb. */
474 void
475 update_status_bar (HWND sb, listview_ctrl_t lv)
476 {
477 char txt_sec[128], txt_pub[128];
478 int nkeys = 0, nsec = 0;
479 int i;
480
481 nkeys = listview_count_items (lv, 0);
482 for (i = 0; i < nkeys; i++) {
483 if (km_check_for_seckey (lv, i, NULL))
484 nsec++;
485 }
486 _snprintf (txt_sec, sizeof (txt_sec)-1, _("%d secret keys"), nsec);
487 _snprintf (txt_pub, sizeof (txt_pub)-1, _("%d keys"), nkeys);
488 SendMessage (sb, SB_SETTEXT, 1, (LPARAM)txt_sec);
489 SendMessage (sb, SB_SETTEXT, 2, (LPARAM)txt_pub);
490 }
491
492
493 long CALLBACK
494 separator_wnd_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
495 {
496 static POINT last_mouse_pos;
497
498 if (msg == WM_CREATE)
499 SetWindowLong (hwnd, GWL_USERDATA,
500 (long)(((CREATESTRUCT*)lparam)->lpCreateParams));
501
502 switch (msg) {
503 case WM_PAINT:
504 PAINTSTRUCT ps;
505 RECT rect;
506 HPEN hpen;
507
508 GetClientRect (hwnd, &rect);
509 BeginPaint (hwnd, &ps);
510
511 /* Background */
512 FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1));
513
514 /* The lines from the light into the dark */
515 MoveToEx(ps.hdc, 0,0, NULL);
516 if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DHILIGHT))) != NULL) {
517 SelectObject (ps.hdc, (LPVOID)hpen);
518 LineTo (ps.hdc, rect.right, 0);
519 DeleteObject (hpen);
520 }
521 MoveToEx(ps.hdc, 0, 1, NULL);
522 if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT))) != NULL) {
523 SelectObject (ps.hdc, (LPVOID)hpen);
524 LineTo (ps.hdc, rect.right, rect.bottom);
525 DeleteObject (hpen);
526 }
527
528 MoveToEx(ps.hdc, 0, rect.bottom-1, NULL);
529 if ((hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW))) != NULL) {
530 SelectObject (ps.hdc, (LPVOID)hpen);
531 LineTo (ps.hdc, rect.right, rect.bottom-1);
532 DeleteObject (hpen);
533 }
534 MoveToEx(ps.hdc, 0, rect.bottom, NULL);
535 if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW))) != NULL) {
536 SelectObject (ps.hdc, (LPVOID)hpen);
537 LineTo (ps.hdc, rect.right, rect.bottom);
538 DeleteObject (hpen);
539 }
540
541 EndPaint (hwnd, &ps);
542 return 0;
543
544 case WM_LBUTTONDOWN:
545 last_mouse_pos.x = LOWORD (lparam);
546 last_mouse_pos.y = HIWORD (lparam);
547 ClientToScreen (hwnd, &last_mouse_pos);
548 SetCapture (hwnd);
549 return 0;
550
551 case WM_LBUTTONUP:
552 ReleaseCapture ();
553 return 0;
554
555 case WM_MOUSEMOVE:
556 if (wparam == MK_LBUTTON) {
557 struct km_info_s *kmi;
558 POINT p;
559 RECT r;
560
561 kmi = (struct km_info_s *)GetWindowLong (hwnd, GWL_USERDATA);
562 if (kmi == NULL)
563 break;
564
565 /* Calculate mouse movement */
566 p.x = LOWORD(lparam);
567 p.y = HIWORD(lparam);
568 ClientToScreen (hwnd, &p);
569
570 GetWindowRect (hwnd, &r);
571 r.top += (short)(p.y - last_mouse_pos.y);
572 r.bottom += (short)(p.y - last_mouse_pos.y);
573
574 last_mouse_pos.y = p.y;
575
576 /* Apply mouse movement to window. Beware the MoveWindow is relaive
577 to parent NOT screen */
578 MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&r, 2);
579 kmi->ypos_sep = r.top;
580 kmi->ypercent_sep = 0; /* This forces do_resize_window to use abs. position */
581 do_resize_window (GetParent(hwnd), kmi);
582 return 0;
583 }
584 }
585
586 return DefWindowProc (hwnd, msg, wparam, lparam);
587 }
588
589
590 /* Register the separator window with @dlg as the parent window. */
591 static HWND
592 regist_sep_wnd (HWND dlg, struct km_info_s *kmi)
593 {
594 WNDCLASS wndclass;
595 HWND h;
596
597 wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
598 wndclass.lpfnWndProc = separator_wnd_proc;
599 wndclass.cbClsExtra = 0;
600 wndclass.cbWndExtra = sizeof (long);
601 wndclass.hInstance = glob_hinst;
602 wndclass.hIcon = NULL;
603 wndclass.hCursor = LoadCursor (NULL, IDC_SIZENS);
604 wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
605 wndclass.lpszMenuName = 0;
606 wndclass.lpszClassName = WINDOWCLASS_SEPARATOR_CHILD;
607 RegisterClass (&wndclass);
608
609 h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL,
610 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
611 0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi);
612 ShowWindow (h, SW_SHOW);
613 return h;
614 }
615
616
617 #define enable_button(hwnd, cid, item_selected) \
618 SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG ((item_selected), 0))
619
620
621 /* Interactive modification of the dialog item which depend if an item
622 is selected or not and what kind of item. @lv is the list view with
623 the items. */
624 void
625 update_ui_items (HWND hwnd, listview_ctrl_t lv)
626 {
627 HWND tb_hwnd;
628 HMENU hmenu;
629 int mult_resids[] = {ID_KEYMISC_PROPS, ID_KEYMISC_SIGN, ID_KEYMISC_EDITKEY,
630 ID_KEYMISC_CHECKSIGS, ID_KEYMISC_REVCERT, 0};
631 int key_selected = 0;
632 int key_has_sec = 0;
633 int key_inv = 0;
634 int i, state=0;
635
636 /* Get some states */
637 key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST),
638 LVM_GETSELECTEDCOUNT, 0, 0)
639 ? TRUE : FALSE;
640 key_has_sec = FALSE;
641 if (key_selected) {
642 i = listview_get_curr_pos (lv);
643 key_has_sec = km_check_for_seckey (lv, i, NULL) ? TRUE : FALSE;
644 key_inv = km_get_key_status (lv, i) & KM_FLAG_REVOKED ||
645 km_get_key_status (lv, i) & KM_FLAG_EXPIRED;
646 }
647
648 /* Enable / disable toolbar buttons */
649 tb_hwnd = GetDlgItem (hwnd, IDR_WINPT_KMTB);
650 enable_button (tb_hwnd, ID_KEYMISC_DELETE, key_selected);
651 enable_button (tb_hwnd, ID_KEYMISC_PROPS, key_selected);
652 enable_button (tb_hwnd, ID_KEYMISC_SIGN, key_selected && !key_inv);
653 enable_button (tb_hwnd, ID_KEYMISC_EXPORT, key_selected);
654 enable_button (tb_hwnd, ID_KEYCTX_COPY, key_selected);
655 enable_button (tb_hwnd, ID_KEYCTX_PASTE, clip_contains_pgpkey ());
656
657 /* Enable / disable menu items */
658 state = key_selected? MF_ENABLED : MF_DISABLED|MF_GRAYED;
659 hmenu = GetMenu (hwnd);
660 set_menu_state (hmenu, ID_KEYMISC_EXPORT, state);
661 set_menu_state (hmenu, ID_KEYMISC_DELETE, state);
662 set_menu_state (hmenu, ID_KEYMISC_PROPS, state);
663 set_menu_state (hmenu, ID_KEYMISC_EDITKEY, state);
664 set_menu_state (hmenu, ID_KEYMISC_CHECKSIGS, state);
665 set_menu_state (hmenu, ID_KEYMISC_SIGN,
666 key_selected && !key_inv ? MF_ENABLED : MF_GRAYED);
667 set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY,
668 key_selected && key_has_sec? MF_ENABLED : MF_GRAYED);
669 set_menu_state (hmenu, ID_KEYMISC_REVCERT,
670 key_selected && key_has_sec? MF_ENABLED : MF_GRAYED);
671
672 /* Disable some menu items when multiple keys are selected. */
673 if (listview_count_items (lv, 1) > 1) {
674 for (i=0; mult_resids[i] != 0; i++)
675 set_menu_state (hmenu, mult_resids[i], MF_GRAYED);
676 }
677
678 /* Disable all secret-key functions when no secret key is available. */
679 {
680 gpg_keycache_t sec = keycache_get_ctx (0);
681 if (gpg_keycache_get_size (sec) == 0) {
682 enable_button (tb_hwnd, ID_KEYMISC_SIGN, FALSE);
683 set_menu_state (hmenu, ID_KEYMISC_SIGN, MF_GRAYED);
684 }
685 }
686 }
687
688
689 /* Disable some context menu items when multiple keys are selected. */
690 static void
691 popup_multiple (HWND dlg, HMENU hm)
692 {
693 int resids[] = {
694 ID_KEYCTX_EDIT,
695 ID_KEYCTX_SIGN,
696 ID_KEYCTX_REV,
697 ID_KEYCTX_ENABLE,
698 ID_KEYCTX_DISABLE,
699 ID_KEYCTX_ADDKEY,
700 ID_KEYCTX_ADDPHOTO,
701 ID_KEYCTX_ADDUID,
702 ID_KEYCTX_ADDREV,
703 ID_KEYCTX_LISTSIGS,
704 ID_KEYCTX_MAXTRUST,
705 ID_KEYCTX_PROPS,
706 ID_KEYCTX_SENDMAIL,
707 0};
708 int i;
709 for (i=0; i < resids[i] != 0; i++)
710 set_menu_state (hm, resids[i], MF_GRAYED);
711 }
712
713
714 /* The items which are shown when GPG is in read-only mode. */
715 static void
716 popup_gpg_readonly (HWND dlg, HMENU hm)
717 {
718 int resids[] = {
719 ID_KEYCTX_PASTE,
720 ID_KEYCTX_EDIT,
721 ID_KEYCTX_SIGN,
722 ID_KEYCTX_REV,
723 ID_KEYCTX_DEL,
724 ID_KEYCTX_ENABLE,
725 ID_KEYCTX_DISABLE,
726 ID_KEYCTX_RECVFROM,
727 ID_KEYCTX_ADDKEY,
728 ID_KEYCTX_ADDPHOTO,
729 ID_KEYCTX_ADDUID,
730 ID_KEYCTX_ADDREV,
731 0
732 };
733 int i;
734
735 if (gpg_read_only == 0)
736 return;
737 for (i=0; resids[i] != 0; i++)
738 set_menu_state (hm, resids[i], MF_GRAYED);
739 }
740
741
742 /* Change the 'Edit' menu based on the current state. */
743 static void
744 change_edit_menu (listview_ctrl_t lv, HMENU hm, int id)
745 {
746 enum item { EDIT_MENU = 1 };
747 int no_sel;
748
749 if (id != EDIT_MENU)
750 return;
751
752 if (!clip_contains_pgpkey ())
753 set_menu_state (hm, ID_KEYMISC_PASTE, MF_GRAYED);
754 else
755 set_menu_state (hm, ID_KEYMISC_PASTE, MF_ENABLED);
756 no_sel = listview_get_curr_pos (lv) == -1? 1 : 0;
757 set_menu_state (hm, ID_KEYMISC_DELETE2, no_sel? MF_GRAYED: MF_ENABLED);
758 set_menu_state (hm, ID_KEYMISC_COPY, no_sel? MF_GRAYED : MF_ENABLED);
759 }
760
761
762
763 /* Show limited key menu entries when GPG is in read-only mode. */
764 static void
765 change_key_menu (HMENU hm, int id)
766 {
767 int key_resids[] = {
768 ID_KEYMISC_SIGN,
769 ID_KEYMISC_DELETE,
770 ID_KEYMISC_REVCERT,
771 ID_KEYMISC_IMPORT_HTTP,
772 ID_KEYMISC_IMPORT,
773 ID_KEYMISC_REFRESH_KEYS,
774 ID_KEYMISC_REBUILD,
775 ID_KEYMISC_KEYWIZARD,
776 ID_KEYMISC_CARDNEW,
777 ID_KEYMISC_NEWKEY,
778 0,
779 };
780 int edit_resids[] = {
781 ID_KEYMISC_PASTE,
782 ID_KEYMISC_OT,
783 ID_KEYMISC_EDITKEY,
784 0
785 };
786 int *resids;
787 int i;
788
789
790 if (gpg_read_only == 0)
791 return;
792 switch (id) {
793 case 0: return;
794 case 3: resids = key_resids; break;
795 case 1: resids = edit_resids;break;
796 default:resids = edit_resids; break;
797 }
798
799 for (i=0; resids[i] != 0; i++)
800 set_menu_state (hm, resids[i], MF_GRAYED);
801 }
802
803
804 /* Reload a single key in the cache. */
805 static void
806 update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair)
807 {
808 gpgme_key_t key;
809
810 keycache_update (0, keyid);
811 if (keypair)
812 keycache_update (1, keyid);
813
814 /* because we replaced the key item, we need to update the
815 address of the pointer in the ListView control. */
816 get_pubkey (keyid, &key);
817 keylist_upd_key (lv, pos, key);
818 keyring_check_last_access ();
819 }
820
821
822 /* Setup status bar for the main window @dlg. */
823 static HWND
824 setup_status_bar (HWND dlg, listview_ctrl_t lv)
825 {
826 HWND statbar;
827 RECT r;
828 int partpos[3];
829 int i;
830
831 GetClientRect (dlg, &r);
832 for (i=1; i <= 3; i++)
833 partpos[i-1] = r.right/3*i;
834 statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM,
835 "status bar", dlg, KM_SEPARATOR_ID);
836
837 ShowWindow (statbar, SW_SHOW);
838 SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos);
839
840 update_default_key_str (statbar);
841 update_status_bar (statbar, lv);
842
843 return statbar;
844 }
845
846
847 /* Remove or add columns which depends on the state of @checked. */
848 void
849 modify_listview_columns (km_info_s *kmi, UINT m_uid, BOOL checked)
850 {
851 UINT resids[] = {
852 0,
853 ID_KEYMISC_VIEWKEYID,
854 ID_KEYMISC_VIEWTYPE,
855 0,
856 ID_KEYMISC_VIEWCIPHER,
857 0,
858 0,
859 ID_KEYMISC_VIEWCREAT,
860 -1
861 };
862 listview_column_s cols[] = {
863 {0, 240, (char *)_("User ID")},
864 {1, 78, (char *)_("Key ID")},
865 {2, 52, (char *)_("Type")},
866 {3, 66, (char *)_("Size")},
867 {4, 60, (char *)_("Cipher")},
868 {5, 66, (char *)_("Validity")},
869 {6, 58, (char *)_("Trust")},
870 {7, 72, (char *)_("Creation")},
871 {0, 0, NULL}
872 };
873 UINT pos;
874
875 for (pos=0; resids[pos] != -1; pos++) {
876 if (m_uid == resids[pos])
877 break;
878 }
879 if (!checked)
880 listview_del_column (kmi->lv, (int)pos);
881 else {
882 listview_add_column (kmi->lv, &cols[pos]);
883 keylist_upd_col (kmi->lv, pos);
884 }
885 }
886
887
888 /* Helper to handle the help file. If @check is 1
889 the existence of the file is checked.
890 Otherwise the help file will be loaded. */
891 static bool
892 start_help (HWND dlg, int check)
893 {
894 DWORD n;
895 char path[MAX_PATH+1+32];
896
897 n = GetModuleFileName (NULL, path, sizeof (path)-1-32);
898 if (!n)
899 return false;
900 path[n] = 0;
901 while (n-- && path[n] != '\\')
902 ;
903 path[n+1] = 0;
904 strcat (path, "winpt.chm");
905 if (!check)
906 ShellExecute (dlg, "open", path, NULL, NULL, SW_SHOW);
907 return file_exist_check (path) == 0? true : false;
908 }
909
910 /* Translate all menu strings. */
911 static void
912 translate_menu_strings (HWND dlg)
913 {
914 HMENU menu;
915
916 menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC);
917 set_menu_text_bypos (menu, 0, _("File"));
918 set_menu_text_bypos (menu, 1, _("Edit"));
919 set_menu_text_bypos (menu, 2, _("View"));
920 set_menu_text_bypos (menu, 3, _("Key"));
921 set_menu_text_bypos (menu, 4, _("Groups"));
922
923 set_menu_text (menu, ID_KEYMISC_EDITKEY, _("Edit"));
924 set_menu_text (menu, ID_KEYMISC_MAIL, _("Send Mail..."));
925 set_menu_text (menu, ID_KEYMISC_OT, _("Ownertrust")); /* XXX */
926 set_menu_text (menu, ID_KEYMISC_COPY, _("&Copy\tCtrl+C"));
927 set_menu_text (menu, ID_KEYMISC_PASTE, _("&Paste\tCtrl+V"));
928 set_menu_text (menu, ID_KEYMISC_FIND, _("Search...\tCtrl+F"));
929 set_menu_text (menu, ID_KEYMISC_SELALL, _("Select All\tCtrl+A"));
930 set_menu_text (menu, ID_KEYMISC_QUIT, _("&Quit"));
931 set_menu_text (menu, ID_KEYMISC_UID, _("User ID"));
932 set_menu_text (menu, ID_KEYMISC_NEWKEY, _("&Expert"));
933 set_menu_text (menu, ID_KEYMISC_KEYWIZARD, _("&Normal"));
934 set_menu_text (menu, ID_KEYMISC_EDIT, _("Edit"));
935 set_menu_text (menu, ID_KEYMISC_SIGN, _("&Sign"));
936 set_menu_text (menu, ID_KEYMISC_DELETE, _("&Delete"));
937 set_menu_text (menu, ID_KEYMISC_DELETE2, _("&Delete"));
938 set_menu_text (menu, ID_KEYMISC_REVCERT, _("&Revoke Cert"));
939 set_menu_text (menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures"));
940 set_menu_text (menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path"));
941 set_menu_text (menu, ID_KEYMISC_EXPORT, _("&Export..."));
942 set_menu_text (menu, ID_KEYMISC_IMPORT, _("&Import..."));
943 set_menu_text (menu, ID_KEYMISC_PROPS, _("&Properties"));
944 set_menu_text (menu, ID_KEYMISC_GPGOPT, _("Options"));
945 set_menu_text (menu, ID_KEYMISC_GPGPREFS, _("Preferences"));
946 set_menu_text (menu, ID_KEYMISC_SENDRECV, _("Keyserver") );
947 set_menu_text (menu, ID_KEYMISC_EXPORT_PRIVKEY, _("E&xport Secret Key"));
948 set_menu_text (menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache"));
949 set_menu_text (menu, ID_KEYMISC_REBUILD, _("R&everify Signatures"));
950 set_menu_text (menu, ID_KEYMISC_REFRESH_KEYS, _("Refresh &Keys (Keyserver)"));
951 set_menu_text (menu, ID_KEYMISC_INFO, _("Info") );
952 set_menu_text (menu, ID_KEYMISC_HELP, _("&Help"));
953
954 set_menu_text (menu, ID_KEYMISC_VIEWKEYID, _("Key ID"));
955 set_menu_text (menu, ID_KEYMISC_VIEWCIPHER, _("Cipher"));
956 set_menu_text (menu, ID_KEYMISC_VIEWTYPE, _("Type"));
957 set_menu_text (menu, ID_KEYMISC_VIEWCREAT, _("Creation"));
958
959 if (!start_help (NULL, 1))
960 set_menu_state (menu, ID_KEYMISC_HELP, MF_GRAYED);
961
962 SetMenu (dlg, menu);
963 }
964
965
966 /* Translate popup menu strings. */
967 static void
968 translate_popupmenu_strings (HMENU popup)
969 {
970 set_menu_text (popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard"));
971 set_menu_text (popup, ID_KEYCTX_KEYID_COPY, _("Copy Key ID to Clipboard"));
972 set_menu_text (popup, ID_KEYCTX_FPR_COPY, _("Copy Fingerprint to Clipboard"));
973 set_menu_text (popup, ID_KEYCTX_KINFO_COPY, _("Copy Key Info to Clipboard"));
974 set_menu_text (popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard"));
975 set_menu_text (popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard"));
976 set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver"));
977 set_menu_text (popup, ID_KEYCTX_MAXTRUST, _("Set Implicit &Trust"));
978 set_menu_text (popup, ID_KEYCTX_LISTSIGS, _("&List Signatures"));
979 set_menu_text (popup, ID_KEYCTX_PROPS, _("&Properties"));
980 set_menu_text (popup, ID_KEYCTX_EDIT, _("Key Edit"));
981 set_menu_text (popup, ID_KEYCTX_DEL, _("&Delete"));
982 set_menu_text (popup, ID_KEYCTX_REV, _("&Revoke Cert"));
983 set_menu_text (popup, ID_KEYCTX_SIGN, _("&Sign"));
984 set_menu_text (popup, ID_KEYCTX_ENABLE, _("&Enable"));
985 set_menu_text (popup, ID_KEYCTX_DISABLE, _("&Disable"));
986 set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Re&fresh from Keyserver"));
987 set_menu_text (popup, ID_KEYCTX_SETPREFKS, _("Set preferred Keyserver URL"));
988 set_menu_text (popup, ID_KEYCTX_SENDMAIL, _("Send Key to Mail Recipient"));
989 set_menu_text (popup, ID_KEYCTX_SETDEFKEY, _("Set as Default Key"));
990
991 set_menu_text (popup, ID_KEYCTX_ADDKEY, _("Key..."));
992 set_menu_text (popup, ID_KEYCTX_ADDUID, _("User ID..."));
993 set_menu_text (popup, ID_KEYCTX_ADDPHOTO, _("Photo ID..."));
994 set_menu_text (popup, ID_KEYCTX_ADDREV, _("Revoker..."));
995
996 /* change popup texts */
997 set_menu_text_bypos (popup, 0, _("Key Attributes"));
998 set_menu_text_bypos (popup, 6, _("Add"));
999 set_menu_text_bypos (popup, 19, _("Send to Keyserver"));
1000 }
1001
1002
1003 /* Return true if the cache contain marked keys. */
1004 static bool
1005 updated_keys_avail (void)
1006 {
1007 gpg_keycache_t kc = keycache_get_ctx (1);
1008 struct keycache_s *k;
1009
1010 for (k = kc->item; k; k = k->next) {
1011 if (k->flags)
1012 return true;
1013 }
1014 return false;
1015 }
1016
1017
1018 /* Find the index of the key identified by @key. */
1019 static int
1020 find_keypos (listview_ctrl_t lv, gpgme_key_t key)
1021 {
1022 gpgme_key_t src;
1023 int i;
1024
1025 for (i=0; i < listview_count_items (lv, 0); i++) {
1026 src = (gpgme_key_t)listview_get_item2 (lv, i);
1027 if (src && src->subkeys->keyid == key->subkeys->keyid)
1028 return i;
1029 }
1030 return -1;
1031 }
1032
1033
1034 /* Add all recently updated keys in the cache to the list
1035 and refresh all GUI elements. */
1036 static void
1037 refresh_keylist (struct km_info_s *kmi)
1038 {
1039 struct keycache_s *ctx;
1040 gpg_keycache_t kc;
1041 int status=0;
1042
1043 kc = keycache_get_ctx (1);
1044 while (!gpg_keycache_next_updated_key (kc, &ctx, &status)) {
1045 if (status == KC_FLAG_ADD)
1046 keylist_add_key (kmi->lv, KEYLIST_LIST, ctx->key);
1047 else
1048 keylist_upd_key (kmi->lv, find_keypos (kmi->lv, ctx->key), ctx->key);
1049 /*log_box ("debug", 0, "(%d) %s", status, ctx->key->uids->name);*/
1050 }
1051 keylist_sort (kmi->lv, KEY_SORT_USERID);
1052 update_status_bar (kmi->statbar, kmi->lv);
1053 keyring_check_last_access ();
1054 }
1055
1056
1057 /* Dialog box procedure for the Key Manager. */
1058 BOOL CALLBACK
1059 keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1060 {
1061 struct km_info_s *kmi;
1062 INITCOMMONCONTROLSEX icex;
1063 HWND kl;
1064 HMENU hm;
1065 gpg_keycache_t c;
1066 gpgme_key_t key;
1067 struct genkey_s genkey;
1068 struct winpt_key_s k = {0};
1069 struct URL_ctx_s *url;
1070 refresh_cache_s rcs = {0};
1071 char type[32], *name;
1072 const char *t, *host;
1073 WORD port = 0;
1074 int l_idx = 0, i=0, rc;
1075
1076 if ((msg != WM_INITDIALOG)
1077 && ((kmi = (struct km_info_s*)GetWindowLong (dlg, GWL_USERDATA)) == NULL))
1078 return FALSE;
1079
1080 switch (msg) {
1081 case WM_INITDIALOG:
1082 kmi = new struct km_info_s;
1083 memset (kmi, 0, sizeof (struct km_info_s));
1084 kmi->lv_idx = -1;
1085 icex.dwSize = sizeof (INITCOMMONCONTROLSEX);
1086 icex.dwICC = ICC_BAR_CLASSES;
1087 InitCommonControlsEx (&icex);
1088 kmi->hwnd_sep = regist_sep_wnd (dlg, kmi);
1089 imagelist_load (dlg);
1090 translate_menu_strings (dlg);
1091 SetWindowText (dlg, _("Key Manager"));
1092
1093 c = keycache_get_ctx (KEYCACHE_PUB);
1094 if (!c)
1095 BUG (NULL);
1096 kl = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST);
1097 kmi->keylist_sortby = KEY_SORT_USERID;
1098 Header_SetImageList(ListView_GetHeader (kl), glob_imagelist);
1099 kmi->lv = keylist_load (GetDlgItem (dlg, IDC_KEYMISC_KEYLIST), c,
1100 NULL, KEYLIST_LIST, kmi->keylist_sortby);
1101 /* init subclassing for the listview */
1102 keylist_proc.dlg = dlg;
1103 keylist_proc.current = (WNDPROC)keylist_subclass_proc;
1104 keylist_proc.old = (WNDPROC)GetWindowLong(kl, GWL_WNDPROC);
1105 if (keylist_proc.old) {
1106 if( !SetWindowLong (kl, GWL_WNDPROC, (LONG)keylist_proc.current)) {
1107 msg_box (dlg, _("Could not set keylist window procedure."),
1108 _("Key Manager"), MB_ERR);
1109 BUG (NULL);
1110 }
1111 }
1112 kmi->statbar = setup_status_bar (dlg, kmi->lv);
1113 SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi);
1114 kmi->toolbar = load_toolbar (dlg, kmi);
1115
1116 do_center_window (dlg, kmi);
1117 do_resize_window (dlg, kmi);
1118 update_ui_items (dlg, kmi->lv);
1119 restore_column_info (kmi->lv);
1120
1121 SetDlgItemText (dlg, IDC_KEYMISC_GTEXT, _("Groups"));
1122 SetClassLong (dlg, GCL_HICON, (LONG)LoadIcon (glob_hinst,
1123 (LPCTSTR)IDI_WINPT));
1124 SetForegroundWindow (dlg);
1125 force_foreground_window (dlg, 1000);
1126 return TRUE;
1127
1128 case WM_DESTROY:
1129 save_column_info (kmi->lv);
1130 if (kmi->lv) {
1131 keylist_delete (kmi->lv);
1132 kmi->lv = NULL;
1133 }
1134 imagelist_destroy ();
1135
1136 ltoa (kmi->pos_x, type, 10);
1137 set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", type);
1138 ltoa (kmi->pos_y, type, 10);
1139 set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", type);
1140
1141 /* Remove runtime information. This should be the last action taken here. */
1142 delete kmi; kmi = NULL;
1143 SetWindowLong (dlg, GWL_USERDATA, 0);
1144 return FALSE;
1145
1146 case WM_SHOWWINDOW:
1147 /*refresh_keylist (kmi);*/
1148 break;
1149
1150 case WM_MOVE:
1151 RECT r;
1152 GetWindowRect (dlg, &r);
1153 kmi->pos_x = r.left;
1154 kmi->pos_y = r.top;
1155 break;
1156
1157
1158 case WM_RBUTTONUP:
1159 do_create_minpopup (dlg);
1160 break;
1161
1162 case WM_NOTIFY:
1163 NMHDR *notify;
1164 POINT p;
1165 HMENU popup;
1166
1167 notify = (NMHDR *)lparam;
1168 if (!notify)
1169 break;
1170 switch (notify->code) {
1171 case TBN_QUERYDELETE:
1172 SetWindowLong (dlg, DWL_MSGRESULT, TRUE);
1173 return TRUE;
1174
1175 case TBN_QUERYINSERT:
1176 SetWindowLong (dlg, DWL_MSGRESULT, TRUE);
1177 return TRUE;
1178
1179 case TBN_GETBUTTONINFO:
1180 LPTBNOTIFY lpTbNotify;
1181 lpTbNotify = (LPTBNOTIFY)lparam;
1182 if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) {
1183 lpTbNotify->tbButton.iBitmap = imagelist_getindex (myb[lpTbNotify->iItem].icon);
1184 lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command;
1185 lpTbNotify->tbButton.fsState = TBSTATE_ENABLED;
1186 lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON;
1187 lpTbNotify->tbButton.iString = 0;
1188 strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText);
1189 SetWindowLong(dlg, DWL_MSGRESULT, TRUE);
1190 }
1191 return TRUE;
1192
1193 case TBN_RESET: /* Restore last saved toolbar status */
1194 TBSAVEPARAMS tbsp;
1195
1196 tbsp.hkr = HKEY_CURRENT_USER;
1197 tbsp.pszSubKey = "Software\\WinPT";
1198 tbsp.pszValueName = "KM_toolbar";
1199 SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp);
1200 break;
1201
1202 case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */
1203 tbsp.hkr = HKEY_CURRENT_USER;
1204 tbsp.pszSubKey = "Software\\WinPT";
1205 tbsp.pszValueName = "KM_toolbar";
1206 SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);
1207 break;
1208
1209 case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */
1210 tbsp.hkr = HKEY_CURRENT_USER;
1211 tbsp.pszSubKey = "Software\\WinPT";
1212 tbsp.pszValueName = "KM_toolbar";
1213 SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);
1214 break;
1215
1216 case TTN_GETDISPINFO:
1217 LPTOOLTIPTEXT lpttt;
1218 lpttt = (LPTOOLTIPTEXT)lparam;
1219
1220 lpttt->hinst = NULL;
1221 switch (lpttt->hdr.idFrom) {
1222 case ID_KEYMISC_KEYWIZARD:
1223 lpttt->lpszText = (char*)_("Generate new key pair");
1224 break;
1225
1226 case ID_KEYMISC_SENDRECV:
1227 lpttt->lpszText = (char*)_("Search for a specific key");
1228 break;
1229
1230 case ID_KEYMISC_DELETE:
1231 lpttt->lpszText = (char *)_("Delete key from keyring");
1232 break;
1233
1234 case ID_KEYMISC_PROPS:
1235 lpttt->lpszText = (char *)_("Show key properties");
1236 break;
1237
1238 case ID_KEYMISC_SIGN:
1239 lpttt->lpszText = (char *)_("Sign key");
1240 break;
1241
1242 case ID_KEYCTX_COPY:
1243 lpttt->lpszText = (char *)_("Copy key to clipboard");
1244 break;
1245
1246 case ID_KEYCTX_PASTE:
1247 lpttt->lpszText = (char*)_("Paste key from clipboard");
1248 break;
1249
1250 case ID_KEYMISC_IMPORT:
1251 lpttt->lpszText = (char *)_("Import key to keyring");
1252 break;
1253
1254 case ID_KEYMISC_EXPORT:
1255 lpttt->lpszText = (char *)_("Export key to a file");
1256 break;
1257 }
1258 return TRUE;
1259
1260 case LVN_ITEMCHANGED:
1261 if (((LPNMLISTVIEW)lparam)->uNewState) { /* item selected? */
1262 kmi->lv_idx = listview_get_curr_pos (kmi->lv);
1263 update_ui_items (dlg, kmi->lv);
1264 return TRUE;
1265 }
1266 break;
1267
1268 case NM_RCLICK:
1269 if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
1270 l_idx =listview_get_curr_pos (kmi->lv);
1271 if (l_idx == -1)
1272 return TRUE; /* Popup only when a item was selected */
1273 GetCursorPos (&p);
1274 hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX));
1275 popup = GetSubMenu (hm, 0);
1276 translate_popupmenu_strings (popup);
1277
1278 if (km_check_for_seckey (kmi->lv, l_idx, &i))
1279 set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED);
1280 if (i == 0)
1281 set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED);
1282 if (!km_check_for_seckey (kmi->lv, l_idx, NULL) ||
1283 (km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED)) {
1284 set_menu_state (popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED);
1285 set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);
1286 set_menu_state (popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED);
1287 set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);
1288 set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED );
1289 set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED);
1290 }
1291 else if (km_check_for_seckey (kmi->lv, l_idx, NULL) &&
1292 km_key_is_v3 (kmi->lv, l_idx)) {
1293 /* PGP 2 keys, version 3 have no no support for photo-id's,
1294 designated revokers and secondary keys. */
1295 set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);
1296 set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);
1297 set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED);
1298 }
1299 if (km_get_key_status( kmi->lv, l_idx ) & KM_FLAG_DISABLED)
1300 set_menu_state (popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED);
1301 else
1302 set_menu_state (popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED);
1303 if (km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED ||
1304 km_get_key_status (kmi->lv, l_idx) & KM_FLAG_EXPIRED)
1305 set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED);
1306 if (!clip_contains_pgpkey ())
1307 set_menu_state (popup, ID_KEYCTX_PASTE, MF_DISABLED|MF_GRAYED);
1308 if (mapi_init ())
1309 set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED);
1310 /* Override 'Default Keyserver' with the actual name. */
1311 host = kserver_get_hostname (0, -1, &port);
1312 set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host);
1313 popup_gpg_readonly (dlg, popup);
1314 if (listview_count_items (kmi->lv, 1) > 1)
1315 popup_multiple (dlg, popup);
1316 TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
1317 DestroyMenu (popup);
1318 DestroyMenu (hm);
1319 return TRUE;
1320 }
1321 break;
1322
1323 case LVN_COLUMNCLICK:
1324 if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
1325 NMLISTVIEW *nft = (LPNMLISTVIEW) lparam;
1326 int sortby = 0;
1327 switch (nft->iSubItem) {
1328 case 0: sortby = KEY_SORT_USERID; break;
1329 case 1: sortby = KEY_SORT_KEYID; break;
1330 case 2: sortby = KEY_SORT_IS_SECRET; break;
1331 case 3: sortby = KEY_SORT_LEN; break;
1332 case 5: sortby = KEY_SORT_VALIDITY; break;
1333 case 6: sortby = KEY_SORT_OTRUST; break;
1334 case 7: sortby = KEY_SORT_CREATED; break;
1335 case 8: sortby = KEY_SORT_ALGO; break;
1336 default: return TRUE; //sortby = KEY_SORT_USERID; break;
1337 }
1338
1339 if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby)
1340 kmi->keylist_sortby ^= KEYLIST_SORT_DESC;
1341 else
1342 kmi->keylist_sortby = sortby;
1343 keylist_sort (kmi->lv, kmi->keylist_sortby);
1344 return TRUE;
1345 }
1346 break;
1347 }
1348 break;
1349
1350 case WM_WINDOWPOSCHANGING:
1351 if (((WINDOWPOS*)lparam)->cx < 400)
1352 ((WINDOWPOS*)lparam)->cx = 400;
1353 if (((WINDOWPOS*)lparam)->cy < 200)
1354 ((WINDOWPOS*)lparam)->cy = 200;
1355 return TRUE;
1356
1357 case WM_SIZE:
1358 do_resize_window (dlg, kmi);
1359 return TRUE;
1360
1361 case WM_SYSCOMMAND:
1362 if (LOWORD (wparam) == SC_CLOSE)
1363 EndDialog (dlg, TRUE);
1364 return FALSE;
1365
1366 case WM_MENUSELECT:
1367 change_edit_menu (kmi->lv, (HMENU)lparam, LOWORD (wparam));
1368 change_key_menu ((HMENU)lparam, LOWORD (wparam));
1369 break;
1370
1371 case WM_INITMENUPOPUP:
1372 if ((UINT)LOWORD (lparam) == 3) {
1373 HMENU h = (HMENU)wparam;
1374 set_menu_text_bypos (h, 0, _("New"));
1375 }
1376 /* XXX: before we can use it, we need to find a way to
1377 update the gpg access timestamp after each operation.
1378 if (keyring_check_last_access ()) {
1379 keycache_reload (dlg);
1380 keylist_reload (kmi->lv, keycache_get_ctx (1),
1381 KEYLIST_LIST, KEY_SORT_USERID);
1382 }*/
1383 return FALSE;
1384
1385 case WM_COMMAND:
1386 /* Allow at least 'Exit' in such a case. */
1387 if (gnupg_access_keyring (1) && LOWORD (wparam) != ID_KEYMISC_QUIT) {
1388 msg_box (dlg, _("Could not access public keyring"),
1389 _("Key Manager"), MB_ERR);
1390 return FALSE;
1391 }
1392
1393 switch (LOWORD (wparam)) {
1394 case ID_KEYMISC_QUIT:
1395 EndDialog (dlg, TRUE);
1396 return TRUE;
1397
1398 case ID_KEYMISC_FIND:
1399 km_find_key (dlg, kmi->lv);
1400 break;
1401
1402 case ID_KEYMISC_DELETE:
1403 case ID_KEYMISC_DELETE2:
1404 if (!km_delete_keys (kmi->lv, dlg))
1405 update_status_bar (kmi->statbar, kmi->lv);
1406 return TRUE;
1407
1408 case ID_KEYMISC_SIGN:
1409 if (kmi->lv_idx == -1) {
1410 msg_box (dlg, _("Please select a key."),
1411 _("Key Manager"), MB_ERR);
1412 return TRUE;
1413 }
1414 if (km_check_key_status (kmi->lv, kmi->lv_idx))
1415 return TRUE;
1416 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1417 memset (&k, 0, sizeof (k));
1418 strncpy (k.tmp_keyid, key->subkeys->keyid+8, 8);
1419 k.ctx = key;
1420 k.keyid = key->subkeys->keyid;
1421 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg,
1422 keysign_dlg_proc, (LPARAM)&k,
1423 _("Key Signing"), IDS_WINPT_KEYSIGN);
1424 if (k.update)
1425 update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1426 return TRUE;
1427
1428 case ID_KEYMISC_REVCERT:
1429 if (kmi->lv_idx == -1) {
1430 msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1431 return TRUE;
1432 }
1433 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1434 if (!key)
1435 BUG (NULL);
1436 if (!km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL)) {
1437 msg_box (dlg, _("There is no secret key available!"),
1438 _("Key Manager"), MB_ERR);
1439 return TRUE;
1440 }
1441
1442 {
1443 char state[64];
1444 listview_get_item_text (kmi->lv, kmi->lv_idx, 5,
1445 state, sizeof (state) -1);
1446 if (strchr (state, 'R' )) {
1447 msg_box (dlg, _("Key already revoked!"),
1448 _("Key Manager"), MB_INFO);
1449 return TRUE;
1450 }
1451 }
1452
1453 memset (&k, 0, sizeof (k));
1454 k.key_pair = 1;
1455 k.keyid = key->subkeys->keyid+8;
1456 k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);
1457 dialog_box_param(glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg,
1458 key_revoke_dlg_proc, (LPARAM)&k,
1459 _("Key Revocation Cert"), IDS_WINPT_KEYREVOKE);
1460 return TRUE;
1461
1462 case ID_KEYMISC_TRUSTPATH:
1463 if (kmi->lv_idx == -1) {
1464 msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1465 return TRUE;
1466 }
1467 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1468 if (km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL)) {
1469 msg_box (dlg, _("It does not make any sense with a key pair!"),
1470 _("Key Manager"), MB_ERR);
1471 return TRUE;
1472 }
1473 memset (&k, 0, sizeof (k));
1474 k.keyid = key->subkeys->keyid+8;
1475 k.uid = key->uids->uid;
1476 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg,
1477 keytrust_dlg_proc, (LPARAM)&k,
1478 _("List Trust Path"), IDS_WINPT_KEYTRUST);
1479 return TRUE;
1480
1481 case ID_KEYMISC_CHECKSIGS:
1482 if (kmi->lv_idx == -1) {
1483 msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1484 return TRUE;
1485 }
1486 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1487 if (!key)
1488 BUG (NULL);
1489 memset (&k, 0, sizeof (k));
1490 strncpy (k.tmp_keyid, key->subkeys->keyid+8, 8);
1491 k.keyid = k.tmp_keyid;
1492 k.uid = key->uids->uid;
1493 k.ctx = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1494 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG, dlg,
1495 keysig_dlg_proc, (LPARAM)&k,
1496 _("Key Signature List" ), IDS_WINPT_KEYSIG);
1497 if (k.update)
1498 update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0);
1499 return TRUE;
1500
1501 case ID_KEYMISC_PROPS:
1502 if (kmi->lv_idx == -1) {
1503 msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );
1504 return TRUE;
1505 }
1506 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1507 if (!key)
1508 BUG (NULL);
1509 memset (&k, 0, sizeof (k));
1510 k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL)? 1 : 0;
1511 k.keyid = key->subkeys->keyid+8;
1512 k.callback.ctl = kmi->lv;
1513 k.callback.idx = kmi->lv_idx;
1514 k.is_v3 = km_key_is_v3 (kmi->lv, kmi->lv_idx);
1515 dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg,
1516 keyprops_dlg_proc, (LPARAM)&k,
1517 _("Key Properties"), IDS_WINPT_KEYPROPS );
1518 if (k.callback.new_val != 0) {
1519 t = get_key_trust_str (k.callback.new_val);
1520 listview_add_sub_item (kmi->lv, kmi->lv_idx, 6, t);
1521 }
1522 if (k.update)
1523 refresh_keylist (kmi);
1524 return TRUE;
1525
1526 case ID_KEYMISC_RECACHE:
1527 if (updated_keys_avail ())
1528 l_idx = IDYES;
1529 else {
1530 char inf[256];
1531 _snprintf (inf, sizeof (inf) -1,
1532 _("This is only useful when the keyring has been "
1533 "modified (sign a key...).\n"
1534 "Do you really want to reload the keycache?"));
1535 l_idx = msg_box (dlg, inf, _("Key Manager"), MB_YESNO);
1536 }
1537 if (l_idx == IDYES) {
1538 rcs.kr_reload = rcs.kr_update = 1;
1539 rcs.tr_update = 0;
1540 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
1541 keycache_dlg_proc, (LPARAM)&rcs);
1542 c = keycache_get_ctx (1);
1543 if (!c)
1544 BUG (dlg);
1545 keylist_reload (kmi->lv, c, KEYLIST_LIST, KEY_SORT_USERID);
1546 }
1547 SetForegroundWindow (dlg);
1548 return TRUE;
1549
1550 case ID_KEYMISC_REBUILD:
1551 name = NULL;
1552 gpg_rebuild_cache (&name);
1553 if (name != NULL) {
1554 char *line = strchr (name, '\n');
1555 show_msg (dlg, 2000, line? name + (line-name)+1 : name);
1556 safe_free (name);
1557 }
1558 SetForegroundWindow (dlg);
1559 return TRUE;
1560
1561 case ID_KEYMISC_NEWKEY:
1562 memset (&genkey, 0, sizeof (genkey));
1563 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,
1564 keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),
1565 IDS_WINPT_KEYGEN);
1566 if (genkey.cancel == 0)
1567 refresh_keylist (kmi);
1568 return TRUE;
1569
1570 case ID_KEYMISC_CARDNEW:
1571 if (!scard_support) {
1572 msg_box (dlg, _("Smart Card support is not available."),
1573 _("Key Manager"), MB_INFO);
1574 return TRUE;
1575 }
1576 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg,
1577 card_keygen_dlg_proc, 0, _("Card Key Generation"),
1578 IDS_WINPT_CARD_KEYGEN);
1579 if (updated_keys_avail ())
1580 send_cmd_id (dlg, ID_KEYMISC_RECACHE);
1581 return TRUE;
1582
1583 case ID_KEYMISC_KEYWIZARD:
1584 memset (&genkey, 0, sizeof (genkey));
1585 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg,
1586 keygen_wizard_dlg_proc, (LPARAM)&genkey,
1587 _("Key Generation Wizard"),
1588 IDS_WINPT_KEYWIZARD);
1589 if (genkey.cancel == 0)
1590 refresh_keylist (kmi);
1591 return TRUE;
1592
1593 case ID_KEYMISC_SENDRECV:
1594 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,
1595 keyserver_dlg_proc, 0, _("Keyserver Access"),
1596 IDS_WINPT_KEYSERVER);
1597 refresh_keylist (kmi);
1598 return TRUE;
1599
1600 case ID_KEYMISC_GPGPREFS:
1601 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, dlg,
1602 gpgprefs_dlg_proc, 0, _("GnuPG Preferences"),
1603 IDS_WINPT_GPGPREFS);
1604 return TRUE;
1605
1606 case ID_KEYMISC_GPGOPT:
1607 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg,
1608 gpgopt_dlg_proc, 0, _("GnuPG Options"),
1609 IDS_WINPT_GPGOPT);
1610 return TRUE;
1611
1612 case ID_KEYMISC_IMPORT:
1613 t = get_fileopen_dlg (dlg, _("Choose Name of the Key File"),
1614 NULL, NULL);
1615 if (!t)
1616 break;
1617 if (!km_file_import (dlg, t))
1618 refresh_keylist (kmi);
1619 return TRUE;
1620
1621 case ID_KEYMISC_IMPORT_HTTP:
1622 url = (struct URL_ctx_s*)get_http_file_dlg (dlg);
1623 if (url->cancel == 0) {
1624 km_http_import (dlg, url->url);
1625 refresh_keylist (kmi);
1626 }
1627 free_if_alloc (url);
1628 break;
1629
1630 case ID_KEYMISC_EXPORT:
1631 if (kmi->lv_idx == -1) {
1632 msg_box (dlg, _("Please select a key."),
1633 _("Key Manager"), MB_ERR);
1634 return TRUE;
1635 }
1636 if (listview_count_items (kmi->lv, 1) > 1)
1637 name = m_strdup ("Exported_GPG_Keys.asc");
1638 else {
1639 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1640 name = km_gen_export_filename (key->subkeys->keyid+8, 0);
1641 }
1642 t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
1643 free_if_alloc (name);
1644 if (t == NULL)
1645 return TRUE;
1646 km_file_export (dlg, kmi->lv, t);
1647 return TRUE;
1648
1649 case ID_KEYMISC_EXPORT_PRIVKEY:
1650 if (kmi->lv_idx == -1) {
1651 msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR);
1652 return TRUE;
1653 }
1654 if( !km_check_for_seckey( kmi->lv, kmi->lv_idx, NULL ) ) {
1655 msg_box (dlg, _("There is no corresponding secret key for this key."),
1656 _("Key Manager"), MB_ERR);
1657 return TRUE;
1658 }
1659 if (listview_count_items (kmi->lv, 1) > 1) {
1660 msg_box (dlg, _("You can only export one secret key."),
1661 _("Key Manager"), MB_ERR);
1662 return TRUE;
1663 }
1664 i = msg_box (dlg,
1665 _("This operation will export your *SECRET* key!\n\n"
1666 "Never send this key to ANYONE, it should be available\n"
1667 "ONLY on your machine and you may use this function\n"
1668 "to copy the key to a safe place.\n\n"
1669 "Do you really want to export the key?"),
1670 _("WARNING"), MB_INFO|MB_YESNO);
1671 if (i == IDYES) {
1672 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1673 if (!key)
1674 BUG (NULL);
1675 name = km_gen_export_filename (key->subkeys->keyid+8, 1);
1676 t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name);
1677 if (t != NULL)
1678 km_privkey_export (dlg, kmi->lv, t);
1679 }
1680 return TRUE;
1681
1682 case ID_KEYMISC_INFO:
1683 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, glob_hwnd,
1684 about_winpt_dlg_proc, 0, _("About WinPT"),
1685 IDS_WINPT_ABOUT);
1686 break;
1687
1688 case ID_KEYMISC_WEBSITE:
1689 ShellExecute (dlg, "open", "http://www.winpt.org",
1690 NULL, NULL, SW_SHOW);
1691 break;
1692
1693 case ID_KEYMISC_HELP:
1694 start_help (dlg, 0);
1695 break;
1696
1697 case ID_KEYMISC_OT:
1698 dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST,
1699 glob_hwnd, ownertrust_dlg_proc, 0,
1700 _("Ownertrust"), IDS_WINPT_OWNERTRUST);
1701 break;
1702
1703 case ID_KEYMISC_EDITKEY:
1704 if (kmi->lv_idx == -1)
1705 break;
1706 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1707 if (!key)
1708 BUG (NULL);
1709 /* XXX: pub/crd = secret key does not work */
1710 memset (&k, 0, sizeof (k));
1711 strncpy (k.tmp_keyid, key->subkeys->keyid+8, 8);
1712 k.keyid = k.tmp_keyid;
1713 k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);
1714 k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);
1715 k.is_v3 = km_key_is_v3 (kmi->lv, kmi->lv_idx);
1716 k.flags = km_get_key_status (kmi->lv, kmi->lv_idx);
1717 dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg,
1718 keyedit_main_dlg_proc, (LPARAM)&k,
1719 _("Key Edit"), IDS_KEYCTX_EDIT);
1720 if (k.update)
1721 update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1722 break;
1723
1724 case ID_KEYMISC_COPY:
1725 km_clip_export (dlg, kmi->lv);
1726 break;
1727
1728 case ID_KEYMISC_SELALL:
1729 listview_select_all (kmi->lv);
1730 break;
1731
1732 case ID_KEYMISC_PASTE:
1733 if (!km_clip_import (dlg))
1734 refresh_keylist (kmi);
1735 break;
1736
1737 case ID_KEYCTX_SETPREFKS:
1738 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1739 if (!key)
1740 BUG (NULL);
1741 memset (&k, 0, sizeof (k));
1742 k.keyid = key->subkeys->keyid+8;
1743 keyedit_set_pref_keyserver (&k, dlg);
1744 break;
1745
1746 case ID_KEYMISC_REFRESH_KEYS:
1747 if (listview_count_items (kmi->lv, 1) == 0) {
1748 msg_box (dlg, _("No key was selected, select all by default."),
1749 _("Key Manager"), MB_INFO);
1750 listview_select_all (kmi->lv);
1751 }
1752 km_refresh_from_keyserver (kmi->lv, dlg);
1753 break;
1754
1755 /** Context menu **/
1756 case ID_KEYCTX_EDIT:
1757 send_cmd_id( dlg, ID_KEYMISC_EDITKEY );
1758 break;
1759
1760 case ID_KEYCTX_PROPS:
1761 send_cmd_id( dlg, ID_KEYMISC_PROPS );
1762 break;
1763
1764 case ID_KEYCTX_UIDS:
1765 send_cmd_id( dlg, ID_KEYMISC_UID );
1766 break;
1767
1768 case ID_KEYCTX_SIGN:
1769 send_cmd_id( dlg, ID_KEYMISC_SIGN );
1770 break;
1771
1772 case ID_KEYCTX_DEL:
1773 send_cmd_id (dlg, ID_KEYMISC_DELETE);
1774 break;
1775
1776 case ID_KEYCTX_REV:
1777 send_cmd_id( dlg, ID_KEYMISC_REVCERT );
1778 break;
1779
1780 case ID_KEYCTX_SENDMAIL:
1781 km_send_to_mail_recipient (kmi->lv, dlg);
1782 break;
1783
1784 case ID_KEYCTX_KS_DEFAULT:
1785 host = kserver_get_hostname (0, -1, &port);
1786 km_send_to_keyserver (kmi->lv, dlg, host, port);
1787 break;
1788
1789 case ID_KEYCTX_ADDKEY:
1790 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1791 if (!key)
1792 BUG (NULL);
1793 memset (&k, 0, sizeof (k));
1794 strncpy (k.tmp_keyid, key->subkeys->keyid+8, 8);
1795 k.keyid = k.tmp_keyid;
1796 k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);
1797 k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);
1798 keyedit_add_subkey (&k, dlg, NULL);
1799 if (k.update)
1800 update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1801 break;
1802
1803 case ID_KEYCTX_ADDUID:
1804 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1805 if (!key)
1806 BUG (NULL);
1807 memset (&k, 0, sizeof (k));
1808 strncpy (k.tmp_keyid, key->subkeys->keyid+8, 8);
1809 k.keyid = k.tmp_keyid;
1810 k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);
1811 k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);
1812 keyedit_add_userid (&k, dlg, NULL);
1813 if (k.update)
1814 update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1815 break;
1816
1817 case ID_KEYCTX_ADDREV:
1818 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1819 if (!key)
1820 BUG (NULL);
1821 memset (&k, 0, sizeof (k));
1822 strncpy (k.tmp_keyid, key->subkeys->keyid+8, 8);
1823 k.keyid = k.tmp_keyid;
1824 k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);
1825 k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);
1826 keyedit_add_revoker (&k, dlg);
1827 if (k.update)
1828 update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1829 break;
1830
1831 case ID_KEYCTX_ADDPHOTO:
1832 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1833 if (!key)
1834 BUG (NULL);
1835 memset (&k, 0, sizeof (k));
1836 strncpy (k.tmp_keyid, key->subkeys->keyid+8, 8);
1837 k.keyid = k.tmp_keyid;
1838 k.is_protected = km_check_if_protected (kmi->lv, kmi->lv_idx);
1839 k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL);
1840 keyedit_add_photo (&k, dlg);
1841 if (k.update)
1842 update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1);
1843 break;
1844
1845 case ID_KEYCTX_KS_NL:
1846 case ID_KEYCTX_KS_PL:
1847 case ID_KEYCTX_KS_AT:
1848 case ID_KEYCTX_KS_DE:
1849 case ID_KEYCTX_KS_DK:
1850 case ID_KEYCTX_KS_CZ:
1851 case ID_KEYCTX_KS_ES:
1852 case ID_KEYCTX_KS_UK:
1853 host = kserver_get_hostname (LOWORD (wparam) - 40107, 0, &port);
1854 km_send_to_keyserver (kmi->lv, dlg, host, port);
1855 break;
1856
1857 case ID_KEYCTX_RECVFROM:
1858 km_refresh_from_keyserver (kmi->lv, dlg);
1859 break;
1860
1861 case ID_KEYCTX_UID_COPY:
1862 /* XXX: add generic function to support multiple selection
1863 with a callback */
1864 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1865 name = utf8_to_wincp2 (key->uids->uid);
1866 set_clip_text (NULL, name, strlen (name));
1867 safe_free (name);
1868 break;
1869
1870 case ID_KEYCTX_KEYID_COPY:
1871 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1872 set_clip_text (NULL, key->subkeys->keyid+8,
1873 strlen (key->subkeys->keyid+8));
1874 break;
1875
1876 case ID_KEYCTX_FPR_COPY:
1877 key = (gpgme_key_t) listview_get_item2 (kmi->lv, kmi->lv_idx);
1878 t = key->subkeys->fpr;
1879 set_clip_text (NULL, t? t : "", t? strlen (t): 0);
1880 break;
1881
1882 case ID_KEYCTX_KINFO_COPY:
1883 key = (gpgme_key_t) listview_get_item2 (kmi->lv, kmi->lv_idx);
1884 if (!key)
1885 BUG (NULL);
1886 km_set_clip_info (key->subkeys->keyid+8);
1887 break;
1888
1889 case ID_KEYCTX_COPY:
1890 send_cmd_id (dlg, ID_KEYMISC_COPY);
1891 break;
1892
1893 case ID_KEYCTX_PASTE:
1894 send_cmd_id (dlg, ID_KEYMISC_PASTE);
1895 break;
1896
1897 case ID_KEYCTX_DISABLE:
1898 case ID_KEYCTX_ENABLE:
1899 i = LOWORD (wparam) == ID_KEYCTX_ENABLE? 1 : 0;
1900 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1901 if (!key)
1902 BUG (NULL);
1903 rc = km_enable_disable_key (kmi->lv, dlg, kmi->lv_idx, i);
1904 if (!rc)
1905 update_key (kmi->lv, kmi->lv_idx, key->subkeys->keyid+8, 0);
1906 /* XXX: switching a key from disabled -> enabled. does not
1907 change the validity field in the KM. */
1908 break;
1909
1910 case ID_KEYCTX_LISTSIGS:
1911 send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS);
1912 break;
1913
1914 case ID_KEYCTX_MAXTRUST:
1915 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1916 if (!key)
1917 BUG (NULL);
1918 rc = km_set_implicit_trust (dlg, kmi->lv, kmi->lv_idx);
1919 if (!rc)
1920 update_key (kmi->lv, kmi->lv_idx, key->subkeys->keyid+8, 0);
1921 break;
1922
1923 case ID_KEYCTX_SETDEFKEY:
1924 if (!km_check_key_status (kmi->lv, kmi->lv_idx)) {
1925 key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx);
1926 rc = set_gnupg_default_key (key->subkeys->keyid+8);
1927 if (rc)
1928 msg_box (dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);
1929 update_default_key_str (kmi->statbar);
1930 }
1931 break;
1932
1933 case ID_KEYMISC_VIEWKEYID:
1934 case ID_KEYMISC_VIEWCIPHER:
1935 case ID_KEYMISC_VIEWTYPE:
1936 case ID_KEYMISC_VIEWCREAT:
1937 DWORD n;
1938
1939 hm = GetMenu (dlg);
1940 n = get_menu_state (hm, LOWORD (wparam));
1941 set_menu_state (hm, LOWORD (wparam),
1942 n & MFS_CHECKED? MFS_UNCHECKED : MFS_CHECKED);
1943 modify_listview_columns (kmi, LOWORD (wparam), !(n & MFS_CHECKED));
1944 break;
1945
1946 case ID_GROUP_NEW:
1947 case ID_GROUP_PASTE:
1948 case ID_GROUP_DELETE:
1949 /* XXX: Implement group manager. */
1950 return TRUE;
1951
1952 case IDCANCEL:
1953 EndDialog (dlg, TRUE);
1954 return TRUE;
1955 }
1956
1957 break;
1958 }
1959
1960 return FALSE;
1961 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26