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