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

Annotation of /trunk/Src/wptKeyRevokersDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations)
Mon Oct 31 14:04:59 2005 UTC (19 years, 4 months ago) by werner
File size: 4870 byte(s)
Minor changes; compiles now but gettext is still missing.

1 werner 36 /* wptKeyRevokersDlg.cpp - Designated Revoker Keys
2     * Copyright (C) 2002, 2003, 2005 Timo Schulz
3     * Copyright (C) 2005 g10 Code GmbH
4     *
5     * This file is part of WinPT.
6     *
7     * WinPT is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * WinPT is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with WinPT; if not, write to the Free Software Foundation,
19     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20     */
21    
22     #ifdef HAVE_CONFIG_H
23     #include <config.h>
24     #endif
25    
26     #include <windows.h>
27     #include <windows.h>
28     #include <commctrl.h>
29    
30 werner 47 #include "resource.h"
31 werner 36 #include "wptCommonCtl.h"
32     #include "wptNLS.h"
33     #include "wptTypes.h"
34     #include "wptGPG.h"
35     #include "wptCommonCtl.h"
36     #include "wptContext.h"
37     #include "wptDlgs.h"
38     #include "wptErrors.h"
39     #include "wptKeyserver.h"
40 werner 47 #include "wptW32API.h"
41 werner 36 #include "wptVersion.h"
42     #include "wptKeyEdit.h"
43 werner 47 #include "wptKeylist.h"
44 werner 36
45    
46     /* Initialize the listview given in @ctrl and return it in @r_lv. */
47     static int
48     revokelist_build (listview_ctrl_t *r_lv, HWND ctrl)
49     {
50     listview_ctrl_t lv;
51     struct listview_column_s rlist[] = {
52     { 0, 55, (char *)_("Algorithm") },
53     { 1, 80, (char *)_("Key ID") },
54     { 2, 160, (char *)_("Name") },
55     {0}
56     };
57     int i, rc;
58    
59     rc = listview_new (&lv);
60     if (rc)
61     return rc;
62     lv->ctrl = ctrl;
63     lv->items = DIM( rlist )-1;
64     for (i = 0; i < lv->items; i++)
65     listview_add_column (lv, &rlist[i]);
66     listview_set_ext_style (lv);
67     *r_lv = lv;
68     return 0;
69     }
70    
71    
72     /* Initialize the listview @ctrl with all designated revokers of the
73     key @key. @ctx is used to retrieve the rev key from the cache to
74     show the user-id.
75     Return value: the initialized listview or NULL on error. */
76     static listview_ctrl_t
77     revokelist_init (HWND ctrl, gpgme_key_t key, gpg_keycache_t ctx)
78     {
79     gpgme_error_t err;
80     gpgme_key_t revkey;
81     GpgKeyEdit *ke;
82     gpg_desig_rev_t rev=NULL, r;
83     listview_ctrl_t lv;
84     const char *id;
85    
86     ke = new GpgKeyEdit (key);
87     if (!ke)
88     BUG (NULL);
89     err = ke->getDesignatedRevoker (&rev);
90     if (err) {
91     delete ke;
92     msg_box (NULL, gpgme_strerror (err), _("Designated Key Revokers"), MB_ERR);
93     return NULL;
94     }
95    
96     if (revokelist_build (&lv, ctrl))
97     BUG (0);
98     for (r = rev; r; r = r->next) {
99     if (get_pubkey (r->fpr+32, &revkey))
100     id = _("user ID not found");
101     else
102     id = revkey->uids->name;
103     listview_add_item (lv, "");
104     listview_add_sub_item (lv, 0, 0, get_key_pubalgo (r->pubkey_algo));
105     listview_add_sub_item (lv, 0, 1, r->fpr+32);
106     listview_add_sub_item (lv, 0, 2, id);
107     }
108    
109     delete ke;
110     gpg_desig_rev_release (rev);
111     return lv;
112     }
113    
114    
115     /* Dialog box procedure to show designated revokers. */
116     BOOL CALLBACK
117     key_revokers_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
118     {
119     static listview_ctrl_t lv;
120     gpgme_key_t key;
121     char buf[128], keyid[32];
122     int rc;
123    
124     switch( msg ) {
125     case WM_INITDIALOG:
126     gpg_keycache_t ctx;
127     key = (gpgme_key_t)lparam;
128     if (!key)
129     dlg_fatal_error( dlg, "Could not get dilaog param" );
130     ctx = keycache_get_ctx (1);
131     if (!ctx)
132     BUG (dlg);
133     lv = revokelist_init( GetDlgItem( dlg, IDC_KEYREVOKERS_LIST ), key, ctx );
134     return TRUE;
135    
136     case WM_NOTIFY:
137     NMHDR *notify;
138     notify = (NMHDR *)lparam;
139     if (notify && notify->code == NM_DBLCLK &&
140     notify->idFrom == IDC_KEYREVOKERS_LIST) {
141     int idx = listview_get_curr_pos (lv);
142     listview_get_item_text (lv, idx, 1, keyid, DIM (keyid)-1);
143     listview_get_item_text (lv, idx, 2, buf, DIM (buf)-1);
144     if (!strcmp( buf, _("user ID not found"))) {
145     int id = log_box (_("Designated Key Revokers"), MB_YESNO|MB_INFO,
146     _("Do you want to retrieve 0x%s via the default keyserver?"), keyid);
147     if (id == IDNO)
148     break;
149     rc = hkp_recv_key (dlg, default_keyserver,
150     default_keyserver_port, buf, 0, 0);
151     if( !rc ) {
152     keycache_reload (dlg);
153     if (get_pubkey (keyid, &key))
154     BUG (NULL);
155     if (key->uids && key->uids->name)
156     listview_add_sub_item (lv, idx, 2, key->uids->name);
157     }
158     }
159     else {
160     struct winpt_key_s k;
161     memset (&k, 0, sizeof k);
162     k.keyid = keyid;
163     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
164     keyprops_dlg_proc, (LPARAM)&k);
165     }
166     }
167     break;
168    
169     case WM_DESTROY:
170     if (lv) {
171     listview_release (lv);
172     lv = NULL;
173     }
174     return FALSE;
175    
176     case WM_COMMAND:
177     switch (LOWORD (wparam)) {
178     case IDOK:
179     EndDialog (dlg, TRUE);
180     break;
181     }
182     break;
183     }
184    
185     return FALSE;
186     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26