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

Contents of /trunk/Src/wptSigTreeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 193 - (show annotations)
Sat Apr 1 12:36:35 2006 UTC (18 years, 11 months ago) by twoaday
File size: 5080 byte(s)
2006-03-31  Timo Schulz  <ts@g10code.de>
 
        * wptCommonDlg.cpp (nls_load_langlist): New.
        (nsl_set_language): New.
        (nls_dlg_proc): New.
        (select_language): New. Allow user to select the language.
        * wptNLS.c (get_gettext_langid): Updated available languages.
        * WinPT.cpp (WinMain): Allow to select the languag on first
        start in non-installer environments.
        * wptVerifyList.cpp (verlist_build): Simplified.
        (verlist_add_sig_log): Likewise.
        * wptListview.cpp (listview_set_column_width,
        listview_get_selected_item): New.
        * wptKeyManager.cpp (gpg_clip_export): Merged into..
        (km_clip_export): ..this function.


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, 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 char *p;
55
56 memset (&tvi, 0, sizeof (tvi));
57 memset (&ctx, 0, sizeof (ctx));
58 for (u=key->uids; u; u = u->next) {
59 if (u->revoked)
60 continue;
61 p = utf8_to_native (u->uid);
62 tvi.pszText = p;
63 tvi.state = TVIS_BOLD;
64 tvi.mask = TVIF_TEXT;
65 tvi.iImage = 0;
66 tvi.iSelectedImage = 0;
67 ctx.hParent = TVI_ROOT;
68 ctx.item = tvi;
69 uid = TreeView_InsertItem (dlg, &ctx);
70 safe_free (p);
71 for (s = u->signatures; s; s=s->next) {
72 if (get_pubkey (s->keyid+8, &signer))
73 continue;
74 p = utf8_to_native (signer->uids->uid);
75 tvi.pszText = p;
76 tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
77 tvi.iImage = 1;
78 tvi.iSelectedImage = 1;
79 tvi.lParam = (LPARAM)s;
80 ctx.hParent = uid;
81 ctx.item = tvi;
82 TreeView_InsertItem (dlg, &ctx);
83 safe_free (p);
84 }
85 }
86 }
87
88
89 /* 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 static void
107 create_popup (HWND dlg)
108 {
109 HMENU hm;
110 POINT p;
111
112 hm = CreatePopupMenu ();
113 if (!hm)
114 BUG (0);
115 insert_menu_item (hm, 0, _ID_SIGCTX_PROPS, _("Signature &Properties"));
116 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 /* 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 static winpt_key_t key;
146 static HWND tree;
147 static HIMAGELIST hil;
148 HICON ico[2];
149 NMHDR *nft;
150 char inf[300], *p;
151
152 switch (msg) {
153 case WM_INITDIALOG:
154 key = (winpt_key_t)lparam;
155 if (!key)
156 BUG (0);
157 ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID);
158 ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG);
159 tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
160 hil = treeview_set_image_list (tree, ico, 2);
161 sigtree_load (tree, key->ctx);
162 p = utf8_to_native (key->ctx->uids->name);
163 _snprintf (inf, sizeof (inf)-1,
164 _("Signature Tree for \"%s\" (0x%s)"),
165 p, key->ctx->subkeys->keyid+8);
166 safe_free (p);
167 SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit..."));
168 SetWindowText (dlg, inf);
169 SetForegroundWindow (dlg);
170 break;
171
172 case WM_DESTROY:
173 ImageList_Destroy (hil);
174 break;
175
176 case WM_NOTIFY:
177 nft = (NMHDR*)lparam;
178 if (nft->code == NM_DBLCLK)
179 show_sigprops (dlg);
180 else if (nft->code == NM_RCLICK)
181 create_popup (dlg);
182 break;
183
184 case WM_COMMAND:
185 switch (LOWORD (wparam)) {
186 case _ID_SIGCTX_PROPS:
187 show_sigprops (dlg);
188 break;
189
190 case IDOK:
191 EndDialog (dlg, 1);
192 break;
193
194 case IDCANCEL:
195 EndDialog (dlg, 0);
196 break;
197
198 case IDC_VKEYSIG_EDIT:
199 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG, dlg,
200 keysig_dlg_proc, (LPARAM)key);
201 }
202 break;
203 }
204
205 return FALSE;
206 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26