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