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

Annotation of /trunk/Src/wptSigTreeDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 179 - (hide annotations)
Fri Feb 24 13:12:26 2006 UTC (19 years ago) by twoaday
File size: 4281 byte(s)
Prepare 0.11.8


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 175
32 twoaday 176 BOOL CALLBACK sigprops_dlg_proc (HWND dlg, UINT msg,
33     WPARAM wparam, LPARAM lparam);
34     BOOL CALLBACK
35     keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam);
36    
37 twoaday 175 /* Initialize the signature tree based on the given key @key. */
38     static void
39     sigtree_load (HWND dlg, gpgme_key_t key)
40     {
41     TVITEM tvi;
42     TVINSERTSTRUCT ctx;
43     HTREEITEM uid;
44     gpgme_user_id_t u;
45     gpgme_key_sig_t s;
46     gpgme_key_t signer;
47    
48     memset (&tvi, 0, sizeof (tvi));
49     memset (&ctx, 0, sizeof (ctx));
50     for (u=key->uids; u; u = u->next) {
51 twoaday 176 if (u->revoked)
52     continue;
53 twoaday 175 tvi.pszText = u->uid;
54     tvi.state = TVIS_BOLD;
55 twoaday 176 tvi.mask = TVIF_TEXT;
56     tvi.iImage = 0;
57     tvi.iSelectedImage = 0;
58 twoaday 175 ctx.hParent = TVI_ROOT;
59     ctx.item = tvi;
60     uid = TreeView_InsertItem (dlg, &ctx);
61     for (s = u->signatures; s; s=s->next) {
62     if (get_pubkey (s->keyid+8, &signer))
63     continue;
64     tvi.pszText = signer->uids->uid;
65 twoaday 176 tvi.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
66     tvi.iImage = 1;
67     tvi.iSelectedImage = 1;
68     tvi.lParam = (LPARAM)s;
69 twoaday 175 ctx.hParent = uid;
70     ctx.item = tvi;
71     TreeView_InsertItem (dlg, &ctx);
72     }
73     }
74     }
75    
76    
77 twoaday 176 /* Associate a signature list based on the icons @ico with
78     the treeview control @tree. */
79     HIMAGELIST
80     treeview_set_image_list (HWND tree, HICON *ico, DWORD nicons)
81     {
82     HIMAGELIST hil;
83     DWORD i;
84    
85     hil = ImageList_Create (16, 16, ILC_COLOR8|ILC_MASK, nicons, 1);
86     ImageList_SetBkColor (hil, CLR_NONE);
87     for (i=0; i < nicons; i++)
88     ImageList_AddIcon (hil, ico[i]);
89     TreeView_SetImageList (tree, hil, TVSIL_NORMAL);
90     return hil;
91     }
92    
93    
94 twoaday 175 /* Dialog box procedure for the tree based signature listing. */
95     BOOL CALLBACK
96     sigtree_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
97     {
98 twoaday 176 static winpt_key_t key;
99 twoaday 175 static HWND tree;
100 twoaday 176 static HIMAGELIST hil;
101    
102     HICON ico[2];
103     NMHDR *nft;
104     char inf[256];
105 twoaday 175
106     switch (msg) {
107     case WM_INITDIALOG:
108 twoaday 176 key = (winpt_key_t)lparam;
109 twoaday 175 if (!key)
110 twoaday 176 BUG (0);
111     ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_USERID);
112     ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEY_SIG);
113 twoaday 175 tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
114 twoaday 176 hil = treeview_set_image_list (tree, ico, 2);
115     sigtree_load (tree, key->ctx);
116     _snprintf (inf, sizeof (inf)-1, _("Signature Tree for \"%s\""),
117     key->ctx->uids->uid);
118 twoaday 179 SetDlgItemText (dlg, IDC_VKEYSIG_EDIT, _("Edit..."));
119 twoaday 176 SetWindowText (dlg, inf);
120 twoaday 175 SetForegroundWindow (dlg);
121     break;
122    
123 twoaday 176 case WM_DESTROY:
124     ImageList_Destroy (hil);
125     break;
126    
127     case WM_NOTIFY:
128     nft = (NMHDR*)lparam;
129     if (nft->code == NM_DBLCLK) {
130     HTREEITEM hti;
131     TVITEM tvi;
132    
133     memset (&tvi, 0, sizeof (tvi));
134     tree = GetDlgItem (dlg, IDC_VKEYSIG_TREE);
135     hti = TreeView_GetSelection (tree);
136     tvi.mask = TVIF_PARAM;
137     tvi.hItem = hti;
138     TreeView_GetItem (tree, &tvi);
139     if (tvi.lParam != 0)
140     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
141     sigprops_dlg_proc, tvi.lParam);
142     }
143     break;
144    
145 twoaday 175 case WM_COMMAND:
146     switch (LOWORD (wparam)) {
147     case IDOK:
148     EndDialog (dlg, 1);
149     break;
150    
151     case IDCANCEL:
152     EndDialog (dlg, 0);
153     break;
154 twoaday 176
155     case IDC_VKEYSIG_EDIT:
156     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSIG, dlg,
157     keysig_dlg_proc, (LPARAM)key);
158 twoaday 175 }
159     break;
160     }
161    
162     return FALSE;
163     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26