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 |
|
|
sigtree_load (HWND dlg, gpgme_key_t key) |
47 |
|
|
{ |
48 |
|
|
TVITEM tvi; |
49 |
|
|
TVINSERTSTRUCT ctx; |
50 |
|
|
HTREEITEM uid; |
51 |
|
|
gpgme_user_id_t u; |
52 |
|
|
gpgme_key_sig_t s; |
53 |
|
|
gpgme_key_t signer; |
54 |
twoaday |
188 |
char *p; |
55 |
twoaday |
175 |
|
56 |
|
|
memset (&tvi, 0, sizeof (tvi)); |
57 |
|
|
memset (&ctx, 0, sizeof (ctx)); |
58 |
|
|
for (u=key->uids; u; u = u->next) { |
59 |
twoaday |
176 |
if (u->revoked) |
60 |
|
|
continue; |
61 |
twoaday |
190 |
p = utf8_to_native (u->uid); |
62 |
|
|
tvi.pszText = p; |
63 |
twoaday |
175 |
tvi.state = TVIS_BOLD; |
64 |
twoaday |
176 |
tvi.mask = TVIF_TEXT; |
65 |
|
|
tvi.iImage = 0; |
66 |
|
|
tvi.iSelectedImage = 0; |
67 |
twoaday |
175 |
ctx.hParent = TVI_ROOT; |
68 |
|
|
ctx.item = tvi; |
69 |
|
|
uid = TreeView_InsertItem (dlg, &ctx); |
70 |
twoaday |
190 |
safe_free (p); |
71 |
twoaday |
175 |
for (s = u->signatures; s; s=s->next) { |
72 |
|
|
if (get_pubkey (s->keyid+8, &signer)) |
73 |
|
|
continue; |
74 |
twoaday |
188 |
p = utf8_to_native (signer->uids->uid); |
75 |
|
|
tvi.pszText = p; |
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 |
|
|
TreeView_InsertItem (dlg, &ctx); |
83 |
twoaday |
188 |
safe_free (p); |
84 |
twoaday |
175 |
} |
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 |
|
|
create_popup (HWND dlg) |
108 |
|
|
{ |
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 |
|
|
static void |
123 |
|
|
show_sigprops (HWND dlg) |
124 |
|
|
{ |
125 |
|
|
HWND tree; |
126 |
|
|
HTREEITEM hti; |
127 |
|
|
TVITEM tvi; |
128 |
|
|
|
129 |
|
|
memset (&tvi, 0, sizeof (tvi)); |
130 |
|
|
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
131 |
|
|
hti = TreeView_GetSelection (tree); |
132 |
|
|
tvi.mask = TVIF_PARAM; |
133 |
|
|
tvi.hItem = hti; |
134 |
|
|
TreeView_GetItem (tree, &tvi); |
135 |
|
|
if (tvi.lParam != 0) |
136 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
137 |
|
|
sigprops_dlg_proc, tvi.lParam); |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
|
141 |
twoaday |
175 |
/* Dialog box procedure for the tree based signature listing. */ |
142 |
|
|
BOOL CALLBACK |
143 |
|
|
sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
144 |
|
|
{ |
145 |
twoaday |
176 |
static winpt_key_t key; |
146 |
twoaday |
175 |
static HWND tree; |
147 |
twoaday |
176 |
static HIMAGELIST hil; |
148 |
|
|
HICON ico[2]; |
149 |
|
|
NMHDR *nft; |
150 |
twoaday |
204 |
char inf[300]; |
151 |
twoaday |
175 |
|
152 |
|
|
switch (msg) { |
153 |
|
|
case WM_INITDIALOG: |
154 |
twoaday |
176 |
key = (winpt_key_t)lparam; |
155 |
twoaday |
175 |
if (!key) |
156 |
twoaday |
176 |
BUG (0); |
157 |
|
|
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID); |
158 |
|
|
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG); |
159 |
twoaday |
175 |
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
160 |
twoaday |
176 |
hil = treeview_set_image_list (tree, ico, 2); |
161 |
|
|
sigtree_load (tree, key->ctx); |
162 |
twoaday |
193 |
_snprintf (inf, sizeof (inf)-1, |
163 |
|
|
_("Signature Tree for \"%s\" (0x%s)"), |
164 |
twoaday |
204 |
key->ctx->uids->uid/*p*/, key->ctx->subkeys->keyid+8); |
165 |
twoaday |
179 |
SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit...")); |
166 |
twoaday |
204 |
SetWindowText_utf8 (dlg, inf); |
167 |
twoaday |
175 |
SetForegroundWindow (dlg); |
168 |
|
|
break; |
169 |
|
|
|
170 |
twoaday |
176 |
case WM_DESTROY: |
171 |
|
|
ImageList_Destroy (hil); |
172 |
|
|
break; |
173 |
|
|
|
174 |
|
|
case WM_NOTIFY: |
175 |
|
|
nft = (NMHDR*)lparam; |
176 |
twoaday |
180 |
if (nft->code == NM_DBLCLK) |
177 |
|
|
show_sigprops (dlg); |
178 |
|
|
else if (nft->code == NM_RCLICK) |
179 |
|
|
create_popup (dlg); |
180 |
twoaday |
176 |
break; |
181 |
|
|
|
182 |
twoaday |
175 |
case WM_COMMAND: |
183 |
|
|
switch (LOWORD (wparam)) { |
184 |
twoaday |
180 |
case _ID_SIGCTX_PROPS: |
185 |
|
|
show_sigprops (dlg); |
186 |
|
|
break; |
187 |
|
|
|
188 |
twoaday |
175 |
case IDOK: |
189 |
|
|
EndDialog (dlg, 1); |
190 |
|
|
break; |
191 |
|
|
|
192 |
|
|
case IDCANCEL: |
193 |
|
|
EndDialog (dlg, 0); |
194 |
|
|
break; |
195 |
twoaday |
176 |
|
196 |
|
|
case IDC_VKEYSIG_EDIT: |
197 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG, dlg, |
198 |
|
|
keysig_dlg_proc, (LPARAM)key); |
199 |
twoaday |
175 |
} |
200 |
|
|
break; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
return FALSE; |
204 |
|
|
} |