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

Annotation of /trunk/Src/wptSigTreeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 188 - (hide annotations)
Wed Mar 22 12:39:02 2006 UTC (18 years, 11 months ago) by twoaday
File size: 5186 byte(s)
2006-03-22  Timo Schulz  <ts@g10code.de>
 
        * wptClipSignDlg.cpp (on_init_dialog): New.
        Check that there is at least one useable signing key.
        * wptSigTreeDlg.cpp (sigtree_load): Correct UTF8 handling.
        * wptKeyEditDlgs.cpp (keyedit_set_pref_keyserver): Show error
        if needed.


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 175 tvi.pszText = u->uid;
61     tvi.state = TVIS_BOLD;
62 twoaday 176 tvi.mask = TVIF_TEXT;
63     tvi.iImage = 0;
64     tvi.iSelectedImage = 0;
65 twoaday 175 ctx.hParent = TVI_ROOT;
66     ctx.item = tvi;
67     uid = TreeView_InsertItem (dlg, &ctx);
68     for (s = u->signatures; s; s=s->next) {
69     if (get_pubkey (s->keyid+8, &signer))
70     continue;
71 twoaday 188 p = utf8_to_native (signer->uids->uid);
72     tvi.pszText = p;
73 twoaday 176 tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
74     tvi.iImage = 1;
75     tvi.iSelectedImage = 1;
76     tvi.lParam = (LPARAM)s;
77 twoaday 175 ctx.hParent = uid;
78     ctx.item = tvi;
79     TreeView_InsertItem (dlg, &ctx);
80 twoaday 188 safe_free (p);
81 twoaday 175 }
82     }
83     }
84    
85    
86 twoaday 176 /* 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 twoaday 180 static void
104     create_popup (HWND dlg)
105     {
106     HMENU hm;
107     MENUITEMINFO mi;
108     POINT p;
109     char *s;
110    
111     hm = CreatePopupMenu ();
112     if (!hm)
113     BUG( NULL );
114     memset (&mi, 0, sizeof mi);
115     mi.cbSize = sizeof mi;
116     s = (char *)_("Signature &Properties");
117     mi.fType = MF_STRING;
118     mi.dwTypeData = s;
119     mi.cch = strlen (s);
120     mi.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
121     mi.wID = _ID_SIGCTX_PROPS;
122     InsertMenuItem (hm, 0, FALSE, &mi);
123     GetCursorPos (&p);
124     TrackPopupMenu (hm, 0, p.x, p.y, 0, dlg, NULL);
125     DestroyMenu (hm);
126     }
127    
128    
129     static void
130     show_sigprops (HWND dlg)
131     {
132     HWND tree;
133     HTREEITEM hti;
134     TVITEM tvi;
135    
136     memset (&tvi, 0, sizeof (tvi));
137     tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
138     hti = TreeView_GetSelection (tree);
139     tvi.mask = TVIF_PARAM;
140     tvi.hItem = hti;
141     TreeView_GetItem (tree, &tvi);
142     if (tvi.lParam != 0)
143     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
144     sigprops_dlg_proc, tvi.lParam);
145     }
146    
147    
148 twoaday 175 /* Dialog box procedure for the tree based signature listing. */
149     BOOL CALLBACK
150     sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
151     {
152 twoaday 176 static winpt_key_t key;
153 twoaday 175 static HWND tree;
154 twoaday 176 static HIMAGELIST hil;
155     HICON ico[2];
156     NMHDR *nft;
157     char inf[256];
158 twoaday 175
159     switch (msg) {
160     case WM_INITDIALOG:
161 twoaday 176 key = (winpt_key_t)lparam;
162 twoaday 175 if (!key)
163 twoaday 176 BUG (0);
164     ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID);
165     ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG);
166 twoaday 175 tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
167 twoaday 176 hil = treeview_set_image_list (tree, ico, 2);
168     sigtree_load (tree, key->ctx);
169     _snprintf (inf, sizeof (inf)-1, _("Signature Tree for \"%s\""),
170     key->ctx->uids->uid);
171 twoaday 179 SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit..."));
172 twoaday 176 SetWindowText (dlg, inf);
173 twoaday 175 SetForegroundWindow (dlg);
174     break;
175    
176 twoaday 176 case WM_DESTROY:
177     ImageList_Destroy (hil);
178     break;
179    
180     case WM_NOTIFY:
181     nft = (NMHDR*)lparam;
182 twoaday 180 if (nft->code == NM_DBLCLK)
183     show_sigprops (dlg);
184     else if (nft->code == NM_RCLICK)
185     create_popup (dlg);
186 twoaday 176 break;
187    
188 twoaday 175 case WM_COMMAND:
189     switch (LOWORD (wparam)) {
190 twoaday 180 case _ID_SIGCTX_PROPS:
191     show_sigprops (dlg);
192     break;
193    
194 twoaday 175 case IDOK:
195     EndDialog (dlg, 1);
196     break;
197    
198     case IDCANCEL:
199     EndDialog (dlg, 0);
200     break;
201 twoaday 176
202     case IDC_VKEYSIG_EDIT:
203     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG, dlg,
204     keysig_dlg_proc, (LPARAM)key);
205 twoaday 175 }
206     break;
207     }
208    
209     return FALSE;
210     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26