1 |
twoaday |
176 |
/* wptSigTreeDlg.cpp - List signatures in a tree view |
2 |
twoaday |
175 |
* Copyright (C) 2006 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
|
|
*/ |
20 |
twoaday |
225 |
#ifdef HAVE_CONFIG_H |
21 |
|
|
#include <config.h> |
22 |
|
|
#endif |
23 |
twoaday |
175 |
|
24 |
|
|
#include <windows.h> |
25 |
|
|
#include <commctrl.h> |
26 |
|
|
|
27 |
|
|
#include "resource.h" |
28 |
|
|
#include "wptGPG.h" |
29 |
|
|
#include "wptNLS.h" |
30 |
twoaday |
176 |
#include "wptVersion.h" |
31 |
|
|
#include "wptTypes.h" |
32 |
|
|
#include "wptCommonCtl.h" |
33 |
|
|
#include "wptContext.h" |
34 |
twoaday |
188 |
#include "wptUTF8.h" |
35 |
twoaday |
193 |
#include "wptW32API.h" |
36 |
twoaday |
175 |
|
37 |
twoaday |
180 |
|
38 |
|
|
/* ID to display signature properties. */ |
39 |
|
|
#define _ID_SIGCTX_PROPS 65000 |
40 |
|
|
|
41 |
|
|
|
42 |
twoaday |
176 |
BOOL CALLBACK sigprops_dlg_proc (HWND dlg, UINT msg, |
43 |
|
|
WPARAM wparam, LPARAM lparam); |
44 |
twoaday |
188 |
BOOL CALLBACK keysig_dlg_proc (HWND dlg, UINT msg, |
45 |
|
|
WPARAM wparam, LPARAM lparam); |
46 |
twoaday |
176 |
|
47 |
twoaday |
175 |
/* Initialize the signature tree based on the given key @key. */ |
48 |
|
|
static void |
49 |
twoaday |
208 |
sigtree_load (HWND dlg, winpt_key_t key) |
50 |
twoaday |
175 |
{ |
51 |
|
|
TVITEM tvi; |
52 |
|
|
TVINSERTSTRUCT ctx; |
53 |
twoaday |
208 |
HTREEITEM uid; |
54 |
twoaday |
175 |
gpgme_key_sig_t s; |
55 |
twoaday |
208 |
winpt_key_s signer; |
56 |
|
|
struct native_uid_s *u; |
57 |
twoaday |
175 |
|
58 |
|
|
memset (&tvi, 0, sizeof (tvi)); |
59 |
|
|
memset (&ctx, 0, sizeof (ctx)); |
60 |
twoaday |
208 |
for (u=key->ext->uids; u; u = u->next) { |
61 |
twoaday |
176 |
if (u->revoked) |
62 |
|
|
continue; |
63 |
twoaday |
208 |
tvi.pszText = u->uid; |
64 |
twoaday |
175 |
tvi.state = TVIS_BOLD; |
65 |
twoaday |
176 |
tvi.mask = TVIF_TEXT; |
66 |
|
|
tvi.iImage = 0; |
67 |
|
|
tvi.iSelectedImage = 0; |
68 |
twoaday |
175 |
ctx.hParent = TVI_ROOT; |
69 |
|
|
ctx.item = tvi; |
70 |
|
|
uid = TreeView_InsertItem (dlg, &ctx); |
71 |
|
|
for (s = u->signatures; s; s=s->next) { |
72 |
twoaday |
208 |
memset (&signer, 0, sizeof (signer)); |
73 |
|
|
if (winpt_get_pubkey (s->keyid+8, &signer)) |
74 |
twoaday |
175 |
continue; |
75 |
twoaday |
208 |
tvi.pszText = signer.ext->uids->uid; |
76 |
twoaday |
176 |
tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; |
77 |
|
|
tvi.iImage = 1; |
78 |
|
|
tvi.iSelectedImage = 1; |
79 |
|
|
tvi.lParam = (LPARAM)s; |
80 |
twoaday |
175 |
ctx.hParent = uid; |
81 |
|
|
ctx.item = tvi; |
82 |
twoaday |
222 |
/* XXX: mark non exportable sigs */ |
83 |
twoaday |
175 |
TreeView_InsertItem (dlg, &ctx); |
84 |
|
|
} |
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
|
89 |
twoaday |
176 |
/* Associate a signature list based on the icons @ico with |
90 |
|
|
the treeview control @tree. */ |
91 |
|
|
HIMAGELIST |
92 |
|
|
treeview_set_image_list (HWND tree, HICON *ico, DWORD nicons) |
93 |
|
|
{ |
94 |
|
|
HIMAGELIST hil; |
95 |
|
|
DWORD i; |
96 |
|
|
|
97 |
|
|
hil = ImageList_Create (16, 16, ILC_COLOR8|ILC_MASK, nicons, 1); |
98 |
|
|
ImageList_SetBkColor (hil, CLR_NONE); |
99 |
|
|
for (i=0; i < nicons; i++) |
100 |
|
|
ImageList_AddIcon (hil, ico[i]); |
101 |
|
|
TreeView_SetImageList (tree, hil, TVSIL_NORMAL); |
102 |
|
|
return hil; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
|
106 |
twoaday |
180 |
static void |
107 |
twoaday |
225 |
show_popup (HWND dlg) |
108 |
twoaday |
180 |
{ |
109 |
|
|
HMENU hm; |
110 |
|
|
POINT p; |
111 |
|
|
|
112 |
|
|
hm = CreatePopupMenu (); |
113 |
|
|
if (!hm) |
114 |
twoaday |
193 |
BUG (0); |
115 |
|
|
insert_menu_item (hm, 0, _ID_SIGCTX_PROPS, _("Signature &Properties")); |
116 |
twoaday |
180 |
GetCursorPos (&p); |
117 |
|
|
TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL); |
118 |
|
|
DestroyMenu (hm); |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
|
122 |
twoaday |
225 |
/* Get the signature properties for the selected item. */ |
123 |
twoaday |
180 |
static void |
124 |
|
|
show_sigprops (HWND dlg) |
125 |
|
|
{ |
126 |
|
|
HWND tree; |
127 |
|
|
HTREEITEM hti; |
128 |
|
|
TVITEM tvi; |
129 |
|
|
|
130 |
|
|
memset (&tvi, 0, sizeof (tvi)); |
131 |
|
|
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
132 |
|
|
hti = TreeView_GetSelection (tree); |
133 |
|
|
tvi.mask = TVIF_PARAM; |
134 |
|
|
tvi.hItem = hti; |
135 |
|
|
TreeView_GetItem (tree, &tvi); |
136 |
|
|
if (tvi.lParam != 0) |
137 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
138 |
|
|
sigprops_dlg_proc, tvi.lParam); |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
|
142 |
twoaday |
175 |
/* Dialog box procedure for the tree based signature listing. */ |
143 |
|
|
BOOL CALLBACK |
144 |
|
|
sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
145 |
|
|
{ |
146 |
twoaday |
208 |
static winpt_key_t key; |
147 |
twoaday |
176 |
static HIMAGELIST hil; |
148 |
twoaday |
208 |
HWND tree; |
149 |
twoaday |
176 |
HICON ico[2]; |
150 |
|
|
NMHDR *nft; |
151 |
twoaday |
208 |
char inf[300]; |
152 |
twoaday |
175 |
|
153 |
|
|
switch (msg) { |
154 |
|
|
case WM_INITDIALOG: |
155 |
twoaday |
176 |
key = (winpt_key_t)lparam; |
156 |
twoaday |
175 |
if (!key) |
157 |
twoaday |
176 |
BUG (0); |
158 |
|
|
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID); |
159 |
|
|
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG); |
160 |
twoaday |
175 |
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
161 |
twoaday |
176 |
hil = treeview_set_image_list (tree, ico, 2); |
162 |
twoaday |
208 |
sigtree_load (tree, key); |
163 |
twoaday |
193 |
_snprintf (inf, sizeof (inf)-1, |
164 |
|
|
_("Signature Tree for \"%s\" (0x%s)"), |
165 |
twoaday |
208 |
key->ext->uids->uid, key->ctx->subkeys->keyid+8); |
166 |
twoaday |
179 |
SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit...")); |
167 |
twoaday |
205 |
SetWindowText (dlg, inf); |
168 |
twoaday |
175 |
SetForegroundWindow (dlg); |
169 |
|
|
break; |
170 |
|
|
|
171 |
twoaday |
176 |
case WM_DESTROY: |
172 |
|
|
ImageList_Destroy (hil); |
173 |
|
|
break; |
174 |
|
|
|
175 |
|
|
case WM_NOTIFY: |
176 |
|
|
nft = (NMHDR*)lparam; |
177 |
twoaday |
180 |
if (nft->code == NM_DBLCLK) |
178 |
|
|
show_sigprops (dlg); |
179 |
|
|
else if (nft->code == NM_RCLICK) |
180 |
twoaday |
225 |
show_popup (dlg); |
181 |
twoaday |
176 |
break; |
182 |
|
|
|
183 |
twoaday |
175 |
case WM_COMMAND: |
184 |
|
|
switch (LOWORD (wparam)) { |
185 |
twoaday |
180 |
case _ID_SIGCTX_PROPS: |
186 |
|
|
show_sigprops (dlg); |
187 |
|
|
break; |
188 |
|
|
|
189 |
twoaday |
175 |
case IDOK: |
190 |
|
|
EndDialog (dlg, 1); |
191 |
|
|
break; |
192 |
|
|
|
193 |
|
|
case IDCANCEL: |
194 |
|
|
EndDialog (dlg, 0); |
195 |
|
|
break; |
196 |
twoaday |
176 |
|
197 |
|
|
case IDC_VKEYSIG_EDIT: |
198 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG, dlg, |
199 |
|
|
keysig_dlg_proc, (LPARAM)key); |
200 |
twoaday |
175 |
} |
201 |
|
|
break; |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
return FALSE; |
205 |
|
|
} |