20 |
|
|
21 |
#include <windows.h> |
#include <windows.h> |
22 |
#include <commctrl.h> |
#include <commctrl.h> |
23 |
|
#include <sys/stat.h> |
24 |
|
|
25 |
#include "../resource.h" |
#include "../resource.h" |
26 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
36 |
#include "wptFileManager.h" |
#include "wptFileManager.h" |
37 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
38 |
|
|
39 |
|
#define FM_SEPARATOR_ID 10001 |
40 |
|
|
41 |
#define send_cmd_id(hwnd, id) \ |
#define send_cmd_id(hwnd, id) \ |
42 |
PostMessage( (hwnd), WM_COMMAND, MAKEWPARAM( (id), 0), 0 ) |
PostMessage( (hwnd), WM_COMMAND, MAKEWPARAM( (id), 0), 0 ) |
43 |
|
|
46 |
struct thread_ctx_s { |
struct thread_ctx_s { |
47 |
HWND dlg; |
HWND dlg; |
48 |
HANDLE fd; |
HANDLE fd; |
49 |
char * drive; |
char *drive; |
50 |
}; |
}; |
51 |
typedef struct thread_ctx_s * thread_ctx_t; |
typedef struct thread_ctx_s *thread_ctx_t; |
52 |
|
|
53 |
|
|
54 |
/* Dialog procedure for selecting recipients for encryption. */ |
/* Dialog procedure for selecting recipients for encryption. */ |
59 |
static fm_state_t c; |
static fm_state_t c; |
60 |
static int req_signer = 0; |
static int req_signer = 0; |
61 |
static keylist_t list = NULL; |
static keylist_t list = NULL; |
62 |
gpgme_keycache_t kc; |
gpg_keycache_t kc; |
63 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
64 |
int force_trust = 0, count = 0; |
int force_trust = 0, count = 0; |
65 |
|
|
131 |
ctx = c->ctx; |
ctx = c->ctx; |
132 |
if (c->recp) |
if (c->recp) |
133 |
free (c->recp); |
free (c->recp); |
134 |
c->recp = keylist_get_recipients (lv, &force_trust, &count); |
c->recp = keylist_get_recipients (lv, &force_trust, &c->n_recp); |
135 |
if (!count) { |
if (!c->n_recp) { |
136 |
msg_box (dlg, _("Please select at least one recipient."), |
msg_box (dlg, _("Please select at least one recipient."), |
137 |
_("File Encrypt"), MB_ERR); |
_("File Encrypt"), MB_ERR); |
138 |
free (c->recp); |
free (c->recp); |
186 |
if (!c) |
if (!c) |
187 |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
188 |
#ifndef LANG_DE |
#ifndef LANG_DE |
189 |
SetWindowText (dlg, _("File Import")); |
SetWindowText (dlg, _("Key Import")); |
190 |
#endif |
#endif |
191 |
ShowWindow( GetDlgItem( dlg, IDC_IMPORT_KEYMNGT ), WS_DISABLED ); |
ShowWindow( GetDlgItem( dlg, IDC_IMPORT_KEYMNGT ), WS_DISABLED ); |
192 |
/* XXX: use the new code */ |
/* XXX: use the new code */ |
193 |
implist_build (&lv, GetDlgItem( dlg, IDC_IMPORT_KEYLIST)); |
implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST)); |
194 |
implist_load (lv, c->opaque, &is_revcert, &has_seckeys); |
implist_load (lv, c->opaque, &is_revcert, &has_seckeys); |
195 |
if (!listview_count_items (lv, 0)) { |
if (!listview_count_items (lv, 0)) { |
196 |
msg_box (dlg, _("No valid OpenPGP data found."), _("File Import"), MB_ERR); |
msg_box (dlg, _("No valid OpenPGP data found."), _("Key Import"), MB_ERR); |
197 |
c->cancel = 1; |
c->cancel = 1; |
198 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
199 |
} |
} |
200 |
else { |
else { |
|
/* XXX: add more information (public keys, secret key...) */ |
|
201 |
const char *s = "File contain(s) %d key(s)."; |
const char *s = "File contain(s) %d key(s)."; |
202 |
char *p = new char[strlen (s) + 32]; |
char *p = new char[strlen (s) + 32]; |
203 |
if (!p) |
if (!p) |
217 |
return FALSE; |
return FALSE; |
218 |
|
|
219 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
220 |
if( LOWORD( wparam ) == SC_CLOSE ) { |
if (LOWORD (wparam) == SC_CLOSE) { |
221 |
c->cancel = 1; |
c->cancel = 1; |
222 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
223 |
} |
} |
224 |
return FALSE; |
return FALSE; |
225 |
|
|
226 |
case WM_COMMAND: |
case WM_COMMAND: |
227 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
228 |
case IDC_IMPORT_DOIT: |
case IDC_IMPORT_DOIT: |
229 |
c->cancel = 0; |
c->cancel = 0; |
230 |
c->implist_revcert = is_revcert? 1 : 0; |
c->import.revcert = is_revcert? 1 : 0; |
231 |
EndDialog( dlg, TRUE ); |
c->import.has_seckey = has_seckeys? 1 : 0; |
232 |
|
EndDialog (dlg, TRUE); |
233 |
return TRUE; |
return TRUE; |
234 |
|
|
235 |
case IDCANCEL: |
case IDCANCEL: |
236 |
c->cancel = 1; |
c->cancel = 1; |
237 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
238 |
return FALSE; |
return FALSE; |
239 |
} |
} |
240 |
break; |
break; |
249 |
{ |
{ |
250 |
static fm_state_t c; |
static fm_state_t c; |
251 |
static listview_ctrl_t lv; |
static listview_ctrl_t lv; |
252 |
gpgme_keycache_t kc, sec_kc; |
gpg_keycache_t kc, sec_kc; |
253 |
gpgme_key_t key; |
gpgme_key_t key; |
254 |
int lv_idx; |
int lv_idx; |
255 |
char signer[32]; |
char signer[32]; |
340 |
|
|
341 |
|
|
342 |
|
|
343 |
BOOL CALLBACK |
static BOOL CALLBACK |
344 |
filelist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
filelist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
345 |
{ |
{ |
346 |
switch (msg) |
switch (msg) { |
|
{ |
|
347 |
case WM_KEYUP: |
case WM_KEYUP: |
348 |
int virt_key = (int)wparam; |
int virt_key = (int)wparam; |
349 |
if (virt_key == VK_DELETE) |
if (virt_key == VK_DELETE) |
354 |
} |
} |
355 |
|
|
356 |
|
|
357 |
|
/* Setup status bar for the main window @dlg. */ |
358 |
|
static HWND |
359 |
|
setup_status_bar (HWND dlg) |
360 |
|
{ |
361 |
|
HWND statbar; |
362 |
|
RECT r; |
363 |
|
int partpos[3]; |
364 |
|
int i; |
365 |
|
|
366 |
|
GetClientRect (dlg, &r); |
367 |
|
for (i=1; i <= 3; i++) |
368 |
|
partpos[i-1] = r.right/3*i; |
369 |
|
|
370 |
|
statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM, |
371 |
|
"", dlg, FM_SEPARATOR_ID); |
372 |
|
ShowWindow (statbar, SW_SHOW); |
373 |
|
SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos); |
374 |
|
return statbar; |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
|
/* Refresh the status bar text with the selected item from @lv. */ |
379 |
|
static void |
380 |
|
update_status_bar (HWND statbar, listview_ctrl_t lv) |
381 |
|
{ |
382 |
|
struct stat st; |
383 |
|
char buf[128]; |
384 |
|
int n = listview_count_items (lv, 1); |
385 |
|
_snprintf (buf, sizeof (buf)-1, "%d Object(s) marked", n); |
386 |
|
SendMessage (statbar, SB_SETTEXT, 0, (LPARAM)buf); |
387 |
|
listview_get_item_text (lv, listview_get_curr_pos (lv), 1, buf, 127); |
388 |
|
if (stat (buf, &st) == 0) { |
389 |
|
_snprintf (buf, sizeof (buf)-1, "%d KB", st.st_size/1024); |
390 |
|
SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)buf); |
391 |
|
} |
392 |
|
} |
393 |
|
|
394 |
|
|
395 |
BOOL CALLBACK |
BOOL CALLBACK |
396 |
file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
397 |
{ |
{ |
398 |
|
static HWND statbar; |
399 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
400 |
static HMENU menu = NULL; |
static HMENU menu = NULL; |
401 |
static int always_ontop = 1; |
static int always_ontop = 1; |
402 |
HWND fl; |
HWND fl; |
403 |
|
|
404 |
switch (msg) |
switch (msg) { |
|
{ |
|
405 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
406 |
always_ontop = 1; |
always_ontop = 1; |
407 |
menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC); |
menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC); |
408 |
SetWindowText( dlg, _("File Manager (use drag & drop to add files)") ); |
SetWindowText (dlg, _("File Manager (use drag & drop to add files)")); |
409 |
set_menu_text( menu, ID_FILEMISC_OPEN, _("&Open...") ); |
set_menu_text (menu, ID_FILEMISC_OPEN, _("&Open...") ); |
410 |
set_menu_text( menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") ); |
set_menu_text (menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") ); |
411 |
set_menu_text( menu, ID_FILEMISC_DECRYPT, _("&Decrypt") ); |
set_menu_text (menu, ID_FILEMISC_DECRYPT, _("&Decrypt") ); |
412 |
set_menu_text( menu, ID_FILEMISC_SIGN, _("&Sign") ); |
set_menu_text (menu, ID_FILEMISC_SIGN, _("&Sign") ); |
413 |
set_menu_text( menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") ); |
set_menu_text (menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") ); |
414 |
set_menu_text( menu, ID_FILEMISC_VERIFY, _("&Verify") ); |
set_menu_text (menu, ID_FILEMISC_VERIFY, _("&Verify") ); |
415 |
set_menu_text( menu, ID_FILEMISC_WIPE, _("&Wipe") ); |
set_menu_text (menu, ID_FILEMISC_WIPE, _("&Wipe") ); |
416 |
set_menu_text( menu, ID_FILEMISC_SYMENC, _("S&ymmetric") ); |
set_menu_text (menu, ID_FILEMISC_SYMENC, _("S&ymmetric") ); |
417 |
set_menu_text( menu, ID_FILEMISC_IMPORT, _("&Import") ); |
set_menu_text (menu, ID_FILEMISC_IMPORT, _("&Import") ); |
418 |
set_menu_text( menu, ID_FILEMISC_EXPORT, _("E&xport") ); |
set_menu_text (menu, ID_FILEMISC_EXPORT, _("E&xport") ); |
419 |
set_menu_text( menu, ID_FILEMISC_QUIT, _("Exit")); |
set_menu_text (menu, ID_FILEMISC_QUIT, _("Exit")); |
420 |
set_menu_text( menu, ID_FILEMISC_PREFS, _("Preferences") ); |
set_menu_text (menu, ID_FILEMISC_PREFS, _("Preferences") ); |
421 |
set_menu_text( menu, ID_FILEMISC_CLEAR, _("&Reset") ); |
set_menu_text (menu, ID_FILEMISC_CLEAR, _("&Reset") ); |
422 |
fl = GetDlgItem (dlg, IDC_FILE_LIST); |
fl = GetDlgItem (dlg, IDC_FILE_LIST); |
423 |
filelist_proc.dlg = dlg; |
filelist_proc.dlg = dlg; |
424 |
filelist_proc.current = (WNDPROC)filelist_subclass_proc; |
filelist_proc.current = (WNDPROC)filelist_subclass_proc; |
426 |
if (filelist_proc.old) { |
if (filelist_proc.old) { |
427 |
if (!SetWindowLong (fl, GWL_WNDPROC, (LONG)filelist_proc.current)) { |
if (!SetWindowLong (fl, GWL_WNDPROC, (LONG)filelist_proc.current)) { |
428 |
msg_box (dlg, _("Could not set filelist window procedure."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("Could not set filelist window procedure."), _("Key Manager"), MB_ERR); |
429 |
BUG (0); |
BUG (NULL); |
430 |
} |
} |
431 |
} |
} |
432 |
SetMenu (dlg, menu); |
SetMenu (dlg, menu); |
434 |
center_window2 (dlg, NULL, HWND_TOPMOST); |
center_window2 (dlg, NULL, HWND_TOPMOST); |
435 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
436 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
437 |
|
statbar = setup_status_bar (dlg); |
438 |
return TRUE; |
return TRUE; |
439 |
|
|
440 |
case WM_DESTROY: |
case WM_DESTROY: |
458 |
HMENU hm; |
HMENU hm; |
459 |
|
|
460 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
461 |
|
if (notify && notify->code == NM_CLICK && |
462 |
|
notify->idFrom == IDC_FILE_LIST) |
463 |
|
update_status_bar (statbar, lv); |
464 |
if (notify && notify->code == NM_RCLICK |
if (notify && notify->code == NM_RCLICK |
465 |
&& notify->idFrom == IDC_FILE_LIST) { |
&& notify->idFrom == IDC_FILE_LIST) { |
466 |
POINT p; |
POINT p; |