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

Annotation of /trunk/Src/wptKeyManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (hide annotations)
Mon Dec 12 11:19:56 2005 UTC (19 years, 2 months ago) by twoaday
File size: 54776 byte(s)
2005-12-11  Timo Schulz  <ts@g10code.com>
 
        * wptW32API.cpp (get_file_version): New.
        * wptGPGUtil.cpp (create_process): Always hide window.
        * wptClipEditDlg.cpp (clipedit_dlg_proc): Use 'Close'
        instead of 'Exit'.
        * wptKeyManager.cpp (km_http_import): New filename
        generation code.
        (km_send_to_mail_recipient): Cleanups.
        * wptKeyEditDlg.cpp (showpref_dlg_proc): Localize dialog.
        * wptKeyManagerDlg.cpp (update_ui_items): Handle the case
        when multiple keys are selected.
        (popup_multiple): New.
        * WinPT.cpp (WinMain): Check that the PTD.dll and WinPT.exe
        file versions are equal. Rewrote --keymanager code.
         
Removed temporary w32gpgme dirctory, all code is now in Src.
Changed configure files.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26