1 |
werner |
36 |
/* wptMainProc.cpp - Main window procedure |
2 |
twoaday |
150 |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
werner |
36 |
* |
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 |
|
|
#ifdef HAVE_CONFIG_H |
22 |
|
|
#include <config.h> |
23 |
|
|
#endif |
24 |
|
|
|
25 |
|
|
#include <windows.h> |
26 |
|
|
#include <commctrl.h> |
27 |
|
|
#include <io.h> |
28 |
|
|
|
29 |
werner |
47 |
#include "resource.h" |
30 |
werner |
36 |
#include "wptTypes.h" |
31 |
|
|
#include "wptGPG.h" |
32 |
|
|
#include "wptW32API.h" |
33 |
|
|
#include "wptVersion.h" |
34 |
|
|
#include "wptCommonCtl.h" |
35 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
36 |
|
|
#include "wptDlgs.h" |
37 |
|
|
#include "wptErrors.h" |
38 |
|
|
#include "wptNLS.h" |
39 |
|
|
#include "wptHotkey.h" |
40 |
|
|
#include "wptRegistry.h" |
41 |
|
|
#include "wptKeyserver.h" |
42 |
|
|
#include "wptAgent.h" |
43 |
|
|
#include "wptKeyManager.h" |
44 |
|
|
#include "wptCard.h" |
45 |
|
|
#include "wptCryptdisk.h" |
46 |
|
|
#include "wptCardEdit.h" |
47 |
|
|
|
48 |
|
|
static int cmd = 0; |
49 |
|
|
static int wipe_contents = 0; |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
/* Dialog box procedure to display all insecure all ElGamal keys. */ |
53 |
|
|
BOOL CALLBACK |
54 |
|
|
elgamal_warn_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
55 |
|
|
{ |
56 |
|
|
gpg_keycache_t pc; |
57 |
|
|
gpgme_key_t key; |
58 |
|
|
char tmp[128+64+1]; |
59 |
|
|
|
60 |
twoaday |
72 |
switch (msg) { |
61 |
werner |
36 |
case WM_INITDIALOG: |
62 |
|
|
pc = keycache_get_ctx (1); |
63 |
|
|
while (!gpg_keycache_next_key (pc, 0, &key)) { |
64 |
|
|
if (key->subkeys->pubkey_algo == GPGME_PK_ELG) { |
65 |
|
|
_snprintf (tmp, sizeof (tmp)-1, "(0x%s) %s", |
66 |
|
|
key->subkeys->keyid+8, key->uids->uid); |
67 |
|
|
SendDlgItemMessage (dlg, IDC_ELGWARN_LIST, LB_ADDSTRING, |
68 |
|
|
0, (LPARAM)(const char *) tmp); |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
gpg_keycache_rewind (pc); |
72 |
|
|
center_window (dlg, NULL); |
73 |
|
|
SetForegroundWindow (dlg); |
74 |
|
|
break; |
75 |
|
|
|
76 |
|
|
case WM_COMMAND: |
77 |
|
|
switch (LOWORD (wparam)) { |
78 |
|
|
case IDOK: |
79 |
|
|
EndDialog (dlg, TRUE); |
80 |
|
|
break; |
81 |
|
|
} |
82 |
|
|
break; |
83 |
|
|
} |
84 |
|
|
return FALSE; |
85 |
twoaday |
32 |
} |
86 |
werner |
36 |
|
87 |
|
|
|
88 |
|
|
/* Dialog box procedure to confirm to delete the clipboard contents. */ |
89 |
|
|
static BOOL CALLBACK |
90 |
|
|
confirm_delclipboard_dlg (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
91 |
|
|
{ |
92 |
|
|
switch (msg) { |
93 |
|
|
case WM_INITDIALOG: |
94 |
|
|
SetWindowText (dlg, _("Delete Clipboard Contents")); |
95 |
twoaday |
95 |
SetDlgItemText (dlg, IDC_CONFDELCLIP_BRAIN, _("&Remember the answer")); |
96 |
|
|
SetDlgItemText (dlg, IDC_CONFDELCLIP_INFO, _("Do you want to delete the contents from the clipboard?")); |
97 |
twoaday |
105 |
SetDlgItemText (dlg, IDYES, _("&Yes")); |
98 |
twoaday |
121 |
SetDlgItemText (dlg, IDNO, _("&No")); |
99 |
werner |
36 |
center_window (dlg, NULL); |
100 |
|
|
SetForegroundWindow (dlg); |
101 |
|
|
break; |
102 |
|
|
|
103 |
|
|
case WM_COMMAND: |
104 |
|
|
switch (LOWORD (wparam)) { |
105 |
|
|
case IDYES: |
106 |
|
|
wipe_contents = 1; |
107 |
|
|
if (IsDlgButtonChecked (dlg, IDC_CONFDELCLIP_BRAIN)) |
108 |
|
|
set_reg_winpt_flag ("WipeClipboard", 1); |
109 |
|
|
EndDialog (dlg, TRUE); |
110 |
|
|
break; |
111 |
|
|
|
112 |
|
|
case IDNO: |
113 |
|
|
wipe_contents = 0; |
114 |
|
|
if (IsDlgButtonChecked (dlg, IDC_CONFDELCLIP_BRAIN)) |
115 |
|
|
set_reg_winpt_flag ("WipeClipboard", 0); |
116 |
|
|
EndDialog (dlg, FALSE); |
117 |
|
|
break; |
118 |
|
|
} |
119 |
|
|
break; |
120 |
|
|
} |
121 |
|
|
return FALSE; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
|
125 |
|
|
static gpgme_error_t |
126 |
|
|
currwnd_gpg_dlg (HWND hwnd, UINT id, int *ret_set) |
127 |
|
|
{ |
128 |
twoaday |
68 |
gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); |
129 |
werner |
36 |
int type; |
130 |
|
|
|
131 |
|
|
if (ret_set) |
132 |
|
|
*ret_set = 1; |
133 |
|
|
switch (id) { |
134 |
|
|
case ID_WINPT_CURRWND_SYMENC: |
135 |
|
|
gpg_encrypt_symmetric (); |
136 |
|
|
break; |
137 |
|
|
|
138 |
|
|
case ID_WINPT_CURRWND_ENCRYPT: |
139 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ENCRYPT, hwnd, |
140 |
twoaday |
68 |
clip_encrypt_dlg_proc, 0, |
141 |
werner |
36 |
_("Encryption"), IDS_WINPT_ENCRYPT ); |
142 |
|
|
break; |
143 |
|
|
|
144 |
|
|
case ID_WINPT_CURRWND_SIGNENCRYPT: |
145 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGNENC, hwnd, |
146 |
twoaday |
68 |
clip_signenc_dlg_proc, 0, |
147 |
werner |
36 |
_("Sign & Encrypt"), IDS_WINPT_SIGNENC ); |
148 |
|
|
break; |
149 |
|
|
|
150 |
|
|
case ID_WINPT_CURRWND_SIGN: |
151 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGN, hwnd, |
152 |
twoaday |
68 |
clip_sign_dlg_proc, 0, |
153 |
werner |
36 |
_("Signing"), IDS_WINPT_SIGN ); |
154 |
|
|
break; |
155 |
|
|
|
156 |
|
|
case ID_WINPT_CURRWND_DECRYPT_VERIFY: |
157 |
|
|
err = gpg_clip_get_pgptype (&type); |
158 |
|
|
if (err) { |
159 |
|
|
msg_box (hwnd, gpgme_strerror (err), _("Clipboard"), MB_ERR); |
160 |
|
|
break; |
161 |
|
|
} |
162 |
|
|
if( (type & PGP_MESSAGE) && !(type & PGP_CLEARSIG) ) { |
163 |
|
|
/* It makes only sense to insert the data in the window if it's |
164 |
|
|
really a ciphertext. Verfied data doesn't need this. */ |
165 |
|
|
err = clip_decrypt_dlg (hwnd); |
166 |
|
|
if (!err && reg_prefs.use_viewer) { |
167 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CLIPEDIT, |
168 |
twoaday |
68 |
GetDesktopWindow(), clip_edit_dlg_proc, 0, |
169 |
werner |
36 |
_("Clipboard Editor"), IDS_WINPT_CLIPEDIT); |
170 |
|
|
if (ret_set) |
171 |
|
|
*ret_set = 0; |
172 |
|
|
} |
173 |
|
|
} |
174 |
|
|
else if ((type & PGP_PUBKEY) && !(type & PGP_CLEARSIG)) |
175 |
twoaday |
165 |
km_clip_import (GetDesktopWindow (), NULL, NULL); |
176 |
werner |
36 |
else { |
177 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd, |
178 |
twoaday |
68 |
clip_verify_dlg_proc, 0, |
179 |
werner |
36 |
_("Verify"), IDS_WINPT_VERIFY ); |
180 |
twoaday |
150 |
err = gpg_error (GPG_ERR_EOF); /* make sure window is not updated. */ |
181 |
werner |
36 |
} |
182 |
|
|
break; |
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
return err; |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
|
189 |
|
|
static void |
190 |
|
|
clip_gpg_dlg (HWND hwnd, UINT id) |
191 |
|
|
{ |
192 |
|
|
gpgme_error_t err; |
193 |
|
|
int type; |
194 |
|
|
|
195 |
twoaday |
129 |
if ((id == ID_WINPT_SIGN || id == ID_WINPT_SIGNENCRYPT) |
196 |
|
|
&& gnupg_access_keyring (0)) { |
197 |
|
|
msg_box (hwnd, _("Could not access secret keyring."), _("Sign"), MB_ERR); |
198 |
werner |
36 |
return; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
switch( id ) { |
202 |
|
|
case ID_WINPT_SYMENC: |
203 |
twoaday |
129 |
gpg_encrypt_symmetric (); |
204 |
werner |
36 |
break; |
205 |
|
|
|
206 |
|
|
case ID_WINPT_ENCRYPT: |
207 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ENCRYPT, hwnd, |
208 |
twoaday |
68 |
clip_encrypt_dlg_proc, 0, |
209 |
werner |
36 |
_("Encryption"), IDS_WINPT_ENCRYPT ); |
210 |
|
|
break; |
211 |
|
|
|
212 |
|
|
case ID_WINPT_SIGN: |
213 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGN, hwnd, |
214 |
twoaday |
68 |
clip_sign_dlg_proc, 0, |
215 |
werner |
36 |
_("Signing"), IDS_WINPT_SIGN ); |
216 |
|
|
break; |
217 |
|
|
|
218 |
|
|
case ID_WINPT_SIGNENCRYPT: |
219 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGNENC, hwnd, |
220 |
twoaday |
68 |
clip_signenc_dlg_proc, 0, |
221 |
werner |
36 |
_("Sign & Encrypt"), IDS_WINPT_SIGNENC ); |
222 |
|
|
break; |
223 |
|
|
|
224 |
|
|
case ID_WINPT_DECRYPT_VERIFY: |
225 |
|
|
err = gpg_clip_get_pgptype (&type); |
226 |
|
|
if (err) { |
227 |
|
|
msg_box( hwnd, gpgme_strerror( err ), _("Clipboard"), MB_ERR ); |
228 |
|
|
break; |
229 |
|
|
} |
230 |
|
|
if( (type & PGP_MESSAGE) && !(type & PGP_CLEARSIG) ) { |
231 |
|
|
err = clip_decrypt_dlg (hwnd); |
232 |
|
|
if (!err && reg_prefs.use_viewer) { |
233 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CLIPEDIT, |
234 |
twoaday |
68 |
GetDesktopWindow(), clip_edit_dlg_proc, 0, |
235 |
werner |
36 |
_("Clipboard Editor"), IDS_WINPT_CLIPEDIT ); |
236 |
|
|
} |
237 |
|
|
} |
238 |
|
|
else if( (type & PGP_SIG) && !(type & PGP_CLEARSIG) ) { |
239 |
|
|
text_input_s input; |
240 |
|
|
gpgme_data_t sig; |
241 |
|
|
|
242 |
|
|
memset( &input, 0, sizeof (input) ); |
243 |
|
|
err = gpg_data_new_from_clipboard (&sig, 0); |
244 |
|
|
if( err ) { |
245 |
|
|
msg_box( hwnd, gpgme_strerror( err ),_("Verify"), MB_ERR ); |
246 |
|
|
return; |
247 |
|
|
} |
248 |
|
|
input.type = 0; |
249 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_TEXT, hwnd, |
250 |
|
|
text_input_dlg_proc, (LPARAM)&input, |
251 |
|
|
_("Text Input"), IDS_WINPT_TEXT ); |
252 |
|
|
|
253 |
|
|
gpg_data_release_and_set_clipboard( sig, 0 ); |
254 |
|
|
if( input.length ) { |
255 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd, |
256 |
|
|
clip_verify_dlg_proc, (LPARAM)&input, |
257 |
|
|
_("Verify"), IDS_WINPT_VERIFY ); |
258 |
|
|
input.length = 0; |
259 |
|
|
free_if_alloc( input.data ); |
260 |
|
|
} |
261 |
|
|
} |
262 |
|
|
else if (type & PGP_CLEARSIG) { |
263 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd, |
264 |
twoaday |
68 |
clip_verify_dlg_proc, 0, |
265 |
werner |
36 |
_("Verify"), IDS_WINPT_VERIFY ); |
266 |
|
|
} |
267 |
|
|
else if ((type & PGP_PUBKEY) || (type & PGP_SECKEY)) |
268 |
twoaday |
165 |
km_clip_import (GetDesktopWindow (), NULL, NULL); |
269 |
werner |
36 |
else |
270 |
|
|
msg_box (hwnd, _("Unknown OpenPGP type."), _("Clipboard"), MB_ERR); |
271 |
|
|
} |
272 |
twoaday |
72 |
} |
273 |
werner |
36 |
|
274 |
|
|
|
275 |
twoaday |
72 |
static bool |
276 |
|
|
secret_key_available (void) |
277 |
|
|
{ |
278 |
|
|
gpg_keycache_t sec = keycache_get_ctx (0); |
279 |
|
|
if (!sec || gpg_keycache_get_size (sec) == 0) |
280 |
|
|
return false; |
281 |
|
|
return true; |
282 |
|
|
} |
283 |
|
|
|
284 |
|
|
|
285 |
werner |
36 |
/* Load the Card Manager with the current card. */ |
286 |
|
|
static void |
287 |
twoaday |
121 |
load_card_manager (void) |
288 |
werner |
36 |
{ |
289 |
|
|
gpg_card_t card; |
290 |
|
|
|
291 |
|
|
card = gpg_card_load (); |
292 |
|
|
if (card) { |
293 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_EDIT, |
294 |
|
|
GetDesktopWindow (), card_edit_dlg_proc, |
295 |
|
|
(LPARAM)card, |
296 |
|
|
_("Card Edit"), IDS_WINPT_CARD_EDIT); |
297 |
twoaday |
121 |
gpg_card_release (card); |
298 |
werner |
36 |
} |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
|
302 |
|
|
/* Add the winpt symbol to the task bar. */ |
303 |
|
|
static void |
304 |
|
|
add_taskbar_icon (HWND hwnd, NOTIFYICONDATA *nid) |
305 |
|
|
{ |
306 |
|
|
nid->cbSize = sizeof (NOTIFYICONDATA); |
307 |
|
|
nid->uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; |
308 |
|
|
nid->uCallbackMessage = WM_USER; |
309 |
|
|
nid->hWnd = hwnd; |
310 |
|
|
nid->hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
311 |
|
|
strcpy (nid->szTip, "Windows Privacy Tray v"PGM_VERSION); |
312 |
|
|
Shell_NotifyIcon (NIM_ADD, nid); |
313 |
|
|
DestroyIcon (nid->hIcon); |
314 |
|
|
} |
315 |
|
|
|
316 |
|
|
|
317 |
|
|
/* Main message loop for the tray window. */ |
318 |
|
|
LRESULT CALLBACK |
319 |
|
|
winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
320 |
|
|
{ |
321 |
|
|
static NOTIFYICONDATA NID; |
322 |
twoaday |
174 |
static DWORD cookie; |
323 |
twoaday |
139 |
static int use_hotkey = 0; |
324 |
|
|
INITCOMMONCONTROLSEX cce; |
325 |
werner |
36 |
LPARAM param; |
326 |
twoaday |
139 |
HWND wnd; |
327 |
|
|
gpgme_error_t err; |
328 |
|
|
curr_wnd_ctx currwnd = {0}; |
329 |
|
|
const char *s; |
330 |
werner |
36 |
int rc, set_wc = 0, has_data = 0; |
331 |
|
|
|
332 |
|
|
switch (msg) { |
333 |
|
|
case WM_CREATE: |
334 |
|
|
add_taskbar_icon (hwnd, &NID); |
335 |
|
|
rc = wsock_init (); |
336 |
|
|
if (rc) |
337 |
|
|
msg_box (NULL, winpt_strerror (rc), "Winsock2 DLL", MB_ERR); |
338 |
|
|
if (!reg_prefs.no_hotkeys) { |
339 |
|
|
rc = hotkeys_register (hwnd); |
340 |
|
|
if (rc) |
341 |
|
|
msg_box (hwnd, hotkeys_strerror (), winpt_strerror (rc), MB_ERR); |
342 |
|
|
} |
343 |
|
|
rc = PTD_initialize (); |
344 |
|
|
if (!rc) |
345 |
|
|
msg_box (hwnd, _("Could not set current window mode hooks."), |
346 |
|
|
_("WinPT Error"), MB_OK); |
347 |
|
|
mapi_init (); |
348 |
|
|
/* init common controls: date control. */ |
349 |
|
|
cce.dwSize = sizeof (INITCOMMONCONTROLSEX); |
350 |
|
|
cce.dwICC = ICC_DATE_CLASSES; |
351 |
|
|
InitCommonControlsEx (&cce); |
352 |
twoaday |
174 |
html_help_init (&cookie); |
353 |
werner |
36 |
LoadLibrary ("RichEd32.Dll"); |
354 |
|
|
break; |
355 |
|
|
|
356 |
|
|
case WM_ENDSESSION: |
357 |
|
|
case WM_DESTROY: |
358 |
|
|
case WM_CLOSE: |
359 |
|
|
case WM_QUIT: |
360 |
twoaday |
185 |
/*cryptdisk_cleanup ();*/ |
361 |
werner |
36 |
mapi_deinit (); |
362 |
|
|
wsock_end (); |
363 |
|
|
keycache_release (1); |
364 |
|
|
gnupg_backup_keyrings (); |
365 |
|
|
free_reg_prefs (); |
366 |
|
|
free_gnupg_table (); |
367 |
|
|
hotkeys_unregister (hwnd); |
368 |
|
|
PTD_delete (); |
369 |
|
|
agent_flush_cache (); |
370 |
twoaday |
174 |
html_help_deinit (cookie); |
371 |
werner |
36 |
if (!gpg_clip_istext_avail (&has_data) && has_data) { |
372 |
|
|
int chk = get_reg_winpt_flag ("WipeClipboard"); |
373 |
twoaday |
78 |
if (chk == -1 && msg != WM_ENDSESSION) |
374 |
werner |
36 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CONFDELCLIP, |
375 |
|
|
GetDesktopWindow (), confirm_delclipboard_dlg, |
376 |
twoaday |
68 |
0); |
377 |
werner |
36 |
if (wipe_contents || chk) |
378 |
|
|
set_clip_text (NULL, " ", 1); |
379 |
|
|
wipe_contents = 0; |
380 |
|
|
} |
381 |
|
|
debug_end (); |
382 |
|
|
Shell_NotifyIcon (NIM_DELETE, &NID); |
383 |
|
|
PostQuitMessage (0); |
384 |
|
|
ExitProcess (0); |
385 |
twoaday |
72 |
break; |
386 |
werner |
36 |
|
387 |
|
|
case WM_USER: |
388 |
|
|
switch (lparam) { |
389 |
|
|
case WM_RBUTTONUP: |
390 |
|
|
HMENU hm, popup; |
391 |
|
|
POINT p; |
392 |
|
|
|
393 |
|
|
gpg_read_only = gpg_check_permissions (0) == 0? 0 : 1; |
394 |
|
|
|
395 |
|
|
SetForegroundWindow (hwnd); |
396 |
|
|
GetCursorPos (&p); |
397 |
|
|
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT)); |
398 |
|
|
popup = GetSubMenu (hm, 0); |
399 |
twoaday |
72 |
|
400 |
werner |
36 |
set_menu_text( popup, ID_WINPT_FILE, _("File Manager") ); |
401 |
|
|
set_menu_text( popup, ID_WINPT_KEY, _("Key Manager") ); |
402 |
|
|
set_menu_text( popup, ID_WINPT_CARD, _("Card Manager") ); |
403 |
|
|
if (!scard_support) |
404 |
|
|
set_menu_state (popup, ID_WINPT_CARD, MF_DISABLED|MF_GRAYED); |
405 |
twoaday |
185 |
/* |
406 |
werner |
36 |
if (!cryptdisk_available ()) { |
407 |
|
|
set_menu_state (popup, ID_WINPT_CDISKNEW, MF_DISABLED|MF_GRAYED); |
408 |
|
|
set_menu_state (popup, ID_WINPT_CDISKMOUNT, MF_DISABLED|MF_GRAYED); |
409 |
|
|
set_menu_state (popup, ID_WINPT_CDISKUNMOUNT, MF_DISABLED|MF_GRAYED); |
410 |
|
|
} |
411 |
twoaday |
185 |
*/ |
412 |
werner |
36 |
|
413 |
|
|
set_menu_text (popup, ID_WINPT_EDIT, _("Edit Clipboard")); |
414 |
|
|
set_menu_text (popup, ID_WINPT_ABOUT, _("About...")); |
415 |
|
|
set_menu_text (popup, ID_WINPT_QUIT, _("Exit")); |
416 |
|
|
set_menu_text (popup, ID_WINPT_SYMENC, _("Symmetric")); |
417 |
|
|
set_menu_text (popup, ID_WINPT_ENCRYPT, _("Encrypt")); |
418 |
twoaday |
72 |
set_menu_text (popup, ID_WINPT_SIGN, _("Sign")); |
419 |
werner |
36 |
set_menu_text (popup, ID_WINPT_SIGNENCRYPT, _("Sign && Encrypt")); |
420 |
|
|
set_menu_text (popup, ID_WINPT_DECRYPT, _("Decrypt/Verify")); |
421 |
|
|
set_menu_text (popup, ID_WINPT_VERIFY, _("Verify")); |
422 |
|
|
set_menu_text (popup, ID_WINPT_CURRWND_ENCRYPT, _("Encrypt")); |
423 |
|
|
set_menu_text (popup, ID_WINPT_CURRWND_SIGNENCRYPT, _("Sign && Encrypt")); |
424 |
|
|
set_menu_text (popup, ID_WINPT_CURRWND_DECRYPT_VERIFY, _("Decrypt/Verify")); |
425 |
|
|
set_menu_text (popup, ID_WINPT_CURRWND_SIGN, _("Sign")); |
426 |
twoaday |
72 |
if (!secret_key_available ()) { |
427 |
|
|
set_menu_state (popup, ID_WINPT_SIGN, MF_DISABLED|MF_GRAYED); |
428 |
|
|
set_menu_state (popup, ID_WINPT_CURRWND_SIGN, MF_DISABLED|MF_GRAYED); |
429 |
|
|
set_menu_state (popup, ID_WINPT_SIGNENCRYPT, MF_DISABLED|MF_GRAYED); |
430 |
|
|
set_menu_state (popup, ID_WINPT_CURRWND_SIGNENCRYPT, MF_DISABLED|MF_GRAYED); |
431 |
|
|
} |
432 |
werner |
36 |
/* change popup texts */ |
433 |
|
|
set_menu_text_bypos (popup, 6, _("Clipboard")); |
434 |
|
|
set_menu_text_bypos (popup, 7, _("Current Window")); |
435 |
|
|
set_menu_text_bypos (popup, 9, _("Preferences")); |
436 |
|
|
|
437 |
twoaday |
72 |
TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, hwnd, NULL); |
438 |
|
|
PostMessage (hwnd, WM_USER, 0, 0); |
439 |
|
|
DestroyMenu (popup); |
440 |
|
|
DestroyMenu (hm); |
441 |
werner |
36 |
break; |
442 |
|
|
|
443 |
|
|
case WM_LBUTTONDBLCLK: |
444 |
twoaday |
78 |
gpg_read_only = gpg_check_permissions (0) == 0? 0 : 1; |
445 |
|
|
SendMessage (hwnd, WM_COMMAND, ID_WINPT_KEY, 0); |
446 |
werner |
36 |
break; |
447 |
|
|
} |
448 |
|
|
break; |
449 |
|
|
|
450 |
|
|
case WM_HOTKEY: |
451 |
|
|
cmd = 0; |
452 |
|
|
switch( wparam ) { |
453 |
|
|
case WPT_CLIP_ENCRYPT_ID: |
454 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_ENCRYPT, 0 ); |
455 |
|
|
break; |
456 |
|
|
|
457 |
|
|
case WPT_CLIP_DECRYPT_VERIFY_ID: |
458 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_DECRYPT_VERIFY, 0 ); |
459 |
|
|
break; |
460 |
|
|
|
461 |
|
|
case WPT_CLIP_SIGN_ID: |
462 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_SIGN, 0 ); |
463 |
|
|
break; |
464 |
|
|
|
465 |
|
|
case WPT_CLIP_SIGN_ENCRYPT_ID: |
466 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_SIGNENCRYPT, 0 ); |
467 |
|
|
break; |
468 |
|
|
|
469 |
|
|
case WPT_CURRWND_ENCRYPT_ID: |
470 |
|
|
use_hotkey = 1; |
471 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_CURRWND_ENCRYPT, 0 ); |
472 |
|
|
break; |
473 |
|
|
|
474 |
|
|
case WPT_CURRWND_SIGN_ID: |
475 |
|
|
use_hotkey = 1; |
476 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_CURRWND_SIGN, 0 ); |
477 |
|
|
break; |
478 |
|
|
|
479 |
|
|
case WPT_CURRWND_SIGN_ENCRYPT_ID: |
480 |
|
|
use_hotkey = 1; |
481 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_CURRWND_SIGNENCRYPT, 0 ); |
482 |
|
|
break; |
483 |
|
|
|
484 |
|
|
case WPT_CURRWND_DECRYPT_VERIFY_ID: |
485 |
|
|
use_hotkey = 1; |
486 |
|
|
SendMessage( hwnd, WM_COMMAND, ID_WINPT_CURRWND_DECRYPT_VERIFY, 0 ); |
487 |
|
|
break; |
488 |
|
|
|
489 |
|
|
case WPT_AGENT_FORGET_ID: |
490 |
|
|
rc = msg_box( hwnd, _("Remove all passphrases from cache?"), |
491 |
|
|
_("WinPT"), MB_YESNO|MB_ICONQUESTION ); |
492 |
|
|
if( rc == IDYES ) |
493 |
|
|
agent_flush_cache(); |
494 |
|
|
break; |
495 |
|
|
} |
496 |
|
|
break; |
497 |
|
|
|
498 |
|
|
case WM_COMMAND: |
499 |
|
|
if( gnupg_access_keyring( 1 ) ) { |
500 |
|
|
if( log_box( "WinPT", MB_ERR|MB_YESNO, |
501 |
|
|
_("Could not access public keyring, exit WinPT?") ) == IDYES ) |
502 |
|
|
SendMessage( hwnd, WM_DESTROY, 0, 0 ); |
503 |
|
|
break; |
504 |
|
|
} |
505 |
|
|
switch( wparam ) { |
506 |
|
|
/** Clipboard operations **/ |
507 |
|
|
case ID_WINPT_SYMENC: |
508 |
|
|
case ID_WINPT_ENCRYPT: |
509 |
|
|
case ID_WINPT_SIGN: |
510 |
|
|
case ID_WINPT_SIGNENCRYPT: |
511 |
|
|
case ID_WINPT_DECRYPT_VERIFY: |
512 |
|
|
err = gpg_clip_istext_avail( &has_data ); |
513 |
|
|
if( err ) { |
514 |
|
|
msg_box( hwnd, gpgme_strerror( err ),_("Clipboard"), MB_ERR ); |
515 |
|
|
break; |
516 |
|
|
} |
517 |
|
|
if( !has_data ) { |
518 |
|
|
msg_box( hwnd, winpt_strerror (WPTERR_CLIP_EMPTY),_("Clipboard"), MB_ERR ); |
519 |
|
|
break; |
520 |
|
|
} |
521 |
twoaday |
129 |
clip_gpg_dlg (hwnd, (int)wparam); |
522 |
werner |
36 |
break; |
523 |
|
|
|
524 |
|
|
/** Current window operations **/ |
525 |
|
|
case ID_WINPT_CURRWND_SYMENC: |
526 |
|
|
case ID_WINPT_CURRWND_ENCRYPT: |
527 |
|
|
case ID_WINPT_CURRWND_SIGNENCRYPT: |
528 |
|
|
case ID_WINPT_CURRWND_DECRYPT_VERIFY: |
529 |
|
|
case ID_WINPT_CURRWND_SIGN: |
530 |
|
|
rc = get_window_contents( hwnd, &currwnd, &use_hotkey ); |
531 |
|
|
if( rc ) { |
532 |
|
|
log_box( _("WinPT Error"), MB_ERR, |
533 |
|
|
_("Make sure that the window contains text.\n" |
534 |
|
|
"%s."), |
535 |
|
|
winpt_strerror( WPTERR_CURR_WND ) ); |
536 |
|
|
break; |
537 |
|
|
} |
538 |
twoaday |
129 |
rc = currwnd_gpg_dlg (hwnd, (UINT)wparam, &set_wc); |
539 |
|
|
if (!rc && set_wc) |
540 |
|
|
set_window_contents (hwnd, &currwnd); |
541 |
werner |
36 |
break; |
542 |
|
|
|
543 |
|
|
/** File handling **/ |
544 |
|
|
case ID_WINPT_FILE: |
545 |
twoaday |
139 |
s = _("File Manager (use drag & drop to add files)"); |
546 |
|
|
wnd = FindWindow (NULL, s); |
547 |
|
|
if (wnd && IsIconic (wnd)) |
548 |
|
|
ShowWindow (wnd, SW_RESTORE); |
549 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_FILE, |
550 |
|
|
GetDesktopWindow (), file_manager_dlg_proc, 0, |
551 |
|
|
s, IDS_WINPT_FILE); |
552 |
werner |
36 |
break; |
553 |
|
|
|
554 |
|
|
/** Misc **/ |
555 |
|
|
case ID_WINPT_KEY: |
556 |
twoaday |
139 |
wnd = FindWindow (NULL, _("Key Manager")); |
557 |
|
|
if (wnd && IsIconic (wnd)) |
558 |
|
|
ShowWindow (wnd, SW_RESTORE); |
559 |
twoaday |
180 |
if (wnd) |
560 |
|
|
SetForegroundWindow (wnd); |
561 |
twoaday |
73 |
param = 0; |
562 |
twoaday |
139 |
if (cmd) |
563 |
werner |
36 |
param = (LPARAM)cmd; |
564 |
twoaday |
139 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC, |
565 |
werner |
36 |
GetDesktopWindow(), keymanager_dlg_proc, param, |
566 |
twoaday |
139 |
_("Key Manager"), IDS_WINPT_KEYMISC); |
567 |
werner |
36 |
cmd = 0; |
568 |
|
|
break; |
569 |
|
|
|
570 |
|
|
case ID_WINPT_CARD: |
571 |
twoaday |
121 |
load_card_manager (); |
572 |
werner |
36 |
break; |
573 |
|
|
|
574 |
|
|
case ID_WINPT_EDIT: |
575 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_CLIPEDIT, |
576 |
twoaday |
68 |
GetDesktopWindow(), clip_edit_dlg_proc, 0, |
577 |
werner |
36 |
_("Clipboard Editor"), IDS_WINPT_CLIPEDIT ); |
578 |
|
|
break; |
579 |
|
|
|
580 |
|
|
case ID_WINPT_ABOUT: |
581 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_ABOUT, GetDesktopWindow(), |
582 |
twoaday |
68 |
about_winpt_dlg_proc, 0, |
583 |
werner |
36 |
_("About WinPT"), IDS_WINPT_ABOUT ); |
584 |
|
|
break; |
585 |
|
|
|
586 |
|
|
case ID_WINPT_PREFS: |
587 |
|
|
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_PREFS, GetDesktopWindow(), |
588 |
twoaday |
68 |
prefs_dlg_proc, 0, |
589 |
werner |
36 |
_("WinPT Preferences"), IDS_WINPT_PREFS ); |
590 |
|
|
break; |
591 |
|
|
|
592 |
|
|
case ID_WINPT_GPGPREFS: |
593 |
|
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, GetDesktopWindow(), |
594 |
twoaday |
68 |
gpgprefs_dlg_proc, 0, |
595 |
werner |
36 |
_("GnuPG Preferences"), IDS_WINPT_GPGPREFS); |
596 |
|
|
break; |
597 |
|
|
|
598 |
twoaday |
185 |
/* |
599 |
werner |
36 |
case ID_WINPT_CDISKNEW: |
600 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CDISK_NEW, |
601 |
twoaday |
68 |
GetDesktopWindow (), cryptdisk_new_dlg_proc, 0); |
602 |
werner |
36 |
break; |
603 |
|
|
|
604 |
|
|
case ID_WINPT_CDISKMOUNT: |
605 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CDISK_MOUNT, |
606 |
twoaday |
68 |
GetDesktopWindow (), cryptdisk_mount_dlg_proc, 0); |
607 |
werner |
36 |
break; |
608 |
|
|
|
609 |
|
|
case ID_WINPT_CDISKUNMOUNT: |
610 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CDISK_UMOUNT, |
611 |
twoaday |
68 |
GetDesktopWindow (), cryptdisk_umount_dlg_proc, 0); |
612 |
werner |
36 |
break; |
613 |
|
|
|
614 |
|
|
case ID_WINPT_CDISKUMOUNTALL: |
615 |
|
|
cryptdisk_unmount (0, 0); |
616 |
|
|
break; |
617 |
twoaday |
185 |
*/ |
618 |
werner |
36 |
|
619 |
|
|
case ID_WINPT_QUIT: |
620 |
|
|
SendMessage (hwnd, WM_DESTROY, 0, 0); |
621 |
|
|
break; |
622 |
|
|
} |
623 |
|
|
break; |
624 |
|
|
} |
625 |
|
|
|
626 |
|
|
return DefWindowProc (hwnd, msg, wparam, lparam); |
627 |
|
|
} |