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 |
|
32 |
BOOL CALLBACK sigprops_dlg_proc (HWND dlg, UINT msg, |
33 |
WPARAM wparam, LPARAM lparam); |
34 |
BOOL CALLBACK |
35 |
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam); |
36 |
|
37 |
/* Initialize the signature tree based on the given key @key. */ |
38 |
static void |
39 |
sigtree_load (HWND dlg, gpgme_key_t key) |
40 |
{ |
41 |
TVITEM tvi; |
42 |
TVINSERTSTRUCT ctx; |
43 |
HTREEITEM uid; |
44 |
gpgme_user_id_t u; |
45 |
gpgme_key_sig_t s; |
46 |
gpgme_key_t signer; |
47 |
|
48 |
memset (&tvi, 0, sizeof (tvi)); |
49 |
memset (&ctx, 0, sizeof (ctx)); |
50 |
for (u=key->uids; u; u = u->next) { |
51 |
if (u->revoked) |
52 |
continue; |
53 |
tvi.pszText = u->uid; |
54 |
tvi.state = TVIS_BOLD; |
55 |
tvi.mask = TVIF_TEXT; |
56 |
tvi.iImage = 0; |
57 |
tvi.iSelectedImage = 0; |
58 |
ctx.hParent = TVI_ROOT; |
59 |
ctx.item = tvi; |
60 |
uid = TreeView_InsertItem (dlg, &ctx); |
61 |
for (s = u->signatures; s; s=s->next) { |
62 |
if (get_pubkey (s->keyid+8, &signer)) |
63 |
continue; |
64 |
tvi.pszText = signer->uids->uid; |
65 |
tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; |
66 |
tvi.iImage = 1; |
67 |
tvi.iSelectedImage = 1; |
68 |
tvi.lParam = (LPARAM)s; |
69 |
ctx.hParent = uid; |
70 |
ctx.item = tvi; |
71 |
TreeView_InsertItem (dlg, &ctx); |
72 |
} |
73 |
} |
74 |
} |
75 |
|
76 |
|
77 |
/* Associate a signature list based on the icons @ico with |
78 |
the treeview control @tree. */ |
79 |
HIMAGELIST |
80 |
treeview_set_image_list (HWND tree, HICON *ico, DWORD nicons) |
81 |
{ |
82 |
HIMAGELIST hil; |
83 |
DWORD i; |
84 |
|
85 |
hil = ImageList_Create (16, 16, ILC_COLOR8|ILC_MASK, nicons, 1); |
86 |
ImageList_SetBkColor (hil, CLR_NONE); |
87 |
for (i=0; i < nicons; i++) |
88 |
ImageList_AddIcon (hil, ico[i]); |
89 |
TreeView_SetImageList (tree, hil, TVSIL_NORMAL); |
90 |
return hil; |
91 |
} |
92 |
|
93 |
|
94 |
/* Dialog box procedure for the tree based signature listing. */ |
95 |
BOOL CALLBACK |
96 |
sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
97 |
{ |
98 |
static winpt_key_t key; |
99 |
static HWND tree; |
100 |
static HIMAGELIST hil; |
101 |
|
102 |
HICON ico[2]; |
103 |
NMHDR *nft; |
104 |
char inf[256]; |
105 |
|
106 |
switch (msg) { |
107 |
case WM_INITDIALOG: |
108 |
key = (winpt_key_t)lparam; |
109 |
if (!key) |
110 |
BUG (0); |
111 |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID); |
112 |
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG); |
113 |
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
114 |
hil = treeview_set_image_list (tree, ico, 2); |
115 |
sigtree_load (tree, key->ctx); |
116 |
_snprintf (inf, sizeof (inf)-1, _("Signature Tree for \"%s\""), |
117 |
key->ctx->uids->uid); |
118 |
SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit...")); |
119 |
SetWindowText (dlg, inf); |
120 |
SetForegroundWindow (dlg); |
121 |
break; |
122 |
|
123 |
case WM_DESTROY: |
124 |
ImageList_Destroy (hil); |
125 |
break; |
126 |
|
127 |
case WM_NOTIFY: |
128 |
nft = (NMHDR*)lparam; |
129 |
if (nft->code == NM_DBLCLK) { |
130 |
HTREEITEM hti; |
131 |
TVITEM tvi; |
132 |
|
133 |
memset (&tvi, 0, sizeof (tvi)); |
134 |
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
135 |
hti = TreeView_GetSelection (tree); |
136 |
tvi.mask = TVIF_PARAM; |
137 |
tvi.hItem = hti; |
138 |
TreeView_GetItem (tree, &tvi); |
139 |
if (tvi.lParam != 0) |
140 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
141 |
sigprops_dlg_proc, tvi.lParam); |
142 |
} |
143 |
break; |
144 |
|
145 |
case WM_COMMAND: |
146 |
switch (LOWORD (wparam)) { |
147 |
case IDOK: |
148 |
EndDialog (dlg, 1); |
149 |
break; |
150 |
|
151 |
case IDCANCEL: |
152 |
EndDialog (dlg, 0); |
153 |
break; |
154 |
|
155 |
case IDC_VKEYSIG_EDIT: |
156 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG, dlg, |
157 |
keysig_dlg_proc, (LPARAM)key); |
158 |
} |
159 |
break; |
160 |
} |
161 |
|
162 |
return FALSE; |
163 |
} |