1 |
/* 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 |
#include "resource.h" |
30 |
#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 |
/* Center window @dlg. */ |
195 |
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 |
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 |
return; |
213 |
} |
214 |
else if (p) |
215 |
pos_x = atol (p); |
216 |
|
217 |
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 |
return; |
222 |
} |
223 |
else if (p) |
224 |
pos_y = atol (p); |
225 |
|
226 |
if (!pos_y && !pos_x) { |
227 |
center_window (dlg, NULL); |
228 |
return; |
229 |
} |
230 |
|
231 |
if (pos_x < 0 || pos_y < 0) |
232 |
pos_x = pos_y = 0; |
233 |
if (pos_x > GetSystemMetrics (SM_CXSCREEN) |
234 |
|| pos_y > GetSystemMetrics (SM_CYSCREEN)) { |
235 |
pos_x = pos_y = 0; |
236 |
} |
237 |
GetClientRect (dlg, &rect); |
238 |
MoveWindow (dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE); |
239 |
} |
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 |
km_complete_status_bar (sb, lv); |
348 |
} |
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 |
RECT rect; |
357 |
|
358 |
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 |
int key_selected = 0, key_has_sec = 0; |
484 |
int i, key_inv = 0; |
485 |
HWND hwnd_child; |
486 |
HMENU hmenu; |
487 |
|
488 |
/* Get some states */ |
489 |
key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST), |
490 |
LVM_GETSELECTEDCOUNT, 0, 0) |
491 |
? TRUE : FALSE; |
492 |
key_has_sec = FALSE; |
493 |
if (key_selected) { |
494 |
i = listview_get_curr_pos (lv); |
495 |
key_has_sec = km_check_for_seckey (lv, i, NULL) ? TRUE : FALSE; |
496 |
key_inv = km_get_key_status (lv, i) & KM_FLAG_REVOKED; |
497 |
} |
498 |
|
499 |
/* Enable / disable toolbar buttons */ |
500 |
hwnd_child = GetDlgItem (hwnd, IDR_WINPT_KMTB); |
501 |
enable_button (hwnd_child, ID_KEYMISC_DELETE); |
502 |
enable_button (hwnd_child, ID_KEYMISC_PROPS); |
503 |
enable_button (hwnd_child, ID_KEYMISC_SIGN); |
504 |
enable_button (hwnd_child, ID_KEYMISC_EXPORT); |
505 |
|
506 |
/* Enable / disable menu items */ |
507 |
hmenu = GetMenu (hwnd); |
508 |
set_menu_state (hmenu, ID_KEYMISC_EXPORT, key_selected ? MF_ENABLED : MF_GRAYED); |
509 |
set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY, key_has_sec ? MF_ENABLED : MF_GRAYED); |
510 |
set_menu_state (hmenu, ID_KEYMISC_REVCERT, key_has_sec ? MF_ENABLED : MF_GRAYED); |
511 |
set_menu_state (hmenu, ID_KEYMISC_DELETE, key_selected ? MF_ENABLED : MF_GRAYED); |
512 |
set_menu_state (hmenu, ID_KEYMISC_PROPS, key_selected ? MF_ENABLED : MF_GRAYED); |
513 |
set_menu_state (hmenu, ID_KEYMISC_SIGN, key_selected && !key_inv ? MF_ENABLED : MF_GRAYED); |
514 |
set_menu_state (hmenu, ID_KEYMISC_EDITKEY, key_selected? MF_ENABLED : MF_GRAYED); |
515 |
set_menu_state (hmenu, ID_KEYMISC_CHECKSIGS, key_selected? MF_ENABLED : MF_GRAYED); |
516 |
} |
517 |
|
518 |
|
519 |
/* The items which are shown when GPG is in read-only mode. */ |
520 |
static void |
521 |
popup_gpg_readonly (HWND dlg, HMENU hm) |
522 |
{ |
523 |
int resids[] = { |
524 |
ID_KEYCTX_PASTE, |
525 |
ID_KEYCTX_EDIT, |
526 |
ID_KEYCTX_SIGN, |
527 |
ID_KEYCTX_REV, |
528 |
ID_KEYCTX_DEL, |
529 |
ID_KEYCTX_ENABLE, |
530 |
ID_KEYCTX_DISABLE, |
531 |
ID_KEYCTX_RECVFROM, |
532 |
ID_KEYCTX_ADDKEY, |
533 |
ID_KEYCTX_ADDPHOTO, |
534 |
ID_KEYCTX_ADDUID, |
535 |
ID_KEYCTX_ADDREV, |
536 |
0 |
537 |
}; |
538 |
int i; |
539 |
|
540 |
if (gpg_read_only == 0) |
541 |
return; |
542 |
for (i=0; resids[i] != 0; i++) |
543 |
set_menu_state (hm, resids[i], MF_GRAYED); |
544 |
} |
545 |
|
546 |
|
547 |
static void |
548 |
menu_gpg_readonly (HWND dlg, HMENU hm, int id) |
549 |
{ |
550 |
int key_resids[] = { |
551 |
ID_KEYMISC_SIGN, |
552 |
ID_KEYMISC_DELETE, |
553 |
ID_KEYMISC_REVCERT, |
554 |
ID_KEYMISC_IMPORT_HTTP, |
555 |
ID_KEYMISC_IMPORT, |
556 |
ID_KEYMISC_REFRESH_KEYS, |
557 |
ID_KEYMISC_REBUILD, |
558 |
ID_KEYMISC_KEYWIZARD, |
559 |
ID_KEYMISC_CARDNEW, |
560 |
ID_KEYMISC_NEWKEY, |
561 |
0, |
562 |
}; |
563 |
int edit_resids[] = { |
564 |
ID_KEYMISC_PASTE, |
565 |
ID_KEYMISC_OT, |
566 |
ID_KEYMISC_EDITKEY, |
567 |
0 |
568 |
}; |
569 |
int *resids; |
570 |
int i; |
571 |
|
572 |
|
573 |
if (gpg_read_only == 0) |
574 |
return; |
575 |
switch (id) { |
576 |
case 0: return; |
577 |
case 3: resids = key_resids; break; |
578 |
case 1: resids = edit_resids;break; |
579 |
default: resids = edit_resids; return; |
580 |
} |
581 |
|
582 |
for (i=0; resids[i] != 0; i++) |
583 |
set_menu_state (hm, resids[i], MF_GRAYED); |
584 |
} |
585 |
|
586 |
|
587 |
static char* |
588 |
gen_export_filename (const char *keyid, int is_secret) |
589 |
{ |
590 |
gpgme_key_t key; |
591 |
const char *s; |
592 |
char *p; |
593 |
|
594 |
if (get_pubkey (keyid, &key)) |
595 |
return m_strdup (keyid); |
596 |
s = key->uids->name; |
597 |
if (!s) |
598 |
return m_strdup (keyid); |
599 |
p = new char[strlen (s) + 8 + 16]; |
600 |
if (!p) |
601 |
BUG (0); |
602 |
sprintf (p, "%s%s.asc", s, is_secret? "_sec" : ""); |
603 |
for (size_t i=0; i < strlen (p); i++) { |
604 |
if (p[i] == ' ' || p[i] == ':' || p[i] == '?' || p[i] == '|') |
605 |
p[i] = '_'; |
606 |
} |
607 |
return p; |
608 |
} |
609 |
|
610 |
|
611 |
static void |
612 |
update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair) |
613 |
{ |
614 |
gpgme_key_t key; |
615 |
|
616 |
keycache_update (0, keyid); |
617 |
if (keypair) |
618 |
keycache_update (1, keyid); |
619 |
|
620 |
/* because we replaced the key item, we need to update the |
621 |
address of the pointer in the ListView control. */ |
622 |
get_pubkey (keyid, &key); |
623 |
keylist_upd_key (lv, pos, key); |
624 |
} |
625 |
|
626 |
|
627 |
/* Setup status bar for the main window @dlg. */ |
628 |
static HWND |
629 |
setup_status_bar (HWND dlg, listview_ctrl_t lv) |
630 |
{ |
631 |
HWND statbar; |
632 |
RECT r; |
633 |
int partpos[3]; |
634 |
int i; |
635 |
|
636 |
GetClientRect (dlg, &r); |
637 |
for (i=1; i <= 3; i++) |
638 |
partpos[i-1] = r.right/3*i; |
639 |
statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM, |
640 |
"status bar", dlg, KM_SEPARATOR_ID); |
641 |
|
642 |
ShowWindow (statbar, SW_SHOW); |
643 |
SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos); |
644 |
|
645 |
km_update_default_key_str (statbar); |
646 |
km_complete_status_bar (statbar, lv); |
647 |
|
648 |
return statbar; |
649 |
} |
650 |
|
651 |
|
652 |
BOOL CALLBACK |
653 |
keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
654 |
{ |
655 |
struct km_info *kmi; |
656 |
/*static km_group_s *gc = NULL;*/ |
657 |
static HMENU menu = NULL; |
658 |
static int refresh_keys = 0; |
659 |
INITCOMMONCONTROLSEX icex; |
660 |
HWND kl; |
661 |
HMENU hm; |
662 |
gpg_keycache_t c; |
663 |
gpgme_key_t key; |
664 |
/*km_group_cb_s gcb; XXX */ |
665 |
struct genkey_s genkey; |
666 |
struct winpt_key_s k = {0}; |
667 |
struct URL_ctx_s *url; |
668 |
refresh_cache_s rcs = {0}; |
669 |
char keyid[48], uid[128], type[32], *name; |
670 |
const char *t, * host; |
671 |
u16 port = 0; |
672 |
int idx = 0, i=0, rc; |
673 |
|
674 |
if ((msg != WM_INITDIALOG) |
675 |
&& ((kmi = (struct km_info*)GetWindowLong (dlg, GWL_USERDATA)) == NULL)) |
676 |
return FALSE; |
677 |
|
678 |
switch (msg) { |
679 |
case WM_INITDIALOG: |
680 |
kmi = new struct km_info; |
681 |
memset (kmi, 0, sizeof (struct km_info)); |
682 |
icex.dwSize = sizeof (INITCOMMONCONTROLSEX); |
683 |
icex.dwICC = ICC_BAR_CLASSES; |
684 |
InitCommonControlsEx (&icex); |
685 |
kmi->hwnd_sep = regist_sep_wnd (dlg, kmi); |
686 |
imagelist_load (dlg); |
687 |
|
688 |
SetWindowText( dlg, _("Key Manager") ); |
689 |
menu = LoadMenu( glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC ); |
690 |
set_menu_text_bypos (menu, 0, _("File")); |
691 |
set_menu_text_bypos (menu, 1, _("Edit")); |
692 |
set_menu_text_bypos (menu, 2, _("View")); |
693 |
set_menu_text_bypos (menu, 3, _("Key")); |
694 |
set_menu_text_bypos (menu, 4, _("Groups")); |
695 |
|
696 |
set_menu_text (menu, ID_KEYMISC_EDITKEY, _("Edit")); |
697 |
set_menu_text (menu, ID_KEYMISC_MAIL, _("Send Mail...")); |
698 |
set_menu_text (menu, ID_KEYMISC_OT, _("Ownertrust")); /* XXX */ |
699 |
set_menu_text (menu, ID_KEYMISC_COPY, _("&Copy\tCtrl+C")); |
700 |
set_menu_text (menu, ID_KEYMISC_PASTE, _("&Paste\tCtrl+V")); |
701 |
set_menu_text (menu, ID_KEYMISC_FIND, _("Search...\tCtrl+F")); |
702 |
set_menu_text (menu, ID_KEYMISC_SELALL, _("Select All\tCtrl+A")); |
703 |
set_menu_text (menu, ID_KEYMISC_QUIT, _("&Quit")); |
704 |
set_menu_text (menu, ID_KEYMISC_UID, _("User ID")); |
705 |
set_menu_text (menu, ID_KEYMISC_NEWKEY, _("&Expert")); |
706 |
set_menu_text (menu, ID_KEYMISC_KEYWIZARD, _("&Normal")); |
707 |
set_menu_text (menu, ID_KEYMISC_EDIT, _("Edit")); |
708 |
set_menu_text (menu, ID_KEYMISC_SIGN, _("&Sign")); |
709 |
set_menu_text (menu, ID_KEYMISC_DELETE, _("&Delete")); |
710 |
set_menu_text (menu, ID_KEYMISC_REVCERT, _("&Revoke")); |
711 |
set_menu_text (menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures")); |
712 |
set_menu_text (menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path")); |
713 |
set_menu_text (menu, ID_KEYMISC_EXPORT, _("&Export...")); |
714 |
set_menu_text (menu, ID_KEYMISC_IMPORT, _("&Import...")); |
715 |
set_menu_text (menu, ID_KEYMISC_PROPS, _("&Properties")); |
716 |
set_menu_text (menu, ID_KEYMISC_GPGOPT, _("Options")); |
717 |
set_menu_text (menu, ID_KEYMISC_GPGPREFS, _("Preferences")); |
718 |
set_menu_text (menu, ID_KEYMISC_SENDRECV, _("Keyserver") ); |
719 |
set_menu_text (menu, ID_KEYMISC_EXPORT_PRIVKEY, _("E&xport Secret Key")); |
720 |
set_menu_text (menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache")); |
721 |
set_menu_text (menu, ID_KEYMISC_REBUILD, _("R&everify Signatures")); |
722 |
set_menu_text (menu, ID_KEYMISC_REFRESH_KEYS, _("Refresh &Keys (Keyserver)")); |
723 |
set_menu_text (menu, ID_KEYMISC_INFO, _("Info") ); |
724 |
set_menu_text (menu, ID_KEYMISC_HELP, _("&Help")); |
725 |
|
726 |
SetMenu (dlg, menu); |
727 |
if( keyring_check_last_access() ) |
728 |
keycache_set_reload( 1 ); |
729 |
if( keycache_get_reload( ) ) |
730 |
keycache_reload( dlg ); |
731 |
c = keycache_get_ctx( KEYCACHE_PUB ); |
732 |
if( !c ) |
733 |
BUG( NULL ); |
734 |
kmi->keylist_sortby = KEY_SORT_USERID; |
735 |
Header_SetImageList(ListView_GetHeader(GetDlgItem( dlg, IDC_KEYMISC_KEYLIST )), |
736 |
glob_imagelist); |
737 |
kmi->lv = keylist_load( GetDlgItem( dlg, IDC_KEYMISC_KEYLIST ), c, |
738 |
NULL, KEYLIST_LIST, kmi->keylist_sortby ); |
739 |
/* init subclassing for the listview */ |
740 |
kl = GetDlgItem( dlg, IDC_KEYMISC_KEYLIST ); |
741 |
keylist_proc.dlg = dlg; |
742 |
keylist_proc.current = (WNDPROC)keylist_subclass_proc; |
743 |
keylist_proc.old = (WNDPROC)GetWindowLong( kl, GWL_WNDPROC ); |
744 |
if( keylist_proc.old ) { |
745 |
if( !SetWindowLong( kl, GWL_WNDPROC, (LONG)keylist_proc.current) ) { |
746 |
msg_box( dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR ); |
747 |
BUG( NULL ); |
748 |
} |
749 |
} |
750 |
#if 0 |
751 |
km_groups_new( &gc, GetDlgItem( dlg, IDC_KEYMISC_GROUP ) ); |
752 |
km_groups_load( gc ); |
753 |
#endif |
754 |
SetClassLong (dlg, GCL_HICON, (LONG)LoadIcon (glob_hinst, (LPCTSTR)IDI_WINPT)); |
755 |
|
756 |
kmi->statbar = setup_status_bar (dlg, kmi->lv); |
757 |
SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi); |
758 |
kmi->toolbar = load_toolbar (dlg, kmi); |
759 |
|
760 |
do_center_window (dlg, kmi); |
761 |
do_resize_window (dlg, kmi); |
762 |
update_ui_items (dlg, kmi->lv); |
763 |
|
764 |
SetDlgItemText (dlg, IDC_KEYMISC_GTEXT, _("Groups")); |
765 |
SetForegroundWindow (dlg); |
766 |
return TRUE; |
767 |
|
768 |
case WM_DESTROY: |
769 |
if (kmi->lv) { |
770 |
keylist_delete (kmi->lv); |
771 |
kmi->lv = NULL; |
772 |
|
773 |
/* |
774 |
if (gc) { |
775 |
km_groups_release (gc); |
776 |
gc = NULL; |
777 |
}*/ |
778 |
imagelist_destroy (); |
779 |
|
780 |
char buf[32]; |
781 |
ltoa (kmi->pos_x, buf, 10); |
782 |
set_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", buf ); |
783 |
ltoa (kmi->pos_y, buf, 10); |
784 |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", buf); |
785 |
/* Remove runtime information. This should be the last action taken here. */ |
786 |
delete kmi; kmi = NULL; |
787 |
SetWindowLong (dlg, GWL_USERDATA, 0); |
788 |
keycache_set_reload (refresh_keys); |
789 |
return FALSE; |
790 |
|
791 |
case WM_MOVE: |
792 |
/* kmi->pos_x = (int)(short)LOWORD(lparam); |
793 |
kmi->pos_y = (int)(short)HIWORD(lparam); */ |
794 |
RECT r; |
795 |
GetWindowRect (dlg, &r); |
796 |
kmi->pos_x = r.left; |
797 |
kmi->pos_y = r.top; |
798 |
break; |
799 |
|
800 |
|
801 |
case WM_RBUTTONUP: |
802 |
do_create_minpopup (dlg); |
803 |
break; |
804 |
|
805 |
case WM_NOTIFY: |
806 |
NMHDR * notify; |
807 |
POINT p; |
808 |
HMENU popup; |
809 |
|
810 |
notify = (NMHDR *)lparam; |
811 |
if (notify == NULL) |
812 |
break; |
813 |
switch (notify->code) |
814 |
{ |
815 |
case TBN_QUERYDELETE: |
816 |
SetWindowLong(dlg, DWL_MSGRESULT, TRUE); |
817 |
return TRUE; |
818 |
|
819 |
case TBN_QUERYINSERT: |
820 |
SetWindowLong(dlg, DWL_MSGRESULT, TRUE); |
821 |
return TRUE; |
822 |
|
823 |
case TBN_GETBUTTONINFO: |
824 |
LPTBNOTIFY lpTbNotify; |
825 |
lpTbNotify = (LPTBNOTIFY)lparam; |
826 |
if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) { |
827 |
lpTbNotify->tbButton.iBitmap = imagelist_getindex(myb[lpTbNotify->iItem].icon); |
828 |
lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command; |
829 |
lpTbNotify->tbButton.fsState = TBSTATE_ENABLED; |
830 |
lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON; |
831 |
lpTbNotify->tbButton.iString = 0; |
832 |
strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText); |
833 |
SetWindowLong(dlg, DWL_MSGRESULT, TRUE); |
834 |
} |
835 |
return TRUE; |
836 |
|
837 |
case TBN_RESET: /* Restore last saved toolbar status */ |
838 |
TBSAVEPARAMS tbsp; |
839 |
|
840 |
tbsp.hkr = HKEY_CURRENT_USER; |
841 |
tbsp.pszSubKey = "Software\\WinPT"; |
842 |
tbsp.pszValueName = "KM_toolbar"; |
843 |
SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp); |
844 |
break; |
845 |
|
846 |
case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */ |
847 |
tbsp.hkr = HKEY_CURRENT_USER; |
848 |
tbsp.pszSubKey = "Software\\WinPT"; |
849 |
tbsp.pszValueName = "KM_toolbar"; |
850 |
SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp); |
851 |
break; |
852 |
|
853 |
case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */ |
854 |
tbsp.hkr = HKEY_CURRENT_USER; |
855 |
tbsp.pszSubKey = "Software\\WinPT"; |
856 |
tbsp.pszValueName = "KM_toolbar"; |
857 |
SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp); |
858 |
break; |
859 |
|
860 |
case TTN_GETDISPINFO: |
861 |
LPTOOLTIPTEXT lpttt; |
862 |
lpttt = (LPTOOLTIPTEXT)lparam; |
863 |
|
864 |
lpttt->hinst = NULL; |
865 |
switch (lpttt->hdr.idFrom) { |
866 |
case ID_KEYMISC_DELETE: |
867 |
lpttt->lpszText = (char *)_("Delete key from keyring"); |
868 |
break; |
869 |
|
870 |
case ID_KEYMISC_PROPS: |
871 |
lpttt->lpszText = (char *)_("Show key properties"); |
872 |
break; |
873 |
|
874 |
case ID_KEYMISC_SIGN: |
875 |
lpttt->lpszText = (char *)_("Sign key"); |
876 |
break; |
877 |
|
878 |
case ID_KEYMISC_IMPORT: |
879 |
lpttt->lpszText = (char *)_("Import key to keyring"); |
880 |
break; |
881 |
|
882 |
case ID_KEYMISC_EXPORT: |
883 |
lpttt->lpszText = (char *)_("Export key to a file"); |
884 |
break; |
885 |
} |
886 |
return TRUE; |
887 |
|
888 |
case LVN_ITEMCHANGED: |
889 |
if (((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */ |
890 |
{ |
891 |
update_ui_items (dlg, kmi->lv); |
892 |
return TRUE; |
893 |
} |
894 |
break; |
895 |
|
896 |
case NM_RCLICK: |
897 |
if (notify->idFrom == IDC_KEYMISC_KEYLIST) { |
898 |
if (listview_get_curr_pos (kmi->lv) == -1) |
899 |
return TRUE; /* Popup only when a item was selected */ |
900 |
do_check_cache (kmi->lv, dlg, kmi->statbar); |
901 |
GetCursorPos (&p); |
902 |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX)); |
903 |
popup = GetSubMenu (hm, 0); |
904 |
|
905 |
set_menu_text (popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard")); |
906 |
set_menu_text (popup, ID_KEYCTX_KEYID_COPY, _("Copy Key ID to Clipboard")); |
907 |
set_menu_text (popup, ID_KEYCTX_FPR_COPY, _("Copy Fingerprint to Clipboard")); |
908 |
set_menu_text (popup, ID_KEYCTX_KINFO_COPY, _("Copy Key Info to Clipboard")); |
909 |
set_menu_text (popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard")); |
910 |
set_menu_text (popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard")); |
911 |
set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver")); |
912 |
set_menu_text (popup, ID_KEYCTX_MAXTRUST, _("Set Implicit &Trust")); |
913 |
set_menu_text (popup, ID_KEYCTX_LISTSIGS, _("&List Signatures")); |
914 |
set_menu_text (popup, ID_KEYCTX_PROPS, _("&Key Properties")); |
915 |
set_menu_text (popup, ID_KEYCTX_EDIT, _("Key Edit")); |
916 |
set_menu_text (popup, ID_KEYCTX_DEL, _("&Delete")); |
917 |
set_menu_text (popup, ID_KEYCTX_REV, _("&Revoke")); |
918 |
set_menu_text (popup, ID_KEYCTX_SIGN, _("&Sign")); |
919 |
set_menu_text (popup, ID_KEYCTX_ENABLE, _("&Enable")); |
920 |
set_menu_text (popup, ID_KEYCTX_DISABLE, _("&Disable")); |
921 |
set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Re&fresh from Keyserver")); |
922 |
set_menu_text (popup, ID_KEYCTX_SETPREFKS, _("Set preferred Keyserver URL")); |
923 |
set_menu_text (popup, ID_KEYCTX_SENDMAIL, _("Send Key to Mail Recipient")); |
924 |
set_menu_text (popup, ID_KEYCTX_SETDEFKEY, _("Set as Default Key")); |
925 |
/* change popup texts */ |
926 |
set_menu_text_bypos (popup, 0, _("Key Attributes")); |
927 |
set_menu_text_bypos (popup, 6, _("Add")); |
928 |
set_menu_text_bypos (popup, 19, _("Send to Keyserver")); |
929 |
|
930 |
set_menu_text (popup, ID_KEYCTX_ADDKEY, _("Key...")); |
931 |
set_menu_text (popup, ID_KEYCTX_ADDUID, _("User ID...")); |
932 |
set_menu_text (popup, ID_KEYCTX_ADDPHOTO, _("Photo ID...")); |
933 |
set_menu_text (popup, ID_KEYCTX_ADDREV, _("Revoker...")); |
934 |
|
935 |
idx = listview_get_curr_pos (kmi->lv); |
936 |
if (km_check_for_seckey (kmi->lv, idx, &i)) |
937 |
set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED); |
938 |
if (i == 0) |
939 |
set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED); |
940 |
if (!km_check_for_seckey (kmi->lv, idx, NULL)) { |
941 |
set_menu_state( popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED ); |
942 |
set_menu_state( popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED ); |
943 |
set_menu_state( popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED ); |
944 |
set_menu_state( popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED ); |
945 |
set_menu_state( popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED ); |
946 |
set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED); |
947 |
} |
948 |
else if( km_check_for_seckey (kmi->lv, idx, NULL) |
949 |
&& km_key_is_v3 (kmi->lv, idx)) { |
950 |
/* PGP 2 keys, version 3 have no no support for photo-id's, |
951 |
designated revokers and secondary keys. */ |
952 |
set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED); |
953 |
set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED); |
954 |
set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED); |
955 |
} |
956 |
if( km_get_key_status( kmi->lv, idx ) & KM_FLAG_DISABLED ) |
957 |
set_menu_state( popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED ); |
958 |
else |
959 |
set_menu_state( popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED ); |
960 |
if (km_get_key_status (kmi->lv, idx) & KM_FLAG_REVOKED) |
961 |
set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED); |
962 |
if (mapi_init()) |
963 |
set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED); |
964 |
/* Override 'Default Keyserver' with the actual name. */ |
965 |
host = kserver_get_hostname (0, -1, &port); |
966 |
set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host); |
967 |
popup_gpg_readonly (dlg, popup); |
968 |
TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
969 |
DestroyMenu (popup); |
970 |
DestroyMenu (hm); |
971 |
return TRUE; |
972 |
} |
973 |
#if 0 /* XXX */ |
974 |
if( notify->idFrom == IDC_KEYMISC_GROUP ) { |
975 |
HWND tree = GetDlgItem( dlg, IDC_KEYMISC_GROUP ); |
976 |
if( TreeView_GetSelection( tree ) ) { |
977 |
GetCursorPos( &p ); |
978 |
hm = LoadMenu( glob_hinst, MAKEINTRESOURCE(IDR_WINPT_GROUP_CTX) ); |
979 |
popup = GetSubMenu( hm, 0 ); |
980 |
if( km_index == -1 ) |
981 |
set_menu_state( popup, ID_GROUP_PASTE, MF_DISABLED|MF_GRAYED ); |
982 |
set_menu_text( popup, ID_GROUP_PASTE, _("Paste into this group") ); |
983 |
set_menu_text( popup, ID_GROUP_DELETE, _("Delete") ); |
984 |
TrackPopupMenu( popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL ); |
985 |
DestroyMenu( popup ); |
986 |
DestroyMenu( hm ); |
987 |
return TRUE; |
988 |
} |
989 |
} |
990 |
#endif |
991 |
break; |
992 |
|
993 |
case LVN_COLUMNCLICK: |
994 |
if (notify->idFrom == IDC_KEYMISC_KEYLIST) { |
995 |
NMLISTVIEW * nml = (LPNMLISTVIEW) lparam; |
996 |
int sortby = 0; |
997 |
switch (nml->iSubItem) { |
998 |
case 0: sortby = KEY_SORT_USERID; break; |
999 |
case 1: sortby = KEY_SORT_KEYID; break; |
1000 |
case 2: sortby = KEY_SORT_IS_SECRET; break; |
1001 |
case 3: sortby = KEY_SORT_LEN; break; |
1002 |
case 5: sortby = KEY_SORT_VALIDITY; break; |
1003 |
case 6: sortby = KEY_SORT_OTRUST; break; |
1004 |
case 7: sortby = KEY_SORT_CREATED; break; |
1005 |
case 8: sortby = KEY_SORT_ALGO; break; |
1006 |
default: return TRUE; //sortby = KEY_SORT_USERID; break; |
1007 |
} |
1008 |
|
1009 |
if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby) |
1010 |
kmi->keylist_sortby ^= KEYLIST_SORT_DESC; |
1011 |
else |
1012 |
kmi->keylist_sortby = sortby; |
1013 |
keylist_sort (kmi->lv, kmi->keylist_sortby); |
1014 |
return TRUE; |
1015 |
} |
1016 |
break; |
1017 |
} |
1018 |
break; |
1019 |
} |
1020 |
|
1021 |
case WM_WINDOWPOSCHANGING: |
1022 |
if (((WINDOWPOS*)lparam)->cx < 400) |
1023 |
((WINDOWPOS*)lparam)->cx = 400; |
1024 |
if (((WINDOWPOS*)lparam)->cy < 200) |
1025 |
((WINDOWPOS*)lparam)->cy = 200; |
1026 |
return TRUE; |
1027 |
|
1028 |
case WM_SIZE: |
1029 |
do_resize_window (dlg, kmi); |
1030 |
return TRUE; |
1031 |
|
1032 |
case WM_SYSCOMMAND: |
1033 |
if( LOWORD (wparam) == SC_CLOSE ) |
1034 |
EndDialog( dlg, TRUE ); |
1035 |
return FALSE; |
1036 |
|
1037 |
case WM_MENUSELECT: |
1038 |
menu_gpg_readonly (dlg, (HMENU)lparam, LOWORD (wparam)); |
1039 |
break; |
1040 |
|
1041 |
case WM_INITMENUPOPUP: |
1042 |
if ((UINT)LOWORD (lparam) == 3) { |
1043 |
HMENU m = (HMENU)wparam; |
1044 |
set_menu_text_bypos (m, 0, _("New")); |
1045 |
} |
1046 |
return FALSE; |
1047 |
|
1048 |
case WM_COMMAND: |
1049 |
if( gnupg_access_keyring( 1 ) ) { |
1050 |
msg_box( dlg, _("Could not access public keyring"), _("Key Manager"), MB_ERR ); |
1051 |
return FALSE; |
1052 |
} |
1053 |
do_check_cache( kmi->lv, dlg, kmi->statbar ); |
1054 |
switch( LOWORD( wparam ) ) { |
1055 |
case ID_KEYMISC_QUIT: |
1056 |
EndDialog( dlg, TRUE ); |
1057 |
return TRUE; |
1058 |
|
1059 |
case ID_KEYMISC_MAIL: |
1060 |
/* XXX |
1061 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_MAIL, GetDesktopWindow (), |
1062 |
winpt_mail_proc, NULL);*/ |
1063 |
break; |
1064 |
|
1065 |
case ID_KEYMISC_FIND: |
1066 |
km_find_key (dlg, kmi->lv); |
1067 |
break; |
1068 |
|
1069 |
case ID_KEYMISC_DELETE: |
1070 |
km_delete_keys (kmi->lv, dlg); |
1071 |
return TRUE; |
1072 |
|
1073 |
case ID_KEYMISC_SIGN: |
1074 |
if ( (idx = listview_get_curr_pos( kmi->lv )) == -1 ) { |
1075 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), |
1076 |
MB_ERR ); |
1077 |
return TRUE;; |
1078 |
} |
1079 |
if (km_check_key_status (kmi->lv, idx)) |
1080 |
return TRUE; |
1081 |
key = (gpgme_key_t)listview_get_item2 (kmi->lv, idx); |
1082 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1083 |
memset (&k, 0, sizeof (k)); |
1084 |
k.ctx = key; |
1085 |
k.keyid = keyid; |
1086 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg, |
1087 |
keysign_dlg_proc, (LPARAM)&k, |
1088 |
_("Key Signing"), IDS_WINPT_KEYSIGN); |
1089 |
if (k.update) |
1090 |
update_key (kmi->lv, idx, k.keyid, 0); |
1091 |
return TRUE; |
1092 |
|
1093 |
case ID_KEYMISC_REVCERT: |
1094 |
idx = listview_get_curr_pos( kmi->lv ); |
1095 |
if( idx == -1 ) { |
1096 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
1097 |
return TRUE; |
1098 |
} |
1099 |
listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 ); |
1100 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 ); |
1101 |
if ( !km_check_for_seckey( kmi->lv, idx, NULL ) ) { |
1102 |
msg_box( dlg, _("There is no secret key available!"), _("Key Manager"), MB_ERR ); |
1103 |
return TRUE; |
1104 |
} |
1105 |
|
1106 |
{ |
1107 |
char rinf[128]; |
1108 |
listview_get_item_text (kmi->lv, idx, 5, rinf, sizeof (rinf) -1); |
1109 |
if (strchr (rinf, 'R')) { |
1110 |
msg_box (dlg, _("Key already revoked!"), |
1111 |
_("Key Manager"), MB_INFO); |
1112 |
return TRUE; |
1113 |
} |
1114 |
} |
1115 |
|
1116 |
memset (&k, 0, sizeof (k)); |
1117 |
k.key_pair = 1; |
1118 |
k.keyid = keyid; |
1119 |
k.is_protected = km_check_if_protected (kmi->lv, idx); |
1120 |
dialog_box_param(glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg, |
1121 |
key_revoke_dlg_proc, (LPARAM)&k, |
1122 |
_("Key Revocation"), IDS_WINPT_KEYREVOKE); |
1123 |
return TRUE; |
1124 |
|
1125 |
case ID_KEYMISC_TRUSTPATH: |
1126 |
idx = listview_get_curr_pos( kmi->lv ); |
1127 |
if( idx == -1 ) { |
1128 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
1129 |
return TRUE; |
1130 |
} |
1131 |
listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 ); |
1132 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid -1 ); |
1133 |
if( km_check_for_seckey( kmi->lv, idx, NULL ) ) { |
1134 |
msg_box( dlg, _("It does not make any sense with a key pair!"), _("Key Manager"), MB_OK ); |
1135 |
return FALSE; |
1136 |
} |
1137 |
memset (&k, 0, sizeof (k)); |
1138 |
k.keyid = keyid; |
1139 |
k.uid = uid; |
1140 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg, |
1141 |
keytrust_dlg_proc, (LPARAM)&k, |
1142 |
_("List Trust Path"), IDS_WINPT_KEYTRUST ); |
1143 |
return TRUE; |
1144 |
|
1145 |
case ID_KEYMISC_CHECKSIGS: |
1146 |
idx = listview_get_curr_pos (kmi->lv); |
1147 |
if( idx == -1 ) { |
1148 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
1149 |
return FALSE; |
1150 |
} |
1151 |
listview_get_item_text (kmi->lv, idx, 0, uid, DIM (uid)-1); |
1152 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1153 |
memset (&k, 0, sizeof (k)); |
1154 |
k.keyid = keyid; |
1155 |
k.uid = uid; |
1156 |
k.ctx = (gpgme_key_t)listview_get_item2 (kmi->lv, idx); |
1157 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG, dlg, |
1158 |
keysig_dlg_proc, (LPARAM)&k, |
1159 |
_("Key Signature List" ), IDS_WINPT_KEYSIG); |
1160 |
return TRUE; |
1161 |
|
1162 |
case ID_KEYMISC_PROPS: |
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 FALSE; |
1167 |
} |
1168 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1169 |
listview_get_item_text (kmi->lv, idx, 2, type, DIM (type)-1); |
1170 |
memset (&k, 0, sizeof (k)); |
1171 |
k.key_pair = 0; |
1172 |
k.keyid = keyid; |
1173 |
if( !strcmp( type, "pub/sec" ) || !strcmp( type, "pub/crd" ) ) |
1174 |
k.key_pair = 1; |
1175 |
k.callback.ctl = kmi->lv; |
1176 |
k.callback.idx = idx; |
1177 |
k.is_v3 = km_key_is_v3 (kmi->lv, idx); |
1178 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg, |
1179 |
keyprops_dlg_proc, (LPARAM)&k, |
1180 |
_("Key Properties"), IDS_WINPT_KEYPROPS ); |
1181 |
if (k.callback.new_val != 0) { |
1182 |
t = get_key_trust_str (k.callback.new_val); |
1183 |
listview_add_sub_item (kmi->lv, idx, 6, t); |
1184 |
} |
1185 |
return TRUE; |
1186 |
|
1187 |
case ID_KEYMISC_RECACHE: |
1188 |
/* If there is already a reload request, don't bother the user with a message. */ |
1189 |
if (keycache_get_reload () == 1) |
1190 |
idx = IDYES; |
1191 |
else { |
1192 |
char inf[256]; |
1193 |
_snprintf (inf, sizeof (inf) -1, |
1194 |
_("This is only useful when the keyring has been " |
1195 |
"modified (sign a key...).\n" |
1196 |
"Do you really want to reload the keycache?")); |
1197 |
idx = msg_box (dlg, inf, _("Key Manager"), MB_YESNO); |
1198 |
} |
1199 |
if( idx == IDYES ) { |
1200 |
rcs.kr_reload = rcs.kr_update = 1; |
1201 |
rcs.tr_update = 0; |
1202 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
1203 |
keycache_dlg_proc, (LPARAM)&rcs ); |
1204 |
c = keycache_get_ctx( 1 ); |
1205 |
if( !c ) |
1206 |
BUG( dlg ); |
1207 |
keylist_reload( kmi->lv, c, KEYLIST_LIST, KEY_SORT_USERID ); |
1208 |
refresh_keys = 0; |
1209 |
} |
1210 |
return TRUE; |
1211 |
|
1212 |
case ID_KEYMISC_REBUILD: |
1213 |
name=NULL; |
1214 |
gpg_rebuild_cache (&name); |
1215 |
if (name) { |
1216 |
char *p = strchr (name, '\n'); |
1217 |
show_msg (dlg, 2000, p? name + (p-name)+1 : name); |
1218 |
free (name); |
1219 |
} |
1220 |
return TRUE; |
1221 |
|
1222 |
case ID_KEYMISC_NEWKEY: |
1223 |
memset (&genkey, 0, sizeof (genkey)); |
1224 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg, |
1225 |
keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"), |
1226 |
IDS_WINPT_KEYGEN); |
1227 |
if (genkey.newkey != NULL) |
1228 |
keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey); |
1229 |
return TRUE; |
1230 |
|
1231 |
case ID_KEYMISC_CARDNEW: |
1232 |
if( !scard_support ) { |
1233 |
msg_box( dlg, _("Smart Card support is not available."), _("Key Manager"), MB_INFO ); |
1234 |
return TRUE; |
1235 |
} |
1236 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg, |
1237 |
card_keygen_dlg_proc, 0, _("Card Key Generation"), |
1238 |
IDS_WINPT_CARD_KEYGEN ); |
1239 |
/* XXX: use new code */ |
1240 |
if( keycache_get_reload() ) |
1241 |
send_cmd_id( dlg, ID_KEYMISC_RECACHE ); |
1242 |
return TRUE; |
1243 |
|
1244 |
case ID_KEYMISC_KEYWIZARD: |
1245 |
memset (&genkey, 0, sizeof (genkey)); |
1246 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg, |
1247 |
keygen_wizard_dlg_proc, (LPARAM)&genkey, _("Key Generation Wizard"), |
1248 |
IDS_WINPT_KEYWIZARD); |
1249 |
if (genkey.newkey != NULL) |
1250 |
keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey); |
1251 |
return TRUE; |
1252 |
|
1253 |
case ID_KEYMISC_SENDRECV: |
1254 |
memset (&genkey, 0, sizeof (genkey)); |
1255 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg, |
1256 |
keyserver_dlg_proc, (LPARAM)&genkey, |
1257 |
_("Keyserver Access"), IDS_WINPT_KEYSERVER); |
1258 |
if (genkey.newkey != NULL) |
1259 |
keylist_add_key (kmi->lv, KEYLIST_LIST, genkey.newkey); |
1260 |
return TRUE; |
1261 |
|
1262 |
case ID_KEYMISC_GPGPREFS: |
1263 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, dlg, |
1264 |
gpgprefs_dlg_proc, 0, _("GnuPG Preferences"), |
1265 |
IDS_WINPT_GPGPREFS ); |
1266 |
return TRUE; |
1267 |
|
1268 |
case ID_KEYMISC_GPGOPT: |
1269 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg, |
1270 |
gpgopt_dlg_proc, 0, _("GnuPG Options" ), |
1271 |
IDS_WINPT_GPGOPT ); |
1272 |
return TRUE; |
1273 |
|
1274 |
case ID_KEYMISC_IMPORT: |
1275 |
t = get_fileopen_dlg (dlg, _("Choose Name of the Key File"), NULL, NULL); |
1276 |
if (t) |
1277 |
km_file_import (dlg, t); |
1278 |
return TRUE; |
1279 |
|
1280 |
case ID_KEYMISC_IMPORT_HTTP: |
1281 |
url = (struct URL_ctx_s*)get_http_file_dlg (dlg); |
1282 |
if (url->cancel == 0) |
1283 |
km_http_import (dlg, url->url); |
1284 |
delete url; url=NULL; |
1285 |
break; |
1286 |
|
1287 |
case ID_KEYMISC_EXPORT: |
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 |
return TRUE; |
1292 |
} |
1293 |
if (listview_count_items (kmi->lv, 1) > 1) |
1294 |
name = m_strdup ("Exported_GPG_Keys.asc"); |
1295 |
else { |
1296 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1297 |
name = gen_export_filename (keyid, 0); |
1298 |
} |
1299 |
t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name); |
1300 |
free_if_alloc (name); |
1301 |
if (t == NULL) |
1302 |
return TRUE; |
1303 |
km_file_export (dlg, kmi->lv, t); |
1304 |
return TRUE; |
1305 |
|
1306 |
case ID_KEYMISC_EXPORT_PRIVKEY: |
1307 |
idx = listview_get_curr_pos( kmi->lv ); |
1308 |
if( idx == -1 ) { |
1309 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
1310 |
return TRUE; |
1311 |
} |
1312 |
if( !km_check_for_seckey( kmi->lv, idx, NULL ) ) { |
1313 |
msg_box( dlg, _("There is no corresponding secret key for this key."), |
1314 |
_("Key Manager"), MB_ERR ); |
1315 |
return TRUE; |
1316 |
} |
1317 |
if( listview_count_items( kmi->lv, 1 ) > 1 ) { |
1318 |
msg_box( dlg, _("You can only export one secret key."), _("Key Manager"), MB_ERR ); |
1319 |
return TRUE; |
1320 |
} |
1321 |
idx = msg_box( dlg, |
1322 |
_("This operation will export your *SECRET* key!\n\n" |
1323 |
"Never send this key to ANYONE, it should be available\n" |
1324 |
"ONLY on your machine and you may use this function\n" |
1325 |
"to copy the key to a safe place.\n\n" |
1326 |
"Do you really want to export the key?"), |
1327 |
_("WARNING"), MB_INFO|MB_YESNO ); |
1328 |
if( idx == IDYES ) { |
1329 |
idx = listview_get_curr_pos( kmi->lv ); |
1330 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof (keyid)-8 ); |
1331 |
name = gen_export_filename (keyid, 1); |
1332 |
t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name); |
1333 |
if (t != NULL) |
1334 |
km_privkey_export (dlg, kmi->lv, t); |
1335 |
} |
1336 |
return TRUE; |
1337 |
|
1338 |
case ID_KEYMISC_INFO: |
1339 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, glob_hwnd, |
1340 |
about_winpt_dlg_proc, 0, _("About WinPT"), |
1341 |
IDS_WINPT_ABOUT ); |
1342 |
break; |
1343 |
|
1344 |
case ID_KEYMISC_HELP: |
1345 |
ShellExecute (dlg, "open", "winpt.chm", NULL, NULL, SW_SHOW); |
1346 |
break; |
1347 |
|
1348 |
case ID_KEYMISC_OT: |
1349 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST, glob_hwnd, |
1350 |
ownertrust_dlg_proc, 0, |
1351 |
_("Ownertrust"), IDS_WINPT_OWNERTRUST ); |
1352 |
break; |
1353 |
|
1354 |
case ID_KEYMISC_EDITKEY: |
1355 |
idx = listview_get_curr_pos (kmi->lv); |
1356 |
if (idx == -1) |
1357 |
break; |
1358 |
listview_get_item_text (kmi->lv, idx, 1, keyid, sizeof (keyid)-1); |
1359 |
/* XXX: pub/crd = secret key does not work */ |
1360 |
memset (&k, 0, sizeof (k)); |
1361 |
k.is_protected = km_check_if_protected (kmi->lv, idx); |
1362 |
k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL); |
1363 |
k.keyid = keyid; |
1364 |
k.is_v3 = km_key_is_v3 (kmi->lv, idx); |
1365 |
k.flags = km_get_key_status (kmi->lv, idx); |
1366 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg, |
1367 |
keyedit_main_dlg_proc, (LPARAM)&k, |
1368 |
_("Key Edit"), IDS_KEYCTX_EDIT); |
1369 |
if (k.update) |
1370 |
update_key (kmi->lv, idx, keyid, 1); |
1371 |
break; |
1372 |
|
1373 |
case ID_KEYMISC_COPY: |
1374 |
km_index = listview_get_curr_pos (kmi->lv); |
1375 |
km_clip_export (dlg, kmi->lv); |
1376 |
break; |
1377 |
|
1378 |
case ID_KEYMISC_SELALL: |
1379 |
listview_select_all (kmi->lv); |
1380 |
break; |
1381 |
|
1382 |
case ID_KEYMISC_PASTE: |
1383 |
km_index = -1; |
1384 |
km_clip_import (dlg); |
1385 |
break; |
1386 |
|
1387 |
case ID_KEYCTX_SETPREFKS: |
1388 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM(keyid)-1); |
1389 |
memset (&k, 0, sizeof (k)); |
1390 |
k.keyid = keyid; |
1391 |
keyedit_set_pref_keyserver (&k, dlg); |
1392 |
break; |
1393 |
|
1394 |
case ID_KEYMISC_REFRESH_KEYS: |
1395 |
if (listview_count_items (kmi->lv, 1) == 0) { |
1396 |
msg_box (dlg, _("No key was selected, select all by default."), _("Key Manager"), MB_INFO); |
1397 |
listview_select_all (kmi->lv); |
1398 |
} |
1399 |
km_refresh_from_keyserver (kmi->lv, dlg); |
1400 |
break; |
1401 |
|
1402 |
/** Context menu **/ |
1403 |
case ID_KEYCTX_EDIT: |
1404 |
send_cmd_id( dlg, ID_KEYMISC_EDITKEY ); |
1405 |
break; |
1406 |
|
1407 |
case ID_KEYCTX_PROPS: |
1408 |
send_cmd_id( dlg, ID_KEYMISC_PROPS ); |
1409 |
break; |
1410 |
|
1411 |
case ID_KEYCTX_UIDS: |
1412 |
send_cmd_id( dlg, ID_KEYMISC_UID ); |
1413 |
break; |
1414 |
|
1415 |
case ID_KEYCTX_SIGN: |
1416 |
send_cmd_id( dlg, ID_KEYMISC_SIGN ); |
1417 |
break; |
1418 |
|
1419 |
case ID_KEYCTX_DEL: |
1420 |
send_cmd_id (dlg, ID_KEYMISC_DELETE); |
1421 |
break; |
1422 |
|
1423 |
case ID_KEYCTX_REV: |
1424 |
send_cmd_id( dlg, ID_KEYMISC_REVCERT ); |
1425 |
break; |
1426 |
|
1427 |
case ID_KEYCTX_SENDMAIL: |
1428 |
km_send_to_mail_recipient (kmi->lv, dlg); |
1429 |
break; |
1430 |
|
1431 |
case ID_KEYCTX_KS_DEFAULT: |
1432 |
host = kserver_get_hostname (0, -1, &port); |
1433 |
km_send_to_keyserver (kmi->lv, dlg, host, port); |
1434 |
break; |
1435 |
|
1436 |
case ID_KEYCTX_ADDKEY: |
1437 |
idx = listview_get_curr_pos (kmi->lv); |
1438 |
listview_get_item_text( kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1439 |
memset (&k, 0, sizeof (k)); |
1440 |
k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL); |
1441 |
k.is_protected = km_check_if_protected (kmi->lv, idx); |
1442 |
k.keyid = keyid; |
1443 |
keyedit_add_subkey (&k, dlg, NULL); |
1444 |
if (k.update) |
1445 |
update_key (kmi->lv, idx, keyid, 1); |
1446 |
break; |
1447 |
|
1448 |
case ID_KEYCTX_ADDUID: |
1449 |
idx = listview_get_curr_pos (kmi->lv); |
1450 |
listview_get_item_text( kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1451 |
memset (&k, 0, sizeof (k)); |
1452 |
k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL); |
1453 |
k.is_protected = km_check_if_protected (kmi->lv, idx); |
1454 |
k.keyid = keyid; |
1455 |
keyedit_add_userid (&k, dlg, NULL); |
1456 |
if (k.update) |
1457 |
update_key (kmi->lv, idx, keyid, 1); |
1458 |
break; |
1459 |
|
1460 |
case ID_KEYCTX_ADDREV: |
1461 |
idx = listview_get_curr_pos (kmi->lv); |
1462 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1463 |
memset (&k, 0, sizeof (k)); |
1464 |
k.keyid = keyid; |
1465 |
k.is_protected = km_check_if_protected (kmi->lv, idx); |
1466 |
k.key_pair = km_check_for_seckey( kmi->lv, idx, NULL ); |
1467 |
keyedit_add_revoker (&k, dlg); |
1468 |
if (k.update) |
1469 |
update_key (kmi->lv, idx, keyid, 1); |
1470 |
break; |
1471 |
|
1472 |
case ID_KEYCTX_ADDPHOTO: |
1473 |
idx = listview_get_curr_pos (kmi->lv); |
1474 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1475 |
memset (&k, 0, sizeof (k)); |
1476 |
k.keyid = keyid; |
1477 |
k.is_protected = km_check_if_protected (kmi->lv, idx); |
1478 |
k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL); |
1479 |
keyedit_add_photo (&k, dlg); |
1480 |
if (k.update) |
1481 |
update_key (kmi->lv, idx, keyid, 1); |
1482 |
break; |
1483 |
|
1484 |
case ID_KEYCTX_KS_NL: |
1485 |
case ID_KEYCTX_KS_PL: |
1486 |
case ID_KEYCTX_KS_AT: |
1487 |
case ID_KEYCTX_KS_DE: |
1488 |
case ID_KEYCTX_KS_DK: |
1489 |
case ID_KEYCTX_KS_CZ: |
1490 |
case ID_KEYCTX_KS_ES: |
1491 |
case ID_KEYCTX_KS_UK: |
1492 |
host = kserver_get_hostname (LOWORD (wparam) - 40107, 0, &port); |
1493 |
km_send_to_keyserver (kmi->lv, dlg, host, port); |
1494 |
break; |
1495 |
|
1496 |
case ID_KEYCTX_RECVFROM: |
1497 |
km_refresh_from_keyserver (kmi->lv, dlg); |
1498 |
break; |
1499 |
|
1500 |
case ID_KEYCTX_UID_COPY: |
1501 |
/* XXX: add generic function to support multiple selection |
1502 |
with a callback */ |
1503 |
idx = listview_get_curr_pos( kmi->lv ); |
1504 |
listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid-1 ); |
1505 |
set_clip_text( NULL, uid, strlen( uid ) ); |
1506 |
break; |
1507 |
|
1508 |
case ID_KEYCTX_KEYID_COPY: |
1509 |
idx = listview_get_curr_pos( kmi->lv ); |
1510 |
listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 ); |
1511 |
set_clip_text( NULL, uid, strlen( uid ) ); |
1512 |
break; |
1513 |
|
1514 |
case ID_KEYCTX_FPR_COPY: |
1515 |
idx = listview_get_curr_pos( kmi->lv ); |
1516 |
key = (gpgme_key_t) listview_get_item2 (kmi->lv, idx); |
1517 |
if (key) { |
1518 |
const char * s = get_key_fpr (key); |
1519 |
set_clip_text (NULL, s? s : "", s? strlen (s): 0); |
1520 |
} |
1521 |
break; |
1522 |
|
1523 |
case ID_KEYCTX_KINFO_COPY: |
1524 |
idx = listview_get_curr_pos( kmi->lv ); |
1525 |
listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 ); |
1526 |
km_set_clip_info( uid ); |
1527 |
break; |
1528 |
|
1529 |
case ID_KEYCTX_COPY: |
1530 |
km_index = listview_get_curr_pos (kmi->lv); |
1531 |
km_clip_export (dlg, kmi->lv); |
1532 |
break; |
1533 |
|
1534 |
case ID_KEYCTX_PASTE: |
1535 |
km_index = -1; |
1536 |
km_clip_import (dlg); |
1537 |
break; |
1538 |
|
1539 |
case ID_KEYCTX_DISABLE: |
1540 |
idx = listview_get_curr_pos (kmi->lv); |
1541 |
km_enable_disable_key (kmi->lv, dlg, idx, 0); |
1542 |
break; |
1543 |
|
1544 |
case ID_KEYCTX_ENABLE: |
1545 |
idx = listview_get_curr_pos (kmi->lv); |
1546 |
km_enable_disable_key (kmi->lv, dlg, idx, 1); |
1547 |
break; |
1548 |
|
1549 |
case ID_KEYCTX_LISTSIGS: |
1550 |
send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS); |
1551 |
break; |
1552 |
|
1553 |
case ID_KEYCTX_MAXTRUST: |
1554 |
idx = listview_get_curr_pos (kmi->lv); |
1555 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1556 |
rc = km_set_implicit_trust (dlg, kmi->lv, idx); |
1557 |
if (!rc) |
1558 |
update_key (kmi->lv, idx, keyid, 0); |
1559 |
break; |
1560 |
|
1561 |
case ID_KEYCTX_SETDEFKEY: |
1562 |
idx = listview_get_curr_pos (kmi->lv); |
1563 |
if (!km_check_key_status (kmi->lv, idx)) { |
1564 |
listview_get_item_text (kmi->lv, idx, 1, keyid, DIM (keyid)-1); |
1565 |
rc = set_gnupg_default_key (keyid); |
1566 |
if (rc) |
1567 |
msg_box( dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR); |
1568 |
km_update_default_key_str (kmi->statbar); |
1569 |
} |
1570 |
break; |
1571 |
|
1572 |
#if 0 /* XXX */ |
1573 |
case ID_GROUP_NEW: |
1574 |
memset (&gcb, 0, sizeof (gcb)); |
1575 |
gcb.gc = gc; |
1576 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GROUP, glob_hwnd, |
1577 |
group_manager_dlg_proc, (LPARAM)&gcb, _("New Group"), |
1578 |
IDS_WINPT_GROUP); |
1579 |
if( gcb.use_name ) |
1580 |
treeview_add_item( GetDlgItem(dlg, IDC_KEYMISC_GROUP), NULL, gcb.name ); |
1581 |
return TRUE; |
1582 |
|
1583 |
case ID_GROUP_PASTE: |
1584 |
km_groups_add (gc, kmi->lv, km_index); |
1585 |
break; |
1586 |
|
1587 |
case ID_GROUP_DELETE: |
1588 |
km_groups_del (gc); |
1589 |
break; |
1590 |
#endif |
1591 |
} |
1592 |
|
1593 |
break; |
1594 |
} |
1595 |
|
1596 |
return FALSE; |
1597 |
} |
1598 |
|
1599 |
|
1600 |
|