1 |
/* wptKeyManagerDlg.cpp - WinPT Key Manager |
/* wptKeyManagerDlg.cpp - WinPT Key Manager |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* Copyright (C) 2004 Andreas Jobs |
* Copyright (C) 2004 Andreas Jobs |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
7 |
* WinPT is free software; you can redistribute it and/or modify |
* 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 |
* 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 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
* (at your option) any later version. |
11 |
* |
* |
12 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
16 |
* |
* |
17 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
18 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
*/ |
*/ |
21 |
|
#ifdef HAVE_CONFIG_H |
22 |
#include <windows.h> |
#include <config.h> |
23 |
#include <commctrl.h> |
#endif |
24 |
|
|
25 |
#include "../resource.h" |
#include <windows.h> |
26 |
#include "wptTypes.h" |
#include <commctrl.h> |
27 |
#include "wptGPG.h" |
|
28 |
#include "wptCommonCtl.h" |
#include "resource.h" |
29 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptTypes.h" |
30 |
#include "wptDlgs.h" |
#include "wptGPG.h" |
31 |
#include "wptW32API.h" |
#include "wptCommonCtl.h" |
32 |
#include "wptVersion.h" |
#include "wptContext.h" /* for passphrase_s */ |
33 |
#include "wptKeylist.h" |
#include "wptDlgs.h" |
34 |
#include "wptNLS.h" |
#include "wptW32API.h" |
35 |
#include "wptErrors.h" |
#include "wptVersion.h" |
36 |
#include "wptHotkey.h" |
#include "wptKeylist.h" |
37 |
#include "wptKeyManager.h" |
#include "wptNLS.h" |
38 |
#include "wptKeyserver.h" |
#include "wptErrors.h" |
39 |
#include "wptKeyEdit.h" |
#include "wptHotkey.h" |
40 |
#include "wptRegistry.h" |
#include "wptKeyManager.h" |
41 |
|
#include "wptKeyserver.h" |
42 |
|
#include "wptKeyEdit.h" |
43 |
#define WINDOWCLASS_SEPARATOR_CHILD "WINPT_SEP_CHILD" |
#include "wptRegistry.h" |
44 |
#define SEPARATOR_HEIGHT 5 |
#include "wptUTF8.h" |
45 |
|
|
46 |
int treeview_add_item (HWND tree, HTREEITEM parent, const char * text); |
/* Name and ID of the separator window. */ |
47 |
|
#define KM_SEPARATOR_ID 10000 |
48 |
static subclass_s keylist_proc; |
#define WINDOWCLASS_SEPARATOR_CHILD "WINPT_SEP_CHILD" |
49 |
static int km_index = -1; |
|
50 |
static int km_def_pos = 0; |
/* Virtual key codes. */ |
51 |
|
#ifndef VK_F |
52 |
HIMAGELIST glob_imagelist; |
#define VK_F 70 |
53 |
|
#endif |
54 |
struct km_info { |
#ifndef VK_A |
55 |
/* Window positions */ |
#define VK_A 65 |
56 |
int pos_x, pos_y; |
#endif |
57 |
int ypos_sep; |
#ifndef VK_C |
58 |
int ypercent_sep; |
#define VK_C 67 |
59 |
|
#endif |
60 |
HWND hwnd_sep; |
#ifndef VK_P |
61 |
HWND toolbar; |
#define VK_P 80 |
62 |
HWND statbar; |
#endif |
63 |
|
|
64 |
listview_ctrl_t lv; |
static subclass_s keylist_proc; |
65 |
int keylist_sortby; |
|
66 |
}; |
/* Handle to the global image list. */ |
67 |
|
HIMAGELIST glob_imagelist; |
68 |
struct mybuttons { |
|
69 |
long icon; |
struct km_info_s { |
70 |
long command; |
/* Window positions */ |
71 |
char *text; |
int pos_x, pos_y; |
72 |
}; |
int ypos_sep; |
73 |
|
int ypercent_sep; |
74 |
struct mybuttons myb[] = { |
|
75 |
{IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"}, |
/* Different kind of windows. */ |
76 |
{IMI_KEY_PROPS, ID_KEYMISC_PROPS, "Properties"}, |
HWND dlg; |
77 |
{IMI_KEY_SIGN, ID_KEYMISC_SIGN, "Sign"}, |
HWND hwnd_sep; |
78 |
{IMI_KEY_IMPORT, ID_KEYMISC_IMPORT, "Import"}, |
HWND toolbar; |
79 |
{IMI_KEY_EXPORT, ID_KEYMISC_EXPORT, "Export"}, |
HWND statbar; |
80 |
}; |
|
81 |
|
listview_ctrl_t lv; |
82 |
|
int lv_idx; |
83 |
static BOOL CALLBACK |
int keylist_sortby; |
84 |
keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
int magic; |
85 |
{ |
|
86 |
switch (msg) |
unsigned int enable_groups:1; |
87 |
{ |
}; |
88 |
case WM_LBUTTONDBLCLK: |
typedef struct km_info_s *km_info_t; |
89 |
send_cmd_id( keylist_proc.dlg, ID_KEYMISC_PROPS ); |
|
90 |
break; |
/* Toolbar button structure. */ |
91 |
|
struct mybuttons { |
92 |
case WM_KEYUP: |
long icon; |
93 |
int virt_key = (int)wparam; |
long command; |
94 |
if (virt_key == VK_SPACE) |
char *text; |
95 |
{ |
}; |
96 |
send_cmd_id( keylist_proc.dlg, ID_KEYMISC_PROPS ); |
|
97 |
break; |
struct mybuttons myb[] = { |
98 |
} |
{IMI_KEY_DELETE, ID_KEYMISC_DELETE, "Delete"}, |
99 |
if (virt_key == VK_DELETE) |
{IMI_KEY_PROPS, ID_KEYMISC_PROPS, "Properties"}, |
100 |
{ |
{IMI_KEY_SIGN, ID_KEYMISC_SIGN, "Sign"}, |
101 |
send_cmd_id( keylist_proc.dlg, ID_KEYMISC_DELETE ); |
{IMI_KEY_IMPORT, ID_KEYMISC_IMPORT, "Import"}, |
102 |
break; |
{IMI_KEY_EXPORT, ID_KEYMISC_EXPORT, "Export"}, |
103 |
} |
}; |
104 |
if (virt_key == VK_INSERT) |
|
105 |
{ |
|
106 |
send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE); |
static void km_gui_import (struct km_info_s *kmi, int cmd_id, void *param); |
107 |
break; |
void key_get_clip_info (const char *keyid, char *buf, size_t buflen); |
108 |
} |
|
109 |
break; |
|
110 |
} |
/* Subclass the keylist listview control to allow extended commands. */ |
111 |
|
static BOOL CALLBACK |
112 |
return CallWindowProc( keylist_proc.old, dlg, msg, wparam, lparam ); |
keylist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
113 |
} /* keylist_subclass_proc */ |
{ |
114 |
|
struct listview_ctrl_s lv; |
115 |
|
struct km_info_s *kmi; |
116 |
static HWND |
|
117 |
load_toolbar (HWND dlg, struct km_info * kmi) |
switch (msg) { |
118 |
{ |
case WM_DROPFILES: |
119 |
HWND tbwnd; |
kmi = (km_info_s *)keylist_proc.opaque; |
120 |
TBSAVEPARAMS tbsp; |
km_gui_import (kmi, WM_DROPFILES, (void*)wparam); |
121 |
TBBUTTON tb_buttons[] = { |
break; |
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}, |
case WM_LBUTTONDBLCLK: |
124 |
{imagelist_getindex(IMI_KEY_PROPS), ID_KEYMISC_PROPS, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS); |
125 |
{imagelist_getindex(IMI_KEY_SIGN), ID_KEYMISC_SIGN, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
break; |
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}, |
case WM_KEYUP: |
128 |
{imagelist_getindex(IMI_KEY_EXPORT), ID_KEYMISC_EXPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
int virt_key = (int)wparam; |
129 |
}; |
switch (virt_key) { |
130 |
|
case VK_SPACE: |
131 |
tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL, |
send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PROPS); |
132 |
WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE, |
break; |
133 |
0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL); |
|
134 |
if (tbwnd) { |
case VK_DELETE: |
135 |
SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0); |
send_cmd_id (keylist_proc.dlg, ID_KEYMISC_DELETE); |
136 |
SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist); |
break; |
137 |
SendMessage (tbwnd, TB_AUTOSIZE, 0, 0); |
|
138 |
ShowWindow (tbwnd, SW_SHOW); |
case VK_INSERT: |
139 |
|
send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE); |
140 |
/* Restore toolbar */ |
break; |
141 |
tbsp.hkr = HKEY_CURRENT_USER; |
|
142 |
tbsp.pszSubKey = "Software\\WinPT"; |
case VK_A: |
143 |
tbsp.pszValueName = "KM_toolbar"; |
if (GetAsyncKeyState (VK_CONTROL)) { |
144 |
if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0) |
lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST); |
145 |
SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]), (LONG)&tb_buttons[0]); |
listview_select_all (&lv); |
146 |
} |
} |
147 |
return tbwnd; |
break; |
148 |
} /* load_toolbar */ |
|
149 |
|
case VK_C: |
150 |
|
if (GetAsyncKeyState (VK_CONTROL)) { |
151 |
static void |
lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST); |
152 |
do_center_window (HWND dlg, struct km_info * kmi) |
km_clip_export (keylist_proc.dlg, &lv); |
153 |
{ |
} |
154 |
RECT rect; |
break; |
155 |
char * p; |
|
156 |
int pos_x = 0, pos_y = 0; |
case VK_P: |
157 |
|
if (GetAsyncKeyState (VK_CONTROL)) |
158 |
/* Find bottom of keylist */ |
send_cmd_id (keylist_proc.dlg, ID_KEYMISC_PASTE); |
159 |
GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect); |
break; |
160 |
MapWindowPoints (NULL, dlg, (POINT*)&rect, 2); |
|
161 |
|
case VK_F: |
162 |
kmi->ypos_sep = rect.bottom; |
if (GetAsyncKeyState (VK_CONTROL)) { |
163 |
|
lv.ctrl = GetDlgItem (keylist_proc.dlg, IDC_KEYMISC_KEYLIST); |
164 |
p = get_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X" ); |
km_find_key (dlg, &lv); |
165 |
if( p && !strcmp( p, " " ) ) { |
} |
166 |
free_if_alloc( p ); |
break; |
167 |
center_window( dlg ); |
} |
168 |
return; |
break; |
169 |
} |
} |
170 |
else if( p ) |
|
171 |
pos_x = atol( p ); |
return CallWindowProc (keylist_proc.old, dlg, msg, wparam, lparam); |
172 |
|
} |
173 |
p = get_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y" ); |
|
174 |
if( p && !strcmp( p, " " ) ) { |
|
175 |
free_if_alloc( p ); |
#define ico2idx(ico) imagelist_getindex((ico)) |
176 |
center_window( dlg ); |
|
177 |
return; |
static HWND |
178 |
} |
load_toolbar (HWND dlg, struct km_info_s *kmi) |
179 |
else if( p ) |
{ |
180 |
pos_y = atol( p ); |
HWND tbwnd; |
181 |
|
TBSAVEPARAMS tbsp; |
182 |
if( !pos_y && !pos_x ) { |
TBBUTTON tb_buttons[] = { |
183 |
center_window( dlg ); |
{ico2idx (IMI_KEY_NEW), ID_KEYMISC_KEYWIZARD, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L}, |
184 |
return; |
{ico2idx (IMI_KEY_DELETE), ID_KEYMISC_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
185 |
} |
{ico2idx (IMI_KEY_PROPS), ID_KEYMISC_PROPS, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
186 |
|
{ico2idx (IMI_KEY_SIGN), ID_KEYMISC_SIGN, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
187 |
if( pos_x > GetSystemMetrics( SM_CXSCREEN ) |
{ico2idx (IMI_KEY_SEARCH), ID_KEYMISC_SENDRECV, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
188 |
|| pos_y > GetSystemMetrics( SM_CYSCREEN ) ) { |
{0, 0, 0, TBSTYLE_SEP, {0}, 0L, 0}, |
189 |
pos_x = pos_y = 0; |
{ico2idx (IMI_KEY_FILE_IMPORT), ID_KEYMISC_IMPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
190 |
} |
{ico2idx (IMI_KEY_FILE_EXPORT), ID_KEYMISC_EXPORT, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
191 |
GetClientRect( dlg, &rect ); |
{ico2idx (IMI_KEY_IMPORT), ID_KEYCTX_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
192 |
MoveWindow( dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE ); |
{ico2idx (IMI_KEY_EXPORT), ID_KEYCTX_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, {0}, 0L, 0}, |
193 |
} |
}; |
194 |
|
|
195 |
|
tbwnd = CreateWindowEx (0, TOOLBARCLASSNAME, NULL, |
196 |
static void |
WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|CCS_ADJUSTABLE, |
197 |
do_resize_window( HWND dlg, struct km_info *kmi) |
0, 0, 0, 0, dlg, (HMENU)IDR_WINPT_KMTB, glob_hinst, NULL); |
198 |
{ |
if (tbwnd) { |
199 |
HWND h; |
SendMessage (tbwnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0); |
200 |
RECT rclient, rect; |
SendMessage (tbwnd, TB_SETIMAGELIST, 0, (LPARAM)glob_imagelist); |
201 |
BOOL bRepaint = FALSE; |
SendMessage (tbwnd, TB_AUTOSIZE, 0, 0); |
202 |
|
ShowWindow (tbwnd, SW_SHOW); |
203 |
/* Get rect of client area and make life easier */ |
|
204 |
GetClientRect( dlg, &rclient ); |
/* Restore toolbar */ |
205 |
|
tbsp.hkr = HKEY_CURRENT_USER; |
206 |
/* Move toolbar to the top of the window */ |
tbsp.pszSubKey = "Software\\WinPT"; |
207 |
if (kmi->toolbar) { |
tbsp.pszValueName = "KM_toolbar"; |
208 |
GetWindowRect(kmi->toolbar, &rect); |
if (SendMessage(tbwnd, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp ) == 0) |
209 |
ScreenToClient(dlg, (POINT*)&rect); |
SendMessage (tbwnd, TB_ADDBUTTONS, sizeof(tb_buttons) / sizeof(tb_buttons[0]), |
210 |
ScreenToClient(dlg, (POINT*)&(rect.right)); |
(LONG)&tb_buttons[0]); |
211 |
|
} |
212 |
rclient.top += rect.bottom - rect.top; |
return tbwnd; |
213 |
MoveWindow (kmi->toolbar, 0, 0, rclient.right - rclient.left, |
} |
214 |
rect.bottom - rect.top, bRepaint); |
|
215 |
} |
|
216 |
|
/* Restore the width of the columns from the registry. |
217 |
/* Move statusbar to the bottom of the window */ |
If no bitstring was found, the default size is used. */ |
218 |
if (kmi->statbar) { |
int |
219 |
GetWindowRect( kmi->statbar, &rect ); |
restore_column_info (struct km_info_s *kmi) |
220 |
ScreenToClient(dlg, (POINT*)&rect); |
{ |
221 |
ScreenToClient(dlg, (POINT*)&(rect.right)); |
WORD *buf; |
222 |
|
HKEY root; |
223 |
rclient.bottom -= rect.bottom - rect.top; |
DWORD type; |
224 |
MoveWindow (kmi->statbar, 0, rclient.bottom, rclient.right - rclient.left, |
DWORD size = kmi->lv->cols*sizeof (WORD), i; |
225 |
rect.bottom - rect.top, bRepaint); |
LONG ec; |
226 |
} |
|
227 |
|
ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0, |
228 |
// Obtain separator information and move it to the desired posistion |
KEY_ALL_ACCESS, &root); |
229 |
if (kmi->ypercent_sep) |
if (ec != ERROR_SUCCESS) |
230 |
kmi->ypos_sep = (rclient.bottom - rclient.top) * kmi->ypercent_sep / 100; |
return -1; |
231 |
else |
|
232 |
kmi->ypercent_sep = kmi->ypos_sep * 100 / (rclient.bottom - rclient.top); |
buf = new WORD[size/2]; |
233 |
|
if (!buf) |
234 |
// Don't move away |
BUG (NULL); |
235 |
if (kmi->ypos_sep+5 > rclient.bottom) |
ec = RegQueryValueEx (root, "KMColumnSize", NULL, &type, |
236 |
kmi->ypos_sep = rclient.bottom - 5; |
(BYTE*)buf, &size); |
237 |
if (kmi->ypos_sep < rclient.top) |
if (ec != ERROR_SUCCESS) { |
238 |
kmi->ypos_sep = rclient.top; |
RegCloseKey (root); |
239 |
MoveWindow (kmi->hwnd_sep, 0, kmi->ypos_sep, (rclient.right - rclient.left), 5, bRepaint); |
free_if_alloc (buf); |
240 |
|
return -1; |
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, |
/* check for garbled values. */ |
244 |
kmi->ypos_sep - rclient.top, bRepaint); |
for (i=0; i < size/2; i++) { |
245 |
rclient.top = kmi->ypos_sep + 5 + 8; |
if (buf[i] == 0 || buf[i] > 512) { |
246 |
|
free_if_alloc (buf); |
247 |
/* Place the group text and the group box below the separator */ |
return -1; |
248 |
h = GetDlgItem( dlg, IDC_KEYMISC_GTEXT ); |
} |
249 |
MoveWindow( h, rclient.left, rclient.top, 100, 14, bRepaint); |
} |
250 |
rclient.top += 18; |
for (i=0; i < size/2; i++) |
251 |
|
listview_set_column_width (kmi->lv, i, buf[i]); |
252 |
h = GetDlgItem( dlg, IDC_KEYMISC_GROUP ); |
free_if_alloc (buf); |
253 |
MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left, |
|
254 |
(rclient.bottom < rclient.top) ? 0 : rclient.bottom - rclient.top, bRepaint); |
size = sizeof (kmi->keylist_sortby); |
255 |
|
ec = RegQueryValueEx (root, "KMSortBy", NULL, &type, |
256 |
/* Repaint the whole thing */ |
(BYTE*)&kmi->keylist_sortby, &size); |
257 |
InvalidateRect (dlg, NULL, TRUE); |
if (ec != ERROR_SUCCESS) |
258 |
} /* do_resize_window */ |
kmi->keylist_sortby = KEY_SORT_USERID; |
259 |
|
RegCloseKey (root); |
260 |
|
return 0; |
261 |
static void |
} |
262 |
do_create_minpopup (HWND dlg) |
|
263 |
{ |
|
264 |
HMENU hm; |
/* Save the current column width to the registry. */ |
265 |
MENUITEMINFO mi; |
int |
266 |
char * s; |
save_column_info (struct km_info_s *kmi) |
267 |
POINT p; |
{ |
268 |
|
HKEY root; |
269 |
if (gpg_read_only) |
WORD *buf; |
270 |
return; |
LONG ec; |
271 |
hm = CreatePopupMenu (); |
int i; |
272 |
if (!hm) |
|
273 |
BUG( NULL ); |
buf = new WORD[kmi->lv->cols]; |
274 |
memset (&mi, 0, sizeof mi); |
if (!buf) |
275 |
mi.cbSize = sizeof mi; |
BUG (NULL); |
276 |
s = (char *)_("Paste Key from Clipboard"); |
for (i=0; i < kmi->lv->cols; i++) { |
277 |
mi.fType = MF_STRING; |
LVCOLUMN lvc; |
278 |
mi.dwTypeData = s; |
|
279 |
mi.cch = strlen (s); |
memset (&lvc, 0, sizeof (lvc)); |
280 |
mi.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE; |
lvc.mask = LVCF_WIDTH; |
281 |
mi.wID = ID_KEYCTX_PASTE; |
ListView_GetColumn (kmi->lv->ctrl, i, &lvc); |
282 |
InsertMenuItem (hm, 0, FALSE, &mi); |
buf[i] = lvc.cx; |
283 |
GetCursorPos (&p); |
} |
284 |
TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL); |
|
285 |
DestroyMenu (hm); |
ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\WinPT", 0, |
286 |
} /* do_create_minpopup */ |
KEY_ALL_ACCESS, &root); |
287 |
|
if (ec != ERROR_SUCCESS) { |
288 |
|
free_if_alloc (buf); |
289 |
static void |
return -1; |
290 |
do_check_cache( listview_ctrl_t lv, HWND dlg, HWND sb ) |
} |
291 |
{ |
|
292 |
gpgme_keycache_t cache; |
ec = RegSetValueEx (root, "KMColumnSize", 0, REG_BINARY, |
293 |
|
(const BYTE*)buf, 2*kmi->lv->cols); |
294 |
if( keycache_get_reload( ) ) { |
if (ec == ERROR_SUCCESS) { |
295 |
keycache_reload( dlg ); |
ec = RegSetValueEx (root, "KMSortBy", 0, REG_DWORD_BIG_ENDIAN, |
296 |
keycache_set_reload( 0 ); |
(const BYTE*)&kmi->keylist_sortby, |
297 |
cache = keycache_get_ctx( 1 ); |
sizeof (kmi->keylist_sortby)); |
298 |
if( !cache ) |
} |
299 |
BUG( dlg ); |
RegCloseKey (root); |
300 |
keylist_reload( lv, cache, KEYLIST_LIST, GPGME_ATTR_USERID ); |
free_if_alloc (buf); |
301 |
km_complete_status_bar (sb, lv, km_def_pos); |
return ec == ERROR_SUCCESS? 0 : -1; |
302 |
} |
} |
303 |
} /* do_check_cache */ |
|
304 |
|
|
305 |
|
/* Restore the original size of the dialog. */ |
306 |
long CALLBACK |
static void |
307 |
separator_wnd_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) |
restore_window_size (HWND dlg, struct km_info_s *kmi) |
308 |
{ |
{ |
309 |
static POINT last_mouse_pos; |
char *p; |
310 |
|
int height = 0, width = 0; |
311 |
if (msg == WM_CREATE) |
|
312 |
SetWindowLong (hwnd, GWL_USERDATA, (long)(((CREATESTRUCT*)lparam)->lpCreateParams)); |
/* Restore the original window size. */ |
313 |
|
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Size_Width"); |
314 |
switch (msg) { |
if (p) { |
315 |
case WM_PAINT: |
width = atoi (p); |
316 |
PAINTSTRUCT ps; |
free_if_alloc (p); |
317 |
RECT rect; |
} |
318 |
HPEN hpen; |
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Size_Height"); |
319 |
|
if (p) { |
320 |
GetClientRect (hwnd, &rect); |
height = atoi (p); |
321 |
BeginPaint (hwnd, &ps); |
free_if_alloc (p); |
322 |
|
} |
323 |
// Background |
if (height > 0 && width > 0) |
324 |
FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1)); |
SetWindowPos (dlg, HWND_TOP, kmi->pos_x, kmi->pos_y, |
325 |
|
height, width, SWP_SHOWWINDOW); |
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); |
/* Center window @dlg. */ |
330 |
LineTo(ps.hdc, rect.right, 0); |
static void |
331 |
DeleteObject(hpen); |
do_center_window (HWND dlg, struct km_info_s *kmi) |
332 |
} |
{ |
333 |
MoveToEx(ps.hdc, 0, 1, NULL); |
RECT rect; |
334 |
if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT))) != NULL) { |
char *p; |
335 |
SelectObject(ps.hdc, (LPVOID)hpen); |
int pos_x = 0; |
336 |
LineTo(ps.hdc, rect.right, rect.bottom); |
int pos_y = 0; |
337 |
DeleteObject(hpen); |
|
338 |
} |
/* Find bottom of keylist */ |
339 |
|
GetWindowRect (GetDlgItem(dlg, IDC_KEYMISC_KEYLIST), &rect); |
340 |
MoveToEx(ps.hdc, 0, rect.bottom-1, NULL); |
MapWindowPoints (NULL, dlg, (POINT*)&rect, 2); |
341 |
if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW))) != NULL) { |
|
342 |
SelectObject(ps.hdc, (LPVOID)hpen); |
kmi->ypos_sep = rect.bottom; |
343 |
LineTo(ps.hdc, rect.right, rect.bottom-1); |
|
344 |
DeleteObject(hpen); |
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X"); |
345 |
} |
if (p && !strcmp (p, " ")) { |
346 |
MoveToEx(ps.hdc, 0, rect.bottom, NULL); |
free_if_alloc (p); |
347 |
if ((hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW))) != NULL) { |
center_window (dlg, NULL); |
348 |
SelectObject(ps.hdc, (LPVOID)hpen); |
return; |
349 |
LineTo(ps.hdc, rect.right, rect.bottom); |
} |
350 |
DeleteObject(hpen); |
else if (p) |
351 |
} |
pos_x = atoi (p); |
352 |
|
|
353 |
EndPaint (hwnd, &ps); |
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y"); |
354 |
return 0; |
if (p && !strcmp (p, " ")) { |
355 |
|
free_if_alloc (p); |
356 |
case WM_LBUTTONDOWN: |
center_window (dlg, NULL); |
357 |
last_mouse_pos.x = LOWORD(lparam); |
return; |
358 |
last_mouse_pos.y = HIWORD(lparam); |
} |
359 |
ClientToScreen (hwnd, &last_mouse_pos); |
else if (p) |
360 |
SetCapture (hwnd); |
pos_y = atoi (p); |
361 |
return 0; |
|
362 |
|
if (!pos_y && !pos_x) { |
363 |
case WM_LBUTTONUP: |
center_window (dlg, NULL); |
364 |
ReleaseCapture (); |
return; |
365 |
return 0; |
} |
366 |
|
|
367 |
case WM_MOUSEMOVE: |
if (pos_x < 0 || pos_y < 0) |
368 |
if (wparam == MK_LBUTTON) { |
pos_x = pos_y = 0; |
369 |
struct km_info *kmi; |
if (pos_x > GetSystemMetrics (SM_CXSCREEN) |
370 |
POINT p; |
|| pos_y > GetSystemMetrics (SM_CYSCREEN)) { |
371 |
RECT rect; |
pos_x = pos_y = 0; |
372 |
|
} |
373 |
if ((kmi = (struct km_info *)GetWindowLong (hwnd, GWL_USERDATA)) == NULL) |
kmi->pos_x = pos_x; |
374 |
break; |
kmi->pos_y = pos_y; |
375 |
|
|
376 |
// Calculate mouse movement |
GetClientRect (dlg, &rect); |
377 |
p.x = LOWORD(lparam); |
MoveWindow (dlg, pos_x, pos_y, rect.right, rect.bottom, TRUE); |
378 |
p.y = HIWORD(lparam); |
} |
379 |
ClientToScreen (hwnd, &p); |
|
380 |
|
|
381 |
GetWindowRect (hwnd, &rect); |
/* Resize the key manager window with the information from @kmi. */ |
382 |
rect.top += (short)(p.y - last_mouse_pos.y); |
static void |
383 |
rect.bottom += (short)(p.y - last_mouse_pos.y); |
do_resize_window (HWND dlg, struct km_info_s *kmi) |
384 |
|
{ |
385 |
last_mouse_pos.y = p.y; |
HWND h; |
386 |
|
RECT rclient, rect; |
387 |
// Apply mouse movement to window. Beware the MoveWindow is relaive |
BOOL bRepaint = FALSE; |
388 |
// to parent NOT screen |
|
389 |
MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&rect, 2); |
/* Get rect of client area and make life easier */ |
390 |
kmi->ypos_sep = rect.top; |
GetClientRect (dlg, &rclient); |
391 |
kmi->ypercent_sep = 0; // This forces do_resize_window to use abs. position |
|
392 |
do_resize_window (GetParent(hwnd), kmi); |
/* Move toolbar to the top of the window */ |
393 |
return 0; |
if (kmi->toolbar) { |
394 |
} |
GetWindowRect (kmi->toolbar, &rect); |
395 |
} |
ScreenToClient (dlg, (POINT*)&rect); |
396 |
|
ScreenToClient (dlg, (POINT*)&(rect.right)); |
397 |
return DefWindowProc (hwnd, msg, wparam, lparam); |
|
398 |
} |
rclient.top += rect.bottom - rect.top; |
399 |
|
MoveWindow (kmi->toolbar, 0, 0, rclient.right - rclient.left, |
400 |
|
rect.bottom - rect.top, bRepaint); |
401 |
static HWND |
} |
402 |
regist_sep_wnd (HWND dlg, struct km_info * kmi) |
|
403 |
{ |
/* Move statusbar to the bottom of the window */ |
404 |
WNDCLASS wndclass; |
if (kmi->statbar) { |
405 |
HWND h; |
GetWindowRect (kmi->statbar, &rect); |
406 |
|
ScreenToClient (dlg, (POINT*)&rect); |
407 |
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; |
ScreenToClient (dlg, (POINT*)&(rect.right)); |
408 |
wndclass.lpfnWndProc = separator_wnd_proc; |
|
409 |
wndclass.cbClsExtra = 0; |
rclient.bottom -= rect.bottom - rect.top; |
410 |
wndclass.cbWndExtra = sizeof (long); |
MoveWindow (kmi->statbar, 0, rclient.bottom, |
411 |
wndclass.hInstance = glob_hinst; |
rclient.right - rclient.left, |
412 |
wndclass.hIcon = NULL; |
rect.bottom - rect.top, bRepaint); |
413 |
wndclass.hCursor = LoadCursor (NULL, IDC_SIZENS); |
} |
414 |
wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH); |
|
415 |
wndclass.lpszMenuName = 0; |
/* Obtain separator information and move it to the desired posistion */ |
416 |
wndclass.lpszClassName = WINDOWCLASS_SEPARATOR_CHILD; |
if (kmi->ypercent_sep) |
417 |
RegisterClass (&wndclass); |
kmi->ypos_sep = (rclient.bottom - rclient.top) * kmi->ypercent_sep / 100; |
418 |
|
else |
419 |
h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL, |
kmi->ypercent_sep = kmi->ypos_sep * 100 / (rclient.bottom - rclient.top); |
420 |
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE, |
|
421 |
0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi); |
/* Don't move away */ |
422 |
ShowWindow (h, SW_SHOW); |
if (kmi->ypos_sep+5 > rclient.bottom) |
423 |
return h; |
kmi->ypos_sep = rclient.bottom - 5; |
424 |
} /* regist_sep_wnd */ |
if (kmi->ypos_sep < rclient.top) |
425 |
|
kmi->ypos_sep = rclient.top; |
426 |
|
MoveWindow (kmi->hwnd_sep, 0, kmi->ypos_sep, |
427 |
|
(rclient.right - rclient.left), 5, bRepaint); |
428 |
#define enable_button(hwnd, cid) \ |
|
429 |
SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG (key_selected, 0)) |
/* Place the keylist above the separator */ |
430 |
|
h = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST); |
431 |
void |
MoveWindow (h, rclient.left, rclient.top, rclient.right - rclient.left, |
432 |
update_ui_items (HWND hwnd, listview_ctrl_t lv) |
kmi->ypos_sep - rclient.top, bRepaint); |
433 |
{ |
rclient.top = kmi->ypos_sep + 5 + 8; |
434 |
int key_selected = 0, key_has_sec = 0; |
|
435 |
int i, key_inv = 0; |
if (kmi->enable_groups != 0) { |
436 |
HWND hwnd_child; |
/* Place the group text and the group box below the separator */ |
437 |
HMENU hmenu; |
h = GetDlgItem (dlg, IDC_KEYMISC_GTEXT); |
438 |
|
MoveWindow (h, rclient.left, rclient.top, 100, 14, bRepaint); |
439 |
/* Get some states */ |
rclient.top += 18; |
440 |
key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST), |
|
441 |
LVM_GETSELECTEDCOUNT, 0, 0) |
h = GetDlgItem (dlg, IDC_KEYMISC_GROUP); |
442 |
? TRUE : FALSE; |
MoveWindow (h, rclient.left, rclient.top, |
443 |
key_has_sec = FALSE; |
rclient.right - rclient.left, |
444 |
if (key_selected) { |
(rclient.bottom < rclient.top) ? |
445 |
i = listview_get_curr_pos (lv); |
0 : rclient.bottom - rclient.top, bRepaint); |
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 |
} |
/* Repaint the whole thing */ |
449 |
|
InvalidateRect (dlg, NULL, TRUE); |
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); |
/* Return true if the clipboard contains an OpenPGP key. */ |
454 |
enable_button (hwnd_child, ID_KEYMISC_SIGN); |
static bool |
455 |
enable_button (hwnd_child, ID_KEYMISC_EXPORT); |
clip_contains_pgpkey (void) |
456 |
|
{ |
457 |
/* Enable / disable menu items */ |
char *ctxt; |
458 |
hmenu = GetMenu (hwnd); |
bool val = false; |
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); |
ctxt = get_clip_text (NULL); |
461 |
set_menu_state (hmenu, ID_KEYMISC_REVCERT, key_has_sec ? MF_ENABLED : MF_GRAYED); |
if (!ctxt || strlen (ctxt) < 512) |
462 |
set_menu_state (hmenu, ID_KEYMISC_DELETE, key_selected ? MF_ENABLED : MF_GRAYED); |
val = false; |
463 |
set_menu_state (hmenu, ID_KEYMISC_PROPS, key_selected ? MF_ENABLED : MF_GRAYED); |
else if (strstr (ctxt, "BEGIN PGP") && strstr (ctxt, "KEY BLOCK") && |
464 |
set_menu_state (hmenu, ID_KEYMISC_SIGN, key_selected && !key_inv ? MF_ENABLED : MF_GRAYED); |
strstr (ctxt, "END PGP")) |
465 |
} /* update_ui_items */ |
val = true; |
466 |
|
free_if_alloc (ctxt); |
467 |
|
return val; |
468 |
static void |
} |
469 |
popup_gpg_readonly (HWND dlg, HMENU hm) |
|
470 |
{ |
|
471 |
int resids[] = { |
/* Show a mini popup menu to import keys. */ |
472 |
ID_KEYCTX_PASTE, |
static void |
473 |
ID_KEYCTX_EDIT, |
do_create_minpopup (HWND dlg) |
474 |
ID_KEYCTX_SIGN, |
{ |
475 |
ID_KEYCTX_REV, |
HMENU hm; |
476 |
ID_KEYCTX_DEL, |
POINT p; |
477 |
ID_KEYCTX_ENABLE, |
|
478 |
ID_KEYCTX_DISABLE, |
if (gpg_read_only || !clip_contains_pgpkey ()) |
479 |
ID_KEYCTX_RECVFROM, |
return; |
480 |
ID_KEYCTX_ADDKEY, |
hm = CreatePopupMenu (); |
481 |
ID_KEYCTX_ADDPHOTO, |
if (!hm) |
482 |
ID_KEYCTX_ADDUID, |
BUG (0); |
483 |
ID_KEYCTX_ADDREV, |
insert_menu_item (hm, 0, ID_KEYCTX_PASTE, _("Paste Key from Clipboard")); |
484 |
0 |
GetCursorPos (&p); |
485 |
}; |
TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL); |
486 |
int i; |
DestroyMenu (hm); |
487 |
|
} |
488 |
if (gpg_read_only == 0) |
|
489 |
return; |
|
490 |
for (i=0; resids[i] != 0; i++) |
/* Update the default key entry in the status bar for dialog @dlg. */ |
491 |
set_menu_state (hm, resids[i], MF_GRAYED); |
void |
492 |
} |
update_default_key_str (HWND dlg) |
493 |
|
{ |
494 |
|
const char *fmt; |
495 |
static void |
char *keyid; |
496 |
menu_gpg_readonly (HWND dlg, HMENU hm, int id) |
char defkeyinf[128]; |
497 |
{ |
|
498 |
int key_resids[] = |
keyid = get_gnupg_default_key (); |
499 |
{ |
if (!keyid) |
500 |
ID_KEYMISC_SIGN, |
return; |
501 |
ID_KEYMISC_DELETE, |
if ((keyid[0] >= 'A' && keyid[0] <= 'Z') || |
502 |
ID_KEYMISC_REVCERT, |
(keyid[0] >= 'a' && keyid[0] <= 'z') || |
503 |
ID_KEYMISC_IMPORT_HTTP, |
(keyid[0] == '0' && keyid[1] == 'x')) |
504 |
ID_KEYMISC_IMPORT, |
fmt = _("Default Key: %s"); |
505 |
ID_KEYMISC_REFRESH_KEYS, |
else |
506 |
ID_KEYMISC_REBUILD, |
fmt = _("Default Key: 0x%s"); |
507 |
ID_KEYMISC_KEYWIZARD, |
_snprintf (defkeyinf, sizeof (defkeyinf) - 1, fmt, keyid); |
508 |
ID_KEYMISC_CARDNEW, |
SendMessage (dlg, SB_SETTEXT, 0, (LPARAM)defkeyinf); |
509 |
ID_KEYMISC_NEWKEY, |
gpg_keycache_set_default_key (keycache_get_ctx (0), keyid); |
510 |
0, |
free_if_alloc (keyid); |
511 |
}; |
} |
512 |
int edit_resids[] = |
|
513 |
{ |
|
514 |
ID_KEYMISC_PASTE, |
/* Count all keys and show from @lv results in the status bar @sb. */ |
515 |
ID_KEYMISC_OT, |
void |
516 |
ID_KEYMISC_EDITKEY, |
update_status_bar (HWND sb, listview_ctrl_t lv) |
517 |
0 |
{ |
518 |
}; |
char txt_sec[128], txt_pub[128]; |
519 |
int * resids; |
int nkeys = 0, nsec = 0; |
520 |
int i; |
int i; |
521 |
|
|
522 |
|
nkeys = listview_count_items (lv, 0); |
523 |
if (gpg_read_only == 0) |
for (i = 0; i < nkeys; i++) { |
524 |
return; |
if (km_check_for_seckey (lv, i, NULL)) |
525 |
switch (id) |
nsec++; |
526 |
{ |
} |
527 |
case 0: return; |
_snprintf (txt_sec, sizeof (txt_sec)-1, _("%d secret keys"), nsec); |
528 |
case 3: resids = key_resids; break; |
_snprintf (txt_pub, sizeof (txt_pub)-1, _("%d keys"), nkeys); |
529 |
case 1: resids = edit_resids;break; |
SendMessage (sb, SB_SETTEXT, 1, (LPARAM)txt_sec); |
530 |
} |
SendMessage (sb, SB_SETTEXT, 2, (LPARAM)txt_pub); |
531 |
|
} |
532 |
for (i=0; resids[i] != 0; i++) |
|
533 |
set_menu_state (hm, resids[i], MF_GRAYED); |
|
534 |
} |
long CALLBACK |
535 |
|
separator_wnd_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
536 |
|
{ |
537 |
BOOL CALLBACK |
static POINT last_mouse_pos; |
538 |
keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
|
539 |
{ |
if (msg == WM_CREATE) |
540 |
struct km_info *kmi; |
SetWindowLong (hwnd, GWL_USERDATA, |
541 |
static km_group_s *gc = NULL; |
(long)(((CREATESTRUCT*)lparam)->lpCreateParams)); |
542 |
static HMENU menu = NULL; |
|
543 |
static int refresh_keys = 0; |
switch (msg) { |
544 |
INITCOMMONCONTROLSEX icex; |
case WM_PAINT: |
545 |
HWND kl; |
PAINTSTRUCT ps; |
546 |
HMENU hm; |
RECT rect; |
547 |
gpgme_keycache_t c; |
HPEN hpen; |
548 |
gpgme_key_t pk; |
|
549 |
km_group_cb_s gcb; |
GetClientRect (hwnd, &rect); |
550 |
struct winpt_key_s k = {0}; |
BeginPaint (hwnd, &ps); |
551 |
struct http_file_s * http; |
|
552 |
refresh_cache_s rcs = {0}; |
/* Background */ |
553 |
char keyid[48], uid[128], type[32], * q; |
FillRect (ps.hdc, &rect, (HBRUSH)(COLOR_3DFACE+1)); |
554 |
const char *t, * host; |
|
555 |
u16 port = 0; |
/* The lines from the light into the dark */ |
556 |
int idx = 0, i=0, rc; |
MoveToEx (ps.hdc, 0,0, NULL); |
557 |
size_t size = 0; |
hpen = CreatePen (PS_SOLID, 0, GetSysColor (COLOR_3DHILIGHT)); |
558 |
|
if (hpen != NULL) { |
559 |
if ((msg != WM_INITDIALOG) |
SelectObject (ps.hdc, (LPVOID)hpen); |
560 |
&& ((kmi = (struct km_info*)GetWindowLong (dlg, GWL_USERDATA)) == NULL)) |
LineTo (ps.hdc, rect.right, 0); |
561 |
return FALSE; |
DeleteObject (hpen); |
562 |
|
} |
563 |
switch (msg) { |
MoveToEx (ps.hdc, 0, 1, NULL); |
564 |
case WM_INITDIALOG: |
hpen = CreatePen (PS_SOLID, 0, GetSysColor (COLOR_3DLIGHT)); |
565 |
kmi = new struct km_info; |
if (hpen != NULL) { |
566 |
memset (kmi, 0, sizeof (struct km_info)); |
SelectObject (ps.hdc, (LPVOID)hpen); |
567 |
icex.dwSize = sizeof (INITCOMMONCONTROLSEX); |
LineTo (ps.hdc, rect.right, rect.bottom); |
568 |
icex.dwICC = ICC_BAR_CLASSES; |
DeleteObject (hpen); |
569 |
InitCommonControlsEx (&icex); |
} |
570 |
kmi->hwnd_sep = regist_sep_wnd (dlg, kmi); |
|
571 |
imagelist_load (dlg); |
MoveToEx (ps.hdc, 0, rect.bottom-1, NULL); |
572 |
|
hpen = CreatePen (PS_SOLID, 0, GetSysColor(COLOR_3DSHADOW)); |
573 |
#ifndef LANG_DE |
if (hpen != NULL) { |
574 |
SetWindowText( dlg, _("Key Manager") ); |
SelectObject (ps.hdc, (LPVOID)hpen); |
575 |
#endif |
LineTo (ps.hdc, rect.right, rect.bottom-1); |
576 |
menu = LoadMenu( glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC ); |
DeleteObject (hpen); |
577 |
#ifndef LANG_DE |
} |
578 |
set_menu_text( menu, ID_KEYMISC_QUIT, _("&Quit") ); |
MoveToEx (ps.hdc, 0, rect.bottom, NULL); |
579 |
set_menu_text( menu, ID_KEYMISC_UID, _("User ID") ); |
hpen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); |
580 |
set_menu_text( menu, ID_KEYMISC_NEWKEY, _("&Expert") ); |
if (hpen != NULL) { |
581 |
set_menu_text( menu, ID_KEYMISC_KEYWIZARD, _("&Normal") ); |
SelectObject (ps.hdc, (LPVOID)hpen); |
582 |
set_menu_text( menu, ID_KEYMISC_EDIT, _("Edit") ); |
LineTo (ps.hdc, rect.right, rect.bottom); |
583 |
set_menu_text( menu, ID_KEYMISC_SIGN, _("&Sign") ); |
DeleteObject (hpen); |
584 |
set_menu_text( menu, ID_KEYMISC_DELETE, _("&Delete") ); |
} |
585 |
set_menu_text( menu, ID_KEYMISC_REVCERT, _("&Revoke") ); |
|
586 |
set_menu_text( menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures") ); |
EndPaint (hwnd, &ps); |
587 |
set_menu_text( menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path") ); |
return 0; |
588 |
set_menu_text( menu, ID_KEYMISC_PROPS, _("&Properties") ); |
|
589 |
set_menu_text( menu, ID_KEYMISC_GPGOPT, _("Options") ); |
case WM_LBUTTONDOWN: |
590 |
set_menu_text( menu, ID_KEYMISC_GPGPREFS, _("Preferences") ); |
last_mouse_pos.x = LOWORD (lparam); |
591 |
set_menu_text( menu, ID_KEYMISC_SENDRECV, _("Keyserver") ); |
last_mouse_pos.y = HIWORD (lparam); |
592 |
set_menu_text( menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache") ); |
ClientToScreen (hwnd, &last_mouse_pos); |
593 |
set_menu_text( menu, ID_KEYMISC_REBUILD, _("R&everify Signatures") ); |
SetCapture (hwnd); |
594 |
set_menu_text( menu, ID_KEYMISC_INFO, _("Info") ); |
return 0; |
595 |
set_menu_text (menu, ID_KEYMISC_HELP, _("Help")); |
|
596 |
#endif |
case WM_LBUTTONUP: |
597 |
SetMenu( dlg, menu ); |
ReleaseCapture (); |
598 |
if( keyring_check_last_access() ) |
return 0; |
599 |
keycache_set_reload( 1 ); |
|
600 |
if( keycache_get_reload( ) ) |
case WM_MOUSEMOVE: |
601 |
keycache_reload( dlg ); |
if (wparam == MK_LBUTTON) { |
602 |
c = keycache_get_ctx( KEYCACHE_PUB ); |
struct km_info_s *kmi; |
603 |
if( !c ) |
POINT p; |
604 |
BUG( NULL ); |
RECT r; |
605 |
kmi->keylist_sortby = GPGME_ATTR_USERID; |
|
606 |
Header_SetImageList(ListView_GetHeader(GetDlgItem( dlg, IDC_KEYMISC_KEYLIST )), |
kmi = (struct km_info_s *)GetWindowLong (hwnd, GWL_USERDATA); |
607 |
glob_imagelist); |
if (kmi == NULL) |
608 |
kmi->lv = keylist_load( GetDlgItem( dlg, IDC_KEYMISC_KEYLIST ), c, |
break; |
609 |
NULL, KEYLIST_LIST, kmi->keylist_sortby ); |
|
610 |
/* init subclassing for the listview */ |
/* Calculate mouse movement */ |
611 |
kl = GetDlgItem( dlg, IDC_KEYMISC_KEYLIST ); |
p.x = LOWORD (lparam); |
612 |
keylist_proc.dlg = dlg; |
p.y = HIWORD (lparam); |
613 |
keylist_proc.current = (WNDPROC)keylist_subclass_proc; |
ClientToScreen (hwnd, &p); |
614 |
keylist_proc.old = (WNDPROC)GetWindowLong( kl, GWL_WNDPROC ); |
|
615 |
if( keylist_proc.old ) { |
GetWindowRect (hwnd, &r); |
616 |
if( !SetWindowLong( kl, GWL_WNDPROC, (LONG)keylist_proc.current) ) { |
r.top += (short)(p.y - last_mouse_pos.y); |
617 |
msg_box( dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR ); |
r.bottom += (short)(p.y - last_mouse_pos.y); |
618 |
BUG( NULL ); |
|
619 |
} |
last_mouse_pos.y = p.y; |
620 |
} |
|
621 |
km_groups_new( &gc, GetDlgItem( dlg, IDC_KEYMISC_GROUP ) ); |
/* Apply mouse movement to window. Beware the MoveWindow is relaive |
622 |
km_groups_load( gc ); |
to parent NOT screen */ |
623 |
SetForegroundWindow( dlg ); |
MapWindowPoints (NULL, GetParent(hwnd), (POINT*)&r, 2); |
624 |
|
kmi->ypos_sep = r.top; |
625 |
kmi->statbar = CreateStatusWindow( WS_CHILD | WS_VISIBLE | CCS_BOTTOM, "status bar", dlg, 100000 ); |
kmi->ypercent_sep = 0; /* This forces do_resize_window to use abs. position */ |
626 |
ShowWindow( kmi->statbar, SW_SHOW ); |
do_resize_window (GetParent (hwnd), kmi); |
627 |
km_update_default_key_str (kmi->statbar, &km_def_pos); |
return 0; |
628 |
km_complete_status_bar( kmi->statbar, kmi->lv, km_def_pos ); |
} |
629 |
|
} |
630 |
SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi); |
|
631 |
kmi->toolbar = load_toolbar (dlg, kmi); |
return DefWindowProc (hwnd, msg, wparam, lparam); |
632 |
|
} |
633 |
do_center_window( dlg, kmi ); |
|
634 |
do_resize_window( dlg, kmi ); |
|
635 |
update_ui_items (dlg, kmi->lv); |
/* Register the separator window with @dlg as the parent window. */ |
636 |
return TRUE; |
static HWND |
637 |
|
regist_sep_wnd (HWND dlg, struct km_info_s *kmi) |
638 |
case WM_DESTROY: |
{ |
639 |
if (kmi->lv) { |
WNDCLASS wndclass; |
640 |
keylist_delete (kmi->lv); |
HWND h; |
641 |
kmi->lv = NULL; |
|
642 |
|
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; |
643 |
if (gc) { |
wndclass.lpfnWndProc = separator_wnd_proc; |
644 |
km_groups_release (gc); |
wndclass.cbClsExtra = 0; |
645 |
gc = NULL; |
wndclass.cbWndExtra = sizeof (long); |
646 |
} |
wndclass.hInstance = glob_hinst; |
647 |
imagelist_destroy (); |
wndclass.hIcon = NULL; |
648 |
|
wndclass.hCursor = LoadCursor (NULL, IDC_SIZENS); |
649 |
char buf[32]; |
wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH); |
650 |
ltoa (kmi->pos_x, buf, 10); |
wndclass.lpszMenuName = 0; |
651 |
set_reg_entry( HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", buf ); |
wndclass.lpszClassName = WINDOWCLASS_SEPARATOR_CHILD; |
652 |
ltoa (kmi->pos_y, buf, 10); |
RegisterClass (&wndclass); |
653 |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", buf); |
|
654 |
/* Remove runtime information. This should be the last action taken here. */ |
h = CreateWindowEx (WS_EX_WINDOWEDGE, WINDOWCLASS_SEPARATOR_CHILD, NULL, |
655 |
delete kmi; kmi = NULL; |
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE, |
656 |
SetWindowLong (dlg, GWL_USERDATA, NULL); |
0, 400, 2000, 5, dlg, (HMENU) 0, glob_hinst, kmi); |
657 |
keycache_set_reload (refresh_keys); |
ShowWindow (h, SW_SHOW); |
658 |
return FALSE; |
return h; |
659 |
|
} |
660 |
case WM_MOVE: |
|
661 |
/* kmi->pos_x = (int)(short)LOWORD(lparam); |
|
662 |
kmi->pos_y = (int)(short)HIWORD(lparam); */ |
#define enable_button(hwnd, cid, item_selected) \ |
663 |
RECT r; |
SendMessage ((hwnd), TB_ENABLEBUTTON, (cid), MAKELONG ((item_selected), 0)) |
664 |
GetWindowRect (dlg, &r); |
|
665 |
kmi->pos_x = r.left; |
|
666 |
kmi->pos_y = r.top; |
/* Interactive modification of the dialog item which depend if an item |
667 |
break; |
is selected or not and what kind of item. @lv is the list view with |
668 |
|
the items. */ |
669 |
|
void |
670 |
case WM_RBUTTONUP: |
update_ui_items (HWND hwnd, listview_ctrl_t lv) |
671 |
do_create_minpopup (dlg); |
{ |
672 |
break; |
HWND tb_hwnd; |
673 |
|
HMENU hmenu; |
674 |
case WM_NOTIFY: |
int mult_resids[] = {ID_KEYMISC_PROPS, ID_KEYMISC_SIGN, ID_KEYMISC_EDITKEY, |
675 |
NMHDR * notify; |
ID_KEYMISC_CHECKSIGS, ID_KEYMISC_REVCERT, 0}; |
676 |
POINT p; |
int key_selected = 0; |
677 |
HMENU popup; |
int key_has_sec = 0; |
678 |
|
int key_inv = 0; |
679 |
notify = (NMHDR *)lparam; |
int i, state=0; |
680 |
if (notify == NULL) |
|
681 |
break; |
/* Get some states */ |
682 |
switch (notify->code) |
key_selected = SendMessage (GetDlgItem (hwnd, IDC_KEYMISC_KEYLIST), |
683 |
{ |
LVM_GETSELECTEDCOUNT, 0, 0) |
684 |
case TBN_QUERYDELETE: |
? TRUE : FALSE; |
685 |
SetWindowLong(dlg, DWL_MSGRESULT, TRUE); |
key_has_sec = FALSE; |
686 |
return TRUE; |
if (key_selected) { |
687 |
|
i = listview_get_curr_pos (lv); |
688 |
case TBN_QUERYINSERT: |
key_has_sec = km_check_for_seckey (lv, i, NULL) ? TRUE : FALSE; |
689 |
SetWindowLong(dlg, DWL_MSGRESULT, TRUE); |
key_inv = km_get_key_status (lv, i) & KM_FLAG_REVOKED || |
690 |
return TRUE; |
km_get_key_status (lv, i) & KM_FLAG_EXPIRED; |
691 |
|
} |
692 |
case TBN_GETBUTTONINFO: |
|
693 |
LPTBNOTIFY lpTbNotify; |
/* Enable / disable toolbar buttons */ |
694 |
lpTbNotify = (LPTBNOTIFY)lparam; |
tb_hwnd = GetDlgItem (hwnd, IDR_WINPT_KMTB); |
695 |
if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) { |
enable_button (tb_hwnd, ID_KEYMISC_DELETE, key_selected); |
696 |
lpTbNotify->tbButton.iBitmap = imagelist_getindex(myb[lpTbNotify->iItem].icon); |
enable_button (tb_hwnd, ID_KEYMISC_PROPS, key_selected); |
697 |
lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command; |
enable_button (tb_hwnd, ID_KEYMISC_SIGN, key_selected && !key_inv); |
698 |
lpTbNotify->tbButton.fsState = TBSTATE_ENABLED; |
enable_button (tb_hwnd, ID_KEYMISC_EXPORT, key_selected); |
699 |
lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON; |
enable_button (tb_hwnd, ID_KEYCTX_COPY, key_selected); |
700 |
lpTbNotify->tbButton.iString = 0; |
enable_button (tb_hwnd, ID_KEYCTX_PASTE, clip_contains_pgpkey ()); |
701 |
strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText); |
|
702 |
SetWindowLong(dlg, DWL_MSGRESULT, TRUE); |
/* Enable / disable menu items */ |
703 |
} |
state = key_selected? MF_ENABLED : MF_DISABLED|MF_GRAYED; |
704 |
return TRUE; |
hmenu = GetMenu (hwnd); |
705 |
|
set_menu_state (hmenu, ID_KEYMISC_EXPORT, state); |
706 |
case TBN_RESET: /* Restore last saved toolbar status */ |
set_menu_state (hmenu, ID_KEYMISC_DELETE, state); |
707 |
TBSAVEPARAMS tbsp; |
set_menu_state (hmenu, ID_KEYMISC_PROPS, state); |
708 |
|
set_menu_state (hmenu, ID_KEYMISC_EDITKEY, state); |
709 |
tbsp.hkr = HKEY_CURRENT_USER; |
set_menu_state (hmenu, ID_KEYMISC_CHECKSIGS, state); |
710 |
tbsp.pszSubKey = "Software\\WinPT"; |
set_menu_state (hmenu, ID_KEYMISC_SIGN, |
711 |
tbsp.pszValueName = "KM_toolbar"; |
key_selected && !key_inv ? MF_ENABLED : MF_GRAYED); |
712 |
SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp); |
set_menu_state (hmenu, ID_KEYMISC_EXPORT_PRIVKEY, |
713 |
break; |
key_selected && key_has_sec? MF_ENABLED : MF_GRAYED); |
714 |
|
set_menu_state (hmenu, ID_KEYMISC_REVCERT, |
715 |
case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */ |
key_selected && key_has_sec? MF_ENABLED : MF_GRAYED); |
716 |
tbsp.hkr = HKEY_CURRENT_USER; |
|
717 |
tbsp.pszSubKey = "Software\\WinPT"; |
/* Disable some menu items when multiple keys are selected. */ |
718 |
tbsp.pszValueName = "KM_toolbar"; |
if (listview_count_items (lv, 1) > 1) { |
719 |
SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp); |
for (i=0; mult_resids[i] != 0; i++) |
720 |
break; |
set_menu_state (hmenu, mult_resids[i], MF_GRAYED); |
721 |
|
} |
722 |
case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */ |
|
723 |
tbsp.hkr = HKEY_CURRENT_USER; |
/* Disable all secret-key functions when no secret key is available. */ |
724 |
tbsp.pszSubKey = "Software\\WinPT"; |
if (!secret_key_available ()) { |
725 |
tbsp.pszValueName = "KM_toolbar"; |
enable_button (tb_hwnd, ID_KEYMISC_SIGN, FALSE); |
726 |
SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp); |
set_menu_state (hmenu, ID_KEYMISC_SIGN, MF_GRAYED); |
727 |
break; |
} |
728 |
|
} |
729 |
case TTN_GETDISPINFO: |
|
730 |
LPTOOLTIPTEXT lpttt; |
|
731 |
lpttt = (LPTOOLTIPTEXT)lparam; |
/* Disable some context menu items when multiple keys are selected. */ |
732 |
|
static void |
733 |
lpttt->hinst = NULL; |
popup_multiple (HWND dlg, HMENU hm) |
734 |
switch (lpttt->hdr.idFrom) { |
{ |
735 |
case ID_KEYMISC_DELETE: |
int resids[] = { |
736 |
lpttt->lpszText = (char *)_("Delete key from keyring"); |
ID_KEYCTX_EDIT, |
737 |
break; |
ID_KEYCTX_SIGN, |
738 |
|
ID_KEYCTX_REV, |
739 |
case ID_KEYMISC_PROPS: |
ID_KEYCTX_ENABLE, |
740 |
lpttt->lpszText = (char *)_("Show key properties"); |
ID_KEYCTX_DISABLE, |
741 |
break; |
ID_KEYCTX_ADDKEY, |
742 |
|
ID_KEYCTX_ADDPHOTO, |
743 |
case ID_KEYMISC_SIGN: |
ID_KEYCTX_ADDUID, |
744 |
lpttt->lpszText = (char *)_("Sign key"); |
ID_KEYCTX_ADDREV, |
745 |
break; |
ID_KEYCTX_LISTSIGS, |
746 |
|
ID_KEYCTX_MAXTRUST, |
747 |
case ID_KEYMISC_IMPORT: |
ID_KEYCTX_PROPS, |
748 |
lpttt->lpszText = (char *)_("Import key to keyring"); |
ID_KEYCTX_SENDMAIL, |
749 |
break; |
0}; |
750 |
|
int i; |
751 |
case ID_KEYMISC_EXPORT: |
for (i=0; i < resids[i] != 0; i++) |
752 |
lpttt->lpszText = (char *)_("Export key to a file"); |
set_menu_state (hm, resids[i], MF_GRAYED); |
753 |
break; |
} |
754 |
} |
|
755 |
return TRUE; |
|
756 |
|
/* The items which are shown when GPG is in read-only mode. */ |
757 |
case LVN_ITEMCHANGED: |
static void |
758 |
if (((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */ |
popup_gpg_readonly (HWND dlg, HMENU hm) |
759 |
{ |
{ |
760 |
update_ui_items (dlg, kmi->lv); |
int resids[] = { |
761 |
return TRUE; |
ID_KEYCTX_PASTE, |
762 |
} |
ID_KEYCTX_EDIT, |
763 |
break; |
ID_KEYCTX_SIGN, |
764 |
|
ID_KEYCTX_REV, |
765 |
case NM_RCLICK: |
ID_KEYCTX_DEL, |
766 |
if (notify->idFrom == IDC_KEYMISC_KEYLIST) |
ID_KEYCTX_ENABLE, |
767 |
{ |
ID_KEYCTX_DISABLE, |
768 |
if (listview_get_curr_pos (kmi->lv) == -1) |
ID_KEYCTX_RECVFROM, |
769 |
return TRUE; /* Popup only when a item was selected */ |
ID_KEYCTX_ADDKEY, |
770 |
do_check_cache (kmi->lv, dlg, kmi->statbar); |
ID_KEYCTX_ADDPHOTO, |
771 |
GetCursorPos (&p); |
ID_KEYCTX_ADDUID, |
772 |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX)); |
ID_KEYCTX_ADDREV, |
773 |
popup = GetSubMenu (hm, 0); |
0 |
774 |
#ifndef LANG_DE |
}; |
775 |
set_menu_text( popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard") ); |
int i; |
776 |
set_menu_text( popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard") ); |
|
777 |
set_menu_text( popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard") ); |
if (gpg_read_only == 0) |
778 |
set_menu_text( popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver") ); |
return; |
779 |
#endif |
for (i=0; resids[i] != 0; i++) |
780 |
idx = listview_get_curr_pos (kmi->lv); |
set_menu_state (hm, resids[i], MF_GRAYED); |
781 |
if (km_check_for_seckey (kmi->lv, idx, &i) && i == 0) |
} |
782 |
{ |
|
783 |
set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED); |
|
784 |
set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED); |
/* Change the 'Edit' menu based on the current state. */ |
785 |
} |
static void |
786 |
if( !km_check_for_seckey( kmi->lv, idx, NULL ) ) { |
change_edit_menu (listview_ctrl_t lv, HMENU hm, int id) |
787 |
set_menu_state( popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED ); |
{ |
788 |
set_menu_state( popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED ); |
enum item { EDIT_MENU = 1 }; |
789 |
set_menu_state( popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED ); |
int no_sel; |
790 |
set_menu_state( popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED ); |
|
791 |
set_menu_state( popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED ); |
if (id != EDIT_MENU) |
792 |
set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED); |
return; |
793 |
} |
|
794 |
else if( km_check_for_seckey( kmi->lv, idx, NULL ) |
if (!clip_contains_pgpkey ()) |
795 |
&& km_key_is_v3( kmi->lv, idx ) ) |
set_menu_state (hm, ID_KEYMISC_PASTE, MF_GRAYED); |
796 |
{ |
else |
797 |
/* PGP 2 keys, version 3 have no no support for photo-id's, |
set_menu_state (hm, ID_KEYMISC_PASTE, MF_ENABLED); |
798 |
designated revokers and secondary keys. */ |
no_sel = listview_get_curr_pos (lv) == -1? 1 : 0; |
799 |
set_menu_state( popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED ); |
set_menu_state (hm, ID_KEYMISC_DELETE2, no_sel? MF_GRAYED: MF_ENABLED); |
800 |
set_menu_state( popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED ); |
set_menu_state (hm, ID_KEYMISC_COPY, no_sel? MF_GRAYED : MF_ENABLED); |
801 |
set_menu_state( popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED ); |
} |
802 |
} |
|
803 |
if( km_get_key_status( kmi->lv, idx ) & KM_FLAG_DISABLED ) |
|
804 |
set_menu_state( popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED ); |
|
805 |
else |
/* Show limited key menu entries when GPG is in read-only mode. */ |
806 |
set_menu_state( popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED ); |
static void |
807 |
if (km_get_key_status (kmi->lv, idx) & KM_FLAG_REVOKED) |
change_key_menu (HMENU hm, int id) |
808 |
set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED); |
{ |
809 |
if( mapi_init() ) |
int key_resids[] = { |
810 |
set_menu_state( popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED ); |
ID_KEYMISC_SIGN, |
811 |
popup_gpg_readonly (dlg, popup); |
ID_KEYMISC_DELETE, |
812 |
TrackPopupMenu( popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL ); |
ID_KEYMISC_REVCERT, |
813 |
DestroyMenu( popup ); |
ID_KEYMISC_IMPORT_HTTP, |
814 |
DestroyMenu( hm ); |
ID_KEYMISC_IMPORT, |
815 |
return TRUE; |
ID_KEYMISC_REFRESH_KEYS, |
816 |
} |
ID_KEYMISC_REBUILD, |
817 |
if( notify->idFrom == IDC_KEYMISC_GROUP ) { |
ID_KEYMISC_KEYWIZARD, |
818 |
HWND tree = GetDlgItem( dlg, IDC_KEYMISC_GROUP ); |
ID_KEYMISC_CARDNEW, |
819 |
if( TreeView_GetSelection( tree ) ) { |
ID_KEYMISC_NEWKEY, |
820 |
GetCursorPos( &p ); |
0, |
821 |
hm = LoadMenu( glob_hinst, MAKEINTRESOURCE(IDR_WINPT_GROUP_CTX) ); |
}; |
822 |
popup = GetSubMenu( hm, 0 ); |
int edit_resids[] = { |
823 |
if( km_index == -1 ) |
ID_KEYMISC_PASTE, |
824 |
set_menu_state( popup, ID_GROUP_PASTE, MF_DISABLED|MF_GRAYED ); |
ID_KEYMISC_OT, |
825 |
set_menu_text( popup, ID_GROUP_PASTE, _("Paste into this group") ); |
ID_KEYMISC_EDITKEY, |
826 |
set_menu_text( popup, ID_GROUP_DELETE, _("Delete") ); |
0 |
827 |
TrackPopupMenu( popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL ); |
}; |
828 |
DestroyMenu( popup ); |
int *resids; |
829 |
DestroyMenu( hm ); |
int i; |
830 |
return TRUE; |
|
831 |
} |
|
832 |
} |
if (gpg_read_only == 0) |
833 |
break; |
return; |
834 |
|
switch (id) { |
835 |
case LVN_COLUMNCLICK: |
case 0: return; |
836 |
if (notify->idFrom == IDC_KEYMISC_KEYLIST) { |
case 3: resids = key_resids; break; |
837 |
NMLISTVIEW * p = (LPNMLISTVIEW) lparam; |
case 1: resids = edit_resids;break; |
838 |
int sortby = 0; |
default:resids = edit_resids; break; |
839 |
switch (p->iSubItem) { |
} |
840 |
case 0: sortby = GPGME_ATTR_USERID; break; |
|
841 |
case 1: sortby = GPGME_ATTR_KEYID; break; |
for (i=0; resids[i] != 0; i++) |
842 |
case 2: sortby = GPGME_ATTR_IS_SECRET; break; |
set_menu_state (hm, resids[i], MF_GRAYED); |
843 |
case 3: sortby = GPGME_ATTR_LEN; break; |
} |
844 |
case 5: sortby = GPGME_ATTR_VALIDITY; break; |
|
845 |
case 6: sortby = GPGME_ATTR_OTRUST; break; |
|
846 |
case 7: sortby = GPGME_ATTR_CREATED; break; |
/* Reload a single key in the cache. */ |
847 |
case 8: sortby = GPGME_ATTR_ALGO; break; |
static void |
848 |
default: return TRUE; //sortby = GPGME_ATTR_USERID; break; |
update_key (listview_ctrl_t lv, int pos, const char *keyid, int keypair) |
849 |
} |
{ |
850 |
|
struct winpt_key_s key; |
851 |
if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby) |
|
852 |
kmi->keylist_sortby ^= KEYLIST_SORT_DESC; |
keycache_update (0, keyid); |
853 |
else |
if (keypair) |
854 |
kmi->keylist_sortby = sortby; |
keycache_update (1, keyid); |
855 |
keylist_sort (kmi->lv, kmi->keylist_sortby); |
|
856 |
return TRUE; |
/* because we replaced the key item, we need to update the |
857 |
} |
address of the pointer in the ListView control. */ |
858 |
break; |
memset (&key, 0, sizeof (key)); |
859 |
} |
winpt_get_pubkey (keyid, &key); |
860 |
break; |
keylist_upd_key (lv, pos, key.ext, key.ctx); |
861 |
} |
keyring_check_last_access (); |
862 |
|
} |
863 |
case WM_WINDOWPOSCHANGING: |
|
864 |
if (((WINDOWPOS*)lparam)->cx < 400) |
|
865 |
((WINDOWPOS*)lparam)->cx = 400; |
/* Setup status bar for the main window @dlg. */ |
866 |
if (((WINDOWPOS*)lparam)->cy < 200) |
static HWND |
867 |
((WINDOWPOS*)lparam)->cy = 200; |
setup_status_bar (HWND dlg, listview_ctrl_t lv) |
868 |
return TRUE; |
{ |
869 |
|
HWND statbar; |
870 |
case WM_SIZE: |
RECT r; |
871 |
do_resize_window (dlg, kmi); |
int partpos[3]; |
872 |
return TRUE; |
int i; |
873 |
|
|
874 |
case WM_SYSCOMMAND: |
GetClientRect (dlg, &r); |
875 |
if( LOWORD (wparam) == SC_CLOSE ) |
for (i=1; i <= 3; i++) |
876 |
EndDialog( dlg, TRUE ); |
partpos[i-1] = r.right/3*i; |
877 |
return FALSE; |
statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM, |
878 |
|
"status bar", dlg, KM_SEPARATOR_ID); |
879 |
case WM_MENUSELECT: |
|
880 |
menu_gpg_readonly (dlg, (HMENU)lparam, LOWORD (wparam)); |
ShowWindow (statbar, SW_SHOW); |
881 |
break; |
SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos); |
882 |
|
|
883 |
case WM_COMMAND: |
update_default_key_str (statbar); |
884 |
if( gnupg_access_keyring( 1 ) ) { |
update_status_bar (statbar, lv); |
885 |
msg_box( dlg, _("Could not access public keyring"), _("Key Manager"), MB_ERR ); |
|
886 |
return FALSE; |
return statbar; |
887 |
} |
} |
888 |
do_check_cache( kmi->lv, dlg, kmi->statbar ); |
|
889 |
switch( LOWORD( wparam ) ) { |
|
890 |
case ID_KEYMISC_QUIT: |
/* Remove or add columns which depends on the state of @checked. */ |
891 |
EndDialog( dlg, TRUE ); |
void |
892 |
return TRUE; |
modify_listview_columns (km_info_s *kmi, UINT m_uid, BOOL checked) |
893 |
|
{ |
894 |
case ID_KEYMISC_MAIL: |
UINT resids[] = { |
895 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_MAIL, GetDesktopWindow (), |
0, |
896 |
winpt_mail_proc, NULL); |
ID_KEYMISC_VIEWKEYID, |
897 |
break; |
ID_KEYMISC_VIEWTYPE, |
898 |
|
0, |
899 |
case ID_KEYMISC_DELETE: |
ID_KEYMISC_VIEWCIPHER, |
900 |
if (km_delete_keys (kmi->lv, dlg)) |
0, |
901 |
return FALSE; |
0, |
902 |
refresh_keys = 1; |
ID_KEYMISC_VIEWCREAT, |
903 |
return TRUE; |
ID_KEYMISC_VIEWDESC, |
904 |
|
-1 |
905 |
case ID_KEYMISC_SIGN: |
}; |
906 |
gpgme_key_t key; |
listview_column_s cols[] = { |
907 |
|
{0, 240, (char *)_("User ID")}, |
908 |
if ( (idx = listview_get_curr_pos( kmi->lv )) == -1 ) { |
{1, 78, (char *)_("Key ID")}, |
909 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), |
{2, 52, (char *)_("Type")}, |
910 |
MB_ERR ); |
{3, 66, (char *)_("Size")}, |
911 |
return FALSE; |
{4, 60, (char *)_("Cipher")}, |
912 |
} |
{5, 66, (char *)_("Validity")}, |
913 |
if( !km_check_key_status( kmi->lv, idx ) ) |
{6, 58, (char *)_("Trust")}, |
914 |
return FALSE; |
{7, 72, (char *)_("Creation")}, |
915 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid ); |
{8, 160,(char *)_("Description")}, |
916 |
listview_get_item_text( kmi->lv, idx, 2, type, sizeof type -1 ); |
{0, 0, NULL} |
917 |
rc = get_pubkey( keyid, &key ); |
}; |
918 |
if( rc ) |
UINT pos; |
919 |
BUG( dlg ); |
|
920 |
if( key ) |
for (pos=0; resids[pos] != -1; pos++) { |
921 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg, |
if (m_uid == resids[pos]) |
922 |
keysign_dlg_proc, (LPARAM)key, |
break; |
923 |
_("Key Signing"), IDS_WINPT_KEYSIGN); |
} |
924 |
return TRUE; |
if (!checked) |
925 |
|
listview_del_column (kmi->lv, (int)pos); |
926 |
case ID_KEYMISC_REVCERT: |
else { |
927 |
idx = listview_get_curr_pos( kmi->lv ); |
listview_add_column (kmi->lv, &cols[pos]); |
928 |
if( idx == -1 ) { |
keylist_upd_col (kmi->lv, pos); |
929 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
} |
930 |
return FALSE; |
} |
931 |
} |
|
932 |
listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 ); |
|
933 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 ); |
/* Helper to handle the help file. If @check is 1 |
934 |
if ( !km_check_for_seckey( kmi->lv, idx, NULL ) ) { |
the existence of the file is checked. |
935 |
msg_box( dlg, _("There is no secret key available!"), _("Key Manager"), MB_ERR ); |
Otherwise the help file will be loaded. */ |
936 |
return FALSE; |
static bool |
937 |
} |
start_help (HWND dlg, int check) |
938 |
|
{ |
939 |
{ |
DWORD n; |
940 |
char t[128]; |
char path[MAX_PATH+1+32]; |
941 |
listview_get_item_text( kmi->lv, idx, 5, t, sizeof t -1 ); |
|
942 |
if( strchr( t, 'R' ) ) { |
n = GetModuleFileName (NULL, path, sizeof (path)-1-32); |
943 |
msg_box( dlg, _("Key already revoked!"), _("Key Manager"), MB_INFO ); |
if (!n) |
944 |
return FALSE; |
return false; |
945 |
} |
path[n] = 0; |
946 |
} |
while (n-- && path[n] != '\\') |
947 |
|
; |
948 |
q = km_quote_uid (uid); |
path[n+1] = 0; |
949 |
k.key_pair = 1; |
strcat (path, "winpt.chm"); |
950 |
k.keyid = keyid; |
if (!check) |
951 |
k.uid = q; |
ShellExecute (dlg, "open", path, NULL, NULL, SW_SHOW); |
952 |
k.is_protected = km_check_if_protected( kmi->lv, idx ); |
return file_exist_check (path) == 0? true : false; |
953 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg, |
} |
954 |
key_revoke_dlg_proc, (LPARAM)&k, |
|
955 |
_("Key Revocation"), IDS_WINPT_KEYREVOKE ); |
/* Translate all menu strings. */ |
956 |
free_if_alloc( q ); |
static void |
957 |
return TRUE; |
translate_menu_strings (HWND dlg) |
958 |
|
{ |
959 |
case ID_KEYMISC_TRUSTPATH: |
HMENU menu; |
960 |
idx = listview_get_curr_pos( kmi->lv ); |
|
961 |
if( idx == -1 ) { |
menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_KEYMISC); |
962 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
set_menu_text_bypos (menu, 0, _("File")); |
963 |
return FALSE; |
set_menu_text_bypos (menu, 1, _("Edit")); |
964 |
} |
set_menu_text_bypos (menu, 2, _("View")); |
965 |
listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid -1 ); |
set_menu_text_bypos (menu, 3, _("Key")); |
966 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid -1 ); |
set_menu_text_bypos (menu, 4, _("Groups")); |
967 |
if( km_check_for_seckey( kmi->lv, idx, NULL ) ) { |
|
968 |
msg_box( dlg, _("It does not make any sense with a key pair!"), _("Key Manager"), MB_OK ); |
set_menu_text (menu, ID_KEYMISC_EDITKEY, _("Edit")); |
969 |
return FALSE; |
set_menu_text (menu, ID_KEYMISC_MAIL, _("Send Mail...")); |
970 |
} |
set_menu_text (menu, ID_KEYMISC_OT, _("Ownertrust")); /* XXX */ |
971 |
k.keyid = keyid; |
set_menu_text (menu, ID_KEYMISC_COPY, _("&Copy\tCtrl+C")); |
972 |
k.uid = uid; |
set_menu_text (menu, ID_KEYMISC_PASTE, _("&Paste\tCtrl+V")); |
973 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg, |
set_menu_text (menu, ID_KEYMISC_FIND, _("Search...\tCtrl+F")); |
974 |
keytrust_dlg_proc, (LPARAM)&k, |
set_menu_text (menu, ID_KEYMISC_SELALL, _("Select All\tCtrl+A")); |
975 |
_("List Trust Path"), IDS_WINPT_KEYTRUST ); |
set_menu_text (menu, ID_KEYMISC_QUIT, _("&Quit")); |
976 |
return TRUE; |
set_menu_text (menu, ID_KEYMISC_UID, _("User ID")); |
977 |
|
set_menu_text (menu, ID_KEYMISC_NEWKEY, _("&Expert")); |
978 |
case ID_KEYMISC_CHECKSIGS: |
set_menu_text (menu, ID_KEYMISC_KEYWIZARD, _("&Normal")); |
979 |
idx = listview_get_curr_pos( kmi->lv ); |
set_menu_text (menu, ID_KEYMISC_EDIT, _("Edit")); |
980 |
if( idx == -1 ) { |
set_menu_text (menu, ID_KEYMISC_SIGN, _("&Sign")); |
981 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
set_menu_text (menu, ID_KEYMISC_DELETE, _("&Delete")); |
982 |
return FALSE; |
set_menu_text (menu, ID_KEYMISC_DELETE2, _("&Delete")); |
983 |
} |
set_menu_text (menu, ID_KEYMISC_REVCERT, _("&Revoke Cert")); |
984 |
listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid-1 ); |
set_menu_text (menu, ID_KEYMISC_CHECKSIGS, _("&List Signatures")); |
985 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 ); |
set_menu_text (menu, ID_KEYMISC_TRUSTPATH, _("List Trust Path")); |
986 |
k.keyid = keyid; |
set_menu_text (menu, ID_KEYMISC_EXPORT, _("&Export...")); |
987 |
k.uid = uid; |
set_menu_text (menu, ID_KEYMISC_IMPORT, _("&Import...")); |
988 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG, dlg, |
set_menu_text (menu, ID_KEYMISC_PROPS, _("&Properties")); |
989 |
keysig_dlg_proc, (LPARAM)&k, |
set_menu_text (menu, ID_KEYMISC_GPGOPT, _("Options")); |
990 |
_("Key Signature List" ), IDS_WINPT_KEYSIG ); |
set_menu_text (menu, ID_KEYMISC_GPGPREFS, _("Preferences")); |
991 |
return TRUE; |
set_menu_text (menu, ID_KEYMISC_SENDRECV, _("Keyserver") ); |
992 |
|
set_menu_text (menu, ID_KEYMISC_EXPORT_PRIVKEY, _("E&xport Secret Key")); |
993 |
case ID_KEYMISC_PROPS: |
set_menu_text (menu, ID_KEYMISC_RECACHE, _("Re&load Key Cache")); |
994 |
idx = listview_get_curr_pos( kmi->lv ); |
set_menu_text (menu, ID_KEYMISC_REBUILD, _("R&everify Signatures")); |
995 |
if( idx == -1 ) { |
set_menu_text (menu, ID_KEYMISC_REFRESH_KEYS, _("Refresh &Keys (Keyserver)")); |
996 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
set_menu_text (menu, ID_KEYMISC_INFO, _("Info") ); |
997 |
return FALSE; |
set_menu_text (menu, ID_KEYMISC_HELP, _("&Help")); |
998 |
} |
|
999 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid -1 ); |
set_menu_text (menu, ID_KEYMISC_VIEWKEYID, _("Key ID")); |
1000 |
listview_get_item_text( kmi->lv, idx, 2, type, sizeof type -1 ); |
set_menu_text (menu, ID_KEYMISC_VIEWCIPHER, _("Cipher")); |
1001 |
k.key_pair = 0; |
set_menu_text (menu, ID_KEYMISC_VIEWTYPE, _("Type")); |
1002 |
k.keyid = keyid; |
set_menu_text (menu, ID_KEYMISC_VIEWCREAT, _("Creation")); |
1003 |
if( !strcmp( type, "pub/sec" ) || !strcmp( type, "pub/crd" ) ) |
|
1004 |
k.key_pair = 1; |
if (!start_help (NULL, 1)) |
1005 |
k.callback.ctl = kmi->lv; |
set_menu_state (menu, ID_KEYMISC_HELP, MF_GRAYED); |
1006 |
k.callback.idx = idx; |
|
1007 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg, |
SetMenu (dlg, menu); |
1008 |
keyprops_dlg_proc, (LPARAM)&k, |
} |
1009 |
_("Key Properties"), IDS_WINPT_KEYPROPS ); |
|
1010 |
if (k.callback.new_val != 0) |
|
1011 |
{ |
/* Translate popup menu strings. */ |
1012 |
t = get_key_trust_str (k.callback.new_val); |
static void |
1013 |
listview_add_sub_item (kmi->lv, idx, 6, t); |
translate_popupmenu_strings (HMENU popup) |
1014 |
} |
{ |
1015 |
return TRUE; |
set_menu_text (popup, ID_KEYCTX_UID_COPY, _("Copy User ID to Clipboard")); |
1016 |
|
set_menu_text (popup, ID_KEYCTX_KEYID_COPY, _("Copy Key ID to Clipboard")); |
1017 |
case ID_KEYMISC_RECACHE: |
set_menu_text (popup, ID_KEYCTX_FPR_COPY, _("Copy Fingerprint to Clipboard")); |
1018 |
/* If there is already a reload request, don't bother the user with a message. */ |
set_menu_text (popup, ID_KEYCTX_KINFO_COPY, _("Copy Key Info to Clipboard")); |
1019 |
if( keycache_get_reload() == 1 ) |
set_menu_text (popup, ID_KEYCTX_COPY, _("Copy Key to Clipboard")); |
1020 |
idx = IDYES; |
set_menu_text (popup, ID_KEYCTX_PASTE, _("Paste Key from Clipboard")); |
1021 |
else { |
set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Refresh from Keyserver")); |
1022 |
char t[256]; |
set_menu_text (popup, ID_KEYCTX_MAXTRUST, _("Set Implicit &Trust")); |
1023 |
_snprintf( t, sizeof t -1, |
set_menu_text (popup, ID_KEYCTX_LISTSIGS, _("&List Signatures")); |
1024 |
_("This is only useful when the keyring has been " |
set_menu_text (popup, ID_KEYCTX_PROPS, _("&Properties")); |
1025 |
"modified (sign a key...).\n" |
set_menu_text (popup, ID_KEYCTX_EDIT, _("Key Edit")); |
1026 |
"Do you really want to reload the keycache?") ); |
set_menu_text (popup, ID_KEYCTX_DEL, _("&Delete")); |
1027 |
idx = msg_box( dlg, t, _("Key Manager"), MB_YESNO ); |
set_menu_text (popup, ID_KEYCTX_REV, _("&Revoke Cert")); |
1028 |
} |
set_menu_text (popup, ID_KEYCTX_SIGN, _("&Sign")); |
1029 |
if( idx == IDYES ) { |
set_menu_text (popup, ID_KEYCTX_ENABLE, _("&Enable")); |
1030 |
rcs.kr_reload = rcs.kr_update = 1; |
set_menu_text (popup, ID_KEYCTX_DISABLE, _("&Disable")); |
1031 |
rcs.tr_update = 0; |
set_menu_text (popup, ID_KEYCTX_RECVFROM, _("Re&fresh from Keyserver")); |
1032 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
set_menu_text (popup, ID_KEYCTX_SETPREFKS, _("Set preferred Keyserver URL")); |
1033 |
keycache_dlg_proc, (LPARAM)&rcs ); |
set_menu_text (popup, ID_KEYCTX_SENDMAIL, _("Send Key to Mail Recipient")); |
1034 |
c = keycache_get_ctx( 1 ); |
set_menu_text (popup, ID_KEYCTX_SETDEFKEY, _("Set as Default Key")); |
1035 |
if( !c ) |
|
1036 |
BUG( dlg ); |
set_menu_text (popup, ID_KEYCTX_ADDKEY, _("Key...")); |
1037 |
keylist_reload( kmi->lv, c, KEYLIST_LIST, GPGME_ATTR_USERID ); |
set_menu_text (popup, ID_KEYCTX_ADDUID, _("User ID...")); |
1038 |
refresh_keys = 0; |
set_menu_text (popup, ID_KEYCTX_ADDPHOTO, _("Photo ID...")); |
1039 |
} |
set_menu_text (popup, ID_KEYCTX_ADDREV, _("Revoker...")); |
1040 |
return TRUE; |
|
1041 |
|
/* change popup texts */ |
1042 |
case ID_KEYMISC_REBUILD: |
set_menu_text_bypos (popup, 0, _("Key Attributes")); |
1043 |
rcs.kr_reload = rcs.kr_update = 1; |
set_menu_text_bypos (popup, 6, _("Add")); |
1044 |
rcs.tr_update = 1; |
set_menu_text_bypos (popup, 19, _("Send to Keyserver")); |
1045 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
} |
1046 |
keycache_dlg_proc, (LPARAM)&rcs ); |
|
1047 |
c = keycache_get_ctx( 1 ); |
|
1048 |
if( !c ) |
/* Return true if the cache contain marked keys. */ |
1049 |
BUG( dlg ); |
static bool |
1050 |
keylist_reload( kmi->lv, c, KEYLIST_LIST, GPGME_ATTR_USERID ); |
updated_keys_avail (void) |
1051 |
return TRUE; |
{ |
1052 |
|
gpg_keycache_t kc = keycache_get_ctx (1); |
1053 |
case ID_KEYMISC_NEWKEY: |
struct keycache_s *k; |
1054 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg, |
|
1055 |
keygen_dlg_proc, NULL, _("Key Generation"), |
for (k = kc->item; k; k = k->next) { |
1056 |
IDS_WINPT_KEYGEN ); |
if (k->flags) |
1057 |
if( keycache_get_reload( ) ) |
return true; |
1058 |
send_cmd_id( dlg, ID_KEYMISC_RECACHE ); |
} |
1059 |
return TRUE; |
return false; |
1060 |
|
} |
1061 |
case ID_KEYMISC_CARDNEW: |
|
1062 |
if( !scard_support ) { |
|
1063 |
msg_box( dlg, _("Smart Card support is not available."), _("Key Manager"), MB_INFO ); |
/* Find the index of the key identified by @key. */ |
1064 |
return FALSE; |
static int |
1065 |
} |
find_keypos (listview_ctrl_t lv, gpgme_key_t key) |
1066 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg, |
{ |
1067 |
card_keygen_dlg_proc, NULL, _("Card Key Generation"), |
char keyid[16+1]; |
1068 |
IDS_WINPT_CARD_KEYGEN ); |
int i; |
1069 |
if( keycache_get_reload() ) |
|
1070 |
send_cmd_id( dlg, ID_KEYMISC_RECACHE ); |
for (i=0; i < listview_count_items (lv, 0); i++) { |
1071 |
return TRUE; |
listview_get_item_text (lv, i, KM_COL_KEYID, keyid, sizeof (keyid)-1); |
1072 |
|
if (!strcmp (key->subkeys->keyid+8, keyid+2)) |
1073 |
case ID_KEYMISC_KEYWIZARD: |
return i; |
1074 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg, |
} |
1075 |
keygen_wizard_dlg_proc, NULL, _("Key Generation Wizard"), |
return -1; |
1076 |
IDS_WINPT_KEYWIZARD ); |
} |
1077 |
if( keycache_get_reload() ) |
|
1078 |
send_cmd_id( dlg, ID_KEYMISC_RECACHE ); |
|
1079 |
return TRUE; |
/* Add all recently updated keys in the cache to the list |
1080 |
|
and refresh all GUI elements. */ |
1081 |
case ID_KEYMISC_SENDRECV: |
static void |
1082 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg, |
refresh_keylist (struct km_info_s *kmi) |
1083 |
keyserver_dlg_proc, NULL, _("Keyserver Access"), |
{ |
1084 |
IDS_WINPT_KEYSERVER ); |
struct keycache_s *ctx; |
1085 |
return TRUE; |
gpg_keycache_t kc; |
1086 |
|
int status=0, pos; |
1087 |
case ID_KEYMISC_GPGPREFS: |
|
1088 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, dlg, |
kc = keycache_get_ctx (1); |
1089 |
gpgprefs_dlg_proc, NULL, _("GnuPG Preferences"), |
while (!gpg_keycache_next_updated_key (kc, &ctx, &status)) { |
1090 |
IDS_WINPT_GPGPREFS ); |
if (status == KC_FLAG_ADD) |
1091 |
return TRUE; |
keylist_add_key (kmi->lv, KEYLIST_LIST, ctx, ctx->key); |
1092 |
|
else { |
1093 |
case ID_KEYMISC_GPGOPT: |
pos = find_keypos (kmi->lv, ctx->key); |
1094 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg, |
if (pos != -1) |
1095 |
gpgopt_dlg_proc, NULL, _("GnuPG Options" ), |
keylist_upd_key (kmi->lv, pos, ctx, ctx->key); |
1096 |
IDS_WINPT_GPGOPT ); |
} |
1097 |
return TRUE; |
} |
1098 |
|
keylist_sort (kmi->lv, kmi->keylist_sortby); |
1099 |
case ID_KEYMISC_IMPORT: |
update_status_bar (kmi->statbar, kmi->lv); |
1100 |
t = get_filename_dlg( dlg, FILE_OPEN, _("Choose Name of the Key File"), NULL, NULL ); |
keyring_check_last_access (); |
1101 |
if( t ) |
} |
1102 |
km_file_import( dlg, t ); |
|
1103 |
return TRUE; |
|
1104 |
|
/* Reload the key cache. */ |
1105 |
case ID_KEYMISC_IMPORT_HTTP: |
static void |
1106 |
http = (struct http_file_s *)get_http_file_dlg (dlg); |
keycache_reload (HWND dlg) |
1107 |
if (http->cancel == 0) |
{ |
1108 |
km_http_import (dlg, http->url); |
refresh_cache_s rcs; |
1109 |
delete http; |
|
1110 |
break; |
memset (&rcs, 0, sizeof rcs); |
1111 |
|
rcs.kr_reload = rcs.kr_update = 1; |
1112 |
case ID_KEYMISC_EXPORT: |
rcs.tr_update = 0; |
1113 |
idx = listview_get_curr_pos( kmi->lv ); |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
1114 |
if( idx == -1 ) { |
keycache_dlg_proc, (LPARAM)&rcs); |
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 ) |
/* Check if the secret keyring contains at least one |
1119 |
strcpy( keyid, _("Exported_GPG_Keys.asc") ); |
key with ultimate trust. |
1120 |
else { |
Return value: 0 on success. */ |
1121 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 ); |
int |
1122 |
strcat( keyid, ".asc" ); |
check_ultimate_trusted_key (gpg_keycache_t _sec) |
1123 |
} |
{ |
1124 |
t = get_filename_dlg( dlg, FILE_SAVE, _("Choose Name for Key File"), NULL, keyid ); |
struct keycache_s *n; |
1125 |
if( !t || overwrite_file( t ) == 0 ) |
int nkeys = 0; |
1126 |
return FALSE; |
|
1127 |
km_file_export( dlg, kmi->lv, t ); |
for (n = _sec->item; n; n = n->next) { |
1128 |
return TRUE; |
if (n->pubpart && |
1129 |
|
n->pubpart->key->owner_trust == GPGME_VALIDITY_ULTIMATE) |
1130 |
case ID_KEYMISC_EXPORT_PRIVKEY: |
return 0; |
1131 |
idx = listview_get_curr_pos( kmi->lv ); |
nkeys++; |
1132 |
if( idx == -1 ) { |
} |
1133 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
|
1134 |
return FALSE; |
/* if we do not have any secret keys, it does not make sense |
1135 |
} |
to return an error. */ |
1136 |
if( !km_check_for_seckey( kmi->lv, idx, NULL ) ) { |
if (nkeys == 0) |
1137 |
msg_box( dlg, _("There is no corresponding secret key for this key."), |
return 0; |
1138 |
_("Key Manager"), MB_ERR ); |
return -1; |
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 ); |
static void |
1143 |
return FALSE; |
reload_keylist (struct km_info_s *kmi) |
1144 |
} |
{ |
1145 |
idx = msg_box( dlg, |
gpg_keycache_t c; |
1146 |
_("This operation will export your *SECRET* key!\n\n" |
|
1147 |
"Never send this key to ANYONE, it should be available\n" |
c = keycache_get_ctx (1); |
1148 |
"ONLY on your machine and you may use this function\n" |
keycache_reload (kmi->dlg); |
1149 |
"to copy the key to a safe place.\n\n" |
keylist_reload (kmi->lv, c, KEYLIST_LIST, kmi->keylist_sortby); |
1150 |
"Do you really want to export the key?"), |
update_status_bar (kmi->statbar, kmi->lv); |
1151 |
_("WARNING"), MB_INFO|MB_YESNO ); |
keyring_check_last_access (); |
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" ); |
/* Reload the entire key cache and update the listview. */ |
1156 |
t = get_filename_dlg( dlg, 1, _("Choose Name for Key File"), NULL, keyid ); |
static void |
1157 |
if( t && !file_exist_check( t ) ) { |
reload_keycache (struct km_info_s *kmi) |
1158 |
idx = log_box( _("Key Manager"), MB_INFO|MB_YESNO, |
{ |
1159 |
_("File %s already exists.\nOverwrite?"), t ); |
refresh_cache_s rcs = {0}; |
1160 |
if( idx == IDNO ) |
gpg_keycache_t c; |
1161 |
return FALSE; |
|
1162 |
} |
rcs.kr_reload = rcs.kr_update = 1; |
1163 |
if( t ) |
rcs.tr_update = 0; |
1164 |
km_privkey_export( dlg, kmi->lv, t ); |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, kmi->dlg, |
1165 |
} |
keycache_dlg_proc, (LPARAM)&rcs); |
1166 |
break; |
c = keycache_get_ctx (1); |
1167 |
|
keylist_reload (kmi->lv, c, KEYLIST_LIST, kmi->keylist_sortby); |
1168 |
case ID_KEYMISC_INFO: |
update_status_bar (kmi->statbar, kmi->lv); |
1169 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, glob_hwnd, |
SetForegroundWindow (kmi->dlg); |
1170 |
about_winpt_dlg_proc, NULL, _("About WinPT"), |
} |
1171 |
IDS_WINPT_ABOUT ); |
|
1172 |
break; |
|
1173 |
|
/* Handle all import request. */ |
1174 |
case ID_KEYMISC_HELP: |
static void |
1175 |
ShellExecute (dlg, "open", "winpt.chm", NULL, NULL, SW_SHOW); |
km_gui_import (struct km_info_s *kmi, int cmd_id, void *param) |
1176 |
break; |
{ |
1177 |
|
int newkeys=0, newsks=0; |
1178 |
case ID_KEYMISC_OT: |
int err = 0; |
1179 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST, glob_hwnd, |
|
1180 |
ownertrust_dlg_proc, NULL, |
switch (cmd_id) { |
1181 |
_("Ownertrust"), IDS_WINPT_OWNERTRUST ); |
case ID_KEYMISC_PASTE: |
1182 |
break; |
err = km_clip_import (kmi->dlg, &newkeys, &newsks); |
1183 |
|
break; |
1184 |
case ID_KEYMISC_EDITKEY: |
|
1185 |
idx = listview_get_curr_pos (kmi->lv); |
case ID_KEYMISC_IMPORT: |
1186 |
if (idx == -1) |
err = km_file_import (kmi->dlg, NULL, &newkeys, &newsks); |
1187 |
break; |
break; |
1188 |
listview_get_item_text (kmi->lv, idx, 1, keyid, sizeof (keyid)-1); |
|
1189 |
/* XXX: pub/crd = secret key does not work */ |
case WM_DROPFILES: |
1190 |
k.is_protected = km_check_if_protected (kmi->lv, idx); |
err = km_dropped_file_import (kmi->dlg, (HDROP)param, |
1191 |
k.key_pair = km_check_for_seckey (kmi->lv, idx, NULL); |
&newkeys, &newsks); |
1192 |
k.keyid = keyid; |
break; |
1193 |
k.flags = km_get_key_status (kmi->lv, idx); |
|
1194 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg, |
default: |
1195 |
keyedit_main_dlg_proc, (LPARAM)&k, |
err = 1; |
1196 |
_("Key Edit"), IDS_KEYCTX_EDIT); |
break; |
1197 |
break; |
} |
1198 |
|
|
1199 |
case ID_GROUP_NEW: |
if (!err && !newsks && (newkeys > 0 && newkeys < KM_PRELOAD_KEYS)) |
1200 |
memset (&gcb, 0, sizeof (gcb)); |
refresh_keylist (kmi); |
1201 |
gcb.gc = gc; |
else if (!err) /* avoid to spawn too much processes. */ |
1202 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GROUP, glob_hwnd, |
reload_keylist (kmi); |
1203 |
group_manager_dlg_proc, (LPARAM)&gcb, _("New Group"), |
|
1204 |
IDS_WINPT_GROUP); |
SetForegroundWindow (kmi->dlg); |
1205 |
if( gcb.use_name ) |
} |
1206 |
treeview_add_item( GetDlgItem(dlg, IDC_KEYMISC_GROUP), NULL, gcb.name ); |
|
1207 |
return TRUE; |
|
1208 |
|
/* Copy the requested key information (@what) to the clipboard. |
1209 |
case ID_KEYMISC_COPY: |
If multiple items were selected, each key info is copied to |
1210 |
km_index = listview_get_curr_pos( kmi->lv ); |
the clipboard. The data is separated by \r\n. */ |
1211 |
km_clip_export( dlg, kmi->lv ); |
static void |
1212 |
break; |
copy_key_info (int what, struct km_info_s *kmi) |
1213 |
|
{ |
1214 |
case ID_KEYMISC_SELALL: |
gpgme_data_t out; |
1215 |
listview_select_all (kmi->lv); |
gpgme_key_t key; |
1216 |
break; |
struct keycache_s *kci = NULL; |
1217 |
|
size_t n=0; |
1218 |
case ID_KEYMISC_PASTE: |
char *p, tmp[256]; |
1219 |
km_index = -1; |
int i=0, end = listview_count_items (kmi->lv, 0); |
1220 |
km_clip_import (dlg); |
bool single = false; |
1221 |
break; |
|
1222 |
|
/* Do not iterate over the entire list if just one item is selected. */ |
1223 |
case ID_KEYCTX_SETPREFKS: |
n = listview_count_items (kmi->lv, 1); |
1224 |
/* XXX: todo */ |
if (n == 1) { |
1225 |
break; |
i = kmi->lv_idx; |
1226 |
|
end = i+1; |
1227 |
case ID_KEYMISC_REFRESH_KEYS: |
single = true; |
1228 |
if (listview_count_items (kmi->lv, 1) == 0) |
} |
1229 |
{ |
|
1230 |
msg_box (dlg, _("No key was selected, select all by default."), _("Key Manager"), MB_INFO); |
gpgme_data_new (&out); |
1231 |
listview_select_all (kmi->lv); |
for (; i < end; i++) { |
1232 |
} |
if (!listview_get_item_state (kmi->lv, i)) |
1233 |
km_refresh_from_keyserver (kmi->lv, dlg); |
continue; |
1234 |
break; |
switch (what) { |
1235 |
|
case ID_KEYCTX_UID_COPY: |
1236 |
/** Context menu **/ |
key = km_get_key_ptr (kmi->lv, i, &kci); |
1237 |
case ID_KEYCTX_EDIT: |
gpgme_data_write (out, kci->uids->uid, strlen (kci->uids->uid)); |
1238 |
send_cmd_id( dlg, ID_KEYMISC_EDITKEY ); |
if (!single) gpgme_data_write (out, "\r\n", 2); |
1239 |
break; |
break; |
1240 |
|
|
1241 |
case ID_KEYCTX_PROPS: |
case ID_KEYCTX_KEYID_COPY: |
1242 |
send_cmd_id( dlg, ID_KEYMISC_PROPS ); |
key = km_get_key_ptr (kmi->lv, i, NULL); |
1243 |
break; |
gpgme_data_write (out, "0x", 2); |
1244 |
|
gpgme_data_write (out, key->subkeys->keyid+8, 8); |
1245 |
case ID_KEYCTX_UIDS: |
if (!single) gpgme_data_write (out, "\r\n", 2); |
1246 |
send_cmd_id( dlg, ID_KEYMISC_UID ); |
break; |
1247 |
break; |
|
1248 |
|
case ID_KEYCTX_FPR_COPY: |
1249 |
case ID_KEYCTX_SIGN: |
key = km_get_key_ptr (kmi->lv, i, NULL); |
1250 |
send_cmd_id( dlg, ID_KEYMISC_SIGN ); |
gpgme_data_write (out, key->subkeys->fpr, strlen (key->subkeys->fpr)); |
1251 |
break; |
if (!single) gpgme_data_write (out, "\r\n", 2); |
1252 |
|
break; |
1253 |
case ID_KEYCTX_DEL: |
|
1254 |
send_cmd_id (dlg, ID_KEYMISC_DELETE); |
case ID_KEYCTX_KINFO_COPY: |
1255 |
break; |
key = km_get_key_ptr (kmi->lv, i, NULL); |
1256 |
|
key_get_clip_info (key->subkeys->keyid+8, tmp, sizeof (tmp)-1); |
1257 |
case ID_KEYCTX_REV: |
gpgme_data_write (out, tmp, strlen (tmp)); |
1258 |
send_cmd_id( dlg, ID_KEYMISC_REVCERT ); |
if (!single) gpgme_data_write (out, "\r\n", 2); |
1259 |
break; |
break; |
1260 |
|
} |
1261 |
case ID_KEYCTX_SENDMAIL: |
} |
1262 |
km_send_to_mail_recipient( kmi->lv, dlg ); |
gpgme_data_write (out, "\0", 1); |
1263 |
break; |
p = gpgme_data_release_and_get_mem (out, &n); |
1264 |
|
set_clip_text (NULL, p, n); |
1265 |
case ID_KEYCTX_KS_DEFAULT: |
gpgme_free (p); |
1266 |
host = kserver_get_hostname (0, -1, &port); |
} |
1267 |
km_send_to_keyserver (kmi->lv, dlg, host, port); |
|
1268 |
break; |
|
1269 |
|
/* Dialog box procedure for the Key Manager. */ |
1270 |
case ID_KEYCTX_ADDKEY: |
BOOL CALLBACK |
1271 |
idx = listview_get_curr_pos( kmi->lv ); |
keymanager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
1272 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid - 1 ); |
{ |
1273 |
k.key_pair = km_check_for_seckey( kmi->lv, idx, NULL ); |
HWND kl; |
1274 |
k.is_protected = km_check_if_protected( kmi->lv, idx ); |
HMENU hm; |
1275 |
k.keyid = keyid; |
RECT r; |
1276 |
keyedit_add_subkey( &k, dlg, NULL ); |
gpg_keycache_t c; |
1277 |
break; |
gpgme_key_t key; |
1278 |
|
km_info_t kmi = NULL; |
1279 |
case ID_KEYCTX_ADDUID: |
struct genkey_s genkey; |
1280 |
idx = listview_get_curr_pos( kmi->lv ); |
struct winpt_key_s k = {0}; |
1281 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 ); |
struct URL_ctx_s *url; |
1282 |
k.key_pair = km_check_for_seckey( kmi->lv, idx, NULL ); |
char type[32], *name; |
1283 |
k.is_protected = km_check_if_protected( kmi->lv, idx ); |
const char *t, *host; |
1284 |
k.keyid = keyid; |
WORD port = 0; |
1285 |
keyedit_add_userid( &k, dlg, NULL ); |
int l_idx = 0, i=0, rc; |
1286 |
break; |
|
1287 |
|
if ((msg != WM_INITDIALOG) |
1288 |
case ID_KEYCTX_ADDREV: |
&& ((kmi = (km_info_t)GetWindowLong (dlg, GWL_USERDATA)) == NULL)) |
1289 |
idx = listview_get_curr_pos( kmi->lv ); |
return FALSE; |
1290 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 ); |
|
1291 |
k.keyid = keyid; |
/* handle dynamic popup items in the keyserver menu. */ |
1292 |
k.is_protected = km_check_if_protected( kmi->lv, idx ); |
if (msg == WM_COMMAND && LOWORD (wparam) >= WM_APP && |
1293 |
k.key_pair = km_check_for_seckey( kmi->lv, idx, NULL ); |
LOWORD (wparam) <= WM_APP+MAX_KEYSERVERS) { |
1294 |
keyedit_add_revoker( &k, dlg ); |
l_idx = LOWORD (wparam)-WM_APP; |
1295 |
break; |
if (l_idx < 0) |
1296 |
|
return TRUE; |
1297 |
case ID_KEYCTX_ADDPHOTO: |
host = kserver_get_hostname (l_idx, 0, &port); |
1298 |
idx = listview_get_curr_pos( kmi->lv ); |
if (host != NULL) |
1299 |
listview_get_item_text( kmi->lv, idx, 1, keyid, sizeof keyid-1 ); |
km_send_to_keyserver (kmi->lv, dlg, host, port); |
1300 |
k.keyid = keyid; |
return TRUE; |
1301 |
k.is_protected = km_check_if_protected( kmi->lv, idx ); |
} |
1302 |
k.key_pair = km_check_for_seckey( kmi->lv, idx, NULL ); |
|
1303 |
keyedit_add_photo( &k, dlg ); |
switch (msg) { |
1304 |
break; |
case WM_INITDIALOG: |
1305 |
|
kmi = new struct km_info_s; |
1306 |
case ID_KEYCTX_KS_NL: |
memset (kmi, 0, sizeof (struct km_info_s)); |
1307 |
case ID_KEYCTX_KS_PL: |
kmi->lv_idx = -1; |
1308 |
case ID_KEYCTX_KS_AT: |
kmi->hwnd_sep = regist_sep_wnd (dlg, kmi); |
1309 |
case ID_KEYCTX_KS_DE: |
imagelist_load (dlg); |
1310 |
case ID_KEYCTX_KS_DK: |
translate_menu_strings (dlg); |
1311 |
case ID_KEYCTX_KS_CZ: |
SetWindowText (dlg, _("Key Manager")); |
1312 |
case ID_KEYCTX_KS_ES: |
|
1313 |
case ID_KEYCTX_KS_UK: |
c = keycache_get_ctx (KEYCACHE_PUB); |
1314 |
host = kserver_get_hostname (LOWORD (wparam) - 40107, 0, &port); |
kl = GetDlgItem (dlg, IDC_KEYMISC_KEYLIST); |
1315 |
km_send_to_keyserver (kmi->lv, dlg, host, port); |
kmi->keylist_sortby = KEY_SORT_USERID; |
1316 |
break; |
Header_SetImageList(ListView_GetHeader (kl), glob_imagelist); |
1317 |
|
kmi->lv = keylist_load (GetDlgItem (dlg, IDC_KEYMISC_KEYLIST), c, |
1318 |
case ID_KEYCTX_RECVFROM: |
NULL, KEYLIST_LIST, kmi->keylist_sortby); |
1319 |
km_refresh_from_keyserver (kmi->lv, dlg); |
if (check_ultimate_trusted_key (keycache_get_ctx (0))) { |
1320 |
break; |
msg_box (dlg, _("No ultimately trusted key found.\n" |
1321 |
|
"Please set at least one secret key to ultimate trust."), |
1322 |
case ID_KEYCTX_UID_COPY: |
_("Key Manager"), MB_WARN); |
1323 |
/* XXX: add generic function to support multiple selection |
} |
1324 |
with a callback */ |
/* init subclassing for the listview */ |
1325 |
idx = listview_get_curr_pos( kmi->lv ); |
keylist_proc.opaque = kmi; |
1326 |
listview_get_item_text( kmi->lv, idx, 0, uid, sizeof uid-1 ); |
keylist_proc.dlg = dlg; |
1327 |
set_clip_text( NULL, uid, strlen( uid ) ); |
keylist_proc.current = (WNDPROC)keylist_subclass_proc; |
1328 |
break; |
keylist_proc.old = (WNDPROC)GetWindowLong(kl, GWL_WNDPROC); |
1329 |
|
if (keylist_proc.old) { |
1330 |
case ID_KEYCTX_KEYID_COPY: |
if( !SetWindowLong (kl, GWL_WNDPROC, (LONG)keylist_proc.current)) { |
1331 |
idx = listview_get_curr_pos( kmi->lv ); |
msg_box (dlg, _("Could not set keylist window procedure."), |
1332 |
listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 ); |
_("Key Manager"), MB_ERR); |
1333 |
set_clip_text( NULL, uid, strlen( uid ) ); |
BUG (NULL); |
1334 |
break; |
} |
1335 |
|
} |
1336 |
case ID_KEYCTX_FPR_COPY: |
kmi->statbar = setup_status_bar (dlg, kmi->lv); |
1337 |
idx = listview_get_curr_pos( kmi->lv ); |
SetWindowLong (dlg, GWL_USERDATA, (LONG)kmi); |
1338 |
listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 ); |
kmi->toolbar = load_toolbar (dlg, kmi); |
1339 |
get_pubkey( uid, &pk ); |
kmi->dlg = dlg; |
1340 |
if( pk ) { |
|
1341 |
const char * s = get_key_fpr( pk ); |
do_center_window (dlg, kmi); |
1342 |
set_clip_text( NULL, s? s : "", s? strlen( s ): 0 ); |
do_resize_window (dlg, kmi); |
1343 |
} |
restore_window_size (dlg, kmi); |
1344 |
break; |
update_ui_items (dlg, kmi->lv); |
1345 |
|
restore_column_info (kmi); |
1346 |
case ID_KEYCTX_KINFO_COPY: |
keylist_sort (kmi->lv, kmi->keylist_sortby); |
1347 |
idx = listview_get_curr_pos( kmi->lv ); |
|
1348 |
listview_get_item_text( kmi->lv, idx, 1, uid, sizeof uid-1 ); |
SetDlgItemText (dlg, IDC_KEYMISC_GTEXT, _("Groups")); |
1349 |
km_set_clip_info( uid ); |
SetDlgItemText (dlg, ID_GROUP_SHOW, _("&Show")); |
1350 |
break; |
SetDlgItemText (dlg, ID_GROUP_NEW, _("&New...")); |
1351 |
|
SetClassLong (dlg, GCL_HICON, (LONG)LoadIcon (glob_hinst, |
1352 |
case ID_KEYCTX_COPY: |
(LPCTSTR)IDI_WINPT)); |
1353 |
km_index = listview_get_curr_pos (kmi->lv); |
SetForegroundWindow (dlg); |
1354 |
km_clip_export (dlg, kmi->lv); |
kmi->magic = SetTimer (dlg, 1, 1000, NULL); |
1355 |
break; |
return TRUE; |
1356 |
|
|
1357 |
case ID_KEYCTX_PASTE: |
case WM_TIMER: |
1358 |
km_index = -1; |
KillTimer (dlg, kmi->magic); |
1359 |
km_clip_import (dlg); |
SetForegroundWindow (dlg); |
1360 |
break; |
break; |
1361 |
|
|
1362 |
case ID_KEYCTX_DISABLE: |
case WM_DESTROY: |
1363 |
idx = listview_get_curr_pos (kmi->lv); |
save_column_info (kmi); |
1364 |
km_enable_disable_key (kmi->lv, dlg, idx, 0); |
if (kmi->lv) { |
1365 |
break; |
keylist_delete (kmi->lv); |
1366 |
|
kmi->lv = NULL; |
1367 |
case ID_KEYCTX_ENABLE: |
} |
1368 |
idx = listview_get_curr_pos (kmi->lv); |
imagelist_destroy (); |
1369 |
km_enable_disable_key (kmi->lv, dlg, idx, 1); |
|
1370 |
break; |
ltoa (kmi->pos_x, type, 10); |
1371 |
|
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", type); |
1372 |
case ID_KEYCTX_LISTSIGS: |
ltoa (kmi->pos_y, type, 10); |
1373 |
send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS); |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", type); |
1374 |
break; |
|
1375 |
|
GetWindowRect (dlg, &r); |
1376 |
case ID_KEYCTX_MAXTRUST: |
sprintf (type, "%d", (int)(r.bottom-r.top)); |
1377 |
idx = listview_get_curr_pos (kmi->lv); |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Size_Width", |
1378 |
km_set_implicit_trust (dlg, kmi->lv, idx); |
type); |
1379 |
break; |
sprintf (type, "%d", (int)(r.right-r.left)); |
1380 |
|
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Size_Height", |
1381 |
case ID_KEYCTX_SETDEFKEY: |
type); |
1382 |
idx = listview_get_curr_pos (kmi->lv); |
|
1383 |
if (km_check_key_status (kmi->lv, idx)) |
/* Remove runtime information. This should be the last action taken here. */ |
1384 |
{ |
delete kmi; |
1385 |
listview_get_item_text (kmi->lv, idx, 1, keyid, sizeof keyid -1); |
kmi = NULL; |
1386 |
rc = set_gnupg_default_key (keyid); |
SetWindowLong (dlg, GWL_USERDATA, 0); |
1387 |
if (rc) |
return FALSE; |
1388 |
msg_box( dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR); |
|
1389 |
km_update_default_key_str (kmi->statbar, &km_def_pos); |
case WM_MOVE: |
1390 |
} |
GetWindowRect (dlg, &r); |
1391 |
break; |
kmi->pos_x = r.left; |
1392 |
|
kmi->pos_y = r.top; |
1393 |
case ID_GROUP_PASTE: |
break; |
1394 |
km_groups_add (gc, kmi->lv, km_index); |
|
1395 |
break; |
|
1396 |
|
case WM_RBUTTONUP: |
1397 |
case ID_GROUP_DELETE: |
do_create_minpopup (dlg); |
1398 |
km_groups_del (gc); |
break; |
1399 |
break; |
|
1400 |
} |
case WM_NOTIFY: |
1401 |
break; |
NMHDR *notify; |
1402 |
} |
POINT p; |
1403 |
|
HMENU popup; |
1404 |
return FALSE; |
|
1405 |
} /* keymanager_dlg_proc */ |
notify = (NMHDR *)lparam; |
1406 |
|
if (!notify) |
1407 |
|
break; |
1408 |
|
switch (notify->code) { |
1409 |
|
case TBN_QUERYDELETE: |
1410 |
|
SetWindowLong (dlg, DWL_MSGRESULT, TRUE); |
1411 |
|
return TRUE; |
1412 |
|
|
1413 |
|
case TBN_QUERYINSERT: |
1414 |
|
SetWindowLong (dlg, DWL_MSGRESULT, TRUE); |
1415 |
|
return TRUE; |
1416 |
|
|
1417 |
|
case TBN_GETBUTTONINFO: |
1418 |
|
LPTBNOTIFY lpTbNotify; |
1419 |
|
lpTbNotify = (LPTBNOTIFY)lparam; |
1420 |
|
if (lpTbNotify->iItem < (sizeof(myb) / sizeof(mybuttons))) { |
1421 |
|
lpTbNotify->tbButton.iBitmap = imagelist_getindex (myb[lpTbNotify->iItem].icon); |
1422 |
|
lpTbNotify->tbButton.idCommand = myb[lpTbNotify->iItem].command; |
1423 |
|
lpTbNotify->tbButton.fsState = TBSTATE_ENABLED; |
1424 |
|
lpTbNotify->tbButton.fsStyle = TBSTYLE_BUTTON; |
1425 |
|
lpTbNotify->tbButton.iString = 0; |
1426 |
|
strncpy (lpTbNotify->pszText, myb[lpTbNotify->iItem].text, lpTbNotify->cchText); |
1427 |
|
SetWindowLong(dlg, DWL_MSGRESULT, TRUE); |
1428 |
|
} |
1429 |
|
return TRUE; |
1430 |
|
|
1431 |
|
case TBN_RESET: /* Restore last saved toolbar status */ |
1432 |
|
TBSAVEPARAMS tbsp; |
1433 |
|
|
1434 |
|
tbsp.hkr = HKEY_CURRENT_USER; |
1435 |
|
tbsp.pszSubKey = "Software\\WinPT"; |
1436 |
|
tbsp.pszValueName = "KM_toolbar"; |
1437 |
|
SendMessage (notify->hwndFrom, TB_SAVERESTORE, FALSE, (LPARAM)&tbsp); |
1438 |
|
break; |
1439 |
|
|
1440 |
|
case TBN_BEGINADJUST: /* User is about to change the toolbar. Save it */ |
1441 |
|
tbsp.hkr = HKEY_CURRENT_USER; |
1442 |
|
tbsp.pszSubKey = "Software\\WinPT"; |
1443 |
|
tbsp.pszValueName = "KM_toolbar"; |
1444 |
|
SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp); |
1445 |
|
break; |
1446 |
|
|
1447 |
|
case TBN_ENDADJUST: /* User has finished customizing the toolbar. Save it. */ |
1448 |
|
tbsp.hkr = HKEY_CURRENT_USER; |
1449 |
|
tbsp.pszSubKey = "Software\\WinPT"; |
1450 |
|
tbsp.pszValueName = "KM_toolbar"; |
1451 |
|
SendMessage (notify->hwndFrom, TB_SAVERESTORE, TRUE, (LPARAM)&tbsp); |
1452 |
|
break; |
1453 |
|
|
1454 |
|
case TTN_GETDISPINFO: |
1455 |
|
LPTOOLTIPTEXT lpttt; |
1456 |
|
lpttt = (LPTOOLTIPTEXT)lparam; |
1457 |
|
|
1458 |
|
lpttt->hinst = NULL; |
1459 |
|
switch (lpttt->hdr.idFrom) { |
1460 |
|
case ID_KEYMISC_KEYWIZARD: |
1461 |
|
lpttt->lpszText = (char*)_("Generate new key pair"); |
1462 |
|
break; |
1463 |
|
|
1464 |
|
case ID_KEYMISC_SENDRECV: |
1465 |
|
lpttt->lpszText = (char*)_("Search for a specific key"); |
1466 |
|
break; |
1467 |
|
|
1468 |
|
case ID_KEYMISC_DELETE: |
1469 |
|
lpttt->lpszText = (char *)_("Delete key from keyring"); |
1470 |
|
break; |
1471 |
|
|
1472 |
|
case ID_KEYMISC_PROPS: |
1473 |
|
lpttt->lpszText = (char *)_("Show key properties"); |
1474 |
|
break; |
1475 |
|
|
1476 |
|
case ID_KEYMISC_SIGN: |
1477 |
|
lpttt->lpszText = (char *)_("Sign key"); |
1478 |
|
break; |
1479 |
|
|
1480 |
|
case ID_KEYCTX_COPY: |
1481 |
|
lpttt->lpszText = (char *)_("Copy key to clipboard"); |
1482 |
|
break; |
1483 |
|
|
1484 |
|
case ID_KEYCTX_PASTE: |
1485 |
|
lpttt->lpszText = (char*)_("Paste key from clipboard"); |
1486 |
|
break; |
1487 |
|
|
1488 |
|
case ID_KEYMISC_IMPORT: |
1489 |
|
lpttt->lpszText = (char *)_("Import key to keyring"); |
1490 |
|
break; |
1491 |
|
|
1492 |
|
case ID_KEYMISC_EXPORT: |
1493 |
|
lpttt->lpszText = (char *)_("Export key to a file"); |
1494 |
|
break; |
1495 |
|
} |
1496 |
|
return TRUE; |
1497 |
|
|
1498 |
|
case LVN_ITEMCHANGED: |
1499 |
|
if (((LPNMLISTVIEW)lparam)->uNewState) { /* item selected? */ |
1500 |
|
kmi->lv_idx = listview_get_curr_pos (kmi->lv); |
1501 |
|
update_ui_items (dlg, kmi->lv); |
1502 |
|
return TRUE; |
1503 |
|
} |
1504 |
|
break; |
1505 |
|
|
1506 |
|
case NM_RCLICK: |
1507 |
|
if (notify->idFrom == IDC_KEYMISC_KEYLIST) { |
1508 |
|
l_idx =listview_get_curr_pos (kmi->lv); |
1509 |
|
if (l_idx == -1) |
1510 |
|
return TRUE; /* Popup only when a item was selected */ |
1511 |
|
GetCursorPos (&p); |
1512 |
|
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYMISC_CTX)); |
1513 |
|
popup = GetSubMenu (hm, 0); |
1514 |
|
translate_popupmenu_strings (popup); |
1515 |
|
|
1516 |
|
if (km_check_for_seckey (kmi->lv, l_idx, &i)) |
1517 |
|
set_menu_state (popup, ID_KEYCTX_SETDEFKEY, MF_ENABLED); |
1518 |
|
if (i == 0) |
1519 |
|
set_menu_state (popup, ID_KEYCTX_MAXTRUST, MF_ENABLED); |
1520 |
|
if (!km_check_for_seckey (kmi->lv, l_idx, NULL) || |
1521 |
|
(km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED)) { |
1522 |
|
set_menu_state (popup, ID_KEYCTX_REV, MF_DISABLED|MF_GRAYED); |
1523 |
|
set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED); |
1524 |
|
set_menu_state (popup, ID_KEYCTX_ADDUID, MF_DISABLED|MF_GRAYED); |
1525 |
|
set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED); |
1526 |
|
set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED ); |
1527 |
|
set_menu_state (popup, ID_KEYCTX_SETPREFKS, MF_DISABLED|MF_GRAYED); |
1528 |
|
} |
1529 |
|
else if (km_check_for_seckey (kmi->lv, l_idx, NULL) && |
1530 |
|
km_key_is_v3 (kmi->lv, l_idx)) { |
1531 |
|
/* PGP 2 keys, version 3 have no no support for photo-id's, |
1532 |
|
designated revokers and secondary keys. */ |
1533 |
|
set_menu_state (popup, ID_KEYCTX_ADDKEY, MF_DISABLED|MF_GRAYED); |
1534 |
|
set_menu_state (popup, ID_KEYCTX_ADDREV, MF_DISABLED|MF_GRAYED); |
1535 |
|
set_menu_state (popup, ID_KEYCTX_ADDPHOTO, MF_DISABLED|MF_GRAYED); |
1536 |
|
} |
1537 |
|
if (km_get_key_status( kmi->lv, l_idx ) & KM_FLAG_DISABLED) |
1538 |
|
set_menu_state (popup, ID_KEYCTX_DISABLE, MF_DISABLED|MF_GRAYED); |
1539 |
|
else |
1540 |
|
set_menu_state (popup, ID_KEYCTX_ENABLE, MF_DISABLED|MF_GRAYED); |
1541 |
|
if (km_get_key_status (kmi->lv, l_idx) & KM_FLAG_REVOKED || |
1542 |
|
km_get_key_status (kmi->lv, l_idx) & KM_FLAG_EXPIRED) |
1543 |
|
set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED); |
1544 |
|
if (!clip_contains_pgpkey ()) |
1545 |
|
set_menu_state (popup, ID_KEYCTX_PASTE, MF_DISABLED|MF_GRAYED); |
1546 |
|
if (mapi_init ()) |
1547 |
|
set_menu_state (popup, ID_KEYCTX_SENDMAIL, MF_DISABLED|MF_GRAYED); |
1548 |
|
if (!secret_key_available ()) |
1549 |
|
set_menu_state (popup, ID_KEYCTX_SIGN, MF_DISABLED|MF_GRAYED); |
1550 |
|
|
1551 |
|
/* Override 'Default Keyserver' with the actual name. */ |
1552 |
|
host = kserver_get_hostname (0, -1, &port); |
1553 |
|
if (!host) |
1554 |
|
host = DEF_HKP_KEYSERVER; |
1555 |
|
set_menu_text (popup, ID_KEYCTX_KS_DEFAULT, host); |
1556 |
|
{ |
1557 |
|
HMENU ks = GetSubMenu (popup, 19); |
1558 |
|
for (i=0; server[i].name != NULL; i++) |
1559 |
|
insert_menu_item (ks, i+2, WM_APP+i, server[i].name); |
1560 |
|
} |
1561 |
|
popup_gpg_readonly (dlg, popup); |
1562 |
|
if (listview_count_items (kmi->lv, 1) > 1) |
1563 |
|
popup_multiple (dlg, popup); |
1564 |
|
TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
1565 |
|
DestroyMenu (popup); |
1566 |
|
DestroyMenu (hm); |
1567 |
|
return TRUE; |
1568 |
|
} |
1569 |
|
break; |
1570 |
|
|
1571 |
|
case LVN_COLUMNCLICK: |
1572 |
|
if (notify->idFrom == IDC_KEYMISC_KEYLIST) { |
1573 |
|
NMLISTVIEW *nft = (LPNMLISTVIEW) lparam; |
1574 |
|
int sortby = 0; |
1575 |
|
switch (nft->iSubItem) { |
1576 |
|
case 0: sortby = KEY_SORT_USERID; break; |
1577 |
|
case 1: sortby = KEY_SORT_KEYID; break; |
1578 |
|
case 2: sortby = KEY_SORT_IS_SECRET; break; |
1579 |
|
case 3: sortby = KEY_SORT_LEN; break; |
1580 |
|
case 5: sortby = KEY_SORT_VALIDITY; break; |
1581 |
|
case 6: sortby = KEY_SORT_OTRUST; break; |
1582 |
|
case 7: sortby = KEY_SORT_CREATED; break; |
1583 |
|
case 8: sortby = KEY_SORT_ALGO; break; |
1584 |
|
default: return TRUE; //sortby = KEY_SORT_USERID; break; |
1585 |
|
} |
1586 |
|
|
1587 |
|
if ((kmi->keylist_sortby & ~KEYLIST_SORT_DESC) == sortby) |
1588 |
|
kmi->keylist_sortby ^= KEYLIST_SORT_DESC; |
1589 |
|
else |
1590 |
|
kmi->keylist_sortby = sortby; |
1591 |
|
keylist_sort (kmi->lv, kmi->keylist_sortby); |
1592 |
|
return TRUE; |
1593 |
|
} |
1594 |
|
break; |
1595 |
|
} |
1596 |
|
break; |
1597 |
|
|
1598 |
|
case WM_WINDOWPOSCHANGING: |
1599 |
|
if (((WINDOWPOS*)lparam)->cx < 400) |
1600 |
|
((WINDOWPOS*)lparam)->cx = 400; |
1601 |
|
if (((WINDOWPOS*)lparam)->cy < 200) |
1602 |
|
((WINDOWPOS*)lparam)->cy = 200; |
1603 |
|
return TRUE; |
1604 |
|
|
1605 |
|
case WM_SIZE: |
1606 |
|
do_resize_window (dlg, kmi); |
1607 |
|
return TRUE; |
1608 |
|
|
1609 |
|
case WM_SYSCOMMAND: |
1610 |
|
if (LOWORD (wparam) == SC_CLOSE) |
1611 |
|
EndDialog (dlg, TRUE); |
1612 |
|
return FALSE; |
1613 |
|
|
1614 |
|
case WM_MENUSELECT: |
1615 |
|
change_edit_menu (kmi->lv, (HMENU)lparam, LOWORD (wparam)); |
1616 |
|
change_key_menu ((HMENU)lparam, LOWORD (wparam)); |
1617 |
|
break; |
1618 |
|
|
1619 |
|
case WM_INITMENUPOPUP: |
1620 |
|
if ((UINT)LOWORD (lparam) == 3) { |
1621 |
|
HMENU h = (HMENU)wparam; |
1622 |
|
set_menu_text_bypos (h, 0, _("New")); |
1623 |
|
} |
1624 |
|
/* XXX: before we can use it, we need to find a way to |
1625 |
|
update the gpg access timestamp after each operation. |
1626 |
|
if (keyring_check_last_access ()) |
1627 |
|
reload_keylist (kmi); |
1628 |
|
*/ |
1629 |
|
return FALSE; |
1630 |
|
|
1631 |
|
case WM_COMMAND: |
1632 |
|
/* Allow at least 'Exit' in such a case. */ |
1633 |
|
if (gnupg_access_keyring (1) && LOWORD (wparam) != ID_KEYMISC_QUIT) { |
1634 |
|
msg_box (dlg, _("Could not access public keyring"), |
1635 |
|
_("Key Manager"), MB_ERR); |
1636 |
|
return FALSE; |
1637 |
|
} |
1638 |
|
|
1639 |
|
switch (LOWORD (wparam)) { |
1640 |
|
case ID_KEYMISC_QUIT: |
1641 |
|
EndDialog (dlg, TRUE); |
1642 |
|
return TRUE; |
1643 |
|
|
1644 |
|
case ID_KEYMISC_FIND: |
1645 |
|
km_find_key (dlg, kmi->lv); |
1646 |
|
break; |
1647 |
|
|
1648 |
|
case ID_KEYMISC_DELETE: |
1649 |
|
case ID_KEYMISC_DELETE2: |
1650 |
|
if (!km_delete_keys (kmi->lv, dlg)) |
1651 |
|
update_status_bar (kmi->statbar, kmi->lv); |
1652 |
|
return TRUE; |
1653 |
|
|
1654 |
|
case ID_KEYMISC_SIGN: |
1655 |
|
if (kmi->lv_idx == -1) { |
1656 |
|
msg_box (dlg, _("Please select a key."), |
1657 |
|
_("Key Manager"), MB_ERR); |
1658 |
|
return TRUE; |
1659 |
|
} |
1660 |
|
if (km_check_key_status (kmi->lv, kmi->lv_idx)) |
1661 |
|
return TRUE; |
1662 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
1663 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIGN, dlg, |
1664 |
|
keysign_dlg_proc, (LPARAM)&k, |
1665 |
|
_("Key Signing"), IDS_WINPT_KEYSIGN); |
1666 |
|
if (k.update) |
1667 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0); |
1668 |
|
return TRUE; |
1669 |
|
|
1670 |
|
case ID_KEYMISC_REVCERT: |
1671 |
|
if (kmi->lv_idx == -1) { |
1672 |
|
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
1673 |
|
return TRUE; |
1674 |
|
} |
1675 |
|
|
1676 |
|
{ |
1677 |
|
char state[64]; |
1678 |
|
listview_get_item_text (kmi->lv, kmi->lv_idx, 5, |
1679 |
|
state, sizeof (state) -1); |
1680 |
|
if (strchr (state, 'R' )) { |
1681 |
|
msg_box (dlg, _("Key already revoked!"), |
1682 |
|
_("Key Manager"), MB_INFO); |
1683 |
|
return TRUE; |
1684 |
|
} |
1685 |
|
} |
1686 |
|
|
1687 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
1688 |
|
if (!k.key_pair) { |
1689 |
|
msg_box (dlg, _("There is no secret key available!"), |
1690 |
|
_("Key Manager"), MB_ERR); |
1691 |
|
return TRUE; |
1692 |
|
} |
1693 |
|
dialog_box_param(glob_hinst, (LPCSTR)IDD_WINPT_KEYREVOKE, dlg, |
1694 |
|
key_revoke_dlg_proc, (LPARAM)&k, |
1695 |
|
_("Key Revocation Cert"), IDS_WINPT_KEYREVOKE); |
1696 |
|
return TRUE; |
1697 |
|
|
1698 |
|
case ID_KEYMISC_TRUSTPATH: |
1699 |
|
if (kmi->lv_idx == -1) { |
1700 |
|
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
1701 |
|
return TRUE; |
1702 |
|
} |
1703 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
1704 |
|
if (!k.key_pair) { |
1705 |
|
msg_box (dlg, _("It does not make any sense with a key pair!"), |
1706 |
|
_("Key Manager"), MB_ERR); |
1707 |
|
return TRUE; |
1708 |
|
} |
1709 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYTRUST, dlg, |
1710 |
|
keytrust_dlg_proc, (LPARAM)&k, |
1711 |
|
_("List Trust Path"), IDS_WINPT_KEYTRUST); |
1712 |
|
return TRUE; |
1713 |
|
|
1714 |
|
case ID_KEYMISC_CHECKSIGS: |
1715 |
|
if (kmi->lv_idx == -1) { |
1716 |
|
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
1717 |
|
return TRUE; |
1718 |
|
} |
1719 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
1720 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSIG_TREE, dlg, |
1721 |
|
sigtree_dlg_proc, (LPARAM)&k, |
1722 |
|
_("Key Signature List"), IDS_WINPT_KEYSIG); |
1723 |
|
if (k.update) |
1724 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0); |
1725 |
|
if (updated_keys_avail ()) |
1726 |
|
refresh_keylist (kmi); |
1727 |
|
return TRUE; |
1728 |
|
|
1729 |
|
case ID_KEYMISC_PROPS: |
1730 |
|
if (kmi->lv_idx == -1) { |
1731 |
|
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
1732 |
|
return TRUE; |
1733 |
|
} |
1734 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
1735 |
|
k.callback.ctl = kmi->lv; |
1736 |
|
k.callback.idx = kmi->lv_idx; |
1737 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg, |
1738 |
|
keyprops_dlg_proc, (LPARAM)&k, |
1739 |
|
_("Key Properties"), IDS_WINPT_KEYPROPS); |
1740 |
|
if (k.update) |
1741 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, k.key_pair); |
1742 |
|
return TRUE; |
1743 |
|
|
1744 |
|
case ID_KEYMISC_RECACHE: |
1745 |
|
if (updated_keys_avail ()) |
1746 |
|
l_idx = IDYES; |
1747 |
|
else { |
1748 |
|
l_idx = log_box (_("Key Manager"), MB_YESNO, |
1749 |
|
_("This is only useful when the keyring has been " |
1750 |
|
"modified (sign a key...).\n" |
1751 |
|
"Do you really want to reload the keycache?")); |
1752 |
|
} |
1753 |
|
if (l_idx == IDYES) |
1754 |
|
reload_keycache (kmi); |
1755 |
|
return TRUE; |
1756 |
|
|
1757 |
|
case ID_KEYMISC_REBUILD: |
1758 |
|
name = NULL; |
1759 |
|
gpg_rebuild_cache (&name); |
1760 |
|
if (name != NULL) { |
1761 |
|
char *line = strchr (name, '\n'); |
1762 |
|
show_msg (dlg, 2000, line? name + (line-name)+1 : name); |
1763 |
|
safe_free (name); |
1764 |
|
} |
1765 |
|
SetForegroundWindow (dlg); |
1766 |
|
return TRUE; |
1767 |
|
|
1768 |
|
case ID_KEYMISC_NEWKEY: |
1769 |
|
memset (&genkey, 0, sizeof (genkey)); |
1770 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYGEN, dlg, |
1771 |
|
keygen_dlg_proc, (LPARAM)&genkey, _("Key Generation"), |
1772 |
|
IDS_WINPT_KEYGEN); |
1773 |
|
if (genkey.cancel == 0) |
1774 |
|
refresh_keylist (kmi); |
1775 |
|
return TRUE; |
1776 |
|
|
1777 |
|
case ID_KEYMISC_CARDNEW: |
1778 |
|
if (!scard_support) { |
1779 |
|
msg_box (dlg, _("Smart Card support is not available."), |
1780 |
|
_("Key Manager"), MB_INFO); |
1781 |
|
return TRUE; |
1782 |
|
} |
1783 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_KEYGEN, dlg, |
1784 |
|
card_keygen_dlg_proc, 0, _("Card Key Generation"), |
1785 |
|
IDS_WINPT_CARD_KEYGEN); |
1786 |
|
if (updated_keys_avail ()) |
1787 |
|
send_cmd_id (dlg, ID_KEYMISC_RECACHE); |
1788 |
|
return TRUE; |
1789 |
|
|
1790 |
|
case ID_KEYMISC_KEYWIZARD: |
1791 |
|
memset (&genkey, 0, sizeof (genkey)); |
1792 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYWIZARD, dlg, |
1793 |
|
keygen_wizard_dlg_proc, (LPARAM)&genkey, |
1794 |
|
_("Key Generation Wizard"), |
1795 |
|
IDS_WINPT_KEYWIZARD); |
1796 |
|
if (genkey.cancel == 0) |
1797 |
|
refresh_keylist (kmi); |
1798 |
|
return TRUE; |
1799 |
|
|
1800 |
|
case ID_KEYMISC_SENDRECV: |
1801 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYSERVER, dlg, |
1802 |
|
keyserver_dlg_proc, 0, _("Keyserver Access"), |
1803 |
|
IDS_WINPT_KEYSERVER); |
1804 |
|
refresh_keylist (kmi); |
1805 |
|
return TRUE; |
1806 |
|
|
1807 |
|
case ID_KEYMISC_GPGPREFS: |
1808 |
|
rc = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, |
1809 |
|
dlg, gpgprefs_dlg_proc, 0, |
1810 |
|
_("GnuPG Preferences"), IDS_WINPT_GPGPREFS); |
1811 |
|
if (rc == TRUE) { |
1812 |
|
reload_keycache (kmi); |
1813 |
|
update_default_key_str (kmi->statbar); |
1814 |
|
} |
1815 |
|
return TRUE; |
1816 |
|
|
1817 |
|
case ID_KEYMISC_GPGOPT: |
1818 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGOPT, dlg, |
1819 |
|
gpgopt_dlg_proc, 0, _("GnuPG Options"), |
1820 |
|
IDS_WINPT_GPGOPT); |
1821 |
|
return TRUE; |
1822 |
|
|
1823 |
|
case ID_KEYMISC_IMPORT: |
1824 |
|
km_gui_import (kmi, LOWORD (wparam), NULL); |
1825 |
|
return TRUE; |
1826 |
|
|
1827 |
|
case ID_KEYMISC_IMPORT_HTTP: |
1828 |
|
url = (struct URL_ctx_s*)get_http_file_dlg (dlg); |
1829 |
|
if (url && url->cancel == 0) { |
1830 |
|
km_http_import (dlg, url->url); |
1831 |
|
refresh_keylist (kmi); |
1832 |
|
} |
1833 |
|
free_if_alloc (url); |
1834 |
|
break; |
1835 |
|
|
1836 |
|
case ID_KEYMISC_EXPORT: |
1837 |
|
if (kmi->lv_idx == -1) { |
1838 |
|
msg_box (dlg, _("Please select a key."), |
1839 |
|
_("Key Manager"), MB_ERR); |
1840 |
|
return TRUE; |
1841 |
|
} |
1842 |
|
if (listview_count_items (kmi->lv, 1) > 1) |
1843 |
|
name = m_strdup ("Exported_GPG_Keys.asc"); |
1844 |
|
else { |
1845 |
|
key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL); |
1846 |
|
name = km_gen_export_filename (key->subkeys->keyid+8, 0); |
1847 |
|
} |
1848 |
|
t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name); |
1849 |
|
free_if_alloc (name); |
1850 |
|
if (t == NULL) |
1851 |
|
return TRUE; |
1852 |
|
km_file_export (dlg, kmi->lv, t); |
1853 |
|
return TRUE; |
1854 |
|
|
1855 |
|
case ID_KEYMISC_EXPORT_PRIVKEY: |
1856 |
|
if (kmi->lv_idx == -1) { |
1857 |
|
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
1858 |
|
return TRUE; |
1859 |
|
} |
1860 |
|
if( !km_check_for_seckey( kmi->lv, kmi->lv_idx, NULL ) ) { |
1861 |
|
msg_box (dlg, _("There is no corresponding secret key for this key."), |
1862 |
|
_("Key Manager"), MB_ERR); |
1863 |
|
return TRUE; |
1864 |
|
} |
1865 |
|
if (listview_count_items (kmi->lv, 1) > 1) { |
1866 |
|
msg_box (dlg, _("You can only export one secret key."), |
1867 |
|
_("Key Manager"), MB_ERR); |
1868 |
|
return TRUE; |
1869 |
|
} |
1870 |
|
i = msg_box (dlg, |
1871 |
|
_("This operation will export your *SECRET* key!\n\n" |
1872 |
|
"Never send this key to ANYONE, it should be available\n" |
1873 |
|
"ONLY on your machine and you may use this function\n" |
1874 |
|
"to copy the key to a safe place.\n\n" |
1875 |
|
"Do you really want to export the key?"), |
1876 |
|
_("WARNING"), MB_INFO|MB_YESNO); |
1877 |
|
if (i == IDYES) { |
1878 |
|
key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL); |
1879 |
|
name = km_gen_export_filename (key->subkeys->keyid+8, 1); |
1880 |
|
t = get_filesave_dlg (dlg, _("Choose Name for Key File"), NULL, name); |
1881 |
|
if (t != NULL) |
1882 |
|
km_privkey_export (dlg, kmi->lv, t); |
1883 |
|
} |
1884 |
|
return TRUE; |
1885 |
|
|
1886 |
|
case ID_KEYMISC_INFO: |
1887 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, dlg, |
1888 |
|
about_winpt_dlg_proc, 0, _("About WinPT"), |
1889 |
|
IDS_WINPT_ABOUT); |
1890 |
|
break; |
1891 |
|
|
1892 |
|
case ID_KEYMISC_WEBSITE: |
1893 |
|
ShellExecute (dlg, "open", "http://www.winpt.org", |
1894 |
|
NULL, NULL, SW_SHOW); |
1895 |
|
break; |
1896 |
|
|
1897 |
|
case ID_KEYMISC_HELP: |
1898 |
|
start_help (dlg, 0); |
1899 |
|
break; |
1900 |
|
|
1901 |
|
case ID_KEYMISC_OT: |
1902 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_OWNERTRUST, |
1903 |
|
dlg, ownertrust_dlg_proc, 0, |
1904 |
|
_("Ownertrust"), IDS_WINPT_OWNERTRUST); |
1905 |
|
break; |
1906 |
|
|
1907 |
|
case ID_KEYMISC_EDITKEY: |
1908 |
|
if (km_get_key (kmi->lv, kmi->lv_idx, &k)) |
1909 |
|
break; |
1910 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT, dlg, |
1911 |
|
keyedit_main_dlg_proc, (LPARAM)&k, |
1912 |
|
_("Key Edit"), IDS_KEYCTX_EDIT); |
1913 |
|
if (k.update) |
1914 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1); |
1915 |
|
break; |
1916 |
|
|
1917 |
|
case ID_KEYMISC_COPY: |
1918 |
|
km_clip_export (dlg, kmi->lv); |
1919 |
|
break; |
1920 |
|
|
1921 |
|
case ID_KEYMISC_SELALL: |
1922 |
|
listview_select_all (kmi->lv); |
1923 |
|
break; |
1924 |
|
|
1925 |
|
case ID_KEYMISC_PASTE: |
1926 |
|
km_gui_import (kmi, LOWORD (wparam), NULL); |
1927 |
|
break; |
1928 |
|
|
1929 |
|
case ID_KEYCTX_SETPREFKS: |
1930 |
|
if (km_get_key (kmi->lv, kmi->lv_idx, &k)) |
1931 |
|
break; |
1932 |
|
keyedit_set_pref_keyserver (&k, dlg); |
1933 |
|
break; |
1934 |
|
|
1935 |
|
case ID_KEYMISC_REFRESH_KEYS: |
1936 |
|
if (listview_count_items (kmi->lv, 1) == 0) { |
1937 |
|
msg_box (dlg, _("No key was selected, select all by default."), |
1938 |
|
_("Key Manager"), MB_INFO); |
1939 |
|
listview_select_all (kmi->lv); |
1940 |
|
} |
1941 |
|
km_refresh_from_keyserver (kmi->lv, dlg); |
1942 |
|
msg_box (dlg, _("Keyserver refresh finished."), |
1943 |
|
_("Key Manager"), MB_OK); |
1944 |
|
break; |
1945 |
|
|
1946 |
|
/** Context menu **/ |
1947 |
|
case ID_KEYCTX_EDIT: |
1948 |
|
send_cmd_id( dlg, ID_KEYMISC_EDITKEY ); |
1949 |
|
break; |
1950 |
|
|
1951 |
|
case ID_KEYCTX_PROPS: |
1952 |
|
send_cmd_id( dlg, ID_KEYMISC_PROPS ); |
1953 |
|
break; |
1954 |
|
|
1955 |
|
case ID_KEYCTX_UIDS: |
1956 |
|
send_cmd_id( dlg, ID_KEYMISC_UID ); |
1957 |
|
break; |
1958 |
|
|
1959 |
|
case ID_KEYCTX_SIGN: |
1960 |
|
send_cmd_id( dlg, ID_KEYMISC_SIGN ); |
1961 |
|
break; |
1962 |
|
|
1963 |
|
case ID_KEYCTX_DEL: |
1964 |
|
send_cmd_id (dlg, ID_KEYMISC_DELETE); |
1965 |
|
break; |
1966 |
|
|
1967 |
|
case ID_KEYCTX_REV: |
1968 |
|
send_cmd_id( dlg, ID_KEYMISC_REVCERT ); |
1969 |
|
break; |
1970 |
|
|
1971 |
|
case ID_KEYCTX_SENDMAIL: |
1972 |
|
km_send_to_mail_recipient (kmi->lv, dlg); |
1973 |
|
break; |
1974 |
|
|
1975 |
|
case ID_KEYCTX_KS_DEFAULT: |
1976 |
|
host = kserver_get_hostname (0, -1, &port); |
1977 |
|
km_send_to_keyserver (kmi->lv, dlg, host, port); |
1978 |
|
break; |
1979 |
|
|
1980 |
|
case ID_KEYCTX_ADDKEY: |
1981 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
1982 |
|
keyedit_add_subkey (&k, dlg, NULL); |
1983 |
|
if (k.update) |
1984 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1); |
1985 |
|
break; |
1986 |
|
|
1987 |
|
case ID_KEYCTX_ADDUID: |
1988 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
1989 |
|
keyedit_add_userid (&k, dlg, NULL); |
1990 |
|
if (k.update) |
1991 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1); |
1992 |
|
break; |
1993 |
|
|
1994 |
|
case ID_KEYCTX_ADDREV: |
1995 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
1996 |
|
keyedit_add_revoker (&k, dlg); |
1997 |
|
if (k.update) |
1998 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1); |
1999 |
|
break; |
2000 |
|
|
2001 |
|
case ID_KEYCTX_ADDPHOTO: |
2002 |
|
km_get_key (kmi->lv, kmi->lv_idx, &k); |
2003 |
|
keyedit_add_photo (&k, dlg); |
2004 |
|
if (k.update) |
2005 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 1); |
2006 |
|
break; |
2007 |
|
|
2008 |
|
case ID_KEYCTX_RECVFROM: |
2009 |
|
km_refresh_from_keyserver (kmi->lv, dlg); |
2010 |
|
if (updated_keys_avail ()) |
2011 |
|
refresh_keylist (kmi); |
2012 |
|
break; |
2013 |
|
|
2014 |
|
case ID_KEYCTX_UID_COPY: |
2015 |
|
case ID_KEYCTX_KEYID_COPY: |
2016 |
|
case ID_KEYCTX_FPR_COPY: |
2017 |
|
case ID_KEYCTX_KINFO_COPY: |
2018 |
|
copy_key_info (LOWORD (wparam), kmi); |
2019 |
|
break; |
2020 |
|
|
2021 |
|
case ID_KEYCTX_COPY: |
2022 |
|
send_cmd_id (dlg, ID_KEYMISC_COPY); |
2023 |
|
break; |
2024 |
|
|
2025 |
|
case ID_KEYCTX_PASTE: |
2026 |
|
send_cmd_id (dlg, ID_KEYMISC_PASTE); |
2027 |
|
break; |
2028 |
|
|
2029 |
|
case ID_KEYCTX_DISABLE: |
2030 |
|
case ID_KEYCTX_ENABLE: |
2031 |
|
i = LOWORD (wparam) == ID_KEYCTX_ENABLE? 1 : 0; |
2032 |
|
if (km_get_key (kmi->lv, kmi->lv_idx, &k)) |
2033 |
|
break; |
2034 |
|
rc = km_enable_disable_key (kmi->lv, dlg, kmi->lv_idx, i); |
2035 |
|
if (!rc) |
2036 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0); |
2037 |
|
break; |
2038 |
|
|
2039 |
|
case ID_KEYCTX_LISTSIGS: |
2040 |
|
send_cmd_id (dlg, ID_KEYMISC_CHECKSIGS); |
2041 |
|
break; |
2042 |
|
|
2043 |
|
case ID_KEYCTX_MAXTRUST: |
2044 |
|
if (km_get_key (kmi->lv, kmi->lv_idx, &k)) |
2045 |
|
break; |
2046 |
|
rc = km_set_implicit_trust (dlg, kmi->lv, kmi->lv_idx); |
2047 |
|
if (!rc) |
2048 |
|
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, 0); |
2049 |
|
break; |
2050 |
|
|
2051 |
|
case ID_KEYCTX_SETDEFKEY: |
2052 |
|
if (!km_check_key_status (kmi->lv, kmi->lv_idx)) { |
2053 |
|
key = km_get_key_ptr (kmi->lv, kmi->lv_idx, NULL); |
2054 |
|
rc = set_gnupg_default_key (key->subkeys->keyid+8); |
2055 |
|
if (rc) |
2056 |
|
msg_box (dlg, winpt_strerror (rc), _("Key Manager"), MB_ERR); |
2057 |
|
update_default_key_str (kmi->statbar); |
2058 |
|
} |
2059 |
|
break; |
2060 |
|
|
2061 |
|
case ID_KEYMISC_VIEWKEYID: |
2062 |
|
case ID_KEYMISC_VIEWCIPHER: |
2063 |
|
case ID_KEYMISC_VIEWTYPE: |
2064 |
|
case ID_KEYMISC_VIEWCREAT: |
2065 |
|
case ID_KEYMISC_VIEWDESC: |
2066 |
|
hm = GetMenu (dlg); |
2067 |
|
i = get_menu_state (hm, LOWORD (wparam)); |
2068 |
|
set_menu_state (hm, LOWORD (wparam), |
2069 |
|
i & MFS_CHECKED? MFS_UNCHECKED : MFS_CHECKED); |
2070 |
|
modify_listview_columns (kmi, LOWORD (wparam), !(i & MFS_CHECKED)); |
2071 |
|
break; |
2072 |
|
|
2073 |
|
case ID_GROUP_NEW: |
2074 |
|
case ID_GROUP_PASTE: |
2075 |
|
case ID_GROUP_DELETE: |
2076 |
|
case ID_GROUP_SHOW: |
2077 |
|
/* XXX: Implement group manager. */ |
2078 |
|
return TRUE; |
2079 |
|
|
2080 |
|
/* |
2081 |
|
case IDCANCEL: |
2082 |
|
EndDialog (dlg, TRUE); |
2083 |
|
return TRUE; |
2084 |
|
*/ |
2085 |
|
} |
2086 |
|
|
2087 |
|
break; |
2088 |
|
} |
2089 |
|
|
2090 |
|
return FALSE; |
2091 |
|
} |