/[winpt]/trunk/Src/wptSigTreeDlg.cpp
ViewVC logotype

Contents of /trunk/Src/wptSigTreeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 222 - (show annotations)
Thu Jun 1 08:30:46 2006 UTC (18 years, 9 months ago) by twoaday
File size: 5031 byte(s)
Applied some more patches.


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26