1 |
/* wptMainProc.cpp - Main window procedure |
/* wptMainProc.cpp - Main window procedure |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
44 |
#include "wptCard.h" |
#include "wptCard.h" |
45 |
#include "wptCryptdisk.h" |
#include "wptCryptdisk.h" |
46 |
#include "wptCardEdit.h" |
#include "wptCardEdit.h" |
|
#include "wptCrypto.h" |
|
47 |
|
|
|
extern HWND activ_hwnd; |
|
48 |
static int cmd = 0; |
static int cmd = 0; |
49 |
static int wipe_contents = 0; |
static int wipe_contents = 0; |
50 |
|
|
85 |
} |
} |
86 |
|
|
87 |
|
|
|
/* @unused |
|
|
static int |
|
|
cleanup_tmp_files (void) |
|
|
{ |
|
|
struct _finddata_t dat; |
|
|
char tmp[384]; |
|
|
long hd; |
|
|
|
|
|
if (GetTempPath (sizeof (tmp)-1, tmp) == FALSE || |
|
|
SetCurrentDirectory (tmp) == FALSE) { |
|
|
winpt_errmsg ("GetTempPath", 0); |
|
|
return WPTERR_GENERAL; |
|
|
} |
|
|
hd = _findfirst ("gpgmeOUT*", &dat); |
|
|
if (hd == -1) |
|
|
return 0; |
|
|
do { |
|
|
secure_unlink (dat.name, WIPE_MODE_SIMPLE); |
|
|
} while (_findnext (hd, &dat) == 0); |
|
|
_findclose (hd); |
|
|
return 0; |
|
|
} |
|
|
*/ |
|
|
|
|
|
|
|
88 |
/* Dialog box procedure to confirm to delete the clipboard contents. */ |
/* Dialog box procedure to confirm to delete the clipboard contents. */ |
89 |
static BOOL CALLBACK |
static BOOL CALLBACK |
90 |
confirm_delclipboard_dlg (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
confirm_delclipboard_dlg (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
94 |
SetWindowText (dlg, _("Delete Clipboard Contents")); |
SetWindowText (dlg, _("Delete Clipboard Contents")); |
95 |
SetDlgItemText (dlg, IDC_CONFDELCLIP_BRAIN, _("&Remember the answer")); |
SetDlgItemText (dlg, IDC_CONFDELCLIP_BRAIN, _("&Remember the answer")); |
96 |
SetDlgItemText (dlg, IDC_CONFDELCLIP_INFO, _("Do you want to delete the contents from the clipboard?")); |
SetDlgItemText (dlg, IDC_CONFDELCLIP_INFO, _("Do you want to delete the contents from the clipboard?")); |
97 |
|
SetDlgItemText (dlg, IDYES, _("&Yes")); |
98 |
|
SetDlgItemText (dlg, IDNO, _("&No")); |
99 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
100 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
101 |
break; |
break; |
172 |
} |
} |
173 |
} |
} |
174 |
else if ((type & PGP_PUBKEY) && !(type & PGP_CLEARSIG)) |
else if ((type & PGP_PUBKEY) && !(type & PGP_CLEARSIG)) |
175 |
km_clip_import (GetDesktopWindow ()); |
km_clip_import (GetDesktopWindow (), NULL, NULL); |
176 |
else { |
else { |
177 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd, |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd, |
178 |
clip_verify_dlg_proc, 0, |
clip_verify_dlg_proc, 0, |
179 |
_("Verify"), IDS_WINPT_VERIFY ); |
_("Verify"), IDS_WINPT_VERIFY ); |
180 |
err = gpg_error (GPG_ERR_EOF); /* make sure window is ot updated. */ |
err = gpg_error (GPG_ERR_EOF); /* make sure window is not updated. */ |
181 |
} |
} |
182 |
break; |
break; |
183 |
} |
} |
192 |
gpgme_error_t err; |
gpgme_error_t err; |
193 |
int type; |
int type; |
194 |
|
|
195 |
if( (id == ID_WINPT_SIGN || id == ID_WINPT_SIGNENCRYPT) |
if ((id == ID_WINPT_SIGN || id == ID_WINPT_SIGNENCRYPT) |
196 |
&& gnupg_access_keyring (0) ) { |
&& gnupg_access_keyring (0)) { |
197 |
msg_box( hwnd, _("Could not access secret keyring."), _("Sign"), MB_ERR ); |
msg_box (hwnd, _("Could not access secret keyring."), _("Sign"), MB_ERR); |
198 |
return; |
return; |
199 |
} |
} |
200 |
|
|
201 |
switch( id ) { |
switch( id ) { |
202 |
case ID_WINPT_SYMENC: |
case ID_WINPT_SYMENC: |
203 |
gpg_encrypt_symmetric(); |
gpg_encrypt_symmetric (); |
204 |
break; |
break; |
205 |
|
|
206 |
case ID_WINPT_ENCRYPT: |
case ID_WINPT_ENCRYPT: |
265 |
_("Verify"), IDS_WINPT_VERIFY ); |
_("Verify"), IDS_WINPT_VERIFY ); |
266 |
} |
} |
267 |
else if ((type & PGP_PUBKEY) || (type & PGP_SECKEY)) |
else if ((type & PGP_PUBKEY) || (type & PGP_SECKEY)) |
268 |
km_clip_import (GetDesktopWindow ()); |
km_clip_import (GetDesktopWindow (), NULL, NULL); |
269 |
else |
else |
270 |
msg_box (hwnd, _("Unknown OpenPGP type."), _("Clipboard"), MB_ERR); |
msg_box (hwnd, _("Unknown OpenPGP type."), _("Clipboard"), MB_ERR); |
271 |
} |
} |
284 |
|
|
285 |
/* Load the Card Manager with the current card. */ |
/* Load the Card Manager with the current card. */ |
286 |
static void |
static void |
287 |
load_smartcard (void) |
load_card_manager (void) |
288 |
{ |
{ |
289 |
gpg_card_t card; |
gpg_card_t card; |
290 |
|
|
294 |
GetDesktopWindow (), card_edit_dlg_proc, |
GetDesktopWindow (), card_edit_dlg_proc, |
295 |
(LPARAM)card, |
(LPARAM)card, |
296 |
_("Card Edit"), IDS_WINPT_CARD_EDIT); |
_("Card Edit"), IDS_WINPT_CARD_EDIT); |
297 |
gpg_card_release (card); |
gpg_card_release (card); |
|
card = NULL; |
|
298 |
} |
} |
299 |
} |
} |
300 |
|
|
319 |
winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
320 |
{ |
{ |
321 |
static NOTIFYICONDATA NID; |
static NOTIFYICONDATA NID; |
322 |
static int use_hotkey = 0; |
static DWORD cookie; |
323 |
reminder_ctx_s ctx; |
static int use_hotkey = 0; |
|
LPARAM param; |
|
|
curr_wnd_ctx currwnd = {0}; |
|
|
int rc, set_wc = 0, has_data = 0; |
|
324 |
INITCOMMONCONTROLSEX cce; |
INITCOMMONCONTROLSEX cce; |
325 |
|
LPARAM param; |
326 |
|
HWND wnd; |
327 |
gpgme_error_t err; |
gpgme_error_t err; |
328 |
|
curr_wnd_ctx currwnd = {0}; |
329 |
|
const char *s; |
330 |
|
int rc, set_wc = 0, has_data = 0; |
331 |
|
|
332 |
switch (msg) { |
switch (msg) { |
333 |
case WM_CREATE: |
case WM_CREATE: |
349 |
cce.dwSize = sizeof (INITCOMMONCONTROLSEX); |
cce.dwSize = sizeof (INITCOMMONCONTROLSEX); |
350 |
cce.dwICC = ICC_DATE_CLASSES; |
cce.dwICC = ICC_DATE_CLASSES; |
351 |
InitCommonControlsEx (&cce); |
InitCommonControlsEx (&cce); |
352 |
|
html_help_init (&cookie); |
353 |
LoadLibrary ("RichEd32.Dll"); |
LoadLibrary ("RichEd32.Dll"); |
354 |
break; |
break; |
355 |
|
|
365 |
free_reg_prefs (); |
free_reg_prefs (); |
366 |
free_gnupg_table (); |
free_gnupg_table (); |
367 |
hotkeys_unregister (hwnd); |
hotkeys_unregister (hwnd); |
|
release_file_lock (&mo_file); |
|
368 |
PTD_delete (); |
PTD_delete (); |
369 |
agent_flush_cache (); |
agent_flush_cache (); |
370 |
|
html_help_deinit (cookie); |
371 |
if (!gpg_clip_istext_avail (&has_data) && has_data) { |
if (!gpg_clip_istext_avail (&has_data) && has_data) { |
372 |
int chk = get_reg_winpt_flag ("WipeClipboard"); |
int chk = get_reg_winpt_flag ("WipeClipboard"); |
373 |
if (chk == -1 && msg != WM_ENDSESSION) |
if (chk == -1 && msg != WM_ENDSESSION) |
379 |
wipe_contents = 0; |
wipe_contents = 0; |
380 |
} |
} |
381 |
debug_end (); |
debug_end (); |
|
/*cleanup_tmp_files ();*/ |
|
382 |
Shell_NotifyIcon (NIM_DELETE, &NID); |
Shell_NotifyIcon (NIM_DELETE, &NID); |
383 |
PostQuitMessage (0); |
PostQuitMessage (0); |
384 |
ExitProcess (0); |
ExitProcess (0); |
516 |
msg_box( hwnd, winpt_strerror (WPTERR_CLIP_EMPTY),_("Clipboard"), MB_ERR ); |
msg_box( hwnd, winpt_strerror (WPTERR_CLIP_EMPTY),_("Clipboard"), MB_ERR ); |
517 |
break; |
break; |
518 |
} |
} |
519 |
ctx.msecs = 500; |
clip_gpg_dlg (hwnd, (int)wparam); |
|
window_reminder( &ctx ); |
|
|
clip_gpg_dlg( hwnd, (int)wparam ); |
|
520 |
break; |
break; |
521 |
|
|
522 |
/** Current window operations **/ |
/** Current window operations **/ |
533 |
winpt_strerror( WPTERR_CURR_WND ) ); |
winpt_strerror( WPTERR_CURR_WND ) ); |
534 |
break; |
break; |
535 |
} |
} |
536 |
ctx.msecs = 500; |
rc = currwnd_gpg_dlg (hwnd, (UINT)wparam, &set_wc); |
537 |
window_reminder( &ctx ); |
if (!rc && set_wc) |
538 |
rc = currwnd_gpg_dlg( hwnd, (UINT)wparam, &set_wc ); |
set_window_contents (hwnd, &currwnd); |
|
if( !rc && set_wc ) |
|
|
set_window_contents( hwnd, &currwnd ); |
|
539 |
break; |
break; |
540 |
|
|
541 |
/** File handling **/ |
/** File handling **/ |
542 |
case ID_WINPT_FILE: |
case ID_WINPT_FILE: |
543 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_FILE, |
s = _("File Manager (use drag & drop to add files)"); |
544 |
GetDesktopWindow(), file_manager_dlg_proc, 0, |
wnd = FindWindow (NULL, s); |
545 |
_("File Manager (use drag & drop to add files)"), IDS_WINPT_FILE ); |
if (wnd && IsIconic (wnd)) |
546 |
|
ShowWindow (wnd, SW_RESTORE); |
547 |
|
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_FILE, |
548 |
|
GetDesktopWindow (), file_manager_dlg_proc, 0, |
549 |
|
s, IDS_WINPT_FILE); |
550 |
break; |
break; |
551 |
|
|
552 |
/** Misc **/ |
/** Misc **/ |
553 |
case ID_WINPT_KEY: |
case ID_WINPT_KEY: |
554 |
|
wnd = FindWindow (NULL, _("Key Manager")); |
555 |
|
if (wnd && IsIconic (wnd)) |
556 |
|
ShowWindow (wnd, SW_RESTORE); |
557 |
|
if (wnd) |
558 |
|
SetForegroundWindow (wnd); |
559 |
param = 0; |
param = 0; |
560 |
if( cmd ) |
if (cmd) |
561 |
param = (LPARAM)cmd; |
param = (LPARAM)cmd; |
562 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC, |
563 |
GetDesktopWindow(), keymanager_dlg_proc, param, |
GetDesktopWindow(), keymanager_dlg_proc, param, |
564 |
_("Key Manager"), IDS_WINPT_KEYMISC ); |
_("Key Manager"), IDS_WINPT_KEYMISC); |
565 |
cmd = 0; |
cmd = 0; |
566 |
break; |
break; |
567 |
|
|
568 |
case ID_WINPT_CARD: |
case ID_WINPT_CARD: |
569 |
load_smartcard (); |
load_card_manager (); |
570 |
break; |
break; |
571 |
|
|
572 |
case ID_WINPT_EDIT: |
case ID_WINPT_EDIT: |