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

Annotation of /trunk/Src/wptSigTreeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (hide annotations)
Mon Mar 27 10:05:14 2006 UTC (18 years, 11 months ago) by twoaday
File size: 5267 byte(s)
2006-03-26  Timo Schulz  <ts@g10code.de>
 
        * wptSigTreeDlg.cpp (sigtree_load): Always use UTF8.
        * wptMainProc.cpp (winpt_main_proc): Reload key cache
        when the GPG settings were changed.
        * wptKeygenDlg.cpp (keygen_wizard_dlg_proc,
        keygen_dlg_proc): Improved check for the email address.
        * wptKeyEditDlgs.cpp (keyedit_adduid_dlg_proc): Likewise.
        * wptKeyserverDlg.cpp (keyserver_dlg_proc): Modified design.
         


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26