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

Annotation of /trunk/Src/wptKeyRevokersDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 193 - (hide annotations)
Sat Apr 1 12:36:35 2006 UTC (18 years, 11 months ago) by twoaday
File size: 5441 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 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     #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25     #include <windows.h>
26     #include <commctrl.h>
27    
28 werner 47 #include "resource.h"
29 werner 36 #include "wptCommonCtl.h"
30     #include "wptNLS.h"
31     #include "wptTypes.h"
32     #include "wptGPG.h"
33     #include "wptCommonCtl.h"
34     #include "wptContext.h"
35     #include "wptDlgs.h"
36     #include "wptErrors.h"
37     #include "wptKeyserver.h"
38 werner 47 #include "wptW32API.h"
39 werner 36 #include "wptVersion.h"
40     #include "wptKeyEdit.h"
41 werner 47 #include "wptKeylist.h"
42 twoaday 129 #include "wptUTF8.h"
43 werner 36
44    
45 twoaday 129 enum revoke_col_t {
46     REV_COL_NAME = 0,
47     REV_COL_KEYID = 1,
48     REV_COL_ALGO = 2
49     };
50    
51 werner 36 /* Initialize the listview given in @ctrl and return it in @r_lv. */
52     static int
53     revokelist_build (listview_ctrl_t *r_lv, HWND ctrl)
54     {
55     listview_ctrl_t lv;
56     struct listview_column_s rlist[] = {
57 twoaday 129 {0, 160, (char *)_("Name") },
58     {1, 80, (char *)_("Key ID")},
59     {2, 55, (char *)_("Algorithm")},
60 werner 36 {0}
61     };
62     int i, rc;
63    
64     rc = listview_new (&lv);
65     if (rc)
66     return rc;
67     lv->ctrl = ctrl;
68     lv->items = DIM( rlist )-1;
69     for (i = 0; i < lv->items; i++)
70     listview_add_column (lv, &rlist[i]);
71     listview_set_ext_style (lv);
72     *r_lv = lv;
73     return 0;
74     }
75    
76    
77     /* Initialize the listview @ctrl with all designated revokers of the
78     key @key. @ctx is used to retrieve the rev key from the cache to
79     show the user-id.
80     Return value: the initialized listview or NULL on error. */
81     static listview_ctrl_t
82     revokelist_init (HWND ctrl, gpgme_key_t key, gpg_keycache_t ctx)
83     {
84     gpgme_error_t err;
85 twoaday 129 gpgme_key_t revkey;
86     GpgKeyEdit *ke;
87 werner 36 gpg_desig_rev_t rev=NULL, r;
88 twoaday 129 listview_ctrl_t lv;
89     const char *alg;
90     char *uid = NULL;
91 twoaday 193 char keyid[32];
92 werner 36
93     ke = new GpgKeyEdit (key);
94     if (!ke)
95     BUG (NULL);
96     err = ke->getDesignatedRevoker (&rev);
97     if (err) {
98     delete ke;
99 twoaday 129 msg_box (NULL, gpgme_strerror (err),
100     _("Designated Key Revokers"), MB_ERR);
101 werner 36 return NULL;
102     }
103    
104     if (revokelist_build (&lv, ctrl))
105     BUG (0);
106     for (r = rev; r; r = r->next) {
107     if (get_pubkey (r->fpr+32, &revkey))
108 twoaday 129 uid = strdup (_("user ID not found"));
109 werner 36 else
110 twoaday 187 uid = utf8_to_native (revkey->uids->name);
111 twoaday 193 _snprintf (keyid, sizeof (keyid)-1, "0x%s", r->fpr+32);
112 werner 36 listview_add_item (lv, "");
113 twoaday 129 alg = get_key_pubalgo (r->pubkey_algo);
114     listview_add_sub_item (lv, 0, REV_COL_ALGO, alg);
115 twoaday 193 listview_add_sub_item (lv, 0, REV_COL_KEYID, keyid);
116 twoaday 129 listview_add_sub_item (lv, 0, REV_COL_NAME, uid);
117     safe_free (uid);
118 werner 36 }
119 twoaday 129
120 werner 36 delete ke;
121     gpg_desig_rev_release (rev);
122     return lv;
123     }
124    
125    
126     /* Dialog box procedure to show designated revokers. */
127     BOOL CALLBACK
128     key_revokers_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
129     {
130     static listview_ctrl_t lv;
131 twoaday 161 static int key_update = 0;
132 werner 36 gpgme_key_t key;
133     char buf[128], keyid[32];
134     int rc;
135    
136     switch( msg ) {
137     case WM_INITDIALOG:
138     gpg_keycache_t ctx;
139     key = (gpgme_key_t)lparam;
140     if (!key)
141     dlg_fatal_error( dlg, "Could not get dilaog param" );
142     ctx = keycache_get_ctx (1);
143     if (!ctx)
144     BUG (dlg);
145 twoaday 88 lv = revokelist_init (GetDlgItem (dlg, IDC_KEYREVOKERS_LIST), key, ctx);
146    
147     SetDlgItemText (dlg, IDC_KEYREVOKERS_INF, _("Designated Revoker Keys"));
148     SetWindowText (dlg, _("Key Revokers"));
149     SetForegroundWindow (dlg);
150 werner 36 return TRUE;
151    
152     case WM_NOTIFY:
153     NMHDR *notify;
154     notify = (NMHDR *)lparam;
155     if (notify && notify->code == NM_DBLCLK &&
156     notify->idFrom == IDC_KEYREVOKERS_LIST) {
157     int idx = listview_get_curr_pos (lv);
158 twoaday 129 listview_get_item_text (lv, idx, REV_COL_KEYID, keyid, DIM (keyid)-1);
159     listview_get_item_text (lv, idx, REV_COL_NAME, buf, sizeof (buf)-1);
160     if (!strcmp (buf, _("user ID not found"))) {
161 werner 36 int id = log_box (_("Designated Key Revokers"), MB_YESNO|MB_INFO,
162     _("Do you want to retrieve 0x%s via the default keyserver?"), keyid);
163     if (id == IDNO)
164     break;
165     rc = hkp_recv_key (dlg, default_keyserver,
166 twoaday 129 default_keyserver_port, keyid, 0, 0);
167     if (!rc) {
168 twoaday 161 keycache_update (0, keyid);
169     key_update = 1;
170 werner 36 if (get_pubkey (keyid, &key))
171     BUG (NULL);
172 twoaday 129 if (key->uids && key->uids->name) {
173 twoaday 187 char *uid = utf8_to_native (key->uids->name);
174 twoaday 129 listview_add_sub_item (lv, idx, REV_COL_NAME, uid);
175     free (uid);
176     }
177 werner 36 }
178     }
179     else {
180     struct winpt_key_s k;
181     memset (&k, 0, sizeof k);
182     k.keyid = keyid;
183     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
184     keyprops_dlg_proc, (LPARAM)&k);
185     }
186     }
187     break;
188    
189     case WM_DESTROY:
190     if (lv) {
191     listview_release (lv);
192     lv = NULL;
193     }
194     return FALSE;
195    
196     case WM_COMMAND:
197     switch (LOWORD (wparam)) {
198     case IDOK:
199 twoaday 161 EndDialog (dlg, key_update);
200 werner 36 break;
201     }
202     break;
203     }
204    
205     return FALSE;
206     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26