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