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

Annotation of /trunk/Src/wptKeyManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (hide annotations)
Sat Oct 8 10:43:08 2005 UTC (19 years, 4 months ago) by twoaday
File size: 51777 byte(s)
Bug fixes to correct some problems introduced by
the MyGPGME to GPGME port.

1 twoaday 2 /* wptKeyManagerDlg.cpp - WinPT Key Manager
2 twoaday 16 * Copyright (C) 2000-2005 Timo Schulz
3 twoaday 2 * 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    
22     #include <windows.h>
23     #include <commctrl.h>
24    
25     #include "../resource.h"
26     #include "wptTypes.h"
27     #include "wptGPG.h"
28     #include "wptCommonCtl.h"
29     #include "wptContext.h" /* for passphrase_s */
30     #include "wptDlgs.h"
31     #include "wptW32API.h"
32     #include "wptVersion.h"
33     #include "wptKeylist.h"
34     #include "wptNLS.h"
35     #include "wptErrors.h"
36     #include "wptHotkey.h"
37     #include "wptKeyManager.h"
38     #include "wptKeyserver.h"
39     #include "wptKeyEdit.h"
40     #include "wptRegistry.h"
41    
42    
43     #define WINDOWCLASS_SEPARATOR_CHILD "WINPT_SEP_CHILD"
44     #define SEPARATOR_HEIGHT 5
45    
46 twoaday 22 void km_dump_key (gpgme_key_t key);
47 twoaday 2
48 twoaday 22
49 twoaday 2 static subclass_s keylist_proc;
50     static int km_index = -1;
51    
52     HIMAGELIST glob_imagelist;
53    
54     struct km_info {
55     /* Window positions */
56     int pos_x, pos_y;
57     int ypos_sep;
58     int ypercent_sep;
59    
60     HWND hwnd_sep;
61     HWND toolbar;
62     HWND statbar;
63    
64     listview_ctrl_t lv;
65     int keylist_sortby;
66     };
67    
68     struct mybuttons {
69     long icon;
70     long command;
71     char *text;
72     };
73    
74     struct mybuttons myb[] = {
75     {IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"},
76     {IMI_KEY_PROPS, ID_KEYMISC_PROPS, "Properties"},
77     {IMI_KEY_SIGN, ID_KEYMISC_SIGN, "Sign"},
78     {IMI_KEY_IMPORT, ID_KEYMISC_IMPORT, "Import"},
79     {IMI_KEY_EXPORT, ID_KEYMISC_EXPORT, "Export"},
80     };
81    
82    
83 twoaday 22 #ifndef VK_F
84     #define VK_F 70
85     #endif
86     #ifndef VK_A
87     #define VK_A 65
88     #endif
89     #ifndef VK_C
90     #define VK_C 67
91     #endif
92     #ifndef VK_P
93     #define VK_P 80
94     #endif
95    
96 twoaday 2 static BOOL CALLBACK
97     keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
98     {
99 twoaday 22 struct listview_ctrl_s lv;
100    
101     switch (msg) {
102 twoaday 2 case WM_LBUTTONDBLCLK:
103 twoaday 22 send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS);
104 twoaday 2 break;
105    
106     case WM_KEYUP:
107     int virt_key = (int)wparam;
108 twoaday 22 switch (virt_key) {
109     case VK_SPACE:
110 twoaday 2 send_cmd_id( keylist_proc.dlg, ID_KEYMISC_PROPS );
111     break;
112 twoaday 22
113     case VK_DELETE:
114 twoaday 2 send_cmd_id( keylist_proc.dlg, ID_KEYMISC_DELETE );
115     break;
116 twoaday 22
117     case VK_INSERT:
118 twoaday 2 send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE);
119     break;
120 twoaday 22
121     case VK_A:
122     if (GetAsyncKeyState (VK_CONTROL)) {
123     lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
124     listview_select_all (&lv);
125     }
126     break;
127    
128     case VK_C:
129     if (GetAsyncKeyState (VK_CONTROL)) {
130     lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
131     km_index = listview_get_curr_pos (&lv);
132     km_clip_export (keylist_proc.dlg, &lv);
133     }
134     break;
135    
136     case VK_P:
137     if (GetAsyncKeyState (VK_CONTROL)) {
138     km_index = -1;
139     km_clip_import (keylist_proc.dlg);
140     }
141     break;
142    
143     case VK_F:
144     if (GetAsyncKeyState (VK_CONTROL)) {
145     lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST);
146     km_find_key (dlg, &lv);
147     }
148     break;
149 twoaday 2 }
150     break;
151     }
152    
153     return CallWindowProc( keylist_proc.old, dlg, msg, wparam, lparam );
154     } /* keylist_subclass_proc */
155    
156    
157     static HWND
158     load_toolbar (HWND dlg, struct km_info * kmi)
159     {
160     HWND tbwnd;
161     TBSAVEPARAMS tbsp;
162     TBBUTTON tb_buttons[] = {
163     /*{imagelist_getindex(IMI_EXIT), ID_KEYMISC_QUIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0L, 0},*/
164     {imagelist_getindex(IMI_KEY_DELETE), ID_KEYMISC_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
165     {imagelist_getindex(IMI_KEY_PROPS), ID_KEYMISC_PROPS, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
166     {imagelist_getindex(IMI_KEY_SIGN), ID_KEYMISC_SIGN, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
167     {0, 0, 0, TBSTYLE_SEP, {0}, 0L, 0},
168     {imagelist_getindex(IMI_KEY_IMPORT), ID_KEYMISC_IMPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
169     {imagelist_getindex(IMI_KEY_EXPORT), ID_KEYMISC_EXPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0},
170     };
171    
172     tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL,
173     WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE,
174     0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL);
175     if (tbwnd) {
176     SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
177     SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist);
178     SendMessage (tbwnd, TB_AUTOSIZE, 0, 0);
179     ShowWindow (tbwnd, SW_SHOW);
180    
181     /* Restore toolbar */
182     tbsp.hkr = HKEY_CURRENT_USER;
183     tbsp.pszSubKey = "Software\\WinPT";
184     tbsp.pszValueName = "KM_toolbar";
185     if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0)
186     SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]), (LONG)&tb_buttons[0]);
187     }
188     return tbwnd;
189     } /* load_toolbar */
190    
191    
192     static void
193     do_center_window (HWND dlg, struct km_info * kmi)
194     {
195     RECT rect;
196     char * p;
197     int pos_x = 0, pos_y = 0;
198    
199     /* Find bottom of keylist */
200     GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect);
201     MapWindowPoints (NULL, dlg, (POINT*)&rect, 2);
202    
203     kmi->ypos_sep = rect.bottom;
204    
205     p = get_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X" );
206     if( p && !strcmp( p, " " ) ) {
207     free_if_alloc( p );
208 twoaday 23 center_window( dlg, NULL );
209 twoaday 2 return;
210     }
211     else if( p )
212     pos_x = atol( p );
213    
214     p = get_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y" );
215     if( p && !strcmp( p, " " ) ) {
216     free_if_alloc( p );
217 twoaday 23 center_window( dlg, NULL );
218 twoaday 2 return;
219     }
220     else if( p )
221     pos_y = atol( p );
222    
223     if( !pos_y && !pos_x ) {
224 twoaday 23 center_window( dlg, NULL );
225 twoaday 2 return;
226     }
227    
228     if( pos_x > GetSystemMetrics( SM_CXSCREEN )
229     || pos_y > GetSystemMetrics( SM_CYSCREEN ) ) {
230     pos_x = pos_y = 0;
231     }
232     GetClientRect( dlg, &rect );
233     MoveWindow( dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE );
234     }
235    
236    
237     static void
238     do_resize_window( HWND dlg, struct km_info *kmi)
239     {
240     HWND h;
241     RECT rclient, rect;
242     BOOL bRepaint = FALSE;
243    
244     /* Get rect of client area and make life easier */
245     GetClientRect( dlg, &rclient );
246    
247     /* Move toolbar to the top of the window */
248     if (kmi->toolbar) {
249     GetWindowRect(kmi->toolbar, &rect);
250     ScreenToClient(dlg, (POINT*)&rect);
251     ScreenToClient(dlg, (POINT*)&(rect.right));
252    
253     rclient.top += rect.bottom - rect.top;
254     MoveWindow (kmi->toolbar, 0, 0, rclient.right - rclient.left,
255     rect.bottom - rect.top, bRepaint);
256     }
257    
258     /* Move statusbar to the bottom of the window */
259     if (kmi->statbar) {
260     GetWindowRect( kmi->statbar, &rect );
261     ScreenToClient(dlg, (POINT*)&rect);
262     ScreenToClient(dlg, (POINT*)&(rect.right));
263    
264     rclient.bottom -= rect.bottom - rect.top;
265     MoveWindow (kmi->statbar, 0, rclient.bottom, rclient.right - rclient.left,
266     rect.bottom - rect.top, bRepaint);
267     }
268    
269     // Obtain separator information and move it to the desired posistion
270     if (kmi->ypercent_sep)
271     kmi->ypos_sep = (rclient.bottom - rclient.top) * kmi->ypercent_sep / 100;
272     else
273     kmi->ypercent_sep = kmi->ypos_sep * 100 / (rclient.bottom - rclient.top);
274    
275     // Don't move away
276     if (kmi->ypos_sep+5 > rclient.bottom)
277     kmi->ypos_sep = rclient.bottom - 5;
278     if (kmi->ypos_sep < rclient.top)
279     kmi->ypos_sep = rclient.top;
280     MoveWindow (kmi->hwnd_sep, 0, kmi->ypos_sep, (rclient.right - rclient.left), 5, bRepaint);
281    
282     // Place the keylist above the separator
283     h = GetDlgItem( dlg, IDC_KEYMISC_KEYLIST );
284     MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,
285     kmi->ypos_sep - rclient.top, bRepaint);
286     rclient.top = kmi->ypos_sep + 5 + 8;
287    
288     /* Place the group text and the group box below the separator */
289     h = GetDlgItem( dlg, IDC_KEYMISC_GTEXT );
290     MoveWindow( h, rclient.left, rclient.top, 100, 14, bRepaint);
291     rclient.top += 18;
292    
293     h = GetDlgItem( dlg, IDC_KEYMISC_GROUP );
294     MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left,
295     (rclient.bottom < rclient.top) ? 0 : rclient.bottom - rclient.top, bRepaint);
296    
297     /* Repaint the whole thing */
298     InvalidateRect (dlg, NULL, TRUE);
299     } /* do_resize_window */
300    
301    
302     static void
303     do_create_minpopup (HWND dlg)
304     {
305     HMENU hm;
306     MENUITEMINFO mi;
307     char * s;
308     POINT p;
309    
310     if (gpg_read_only)
311     return;
312     hm = CreatePopupMenu ();
313     if (!hm)
314     BUG( NULL );
315     memset (&mi, 0, sizeof mi);
316     mi.cbSize = sizeof mi;
317     s = (char *)_("Paste Key from Clipboard");
318     mi.fType = MF_STRING;
319     mi.dwTypeData = s;
320     mi.cch = strlen (s);
321     mi.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
322     mi.wID = ID_KEYCTX_PASTE;
323     InsertMenuItem (hm, 0, FALSE, &mi);
324     GetCursorPos (&p);
325     TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);
326     DestroyMenu (hm);
327     } /* do_create_minpopup */
328    
329    
330     static void
331     do_check_cache( listview_ctrl_t lv, HWND dlg, HWND sb )
332     {
333     gpgme_keycache_t cache;
334    
335     if( keycache_get_reload( ) ) {
336     keycache_reload( dlg );
337     keycache_set_reload( 0 );
338     cache = keycache_get_ctx( 1 );
339     if( !cache )
340     BUG( dlg );
341 twoaday 23 keylist_reload( lv, cache, KEYLIST_LIST, KEY_SORT_USERID );
342     km_complete_status_bar (sb, lv);
343 twoaday 2 }
344     } /* do_check_cache */
345    
346    
347     long CALLBACK
348     separator_wnd_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
349     {
350     static POINT last_mouse_pos;
351    
352     if (msg == WM_CREATE)
353     SetWindowLong (hwnd, GWL_USERDATA, (long)(((CREATESTRUCT*)lparam)->lpCreateParams));
354    
355     switch (msg) {
356     case WM_PAINT:
357     PAINTSTRUCT ps;
358     RECT rect;
359     HPEN hpen;
360    
361     GetClientRect (hwnd, &rect);
362     BeginPaint (hwnd, &ps);
363    
364     // Background
365     FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1));
366    
367     // The lines from the light into the dark
368     MoveToEx(ps.hdc, 0,0, NULL);
369     if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DHILIGHT))) != NULL) {
370     SelectObject(ps.hdc, (LPVOID)hpen);
371     LineTo(ps.hdc, rect.right, 0);
372     DeleteObject(hpen);
373     }
374     MoveToEx(ps.hdc, 0, 1, NULL);
375     if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT))) != NULL) {
376     SelectObject(ps.hdc, (LPVOID)hpen);
377     LineTo(ps.hdc, rect.right, rect.bottom);
378     DeleteObject(hpen);
379     }
380    
381     MoveToEx(ps.hdc, 0, rect.bottom-1, NULL);
382     if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW))) != NULL) {
383     SelectObject(ps.hdc, (LPVOID)hpen);
384     LineTo(ps.hdc, rect.right, rect.bottom-1);
385     DeleteObject(hpen);
386     }
387     MoveToEx(ps.hdc, 0, rect.bottom, NULL);
388     if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW))) != NULL) {
389     SelectObject(ps.hdc, (LPVOID)hpen);
390     LineTo(ps.hdc, rect.right, rect.bottom);
391     DeleteObject(hpen);
392     }
393    
394     EndPaint (hwnd, &ps);
395     return 0;
396    
397     case WM_LBUTTONDOWN:
398     last_mouse_pos.x = LOWORD(lparam);
399     last_mouse_pos.y = HIWORD(lparam);
400     ClientToScreen (hwnd, &last_mouse_pos);
401     SetCapture (hwnd);
402     return 0;
403    
404     case WM_LBUTTONUP:
405     ReleaseCapture ();
406     return 0;
407    
408     case WM_MOUSEMOVE:
409     if (wparam == MK_LBUTTON) {
410     struct km_info *kmi;
411     POINT p;
412     RECT rect;
413    
414     if ((kmi = (struct km_info *)GetWindowLong (hwnd, GWL_USERDATA)) == NULL)
415     break;
416    
417     // Calculate mouse movement
418     p.x = LOWORD(lparam);
419     p.y = HIWORD(lparam);
420     ClientToScreen (hwnd, &p);
421    
422     GetWindowRect (hwnd, &rect);
423     rect.top += (short)(p.y - last_mouse_pos.y);
424     rect.bottom += (short)(p.y - last_mouse_pos.y);
425    
426     last_mouse_pos.y = p.y;
427    
428     // Apply mouse movement to window. Beware the MoveWindow is relaive
429     // to parent NOT screen
430     MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&rect, 2);
431     kmi->ypos_sep = rect.top;
432     kmi->ypercent_sep = 0; // This forces do_resize_window to use abs. position
433     do_resize_window (GetParent(hwnd), kmi);
434     return 0;
435     }
436     }
437    
438     return DefWindowProc (hwnd, msg, wparam, lparam);
439     }
440    
441    
442     static HWND
443     regist_sep_wnd (HWND dlg, struct km_info * kmi)
444     {
445     WNDCLASS wndclass;
446     HWND h;
447    
448     wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
449     wndclass.lpfnWndProc = separator_wnd_proc;
450     wndclass.cbClsExtra = 0;
451     wndclass.cbWndExtra = sizeof (long);
452     wndclass.hInstance = glob_hinst;
453     wndclass.hIcon = NULL;
454     wndclass.hCursor = LoadCursor (NULL, IDC_SIZENS);
455     wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
456     wndclass.lpszMenuName = 0;
457     wndclass.lpszClassName = WINDOWCLASS_SEPARATOR_CHILD;
458     RegisterClass (&wndclass);
459    
460     h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL,
461     WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
462     0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi);
463     ShowWindow (h, SW_SHOW);
464     return h;
465     } /* regist_sep_wnd */
466    
467    
468    
469     #define enable_button(hwnd, cid) \
470     SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG (key_selected, 0))
471    
472     void
473     update_ui_items (HWND hwnd, listview_ctrl_t lv)
474     {
475     int key_selected = 0, key_has_sec = 0;
476     int i, key_inv = 0;
477     HWND hwnd_child;
478     HMENU hmenu;
479    
480     /* Get some states */
481     key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST),
482     LVM_GETSELECTEDCOUNT, 0, 0)
483     ? TRUE : FALSE;
484     key_has_sec = FALSE;
485     if (key_selected) {
486     i = listview_get_curr_pos (lv);
487     key_has_sec = km_check_for_seckey( lv, i, NULL ) ? TRUE : FALSE;
488     key_inv = km_get_key_status (lv, i) & KM_FLAG_REVOKED;
489     }
490    
491     /* Enable / disable toolbar buttons */
492     hwnd_child = GetDlgItem(hwnd, IDR_WINPT_KMTB);
493     enable_button (hwnd_child, ID_KEYMISC_DELETE);
494     enable_button (hwnd_child, ID_KEYMISC_PROPS);
495     enable_button (hwnd_child, ID_KEYMISC_SIGN);
496     enable_button (hwnd_child, ID_KEYMISC_EXPORT);
497    
498     /* Enable / disable menu items */
499     hmenu = GetMenu (hwnd);
500     set_menu_state (hmenu, ID_KEYMISC_EXPORT, key_selected ? MF_ENABLED : MF_GRAYED);
501     set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY, key_has_sec ? MF_ENABLED : MF_GRAYED);
502     set_menu_state (hmenu, ID_KEYMISC_REVCERT, key_has_sec ? MF_ENABLED : MF_GRAYED);
503     set_menu_state (hmenu, ID_KEYMISC_DELETE, key_selected ? MF_ENABLED : MF_GRAYED);
504     set_menu_state (hmenu, ID_KEYMISC_PROPS, key_selected ? MF_ENABLED : MF_GRAYED);
505     set_menu_state (hmenu, ID_KEYMISC_SIGN, key_selected && !key_inv ? MF_ENABLED : MF_GRAYED);
506     } /* update_ui_items */
507    
508    
509     static void
510     popup_gpg_readonly (HWND dlg, HMENU hm)
511     {
512     int resids[] = {
513     ID_KEYCTX_PASTE,
514     ID_KEYCTX_EDIT,
515     ID_KEYCTX_SIGN,
516     ID_KEYCTX_REV,
517     ID_KEYCTX_DEL,
518     ID_KEYCTX_ENABLE,
519     ID_KEYCTX_DISABLE,
520     ID_KEYCTX_RECVFROM,
521     ID_KEYCTX_ADDKEY,
522     ID_KEYCTX_ADDPHOTO,
523     ID_KEYCTX_ADDUID,
524     ID_KEYCTX_ADDREV,
525     0
526     };
527     int i;
528    
529     if (gpg_read_only == 0)
530     return;
531     for (i=0; resids[i] != 0; i++)
532     set_menu_state (hm, resids[i], MF_GRAYED);
533     }
534    
535    
536     static void
537     menu_gpg_readonly (HWND dlg, HMENU hm, int id)
538     {
539 twoaday 19 int key_resids[] = {
540 twoaday 2 ID_KEYMISC_SIGN,
541     ID_KEYMISC_DELETE,
542     ID_KEYMISC_REVCERT,
543     ID_KEYMISC_IMPORT_HTTP,
544     ID_KEYMISC_IMPORT,
545     ID_KEYMISC_REFRESH_KEYS,
546     ID_KEYMISC_REBUILD,
547     ID_KEYMISC_KEYWIZARD,
548     ID_KEYMISC_CARDNEW,
549     ID_KEYMISC_NEWKEY,
550     0,
551     };
552 twoaday 19 int edit_resids[] = {
553 twoaday 2 ID_KEYMISC_PASTE,
554     ID_KEYMISC_OT,
555     ID_KEYMISC_EDITKEY,
556     0
557     };
558     int * resids;
559     int i;
560    
561    
562     if (gpg_read_only == 0)
563     return;
564 twoaday 19 switch (id) {
565 twoaday 2 case 0: return;
566     case 3: resids = key_resids; break;
567     case 1: resids = edit_resids;break;
568     }
569    
570     for (i=0; resids[i] != 0; i++)
571     set_menu_state (hm, resids[i], MF_GRAYED);
572     }
573    
574    
575 twoaday 22 static char*
576 twoaday 24 gen_export_filename (const char *keyid, int is_secret)
577 twoaday 22 {
578     gpgme_key_t key;
579     const char *s;
580     char *p;
581    
582     if (get_pubkey (keyid, &key))
583     return m_strdup (keyid);
584 twoaday 23 s = key->uids->name;
585 twoaday 22 if (!s)
586     return m_strdup (keyid);
587 twoaday 24 p = new char[strlen (s) + 8 + 16];
588 twoaday 22 if (!p)
589     BUG (0);
590 twoaday 24 sprintf (p, "%s%s.asc", s, is_secret? "_sec" : "");
591 twoaday 22 for (size_t i=0; i < strlen (p); i++) {
592     if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|')
593     p[i] = '_';
594     }
595     return p;
596     }
597    
598    
599     static void
600     update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair)
601     {
602     gpgme_key_t key;
603    
604     keycache_update (0, keyid);
605     if (keypair)
606     keycache_update (1, keyid);
607    
608     /* because we replaced the key item, we need to update the
609     address of the pointer in the ListView control. */
610     get_pubkey (keyid, &key);
611     keylist_upd_key (lv, pos, key);
612     }
613    
614    
615    
616 twoaday 2 BOOL CALLBACK
617     keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
618     {
619     struct km_info *kmi;
620     static km_group_s *gc = NULL;
621     static HMENU menu = NULL;
622     static int refresh_keys = 0;
623     INITCOMMONCONTROLSEX icex;
624     HWND kl;
625     HMENU hm;
626     gpgme_keycache_t c;
627 twoaday 22 gpgme_key_t key;
628     /*km_group_cb_s gcb; XXX */
629 twoaday 20 struct genkey_s genkey;
630 twoaday 2 struct winpt_key_s k = {0};
631 twoaday 19 struct URL_ctx_s *url;
632 twoaday 2 refresh_cache_s rcs = {0};
633 twoaday 24 char keyid[48], uid[128], type[32], *name;
634 twoaday 2 const char *t, * host;
635     u16 port = 0;
636     int idx = 0, i=0, rc;
637     size_t size = 0;
638    
639     if ((msg != WM_INITDIALOG)
640     && ((kmi = (struct km_info*)GetWindowLong (dlg, GWL_USERDATA)) == NULL))
641     return FALSE;
642    
643     switch (msg) {
644     case WM_INITDIALOG:
645     kmi = new struct km_info;
646     memset (kmi, 0, sizeof (struct km_info));
647     icex.dwSize = sizeof (INITCOMMONCONTROLSEX);
648     icex.dwICC = ICC_BAR_CLASSES;
649     InitCommonControlsEx (&icex);
650     kmi->hwnd_sep = regist_sep_wnd (dlg, kmi);
651     imagelist_load (dlg);
652    
653     #ifndef LANG_DE
654     SetWindowText( dlg, _("Key Manager") );
655     #endif
656     menu = LoadMenu( glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC );
657     #ifndef LANG_DE
658     set_menu_text( menu, ID_KEYMISC_QUIT, _("&Quit") );
659     set_menu_text( menu, ID_KEYMISC_UID, _("User ID") );
660     set_menu_text( menu, ID_KEYMISC_NEWKEY, _("&Expert") );
661     set_menu_text( menu, ID_KEYMISC_KEYWIZARD, _("&Normal") );
662     set_menu_text( menu, ID_KEYMISC_EDIT, _("Edit") );
663     set_menu_text( menu, ID_KEYMISC_SIGN, _("&Sign") );
664     set_menu_text( menu, ID_KEYMISC_DELETE, _("&Delete") );
665     set_menu_text( menu, ID_KEYMISC_REVCERT, _("&Revoke") );
666     set_menu_text( menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures") );
667     set_menu_text( menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path") );
668     set_menu_text( menu, ID_KEYMISC_PROPS, _("&Properties") );
669     set_menu_text( menu, ID_KEYMISC_GPGOPT, _("Options") );
670     set_menu_text( menu, ID_KEYMISC_GPGPREFS, _("Preferences") );
671     set_menu_text( menu, ID_KEYMISC_SENDRECV, _("Keyserver") );
672     set_menu_text( menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache") );
673     set_menu_text( menu, ID_KEYMISC_REBUILD, _("R&everify Signatures") );
674     set_menu_text( menu, ID_KEYMISC_INFO, _("Info") );
675     set_menu_text (menu, ID_KEYMISC_HELP, _("Help"));
676     #endif
677     SetMenu( dlg, menu );
678     if( keyring_check_last_access() )
679     keycache_set_reload( 1 );
680     if( keycache_get_reload( ) )
681     keycache_reload( dlg );
682     c = keycache_get_ctx( KEYCACHE_PUB );
683     if( !c )
684     BUG( NULL );
685 twoaday 23 kmi->keylist_sortby = KEY_SORT_USERID;
686 twoaday 2 Header_SetImageList(ListView_GetHeader(GetDlgItem( dlg, IDC_KEYMISC_KEYLIST )),
687     glob_imagelist);
688     kmi->lv = keylist_load( GetDlgItem( dlg, IDC_KEYMISC_KEYLIST ), c,
689     NULL, KEYLIST_LIST, kmi->keylist_sortby );
690     /* init subclassing for the listview */
691     kl = GetDlgItem( dlg, IDC_KEYMISC_KEYLIST );
692     keylist_proc.dlg = dlg;
693     keylist_proc.current = (WNDPROC)keylist_subclass_proc;
694     keylist_proc.old = (WNDPROC)GetWindowLong( kl, GWL_WNDPROC );
695     if( keylist_proc.old ) {
696     if( !SetWindowLong( kl, GWL_WNDPROC, (LONG)keylist_proc.current) ) {
697     msg_box( dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR );
698     BUG( NULL );
699     }
700     }
701 twoaday 22 #if 0
702 twoaday 2 km_groups_new( &gc, GetDlgItem( dlg, IDC_KEYMISC_GROUP ) );
703     km_groups_load( gc );
704 twoaday 22 #endif
705 twoaday 2 SetForegroundWindow( dlg );
706 twoaday 23
707     int partpos[3];
708     RECT r;
709 twoaday 2
710 twoaday 23 GetClientRect (dlg, &r);
711     for (i=1; i <= 3; i++)
712     partpos[i-1] = r.right/3*i;
713     kmi->statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM,
714     "status bar", dlg, 100000);
715     ShowWindow (kmi->statbar, SW_SHOW);
716     SendMessage (kmi->statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos);
717    
718     km_update_default_key_str (kmi->statbar);
719     km_complete_status_bar( kmi->statbar, kmi->lv);
720 twoaday 2
721     SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi);
722     kmi->toolbar = load_toolbar (dlg, kmi);
723    
724     do_center_window( dlg, kmi );
725     do_resize_window( dlg, kmi );
726     update_ui_items (dlg, kmi->lv);
727     return TRUE;
728    
729     case WM_DESTROY:
730     if (kmi->lv) {
731     keylist_delete (kmi->lv);
732     kmi->lv = NULL;
733 twoaday 23
734     /*
735 twoaday 2 if (gc) {
736     km_groups_release (gc);
737     gc = NULL;
738 twoaday 23 }*/
739 twoaday 2 imagelist_destroy ();
740    
741     char buf[32];
742     ltoa (kmi->pos_x, buf, 10);
743     set_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", buf );
744     ltoa (kmi->pos_y, buf, 10);
745     set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", buf);
746     /* Remove runtime information. This should be the last action taken here. */
747     delete kmi; kmi = NULL;
748     SetWindowLong (dlg, GWL_USERDATA, NULL);
749     keycache_set_reload (refresh_keys);
750     return FALSE;
751    
752     case WM_MOVE:
753     /* kmi->pos_x = (int)(short)LOWORD(lparam);
754     kmi->pos_y = (int)(short)HIWORD(lparam); */
755     RECT r;
756     GetWindowRect (dlg, &r);
757     kmi->pos_x = r.left;
758     kmi->pos_y = r.top;
759     break;
760    
761    
762     case WM_RBUTTONUP:
763     do_create_minpopup (dlg);
764     break;
765    
766     case WM_NOTIFY:
767     NMHDR * notify;
768     POINT p;
769     HMENU popup;
770    
771     notify = (NMHDR *)lparam;
772     if (notify == NULL)
773     break;
774     switch (notify->code)
775     {
776     case TBN_QUERYDELETE:
777     SetWindowLong(dlg, DWL_MSGRESULT, TRUE);
778     return TRUE;
779    
780     case TBN_QUERYINSERT:
781     SetWindowLong(dlg, DWL_MSGRESULT, TRUE);
782     return TRUE;
783    
784     case TBN_GETBUTTONINFO:
785     LPTBNOTIFY lpTbNotify;
786     lpTbNotify = (LPTBNOTIFY)lparam;
787     if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) {
788     lpTbNotify->tbButton.iBitmap = imagelist_getindex(myb[lpTbNotify->iItem].icon);
789     lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command;
790     lpTbNotify->tbButton.fsState = TBSTATE_ENABLED;
791     lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON;
792     lpTbNotify->tbButton.iString = 0;
793     strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText);
794     SetWindowLong(dlg, DWL_MSGRESULT, TRUE);
795     }
796     return TRUE;
797    
798     case TBN_RESET: /* Restore last saved toolbar status */
799     TBSAVEPARAMS tbsp;
800    
801     tbsp.hkr = HKEY_CURRENT_USER;
802     tbsp.pszSubKey = "Software\\WinPT";
803     tbsp.pszValueName = "KM_toolbar";
804     SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp);
805     break;
806    
807     case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */
808     tbsp.hkr = HKEY_CURRENT_USER;
809     tbsp.pszSubKey = "Software\\WinPT";
810     tbsp.pszValueName = "KM_toolbar";
811     SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);
812     break;
813    
814     case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */
815     tbsp.hkr = HKEY_CURRENT_USER;
816     tbsp.pszSubKey = "Software\\WinPT";
817     tbsp.pszValueName = "KM_toolbar";
818     SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp);
819     break;
820    
821     case TTN_GETDISPINFO:
822     LPTOOLTIPTEXT lpttt;
823     lpttt = (LPTOOLTIPTEXT)lparam;
824    
825     lpttt->hinst = NULL;
826     switch (lpttt->hdr.idFrom) {
827     case ID_KEYMISC_DELETE:
828     lpttt->lpszText = (char *)_("Delete key from keyring");
829     break;
830    
831     case ID_KEYMISC_PROPS:
832     lpttt->lpszText = (char *)_("Show key properties");
833     break;
834    
835     case ID_KEYMISC_SIGN:
836     lpttt->lpszText = (char *)_("Sign key");
837     break;
838    
839     case ID_KEYMISC_IMPORT:
840     lpttt->lpszText = (char *)_("Import key to keyring");
841     break;
842    
843     case ID_KEYMISC_EXPORT:
844     lpttt->lpszText = (char *)_("Export key to a file");
845     break;
846     }
847     return TRUE;
848    
849     case LVN_ITEMCHANGED:
850     if (((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */
851     {
852     update_ui_items (dlg, kmi->lv);
853     return TRUE;
854     }
855     break;
856    
857     case NM_RCLICK:
858 twoaday 22 if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
859 twoaday 2 if (listview_get_curr_pos (kmi->lv) == -1)
860     return TRUE; /* Popup only when a item was selected */
861     do_check_cache (kmi->lv, dlg, kmi->statbar);
862     GetCursorPos (&p);
863     hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX));
864     popup = GetSubMenu (hm, 0);
865     #ifndef LANG_DE
866     set_menu_text( popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard") );
867     set_menu_text( popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard") );
868     set_menu_text( popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard") );
869     set_menu_text( popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver") );
870     #endif
871     idx = listview_get_curr_pos (kmi->lv);
872 twoaday 22 if (km_check_for_seckey (kmi->lv, idx, &i))
873 twoaday 2 set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED);
874 twoaday 22 if (i == 0)
875 twoaday 2 set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED);
876 twoaday 19 if (!km_check_for_seckey (kmi->lv, idx, NULL)) {
877 twoaday 2 set_menu_state( popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED );
878     set_menu_state( popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED );
879     set_menu_state( popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED );
880     set_menu_state( popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED );
881     set_menu_state( popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED );
882     set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED);
883     }
884     else if( km_check_for_seckey( kmi->lv, idx, NULL )
885     && km_key_is_v3( kmi->lv, idx ) )
886     {
887     /* PGP 2 keys, version 3 have no no support for photo-id's,
888     designated revokers and secondary keys. */
889 twoaday 20 set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED);
890     set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED);
891     set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED);
892 twoaday 2 }
893     if( km_get_key_status( kmi->lv, idx ) & KM_FLAG_DISABLED )
894     set_menu_state( popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED );
895     else
896     set_menu_state( popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED );
897     if (km_get_key_status (kmi->lv, idx) & KM_FLAG_REVOKED)
898     set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED);
899 twoaday 22 if (mapi_init())
900     set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED);
901     /* Override 'Default Keyserver' with the actual name. */
902     host = kserver_get_hostname (0, -1, &port);
903     set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host);
904 twoaday 2 popup_gpg_readonly (dlg, popup);
905 twoaday 22 TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
906     DestroyMenu (popup);
907     DestroyMenu (hm);
908 twoaday 2 return TRUE;
909     }
910 twoaday 22 #if 0 /* XXX */
911 twoaday 2 if( notify->idFrom == IDC_KEYMISC_GROUP ) {
912     HWND tree = GetDlgItem( dlg, IDC_KEYMISC_GROUP );
913     if( TreeView_GetSelection( tree ) ) {
914     GetCursorPos( &p );
915     hm = LoadMenu( glob_hinst, MAKEINTRESOURCE(IDR_WINPT_GROUP_CTX) );
916     popup = GetSubMenu( hm, 0 );
917     if( km_index == -1 )
918     set_menu_state( popup, ID_GROUP_PASTE, MF_DISABLED|MF_GRAYED );
919     set_menu_text( popup, ID_GROUP_PASTE, _("Paste into this group") );
920     set_menu_text( popup, ID_GROUP_DELETE, _("Delete") );
921     TrackPopupMenu( popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL );
922     DestroyMenu( popup );
923     DestroyMenu( hm );
924     return TRUE;
925     }
926     }
927 twoaday 22 #endif
928 twoaday 2 break;
929    
930     case LVN_COLUMNCLICK:
931     if (notify->idFrom == IDC_KEYMISC_KEYLIST) {
932     NMLISTVIEW * p = (LPNMLISTVIEW) lparam;
933     int sortby = 0;
934     switch (p->iSubItem) {
935 twoaday 23 case 0: sortby = KEY_SORT_USERID; break;
936     case 1: sortby = KEY_SORT_KEYID; break;
937     case 2: sortby = KEY_SORT_IS_SECRET; break;
938     case 3: sortby = KEY_SORT_LEN; break;
939     case 5: sortby = KEY_SORT_VALIDITY; break;
940     case 6: sortby = KEY_SORT_OTRUST; break;
941     case 7: sortby = KEY_SORT_CREATED; break;
942     case 8: sortby = KEY_SORT_ALGO; break;
943     default: return TRUE; //sortby = KEY_SORT_USERID; break;
944 twoaday 2 }
945    
946     if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby)
947     kmi->keylist_sortby ^= KEYLIST_SORT_DESC;
948     else
949     kmi->keylist_sortby = sortby;
950     keylist_sort (kmi->lv, kmi->keylist_sortby);
951     return TRUE;
952     }
953     break;
954     }
955     break;
956     }
957    
958     case WM_WINDOWPOSCHANGING:
959     if (((WINDOWPOS*)lparam)->cx < 400)
960     ((WINDOWPOS*)lparam)->cx = 400;
961     if (((WINDOWPOS*)lparam)->cy < 200)
962     ((WINDOWPOS*)lparam)->cy = 200;
963     return TRUE;
964    
965     case WM_SIZE:
966     do_resize_window (dlg, kmi);
967     return TRUE;
968    
969     case WM_SYSCOMMAND:
970     if( LOWORD (wparam) == SC_CLOSE )
971     EndDialog( dlg, TRUE );
972     return FALSE;
973    
974     case WM_MENUSELECT:
975     menu_gpg_readonly (dlg, (HMENU)lparam, LOWORD (wparam));
976     break;
977    
978     case WM_COMMAND:
979     if( gnupg_access_keyring( 1 ) ) {
980     msg_box( dlg, _("Could not access public keyring"), _("Key Manager"), MB_ERR );
981     return FALSE;
982     }
983     do_check_cache( kmi->lv, dlg, kmi->statbar );
984     switch( LOWORD( wparam ) ) {
985     case ID_KEYMISC_QUIT:
986     EndDialog( dlg, TRUE );
987     return TRUE;
988    
989     case ID_KEYMISC_MAIL:
990 twoaday 24 /* XXX
991 twoaday 2 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_MAIL, GetDesktopWindow (),
992 twoaday 24 winpt_mail_proc, NULL);*/
993 twoaday 2 break;
994 twoaday 22
995     case ID_KEYMISC_FIND:
996     km_find_key (dlg, kmi->lv);
997     break;
998    
999 twoaday 2 case ID_KEYMISC_DELETE:
1000 twoaday 24 km_delete_keys (kmi->lv, dlg);
1001 twoaday 2 return TRUE;
1002    
1003 twoaday 22 case ID_KEYMISC_SIGN:
1004 twoaday 2 if ( (idx = listview_get_curr_pos( kmi->lv )) == -1 ) {
1005     msg_box( dlg, _("Please select a key."), _("Key Manager"),
1006     MB_ERR );
1007 twoaday 24 return TRUE;;
1008 twoaday 2 }
1009 twoaday 22 if (km_check_key_status (kmi->lv, idx))
1010 twoaday 24 return TRUE;
1011 twoaday 22 key = (gpgme_key_t)listview_get_item2 (kmi->lv, idx);
1012     listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1013     memset (&k, 0, sizeof (k));
1014     k.ctx = key;
1015     k.keyid = keyid;
1016     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg,
1017     keysign_dlg_proc, (LPARAM)&k,
1018     _("Key Signing"), IDS_WINPT_KEYSIGN);
1019     if (k.update)
1020     update_key (kmi->lv, idx, k.keyid, 0);
1021 twoaday 2 return TRUE;
1022    
1023     case ID_KEYMISC_REVCERT:
1024     idx = listview_get_curr_pos( kmi->lv );
1025     if( idx == -1 ) {
1026     msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );
1027 twoaday 24 return TRUE;
1028 twoaday 2 }
1029     listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 );
1030     listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 );
1031     if ( !km_check_for_seckey( kmi->lv, idx, NULL ) ) {
1032     msg_box( dlg, _("There is no secret key available!"), _("Key Manager"), MB_ERR );
1033 twoaday 24 return TRUE;
1034 twoaday 2 }
1035    
1036     {
1037     char t[128];
1038     listview_get_item_text( kmi->lv, idx, 5, t, sizeof t -1 );
1039     if( strchr( t, 'R' ) ) {
1040     msg_box( dlg, _("Key already revoked!"), _("Key Manager"), MB_INFO );
1041 twoaday 24 return TRUE;
1042 twoaday 2 }
1043     }
1044    
1045 twoaday 22 name = km_quote_uid (uid);
1046 twoaday 19 memset (&k, 0, sizeof (k));
1047 twoaday 2 k.key_pair = 1;
1048     k.keyid = keyid;
1049 twoaday 22 k.uid = name;
1050 twoaday 2 k.is_protected = km_check_if_protected( kmi->lv, idx );
1051     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg,
1052     key_revoke_dlg_proc, (LPARAM)&k,
1053     _("Key Revocation"), IDS_WINPT_KEYREVOKE );
1054 twoaday 22 free_if_alloc (name);
1055 twoaday 2 return TRUE;
1056    
1057     case ID_KEYMISC_TRUSTPATH:
1058     idx = listview_get_curr_pos( kmi->lv );
1059     if( idx == -1 ) {
1060     msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );
1061 twoaday 24 return TRUE;
1062 twoaday 2 }
1063     listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 );
1064     listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid -1 );
1065     if( km_check_for_seckey( kmi->lv, idx, NULL ) ) {
1066     msg_box( dlg, _("It does not make any sense with a key pair!"), _("Key Manager"), MB_OK );
1067     return FALSE;
1068     }
1069 twoaday 19 memset (&k, 0, sizeof (k));
1070 twoaday 2 k.keyid = keyid;
1071     k.uid = uid;
1072     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg,
1073     keytrust_dlg_proc, (LPARAM)&k,
1074     _("List Trust Path"), IDS_WINPT_KEYTRUST );
1075     return TRUE;
1076    
1077     case ID_KEYMISC_CHECKSIGS:
1078 twoaday 22 idx = listview_get_curr_pos (kmi->lv);
1079 twoaday 2 if( idx == -1 ) {
1080     msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );
1081     return FALSE;
1082     }
1083 twoaday 19 listview_get_item_text (kmi->lv, idx, 0, uid, DIM (uid)-1);
1084     listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1085     memset (&k, 0, sizeof (k));
1086 twoaday 2 k.keyid = keyid;
1087     k.uid = uid;
1088 twoaday 22 k.ctx = (gpgme_key_t)listview_get_item2 (kmi->lv, idx);
1089 twoaday 19 dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG, dlg,
1090 twoaday 2 keysig_dlg_proc, (LPARAM)&k,
1091 twoaday 19 _("Key Signature List" ), IDS_WINPT_KEYSIG);
1092 twoaday 2 return TRUE;
1093    
1094     case ID_KEYMISC_PROPS:
1095     idx = listview_get_curr_pos( kmi->lv );
1096     if( idx == -1 ) {
1097     msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );
1098     return FALSE;
1099     }
1100 twoaday 22 listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1101     listview_get_item_text (kmi->lv, idx, 2, type, DIM (type)-1);
1102 twoaday 19 memset (&k, 0, sizeof (k));
1103 twoaday 2 k.key_pair = 0;
1104     k.keyid = keyid;
1105     if( !strcmp( type, "pub/sec" ) || !strcmp( type, "pub/crd" ) )
1106     k.key_pair = 1;
1107     k.callback.ctl = kmi->lv;
1108     k.callback.idx = idx;
1109 twoaday 23 k.is_v3 = km_key_is_v3 (kmi->lv, idx);
1110 twoaday 2 dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg,
1111     keyprops_dlg_proc, (LPARAM)&k,
1112     _("Key Properties"), IDS_WINPT_KEYPROPS );
1113 twoaday 22 if (k.callback.new_val != 0) {
1114 twoaday 2 t = get_key_trust_str (k.callback.new_val);
1115     listview_add_sub_item (kmi->lv, idx, 6, t);
1116     }
1117     return TRUE;
1118    
1119     case ID_KEYMISC_RECACHE:
1120     /* If there is already a reload request, don't bother the user with a message. */
1121     if( keycache_get_reload() == 1 )
1122     idx = IDYES;
1123     else {
1124     char t[256];
1125     _snprintf( t, sizeof t -1,
1126     _("This is only useful when the keyring has been "
1127     "modified (sign a key...).\n"
1128     "Do you really want to reload the keycache?") );
1129     idx = msg_box( dlg, t, _("Key Manager"), MB_YESNO );
1130     }
1131     if( idx == IDYES ) {
1132     rcs.kr_reload = rcs.kr_update = 1;
1133     rcs.tr_update = 0;
1134     DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg,
1135     keycache_dlg_proc, (LPARAM)&rcs );
1136     c = keycache_get_ctx( 1 );
1137     if( !c )
1138     BUG( dlg );
1139 twoaday 23 keylist_reload( kmi->lv, c, KEYLIST_LIST, KEY_SORT_USERID );
1140 twoaday 2 refresh_keys = 0;
1141     }
1142     return TRUE;
1143    
1144     case ID_KEYMISC_REBUILD:
1145 twoaday 24 name=NULL;
1146     gpg_rebuild_cache (&name);
1147     if (name) {
1148     char *p = strchr (name, '\n');
1149     show_msg (dlg, 2000, p? name + (p-name)+1 : name);
1150     free (name);
1151     }
1152 twoaday 2 return TRUE;
1153    
1154     case ID_KEYMISC_NEWKEY:
1155 twoaday 20 memset (&genkey, 0, sizeof (genkey));
1156     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg,
1157     keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"),
1158     IDS_WINPT_KEYGEN);
1159 twoaday 22 if (genkey.newkey != NULL)
1160 twoaday 20 keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);
1161 twoaday 2 return TRUE;
1162    
1163     case ID_KEYMISC_CARDNEW:
1164     if( !scard_support ) {
1165     msg_box( dlg, _("Smart Card support is not available."), _("Key Manager"), MB_INFO );
1166 twoaday 24 return TRUE;
1167 twoaday 2 }
1168     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg,
1169     card_keygen_dlg_proc, NULL, _("Card Key Generation"),
1170     IDS_WINPT_CARD_KEYGEN );
1171 twoaday 22 /* XXX: use new code */
1172 twoaday 2 if( keycache_get_reload() )
1173     send_cmd_id( dlg, ID_KEYMISC_RECACHE );
1174     return TRUE;
1175    
1176     case ID_KEYMISC_KEYWIZARD:
1177 twoaday 20 memset (&genkey, 0, sizeof (genkey));
1178     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg,
1179     keygen_wizard_dlg_proc, (LPARAM)&genkey, _("Key Generation Wizard"),
1180     IDS_WINPT_KEYWIZARD);
1181 twoaday 22 if (genkey.newkey != NULL)
1182 twoaday 20 keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey);
1183 twoaday 2 return TRUE;
1184    
1185     case ID_KEYMISC_SENDRECV:
1186     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg,
1187     keyserver_dlg_proc, NULL, _("Keyserver Access"),
1188     IDS_WINPT_KEYSERVER );
1189     return TRUE;
1190    
1191     case ID_KEYMISC_GPGPREFS:
1192     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, dlg,
1193     gpgprefs_dlg_proc, NULL, _("GnuPG Preferences"),
1194     IDS_WINPT_GPGPREFS );
1195     return TRUE;
1196    
1197     case ID_KEYMISC_GPGOPT:
1198     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg,
1199     gpgopt_dlg_proc, NULL, _("GnuPG Options" ),
1200     IDS_WINPT_GPGOPT );
1201     return TRUE;
1202    
1203     case ID_KEYMISC_IMPORT:
1204 twoaday 22 t = get_filename_dlg (dlg, FILE_OPEN, _("Choose Name of the Key File"), NULL, NULL);
1205     if (t)
1206     km_file_import (dlg, t);
1207 twoaday 2 return TRUE;
1208    
1209     case ID_KEYMISC_IMPORT_HTTP:
1210 twoaday 19 url = (struct URL_ctx_s*)get_http_file_dlg (dlg);
1211     if (url->cancel == 0)
1212     km_http_import (dlg, url->url);
1213     delete url; url=NULL;
1214 twoaday 2 break;
1215    
1216     case ID_KEYMISC_EXPORT:
1217 twoaday 22 idx = listview_get_curr_pos (kmi->lv);
1218     if (idx == -1) {
1219 twoaday 2 msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );
1220 twoaday 24 return TRUE;
1221 twoaday 2 }
1222 twoaday 22 if (listview_count_items (kmi->lv, 1) > 1)
1223     name = m_strdup ("Exported_GPG_Keys.asc");
1224 twoaday 2 else {
1225 twoaday 22 listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1226 twoaday 24 name = gen_export_filename (keyid, 0);
1227 twoaday 2 }
1228 twoaday 22 t = get_filename_dlg (dlg, FILE_SAVE, _("Choose Name for Key File"), NULL, name);
1229     free_if_alloc (name);
1230 twoaday 24 if (t == NULL)
1231     return TRUE;
1232 twoaday 22 km_file_export (dlg, kmi->lv, t);
1233 twoaday 2 return TRUE;
1234    
1235     case ID_KEYMISC_EXPORT_PRIVKEY:
1236     idx = listview_get_curr_pos( kmi->lv );
1237     if( idx == -1 ) {
1238     msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR );
1239 twoaday 24 return TRUE;
1240 twoaday 2 }
1241     if( !km_check_for_seckey( kmi->lv, idx, NULL ) ) {
1242     msg_box( dlg, _("There is no corresponding secret key for this key."),
1243     _("Key Manager"), MB_ERR );
1244 twoaday 24 return TRUE;
1245 twoaday 2 }
1246     if( listview_count_items( kmi->lv, 1 ) > 1 ) {
1247     msg_box( dlg, _("You can only export one secret key."), _("Key Manager"), MB_ERR );
1248 twoaday 24 return TRUE;
1249 twoaday 2 }
1250     idx = msg_box( dlg,
1251     _("This operation will export your *SECRET* key!\n\n"
1252     "Never send this key to ANYONE, it should be available\n"
1253     "ONLY on your machine and you may use this function\n"
1254     "to copy the key to a safe place.\n\n"
1255     "Do you really want to export the key?"),
1256     _("WARNING"), MB_INFO|MB_YESNO );
1257     if( idx == IDYES ) {
1258     idx = listview_get_curr_pos( kmi->lv );
1259     listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof (keyid)-8 );
1260 twoaday 24 name = gen_export_filename (keyid, 1);
1261 twoaday 23 t = get_filename_dlg (dlg, FILE_SAVE, _("Choose Name for Key File"), NULL, name);
1262     if (t != NULL)
1263 twoaday 22 km_privkey_export (dlg, kmi->lv, t);
1264 twoaday 2 }
1265     break;
1266    
1267     case ID_KEYMISC_INFO:
1268     dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, glob_hwnd,
1269     about_winpt_dlg_proc, NULL, _("About WinPT"),
1270     IDS_WINPT_ABOUT );
1271     break;
1272    
1273     case ID_KEYMISC_HELP:
1274     ShellExecute (dlg, "open", "winpt.chm", NULL, NULL, SW_SHOW);
1275     break;
1276    
1277     case ID_KEYMISC_OT:
1278     dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST, glob_hwnd,
1279     ownertrust_dlg_proc, NULL,
1280     _("Ownertrust"), IDS_WINPT_OWNERTRUST );
1281     break;
1282    
1283     case ID_KEYMISC_EDITKEY:
1284     idx = listview_get_curr_pos (kmi->lv);
1285 twoaday 16 if (idx == -1)
1286 twoaday 2 break;
1287 twoaday 16 listview_get_item_text (kmi->lv, idx, 1, keyid, sizeof (keyid)-1);
1288     /* XXX: pub/crd = secret key does not work */
1289 twoaday 19 memset (&k, 0, sizeof (k));
1290 twoaday 16 k.is_protected = km_check_if_protected (kmi->lv, idx);
1291     k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);
1292 twoaday 2 k.keyid = keyid;
1293 twoaday 20 k.is_v3 = km_key_is_v3 (kmi->lv, idx);
1294 twoaday 16 k.flags = km_get_key_status (kmi->lv, idx);
1295     dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg,
1296 twoaday 2 keyedit_main_dlg_proc, (LPARAM)&k,
1297 twoaday 16 _("Key Edit"), IDS_KEYCTX_EDIT);
1298 twoaday 22 if (k.update)
1299     update_key (kmi->lv, idx, keyid, 1);
1300 twoaday 2 break;
1301    
1302     case ID_KEYMISC_COPY:
1303 twoaday 22 km_index = listview_get_curr_pos (kmi->lv);
1304     km_clip_export (dlg, kmi->lv);
1305 twoaday 2 break;
1306    
1307     case ID_KEYMISC_SELALL:
1308     listview_select_all (kmi->lv);
1309     break;
1310    
1311     case ID_KEYMISC_PASTE:
1312     km_index = -1;
1313     km_clip_import (dlg);
1314     break;
1315    
1316     case ID_KEYCTX_SETPREFKS:
1317 twoaday 19 listview_get_item_text (kmi->lv, idx, 1, keyid, DIM(keyid)-1);
1318     memset (&k, 0, sizeof (k));
1319     k.keyid = keyid;
1320     keyedit_set_pref_keyserver (&k, dlg);
1321 twoaday 2 break;
1322    
1323     case ID_KEYMISC_REFRESH_KEYS:
1324 twoaday 19 if (listview_count_items (kmi->lv, 1) == 0) {
1325 twoaday 2 msg_box (dlg, _("No key was selected, select all by default."), _("Key Manager"), MB_INFO);
1326     listview_select_all (kmi->lv);
1327     }
1328     km_refresh_from_keyserver (kmi->lv, dlg);
1329     break;
1330    
1331     /** Context menu **/
1332     case ID_KEYCTX_EDIT:
1333     send_cmd_id( dlg, ID_KEYMISC_EDITKEY );
1334     break;
1335    
1336     case ID_KEYCTX_PROPS:
1337     send_cmd_id( dlg, ID_KEYMISC_PROPS );
1338     break;
1339    
1340     case ID_KEYCTX_UIDS:
1341     send_cmd_id( dlg, ID_KEYMISC_UID );
1342     break;
1343    
1344     case ID_KEYCTX_SIGN:
1345     send_cmd_id( dlg, ID_KEYMISC_SIGN );
1346     break;
1347    
1348     case ID_KEYCTX_DEL:
1349     send_cmd_id (dlg, ID_KEYMISC_DELETE);
1350     break;
1351    
1352     case ID_KEYCTX_REV:
1353     send_cmd_id( dlg, ID_KEYMISC_REVCERT );
1354     break;
1355    
1356     case ID_KEYCTX_SENDMAIL:
1357 twoaday 22 km_send_to_mail_recipient (kmi->lv, dlg);
1358 twoaday 2 break;
1359    
1360     case ID_KEYCTX_KS_DEFAULT:
1361     host = kserver_get_hostname (0, -1, &port);
1362     km_send_to_keyserver (kmi->lv, dlg, host, port);
1363     break;
1364    
1365     case ID_KEYCTX_ADDKEY:
1366 twoaday 22 idx = listview_get_curr_pos (kmi->lv);
1367 twoaday 19 listview_get_item_text( kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1368     memset (&k, 0, sizeof (k));
1369 twoaday 22 k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);
1370     k.is_protected = km_check_if_protected (kmi->lv, idx);
1371 twoaday 2 k.keyid = keyid;
1372 twoaday 22 keyedit_add_subkey (&k, dlg, NULL);
1373     if (k.update)
1374     update_key (kmi->lv, idx, keyid, 1);
1375 twoaday 2 break;
1376    
1377     case ID_KEYCTX_ADDUID:
1378 twoaday 22 idx = listview_get_curr_pos (kmi->lv);
1379 twoaday 19 listview_get_item_text( kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1380     memset (&k, 0, sizeof (k));
1381 twoaday 22 k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);
1382     k.is_protected = km_check_if_protected (kmi->lv, idx);
1383 twoaday 2 k.keyid = keyid;
1384 twoaday 22 keyedit_add_userid (&k, dlg, NULL);
1385     if (k.update)
1386     update_key (kmi->lv, idx, keyid, 1);
1387 twoaday 2 break;
1388    
1389     case ID_KEYCTX_ADDREV:
1390 twoaday 19 idx = listview_get_curr_pos (kmi->lv);
1391     listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1392     memset (&k, 0, sizeof (k));
1393 twoaday 2 k.keyid = keyid;
1394 twoaday 22 k.is_protected = km_check_if_protected (kmi->lv, idx);
1395 twoaday 2 k.key_pair = km_check_for_seckey( kmi->lv, idx, NULL );
1396 twoaday 22 keyedit_add_revoker (&k, dlg);
1397     if (k.update)
1398     update_key (kmi->lv, idx, keyid, 1);
1399 twoaday 2 break;
1400    
1401     case ID_KEYCTX_ADDPHOTO:
1402 twoaday 19 idx = listview_get_curr_pos (kmi->lv);
1403     listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1404     memset (&k, 0, sizeof (k));
1405 twoaday 2 k.keyid = keyid;
1406 twoaday 19 k.is_protected = km_check_if_protected (kmi->lv, idx);
1407     k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL);
1408     keyedit_add_photo (&k, dlg);
1409 twoaday 22 if (k.update)
1410     update_key (kmi->lv, idx, keyid, 1);
1411 twoaday 2 break;
1412    
1413     case ID_KEYCTX_KS_NL:
1414     case ID_KEYCTX_KS_PL:
1415     case ID_KEYCTX_KS_AT:
1416     case ID_KEYCTX_KS_DE:
1417     case ID_KEYCTX_KS_DK:
1418     case ID_KEYCTX_KS_CZ:
1419     case ID_KEYCTX_KS_ES:
1420     case ID_KEYCTX_KS_UK:
1421     host = kserver_get_hostname (LOWORD (wparam) - 40107, 0, &port);
1422     km_send_to_keyserver (kmi->lv, dlg, host, port);
1423     break;
1424    
1425     case ID_KEYCTX_RECVFROM:
1426     km_refresh_from_keyserver (kmi->lv, dlg);
1427     break;
1428    
1429     case ID_KEYCTX_UID_COPY:
1430     /* XXX: add generic function to support multiple selection
1431     with a callback */
1432     idx = listview_get_curr_pos( kmi->lv );
1433     listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid-1 );
1434     set_clip_text( NULL, uid, strlen( uid ) );
1435     break;
1436    
1437     case ID_KEYCTX_KEYID_COPY:
1438     idx = listview_get_curr_pos( kmi->lv );
1439     listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 );
1440     set_clip_text( NULL, uid, strlen( uid ) );
1441     break;
1442    
1443     case ID_KEYCTX_FPR_COPY:
1444     idx = listview_get_curr_pos( kmi->lv );
1445 twoaday 22 key = (gpgme_key_t) listview_get_item2 (kmi->lv, idx);
1446     if (key) {
1447     const char * s = get_key_fpr (key);
1448     set_clip_text (NULL, s? s : "", s? strlen (s): 0);
1449 twoaday 2 }
1450     break;
1451    
1452     case ID_KEYCTX_KINFO_COPY:
1453     idx = listview_get_curr_pos( kmi->lv );
1454     listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 );
1455     km_set_clip_info( uid );
1456     break;
1457    
1458     case ID_KEYCTX_COPY:
1459     km_index = listview_get_curr_pos (kmi->lv);
1460     km_clip_export (dlg, kmi->lv);
1461     break;
1462    
1463     case ID_KEYCTX_PASTE:
1464     km_index = -1;
1465     km_clip_import (dlg);
1466     break;
1467    
1468     case ID_KEYCTX_DISABLE:
1469     idx = listview_get_curr_pos (kmi->lv);
1470     km_enable_disable_key (kmi->lv, dlg, idx, 0);
1471     break;
1472    
1473     case ID_KEYCTX_ENABLE:
1474     idx = listview_get_curr_pos (kmi->lv);
1475     km_enable_disable_key (kmi->lv, dlg, idx, 1);
1476     break;
1477    
1478     case ID_KEYCTX_LISTSIGS:
1479     send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS);
1480     break;
1481    
1482     case ID_KEYCTX_MAXTRUST:
1483     idx = listview_get_curr_pos (kmi->lv);
1484 twoaday 22 listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1485     rc = km_set_implicit_trust (dlg, kmi->lv, idx);
1486     if (!rc)
1487     update_key (kmi->lv, idx, keyid, 0);
1488 twoaday 2 break;
1489    
1490     case ID_KEYCTX_SETDEFKEY:
1491     idx = listview_get_curr_pos (kmi->lv);
1492 twoaday 22 if (!km_check_key_status (kmi->lv, idx)) {
1493     listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1);
1494 twoaday 2 rc = set_gnupg_default_key (keyid);
1495     if (rc)
1496     msg_box( dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR);
1497 twoaday 23 km_update_default_key_str (kmi->statbar);
1498 twoaday 2 }
1499     break;
1500 twoaday 22
1501     #if 0 /* XXX */
1502     case ID_GROUP_NEW:
1503     memset (&gcb, 0, sizeof (gcb));
1504     gcb.gc = gc;
1505     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GROUP, glob_hwnd,
1506     group_manager_dlg_proc, (LPARAM)&gcb, _("New Group"),
1507     IDS_WINPT_GROUP);
1508     if( gcb.use_name )
1509     treeview_add_item( GetDlgItem(dlg, IDC_KEYMISC_GROUP), NULL, gcb.name );
1510     return TRUE;
1511 twoaday 2
1512     case ID_GROUP_PASTE:
1513     km_groups_add (gc, kmi->lv, km_index);
1514     break;
1515    
1516     case ID_GROUP_DELETE:
1517     km_groups_del (gc);
1518     break;
1519 twoaday 22 #endif
1520     }
1521    
1522 twoaday 2 break;
1523     }
1524    
1525     return FALSE;
1526 twoaday 24 }
1527 twoaday 2
1528    
1529 twoaday 24

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26