1 |
/* wptClipEncryptDlg.cpp - Clipboard encrypt dialog |
/* wptClipEncryptDlg.cpp - Clipboard encrypt dialog |
2 |
* Copyright (C) 2000-2006 Timo Schulz |
* Copyright (C) 2000-2006, 2009 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
16 |
*/ |
*/ |
|
|
|
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
18 |
#include <config.h> |
#include <config.h> |
19 |
#endif |
#endif |
58 |
the textmode even for non-text (binary) data. This leads to |
the textmode even for non-text (binary) data. This leads to |
59 |
serious trouble. But because our clipboard functions only support |
serious trouble. But because our clipboard functions only support |
60 |
the text format, the returned data is pure text or at least a |
the text format, the returned data is pure text or at least a |
61 |
conversion of it so we can safely use the textmode here. */ |
conversion of it, so we can safely use the textmode here. */ |
62 |
gpgme_set_textmode (ctx, 1); |
gpgme_set_textmode (ctx, 1); |
63 |
gpgme_set_armor (ctx, 1); |
gpgme_set_armor (ctx, 1); |
64 |
|
|
65 |
err = gpg_data_new_from_clipboard (&plain, 0); |
err = gpg_data_utf8_new_from_clipboard (&plain, 0, NULL); |
66 |
if (err) |
if (err) |
67 |
goto leave; |
goto leave; |
68 |
err = gpgme_data_new (&ciph); |
err = gpgme_data_new (&ciph); |
69 |
if (err) |
if (err) |
70 |
goto leave; |
goto leave; |
71 |
flags = always_trust? GPGME_ENCRYPT_ALWAYS_TRUST : (gpgme_encrypt_flags_t)0; |
flags = always_trust? GPGME_ENCRYPT_ALWAYS_TRUST : |
72 |
|
(gpgme_encrypt_flags_t)0; |
73 |
err = gpgme_op_encrypt (ctx, rset, flags, plain, ciph); |
err = gpgme_op_encrypt (ctx, rset, flags, plain, ciph); |
74 |
*r_ctx = ctx; |
*r_ctx = ctx; |
75 |
if (err) |
if (err) |
76 |
goto leave; |
goto leave; |
77 |
|
|
78 |
gpg_data_release_and_set_clipboard (ciph, 1); |
gpg_data_release_to_clipboard (ciph, 1); |
79 |
ciph = NULL; |
ciph = NULL; |
80 |
|
|
81 |
leave: |
leave: |
97 |
gpgme_invalid_key_t k; |
gpgme_invalid_key_t k; |
98 |
gpgme_key_t key; |
gpgme_key_t key; |
99 |
StringBuffer p; |
StringBuffer p; |
|
size_t len=0; |
|
100 |
const char *keyid; |
const char *keyid; |
101 |
const char *warn = _("key not found"); |
const char *warn = _("key not found"); |
102 |
char *uid; |
char *uid; |
107 |
if (!res || !res->invalid_recipients) |
if (!res || !res->invalid_recipients) |
108 |
return -1; |
return -1; |
109 |
|
|
110 |
for (k=res->invalid_recipients; k; k = k->next) { |
p = _("Recipients unusable for encryption:\n"); |
|
if (!get_pubkey (k->fpr, &key)) |
|
|
len += (32 + strlen (k->fpr)+8 + strlen (key->uids->name) + 2) + 4; |
|
|
else |
|
|
len += strlen (warn) + strlen (k->fpr)+8 + 2 + 4; |
|
|
} |
|
|
|
|
|
p = _("Recipients unsuable for encryption:\n"); |
|
111 |
for (k = res->invalid_recipients; k; k = k->next) { |
for (k = res->invalid_recipients; k; k = k->next) { |
112 |
if (!get_pubkey (k->fpr, &key)) { |
if (!get_pubkey (k->fpr, &key)) { |
113 |
uid = utf8_to_native (key->uids->name); |
uid = utf8_to_native (key->uids->name); |
125 |
} |
} |
126 |
|
|
127 |
|
|
128 |
|
struct dlg_ctx_s { |
129 |
|
int keys_sortby; |
130 |
|
int enable_redraw; |
131 |
|
keylist_ctrl_t kl; |
132 |
|
}; |
133 |
|
// FIXME: associate the context with the window |
134 |
|
static struct dlg_ctx_s state; |
135 |
|
|
136 |
/* Dialog procedure for the clipboard encryption. */ |
/* Dialog procedure for the clipboard encryption. */ |
137 |
BOOL CALLBACK |
BOOL CALLBACK |
138 |
clip_encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
clip_encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
139 |
{ |
{ |
|
static listview_ctrl_t lv = NULL; |
|
|
static int keys_sortby = 0; |
|
140 |
gpg_keycache_t kc; |
gpg_keycache_t kc; |
141 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
142 |
gpgme_ctx_t ctx=NULL; |
gpgme_ctx_t ctx=NULL; |
143 |
gpgme_error_t err; |
gpgme_error_t err; |
144 |
char tmpbuf[64]; |
char tmpbuf[64]; |
145 |
size_t n; |
size_t n; |
|
int force_trust = 0; |
|
146 |
|
|
147 |
switch (msg) { |
switch (msg) { |
148 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
149 |
SetWindowText (dlg, _("Encryption")); |
SetWindowText (dlg, _("Encryption")); |
150 |
SetDlgItemText (dlg, IDC_ENCRYPT_FNDCMD, _("&Find")); |
SetDlgItemText (dlg, IDC_ENCRYPT_FINDKEY, _("&Find Key:")); |
151 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
152 |
|
SetDlgItemText (dlg, IDC_ENCRYPT_FNDCMD, _("&Find")); |
153 |
kc = keycache_get_ctx (KEYCACHE_PUB); |
kc = keycache_get_ctx (KEYCACHE_PUB); |
154 |
lv = keylist_load (GetDlgItem (dlg, IDC_ENCRYPT_KEYLIST), kc, NULL, |
state.kl = keylist_load (GetDlgItem (dlg, IDC_ENCRYPT_KEYLIST), kc, NULL, |
155 |
KEYLIST_ENCRYPT_MIN, KEY_SORT_USERID); |
KEYLIST_ENCRYPT_MIN, KEY_SORT_USERID); |
156 |
|
|
157 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
158 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
159 |
|
|
160 |
|
state.enable_redraw = 1; |
161 |
|
InvalidateRect(GetDlgItem (dlg, IDC_ENCRYPT_KEYLIST), NULL, TRUE); |
162 |
return TRUE; |
return TRUE; |
163 |
|
|
164 |
case WM_DESTROY: |
case WM_DESTROY: |
165 |
if (lv) { |
if (state.kl) { |
166 |
keylist_delete (lv); |
keylist_delete (state.kl); |
167 |
lv = NULL; |
state.kl = NULL; |
168 |
} |
} |
169 |
return FALSE; |
break; |
170 |
|
|
171 |
case WM_NOTIFY: |
case WM_NOTIFY: |
172 |
NMHDR *notify; |
NMHDR *notify; |
|
|
|
173 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
174 |
|
if (!notify) |
175 |
|
break; |
176 |
|
|
177 |
|
/* |
178 |
|
if (state.enable_redraw) { |
179 |
|
int ret; |
180 |
|
ret = keylist_listview_notify (dlg, state.kl->keys, |
181 |
|
IDC_ENCRYPT_KEYLIST, lparam); |
182 |
|
if (ret != 0) { |
183 |
|
SetWindowLong (dlg, DWL_MSGRESULT, ret); |
184 |
|
return TRUE; |
185 |
|
} |
186 |
|
}*/ |
187 |
|
|
188 |
if (notify && notify->code == NM_DBLCLK && |
if (notify && notify->code == NM_DBLCLK && |
189 |
notify->idFrom == IDC_ENCRYPT_KEYLIST) |
notify->idFrom == IDC_ENCRYPT_KEYLIST) |
190 |
PostMessage( dlg, WM_COMMAND, MAKEWPARAM (IDOK, 0), 0); |
PostMessage( dlg, WM_COMMAND, MAKEWPARAM (IDOK, 0), 0); |
200 |
case 4: sortby = KEY_SORT_VALIDITY; break; |
case 4: sortby = KEY_SORT_VALIDITY; break; |
201 |
default: sortby = KEY_SORT_USERID; break; |
default: sortby = KEY_SORT_USERID; break; |
202 |
} |
} |
203 |
if ((keys_sortby & ~KEYLIST_SORT_DESC) == sortby) |
if ((state.keys_sortby & ~KEYLIST_SORT_DESC) == sortby) |
204 |
keys_sortby ^= KEYLIST_SORT_DESC; |
state.keys_sortby ^= KEYLIST_SORT_DESC; |
205 |
else |
else |
206 |
keys_sortby = sortby; |
state.keys_sortby = sortby; |
207 |
keylist_sort (lv, keys_sortby); |
keylist_sort (state.kl, state.keys_sortby); |
208 |
} |
} |
209 |
return TRUE; |
break; |
210 |
|
|
211 |
case WM_COMMAND: |
case WM_COMMAND: |
212 |
|
state.enable_redraw = 0; |
213 |
|
|
214 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
215 |
case IDOK: |
case IDOK: |
216 |
rset = keylist_get_recipients (lv, &force_trust, &n); |
int force_trust; |
217 |
|
rset = keylist_get_recipients (state.kl, &force_trust, &n); |
218 |
if (!n) { |
if (!n) { |
219 |
msg_box (dlg, _("You must select at least one key."), |
msg_box (dlg, _("You must select at least one key."), |
220 |
_("Encryption"), MB_ERR); |
_("Encryption"), MB_ERR); |
233 |
gpgme_release (ctx); |
gpgme_release (ctx); |
234 |
if (!err) |
if (!err) |
235 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
236 |
return TRUE; |
break; |
237 |
|
|
238 |
case IDCANCEL: |
case IDCANCEL: |
239 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
240 |
return FALSE; |
break; |
241 |
|
|
242 |
case IDC_ENCRYPT_FNDCMD: |
case IDC_ENCRYPT_FNDCMD: |
243 |
n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1); |
n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1); |
244 |
if (!n) |
if (!n) |
245 |
break; |
break; |
246 |
n = listview_find (lv, tmpbuf, 0); |
n = listview_find (state.kl->lv, tmpbuf, 0); |
247 |
if (n != -1) { |
if (n != -1) { |
248 |
int oldpos = listview_get_curr_pos (lv); |
int oldpos = listview_get_curr_pos (state.kl->lv); |
249 |
listview_select_one (lv, n); |
listview_select_one (state.kl->lv, n); |
250 |
listview_scroll (lv, oldpos, n); |
listview_scroll (state.kl->lv, oldpos, n); |
251 |
} |
} |
252 |
else |
else |
253 |
log_box (_("Encryption"), MB_ERR, |
log_box (_("Encryption"), MB_ERR, |