1 |
/* wptSigTreeDlg.cpp - List signatures in a tree view |
2 |
* 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 |
|
21 |
#include <windows.h> |
22 |
#include <commctrl.h> |
23 |
|
24 |
#include "resource.h" |
25 |
#include "wptGPG.h" |
26 |
#include "wptNLS.h" |
27 |
#include "wptVersion.h" |
28 |
#include "wptTypes.h" |
29 |
#include "wptCommonCtl.h" |
30 |
#include "wptContext.h" |
31 |
#include "wptUTF8.h" |
32 |
|
33 |
|
34 |
/* ID to display signature properties. */ |
35 |
#define _ID_SIGCTX_PROPS 65000 |
36 |
|
37 |
|
38 |
BOOL CALLBACK sigprops_dlg_proc (HWND dlg, UINT msg, |
39 |
WPARAM wparam, LPARAM lparam); |
40 |
BOOL CALLBACK keysig_dlg_proc (HWND dlg, UINT msg, |
41 |
WPARAM wparam, LPARAM lparam); |
42 |
|
43 |
/* Initialize the signature tree based on the given key @key. */ |
44 |
static void |
45 |
sigtree_load (HWND dlg, gpgme_key_t key) |
46 |
{ |
47 |
TVITEM tvi; |
48 |
TVINSERTSTRUCT ctx; |
49 |
HTREEITEM uid; |
50 |
gpgme_user_id_t u; |
51 |
gpgme_key_sig_t s; |
52 |
gpgme_key_t signer; |
53 |
char *p; |
54 |
|
55 |
memset (&tvi, 0, sizeof (tvi)); |
56 |
memset (&ctx, 0, sizeof (ctx)); |
57 |
for (u=key->uids; u; u = u->next) { |
58 |
if (u->revoked) |
59 |
continue; |
60 |
p = utf8_to_native (u->uid); |
61 |
tvi.pszText = p; |
62 |
tvi.state = TVIS_BOLD; |
63 |
tvi.mask = TVIF_TEXT; |
64 |
tvi.iImage = 0; |
65 |
tvi.iSelectedImage = 0; |
66 |
ctx.hParent = TVI_ROOT; |
67 |
ctx.item = tvi; |
68 |
uid = TreeView_InsertItem (dlg, &ctx); |
69 |
safe_free (p); |
70 |
for (s = u->signatures; s; s=s->next) { |
71 |
if (get_pubkey (s->keyid+8, &signer)) |
72 |
continue; |
73 |
p = utf8_to_native (signer->uids->uid); |
74 |
tvi.pszText = p; |
75 |
tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; |
76 |
tvi.iImage = 1; |
77 |
tvi.iSelectedImage = 1; |
78 |
tvi.lParam = (LPARAM)s; |
79 |
ctx.hParent = uid; |
80 |
ctx.item = tvi; |
81 |
TreeView_InsertItem (dlg, &ctx); |
82 |
safe_free (p); |
83 |
} |
84 |
} |
85 |
} |
86 |
|
87 |
|
88 |
/* Associate a signature list based on the icons @ico with |
89 |
the treeview control @tree. */ |
90 |
HIMAGELIST |
91 |
treeview_set_image_list (HWND tree, HICON *ico, DWORD nicons) |
92 |
{ |
93 |
HIMAGELIST hil; |
94 |
DWORD i; |
95 |
|
96 |
hil = ImageList_Create (16, 16, ILC_COLOR8|ILC_MASK, nicons, 1); |
97 |
ImageList_SetBkColor (hil, CLR_NONE); |
98 |
for (i=0; i < nicons; i++) |
99 |
ImageList_AddIcon (hil, ico[i]); |
100 |
TreeView_SetImageList (tree, hil, TVSIL_NORMAL); |
101 |
return hil; |
102 |
} |
103 |
|
104 |
|
105 |
static void |
106 |
create_popup (HWND dlg) |
107 |
{ |
108 |
HMENU hm; |
109 |
MENUITEMINFO mi; |
110 |
POINT p; |
111 |
char *s; |
112 |
|
113 |
hm = CreatePopupMenu (); |
114 |
if (!hm) |
115 |
BUG( NULL ); |
116 |
memset (&mi, 0, sizeof mi); |
117 |
mi.cbSize = sizeof mi; |
118 |
s = (char *)_("Signature &Properties"); |
119 |
mi.fType = MF_STRING; |
120 |
mi.dwTypeData = s; |
121 |
mi.cch = strlen (s); |
122 |
mi.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE; |
123 |
mi.wID = _ID_SIGCTX_PROPS; |
124 |
InsertMenuItem (hm, 0, FALSE, &mi); |
125 |
GetCursorPos (&p); |
126 |
TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL); |
127 |
DestroyMenu (hm); |
128 |
} |
129 |
|
130 |
|
131 |
static void |
132 |
show_sigprops (HWND dlg) |
133 |
{ |
134 |
HWND tree; |
135 |
HTREEITEM hti; |
136 |
TVITEM tvi; |
137 |
|
138 |
memset (&tvi, 0, sizeof (tvi)); |
139 |
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
140 |
hti = TreeView_GetSelection (tree); |
141 |
tvi.mask = TVIF_PARAM; |
142 |
tvi.hItem = hti; |
143 |
TreeView_GetItem (tree, &tvi); |
144 |
if (tvi.lParam != 0) |
145 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
146 |
sigprops_dlg_proc, tvi.lParam); |
147 |
} |
148 |
|
149 |
|
150 |
/* Dialog box procedure for the tree based signature listing. */ |
151 |
BOOL CALLBACK |
152 |
sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
153 |
{ |
154 |
static winpt_key_t key; |
155 |
static HWND tree; |
156 |
static HIMAGELIST hil; |
157 |
HICON ico[2]; |
158 |
NMHDR *nft; |
159 |
char inf[256], *p; |
160 |
|
161 |
switch (msg) { |
162 |
case WM_INITDIALOG: |
163 |
key = (winpt_key_t)lparam; |
164 |
if (!key) |
165 |
BUG (0); |
166 |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID); |
167 |
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG); |
168 |
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
169 |
hil = treeview_set_image_list (tree, ico, 2); |
170 |
sigtree_load (tree, key->ctx); |
171 |
p = utf8_to_native (key->ctx->uids->uid); |
172 |
_snprintf (inf, sizeof (inf)-1, _("Signature Tree for \"%s\""), p); |
173 |
safe_free (p); |
174 |
SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit...")); |
175 |
SetWindowText (dlg, inf); |
176 |
SetForegroundWindow (dlg); |
177 |
break; |
178 |
|
179 |
case WM_DESTROY: |
180 |
ImageList_Destroy (hil); |
181 |
break; |
182 |
|
183 |
case WM_NOTIFY: |
184 |
nft = (NMHDR*)lparam; |
185 |
if (nft->code == NM_DBLCLK) |
186 |
show_sigprops (dlg); |
187 |
else if (nft->code == NM_RCLICK) |
188 |
create_popup (dlg); |
189 |
break; |
190 |
|
191 |
case WM_COMMAND: |
192 |
switch (LOWORD (wparam)) { |
193 |
case _ID_SIGCTX_PROPS: |
194 |
show_sigprops (dlg); |
195 |
break; |
196 |
|
197 |
case IDOK: |
198 |
EndDialog (dlg, 1); |
199 |
break; |
200 |
|
201 |
case IDCANCEL: |
202 |
EndDialog (dlg, 0); |
203 |
break; |
204 |
|
205 |
case IDC_VKEYSIG_EDIT: |
206 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG, dlg, |
207 |
keysig_dlg_proc, (LPARAM)key); |
208 |
} |
209 |
break; |
210 |
} |
211 |
|
212 |
return FALSE; |
213 |
} |