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

Annotation of /trunk/Src/wptKeyManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30 - (hide annotations)
Sat Oct 22 10:17:59 2005 UTC (19 years, 4 months ago) by twoaday
File size: 54437 byte(s)
Sync with old SVN repository.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26