/[gpgoe]/trunk/src/OEDlgEncrypt.c
ViewVC logotype

Annotation of /trunk/src/OEDlgEncrypt.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sat Mar 25 09:02:36 2006 UTC (19 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 5715 byte(s)
Complete autoconf support and cleanups.


1 twoaday 1 /* OEDlgEncrypt.c - OE encrypt dialog
2     * Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz
3     *
4     * This file is part of GPGOE.
5     *
6     * GPGOE is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU Lesser General Public License as published by
8     * the Free Software Foundation; either version 2.1 of the License, or
9     * (at your option) any later version.
10     *
11     * GPGOE 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 Lesser General Public License
17     * along with GPGOE; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24     #include <windows.h>
25     #include <commctrl.h>
26     #include <assert.h>
27     #include "resource.h"
28     #include "gpgme.h"
29     #include "GPGOE.h"
30    
31    
32     void add_recipient (recip_list_t *rset, const char *addr, gpgme_key_t key);
33    
34    
35     /* Add a column to the given list view @ctl. */
36     int
37     listview_add_column (HWND ctl, const char *fieldname, int width, int pos)
38     {
39     LV_COLUMN lvc;
40    
41     memset (&lvc, 0, sizeof (lvc));
42     lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
43     lvc.pszText = (char*)fieldname;
44     lvc.cx = width;
45     lvc.fmt = LVCFMT_LEFT;
46     lvc.iSubItem = pos;
47     if (ListView_InsertColumn (ctl, pos, &lvc) == -1)
48     return -1;
49     return 0;
50     }
51    
52    
53    
54     /* Return a human readable key information from @key. */
55     const char*
56     get_key_info (gpgme_key_t key)
57     {
58     static char buf[64];
59     gpgme_subkey_t s;
60    
61     if (key->subkeys->can_encrypt)
62     s = key->subkeys;
63     else
64     s = key->subkeys->next;
65    
66     switch (s->pubkey_algo) {
67     case GPGME_PK_RSA:
68     sprintf (buf, "RSA/%d", s->length);
69     break;
70     case GPGME_PK_ELG_E:
71     sprintf (buf, "ELG/%d", s->length);
72     break;
73     }
74     return buf;
75     }
76    
77    
78     /* Add the given key @key to the list view @ctl. */
79     int
80     listview_add_key_item (HWND ctl, gpgme_key_t key)
81     {
82     LVITEM lvi;
83     char *p;
84    
85     if (!key || key->can_encrypt == 0)
86     return 0;
87     if (key->disabled || key->expired || key->revoked)
88     return 0;
89    
90     p = utf8_to_native (key->uids->uid);
91     memset (&lvi, 0, sizeof(lvi));
92     lvi.mask = LVIF_TEXT|LVIF_PARAM;
93     lvi.lParam = (LPARAM)key;
94     lvi.pszText = p;
95     if (ListView_InsertItem (ctl, &lvi) == -1) {
96     free (p);
97     return -1;
98     }
99     ListView_SetItemText (ctl, 0, 1, key->subkeys->keyid+8);
100     ListView_SetItemText (ctl, 0, 2, (char*)get_key_info (key));
101     free_if_alloc (p);
102     return 0;
103     }
104    
105    
106     /* Return the stored LPARAM from the item at position @pos. */
107     LPARAM
108     listview_get_item2 (HWND ctrl, int pos)
109     {
110     LVITEM lvi;
111    
112     memset (&lvi, 0, sizeof lvi);
113     lvi.mask = LVIF_PARAM;
114     lvi.iItem = pos;
115     ListView_GetItem (ctrl, &lvi);
116     return lvi.lParam;
117     }
118    
119    
120     /* Load the keylist in the list view @ctl. */
121     static void
122     keylist_load (HWND ctl)
123     {
124     gpgme_ctx_t ctx;
125     gpgme_key_t key;
126     gpgme_error_t err;
127    
128     ListView_SetExtendedListViewStyle(ctl, LVS_EX_FULLROWSELECT);
129     ListView_SetExtendedListViewStyle(ctl, LVS_EX_CHECKBOXES);
130     listview_add_column (ctl, _("User ID"), 240, 0);
131     listview_add_column (ctl, _("Key ID"), 70, 1);
132     listview_add_column (ctl, _("Algorithm"), 70, 2);
133    
134     err = gpgme_new (&ctx);
135     if (err)
136     return;
137     err = gpgme_op_keylist_start (ctx, NULL, 0);
138     while (!err) {
139     err = gpgme_op_keylist_next (ctx, &key);
140     if (err)
141     break;
142     listview_add_key_item (ctl, key);
143     }
144     gpgme_release (ctx);
145     }
146    
147    
148     /* Dialog initialisation. */
149     static void
150     on_init_dialog (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
151     {
152     HWND lb;
153     recip_list_t t;
154    
155     lb = GetDlgItem (dlg, IDC_ENCRYPT_KEYLIST);
156     keylist_load (lb);
157    
158     SetDlgItemText (dlg, IDC_ENCRYPT_RECPMSG, _("Recipients which were NOT found"));
159     lb = GetDlgItem (dlg, IDC_ENCRYPT_INVLIST);
160     for (t=((plugin_ctx_t)lparam)->rset; t; t = t->next) {
161     if (t->key == NULL)
162     SendMessage (lb, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)t->addr);
163     }
164     SetWindowText (dlg, _("Select Recipient for Encryption"));
165     SetForegroundWindow (dlg);
166     }
167    
168    
169     /* Dialog box procedure to select the recipients. */
170     BOOL CALLBACK
171     encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
172     {
173     static plugin_ctx_t ctx;
174     HWND lb;
175     NMHDR *notify;
176     int i, ncount=0;
177     const char *email;
178     gpgme_key_t key;
179    
180     switch (msg) {
181     case WM_INITDIALOG:
182     ctx = (plugin_ctx_t)lparam;
183     assert (ctx);
184     on_init_dialog (dlg, msg, wparam, lparam);
185     return TRUE;
186    
187     case WM_DESTROY:
188     return FALSE;
189    
190     case WM_NOTIFY:
191     notify = (NMHDR *)lparam;
192     if (notify && notify->code == NM_DBLCLK
193     && notify->idFrom == IDC_ENCRYPT_KEYLIST)
194     PostMessage (dlg, WM_COMMAND, MAKEWPARAM (IDOK, 0), 0);
195     return TRUE;
196    
197     case WM_SYSCOMMAND:
198     if (LOWORD (wparam) == SC_CLOSE)
199     EndDialog (dlg, 0);
200     return FALSE;
201    
202     case WM_COMMAND:
203     switch (LOWORD (wparam)) {
204     case IDOK:
205     lb = GetDlgItem (dlg, IDC_ENCRYPT_KEYLIST);
206     for (i = 0; i < ListView_GetItemCount (lb); i++) {
207     key = (gpgme_key_t)listview_get_item2 (lb, i);
208     if (key != NULL && ListView_GetCheckState (lb, i)) {
209     email = key->uids->email? key->uids->email : "none";
210     add_recipient (&ctx->rset, email, key);
211     ncount++;
212     }
213     else
214     gpgme_key_release (key);
215     }
216     EndDialog (dlg, ncount);
217     return TRUE;
218    
219     case IDCANCEL:
220     lb = GetDlgItem (dlg, IDC_ENCRYPT_KEYLIST);
221     for (i=0; i < ListView_GetItemCount (lb); i++) {
222     key = (gpgme_key_t)listview_get_item2 (lb, i);
223     gpgme_key_release (key);
224     }
225     EndDialog (dlg, 0);
226     return FALSE;
227     }
228     break;
229     }
230     return FALSE;
231     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26