1 |
/* wptSigTreeDlg.cpp - List signatures in a tree view |
/* wptSigTreeDlg.cpp - List signatures in a tree view |
2 |
* Copyright (C) 2006 Timo Schulz |
* Copyright (C) 2006, 2009 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
29 |
#include "wptContext.h" |
#include "wptContext.h" |
30 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
31 |
#include "wptW32API.h" |
#include "wptW32API.h" |
32 |
|
#include "StringBuffer.h" |
33 |
|
|
34 |
|
|
35 |
/* ID to display signature properties. */ |
/* ID to display signature properties. */ |
51 |
gpgme_key_sig_t s; |
gpgme_key_sig_t s; |
52 |
winpt_key_s signer; |
winpt_key_s signer; |
53 |
struct native_uid_s *u; |
struct native_uid_s *u; |
54 |
|
StringBuffer buf; |
55 |
|
|
56 |
memset (&tvi, 0, sizeof (tvi)); |
memset (&tvi, 0, sizeof (tvi)); |
57 |
memset (&ctx, 0, sizeof (ctx)); |
memset (&ctx, 0, sizeof (ctx)); |
60 |
continue; |
continue; |
61 |
tvi.pszText = u->uid; |
tvi.pszText = u->uid; |
62 |
tvi.state = TVIS_BOLD; |
tvi.state = TVIS_BOLD; |
63 |
tvi.mask = TVIF_TEXT; |
tvi.stateMask = TVIS_BOLD; |
64 |
|
tvi.mask = TVIF_TEXT|TVIF_STATE; |
65 |
tvi.iImage = 0; |
tvi.iImage = 0; |
66 |
tvi.iSelectedImage = 0; |
tvi.iSelectedImage = 0; |
67 |
ctx.hParent = TVI_ROOT; |
ctx.hParent = TVI_ROOT; |
68 |
ctx.item = tvi; |
ctx.item = tvi; |
69 |
uid = TreeView_InsertItem (dlg, &ctx); |
uid = TreeView_InsertItem (dlg, &ctx); |
70 |
for (s = u->signatures; s; s=s->next) { |
for (s = u->signatures; s; s=s->next) { |
71 |
|
buf.reset (); |
72 |
memset (&signer, 0, sizeof (signer)); |
memset (&signer, 0, sizeof (signer)); |
73 |
if (winpt_get_pubkey (s->keyid+8, &signer)) |
if (winpt_get_pubkey (s->keyid+8, &signer)) |
74 |
continue; |
continue; |
75 |
tvi.pszText = signer.ext->uids->uid; |
if (!s->exportable) { |
76 |
|
buf.add ("("); |
77 |
|
buf.add (_("non-exportable")); |
78 |
|
buf.add (") "); |
79 |
|
} |
80 |
|
buf.add (signer.ext->uids->uid); |
81 |
|
tvi.pszText = (char*)buf.getBuffer (); |
82 |
tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; |
tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; |
83 |
tvi.iImage = 1; |
tvi.iImage = 1; |
84 |
tvi.iSelectedImage = 1; |
tvi.iSelectedImage = 1; |
85 |
tvi.lParam = (LPARAM)s; |
tvi.lParam = (LPARAM)s; |
86 |
ctx.hParent = uid; |
ctx.hParent = uid; |
87 |
ctx.item = tvi; |
ctx.item = tvi; |
|
/* XXX: mark non exportable sigs */ |
|
88 |
TreeView_InsertItem (dlg, &ctx); |
TreeView_InsertItem (dlg, &ctx); |
89 |
} |
} |
90 |
} |
} |
93 |
|
|
94 |
/* Associate a signature list based on the icons @ico with |
/* Associate a signature list based on the icons @ico with |
95 |
the treeview control @tree. */ |
the treeview control @tree. */ |
96 |
HIMAGELIST |
static HIMAGELIST |
97 |
treeview_set_image_list (HWND tree, HICON *ico, DWORD nicons) |
treeview_set_image_list (HWND tree) |
98 |
{ |
{ |
99 |
|
HICON ico[2]; |
100 |
HIMAGELIST hil; |
HIMAGELIST hil; |
|
DWORD i; |
|
101 |
|
|
102 |
hil = ImageList_Create (16, 16, ILC_COLOR8|ILC_MASK, nicons, 1); |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID); |
103 |
|
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG); |
104 |
|
|
105 |
|
hil = ImageList_Create (16, 16, ILC_COLOR8|ILC_MASK, 2, 1); |
106 |
ImageList_SetBkColor (hil, CLR_NONE); |
ImageList_SetBkColor (hil, CLR_NONE); |
107 |
for (i=0; i < nicons; i++) |
ImageList_AddIcon (hil, ico[0]); |
108 |
ImageList_AddIcon (hil, ico[i]); |
ImageList_AddIcon (hil, ico[1]); |
109 |
TreeView_SetImageList (tree, hil, TVSIL_NORMAL); |
(void)TreeView_SetImageList (tree, hil, TVSIL_NORMAL); |
110 |
return hil; |
return hil; |
111 |
} |
} |
112 |
|
|
113 |
|
|
114 |
static void |
static void |
115 |
show_popup (HWND dlg) |
show_popup (HWND dlg) |
116 |
{ |
{ |
|
HMENU hm; |
|
117 |
POINT p; |
POINT p; |
118 |
|
|
119 |
hm = CreatePopupMenu (); |
HMENU hm = CreatePopupMenu (); |
120 |
if (!hm) |
if (!hm) |
121 |
BUG (0); |
BUG (0); |
122 |
insert_menu_item (hm, 0, _ID_SIGCTX_PROPS, _("Signature &Properties")); |
insert_menu_item (hm, 0, _ID_SIGCTX_PROPS, _("Signature &Properties")); |
142 |
TreeView_GetItem (tree, &tvi); |
TreeView_GetItem (tree, &tvi); |
143 |
if (tvi.lParam != 0) |
if (tvi.lParam != 0) |
144 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
145 |
sigprops_dlg_proc, tvi.lParam); |
sigprops_dlg_proc, tvi.lParam); |
146 |
} |
} |
147 |
|
|
148 |
|
|
151 |
sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
152 |
{ |
{ |
153 |
static winpt_key_t key; |
static winpt_key_t key; |
154 |
static HIMAGELIST hil; |
static HIMAGELIST hil; |
|
HWND tree; |
|
|
HICON ico[2]; |
|
155 |
NMHDR *nft; |
NMHDR *nft; |
156 |
char inf[300]; |
char inf[300]; |
157 |
|
|
158 |
switch (msg) { |
switch (msg) { |
159 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
160 |
|
HWND tree; |
161 |
key = (winpt_key_t)lparam; |
key = (winpt_key_t)lparam; |
162 |
if (!key) |
if (!key) |
163 |
BUG (0); |
BUG (0); |
|
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID); |
|
|
ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG); |
|
164 |
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE); |
165 |
hil = treeview_set_image_list (tree, ico, 2); |
hil = treeview_set_image_list (tree); |
166 |
sigtree_load (tree, key); |
sigtree_load (tree, key); |
167 |
_snprintf (inf, DIM (inf)-1, |
_snprintf (inf, DIM (inf)-1, |
168 |
_("Signature Tree for \"%s\" (0x%s)"), |
_("Signature Tree for Key 0x%s"), |
169 |
key->ext->uids->name, key->ctx->subkeys->keyid+8); |
key->ctx->subkeys->keyid+8); |
170 |
SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit...")); |
SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Check...")); |
171 |
SetWindowText (dlg, inf); |
SetWindowText (dlg, inf); |
172 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
173 |
break; |
break; |
178 |
|
|
179 |
case WM_NOTIFY: |
case WM_NOTIFY: |
180 |
nft = (NMHDR*)lparam; |
nft = (NMHDR*)lparam; |
181 |
if (nft->code == NM_DBLCLK) |
if (nft != NULL && nft->code == NM_DBLCLK) |
182 |
show_sigprops (dlg); |
show_sigprops (dlg); |
183 |
else if (nft->code == NM_RCLICK) |
else if (nft != NULL && nft->code == NM_RCLICK) |
184 |
show_popup (dlg); |
show_popup (dlg); |
185 |
break; |
break; |
186 |
|
|