/[winpt]/trunk/Src/wptFileManagerDlg.cpp
ViewVC logotype

Contents of /trunk/Src/wptFileManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 204 - (show annotations)
Wed Apr 26 06:37:23 2006 UTC (18 years, 10 months ago) by twoaday
File size: 28289 byte(s)
2006-04-25  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptFileManagerDlg.cpp (file_manager_dlg_proc): Handle IDCANCEL.
        * wptMDSumDlg.cpp (hash_selected_files): New.
        (mdsum_dlg_proc): Cleanups.
        * wptKeysignDlg.cpp (keysign_dlg_proc): Fix segv.
                                                                                
2006-04-23  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptW32API.cpp (SetDlgItemText_utf8): New.
        (SetWindowText_utf8): New.
        (GetDlgItemText_utf8): New.
        * wptListView.cpp (listview_add_sub_item): Internal
        utf8 support.


1 /* wptFileMangerDlg.cpp - File Manager
2 * Copyright (C) 2001-2005 Timo Schulz
3 *
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 <sys/stat.h>
28 #include <stdio.h>
29
30 #include "resource.h"
31 #include "wptCommonCtl.h"
32 #include "wptGPG.h"
33 #include "wptW32API.h"
34 #include "wptKeylist.h"
35 #include "wptErrors.h"
36 #include "wptContext.h" /* for passphrase_s */
37 #include "wptDlgs.h"
38 #include "wptTypes.h"
39 #include "wptNLS.h"
40 #include "wptVersion.h"
41 #include "wptFileManager.h"
42 #include "wptRegistry.h"
43 #include "wptCrypto.h"
44
45 #define FM_SEPARATOR_ID 10001
46
47 #define send_cmd_id(hwnd, id) \
48 PostMessage ((hwnd), WM_COMMAND, MAKEWPARAM( (id), 0), 0)
49
50 static subclass_s filelist_proc;
51
52 struct thread_ctx_s {
53 HWND dlg;
54 HANDLE fd;
55 char *drive;
56 };
57 typedef struct thread_ctx_s *thread_ctx_t;
58
59
60 /* Dialog procedure for selecting recipients for encryption. */
61 BOOL CALLBACK
62 file_encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
63 {
64 static listview_ctrl_t lv = NULL;
65 static fm_state_t c;
66 static keylist_t list = NULL;
67 gpg_keycache_t kc;
68 gpgme_ctx_t ctx;
69 int force_trust = 0;
70
71 switch (msg) {
72 case WM_INITDIALOG:
73 c = (fm_state_t)lparam;
74 if (!c)
75 dlg_fatal_error( dlg, "Could not get dialog state!" );
76 kc = keycache_get_ctx (KEYCACHE_PUB);
77 if (!kc)
78 BUG (dlg);
79 SetWindowText (dlg, _("File Encrypt"));
80 SetDlgItemText (dlg, IDC_ENCRYPT_ARMOR, _("&Text Output"));
81 SetDlgItemText (dlg, IDC_ENCRYPT_WIPE, _("&Wipe Original"));
82 SetDlgItemText (dlg, IDC_ENCRYPT_ANON, _("Anonymize (throw keyid)"));
83 SetDlgItemText (dlg, IDC_ENCRYPT_SIGN, _("&Select Key for signing"));
84 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
85
86 /* XXX: support --hidden-recipient */
87 EnableWindow (GetDlgItem (dlg, IDC_ENCRYPT_ANON), FALSE);
88
89 if (c->req_signer) {
90 EnableWindow (GetDlgItem (dlg, IDC_ENCRYPT_SIGN), TRUE);
91 seclist_init (dlg, IDC_ENCRYPT_SECLIST, KEYLIST_FLAG_SHORT, &list);
92 }
93 lv = keylist_load (GetDlgItem (dlg, IDC_ENCRYPT_LIST), kc, NULL,
94 KEYLIST_ENCRYPT_MIN|KEYLIST_FLAG_FILE,
95 KEY_SORT_USERID);
96 SetForegroundWindow (dlg);
97 return TRUE;
98
99 case WM_DESTROY:
100 seclist_destroy (&list);
101 if (lv) {
102 keylist_delete (lv);
103 lv = NULL;
104 }
105 return FALSE;
106
107 case WM_NOTIFY:
108 NMHDR *notify;
109 notify = (NMHDR *)lparam;
110 if (notify && notify->code == LVN_COLUMNCLICK
111 && notify->idFrom == IDC_ENCRYPT_LIST) {
112 NMLISTVIEW *p = (LPNMLISTVIEW) lparam;
113 int sortby = 0;
114
115 switch (p->iSubItem) {
116 case 0: sortby = KEY_SORT_USERID; break;
117 case 1: sortby = KEY_SORT_KEYID; break;
118 case 2: sortby = KEY_SORT_LEN; break;
119 case 4: sortby = KEY_SORT_VALIDITY; break;
120 default:sortby = KEY_SORT_USERID; break;
121 }
122 keylist_sort (lv, sortby);
123 }
124
125 case WM_SYSCOMMAND:
126 if (LOWORD (wparam) == SC_CLOSE) {
127 c->cancel = 1;
128 EndDialog (dlg, TRUE);
129 }
130 return FALSE;
131
132 case WM_COMMAND:
133 if (HIWORD (wparam) == BN_CLICKED
134 && LOWORD (wparam) == IDC_ENCRYPT_SIGN) {
135 int req_signer = IsDlgButtonChecked (dlg, IDC_ENCRYPT_SIGN);
136 EnableWindow (GetDlgItem (dlg, IDC_ENCRYPT_SECLIST),
137 req_signer? TRUE : FALSE);
138 }
139 switch( LOWORD( wparam ) ) {
140 case IDOK:
141 ctx = c->ctx;
142 safe_free (c->recp);
143 c->recp = keylist_get_recipients (lv, &force_trust, &c->n_recp);
144 if (!c->n_recp) {
145 msg_box (dlg, _("Please select at least one recipient."),
146 _("File Encrypt"), MB_ERR);
147 safe_free (c->recp);
148 c->recp = NULL;
149 c->cancel = 1;
150 return TRUE;
151 }
152 if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_SIGN)) {
153 gpgme_key_t key;
154
155 if (seclist_select_key (dlg, IDC_ENCRYPT_SECLIST, &key))
156 return TRUE;
157 else
158 gpgme_signers_add (c->ctx, key);
159 }
160
161 if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_ARMOR))
162 gpgme_set_armor (ctx, 1);
163 if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_WIPE))
164 c->wipe = 1;
165 /* XXX: implement this
166 if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_ANON))
167 ;
168 */
169 c->cancel = 0;
170 EndDialog (dlg, TRUE);
171 return TRUE;
172
173 case IDCANCEL:
174 c->cancel = 1;
175 EndDialog (dlg, FALSE);
176 return TRUE;
177 }
178 return TRUE;
179 }
180
181 return FALSE;
182 }
183
184
185 /* Dialog box procedure for importing keys. */
186 BOOL CALLBACK
187 file_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
188 {
189 static listview_ctrl_t lv = NULL;
190 static fm_state_t c;
191 static int is_revcert = 0, has_seckeys = 0;
192
193 switch (msg) {
194 case WM_INITDIALOG:
195 c = (fm_state_s *)lparam;
196 if (!c)
197 dlg_fatal_error( dlg, "Could not get dialog param!" );
198 ShowWindow (GetDlgItem( dlg, IDC_IMPORT_KEYMNGT ), WS_DISABLED);
199 implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST));
200 implist_load (lv, c->import.is_clip? NULL: c->opaque,
201 &is_revcert, &has_seckeys);
202 if (!listview_count_items (lv, 0)) {
203 msg_box (dlg, _("No valid OpenPGP data found."), _("Key Import"), MB_ERR);
204 c->cancel = 1;
205 EndDialog (dlg, FALSE);
206 }
207 else {
208 const char *s = _("%s contain(s) %d key(s).");
209 char *p = new char[strlen (s) + 32];
210 if (!p)
211 BUG (NULL);
212 sprintf (p, s, c->import.is_clip? _("Clipboard") : _("File"),
213 listview_count_items (lv, 0));
214 SetDlgItemText (dlg, IDC_IMPORT_INFO, p);
215 free_if_alloc (p);
216 }
217 SetWindowText (dlg, _("Key Import"));
218 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
219 center_window (dlg, NULL);
220 SetForegroundWindow (dlg);
221 return TRUE;
222
223 case WM_DESTROY:
224 if (lv) {
225 listview_release (lv);
226 lv = NULL;
227 }
228 return FALSE;
229
230 case WM_SYSCOMMAND:
231 if (LOWORD (wparam) == SC_CLOSE) {
232 c->cancel = 1;
233 EndDialog (dlg, FALSE);
234 }
235 return FALSE;
236
237 case WM_COMMAND:
238 switch (LOWORD (wparam)) {
239 case IDC_IMPORT_DOIT:
240 if (has_seckeys > 0) {
241 msg_box (dlg, _("Some of the imported keys are secret keys.\n\n"
242 "The ownertrust values of these keys must be\n"
243 "set manually via the Key Properties dialog."),
244 _("Import"), MB_INFO);
245 }
246 c->cancel = 0;
247 c->import.revcert = is_revcert? 1 : 0;
248 c->import.has_seckey = has_seckeys? 1 : 0;
249 EndDialog (dlg, TRUE);
250 return TRUE;
251
252 case IDCANCEL:
253 c->cancel = 1;
254 EndDialog (dlg, FALSE);
255 return FALSE;
256 }
257 break;
258 }
259
260 return FALSE;
261 }
262
263
264 /* Dialog box procedure for file signing. */
265 BOOL CALLBACK
266 file_sign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
267 {
268 static fm_state_t c;
269 static listview_ctrl_t lv;
270 gpg_keycache_t kc, sec_kc;
271 gpgme_key_t key;
272 int lv_idx;
273 char signer[32];
274
275 switch (msg) {
276 case WM_INITDIALOG:
277 c = (fm_state_s *)lparam;
278 if (c == NULL)
279 dlg_fatal_error (dlg, "Could not get dialog state!");
280 SetWindowText (dlg, _("File Sign"));
281 SetDlgItemText (dlg, IDC_FILE_SIG_ARMOR, _("&Text Output") );
282 SetDlgItemText (dlg, IDC_FILE_SIG_NORMAL, _("&Normal Signature"));
283 SetDlgItemText (dlg, IDC_FILE_SIG_DETACH, _("&Detached Signature"));
284 SetDlgItemText (dlg, IDC_FILE_SIG_CLEAR, _("&Cleartext Signature"));
285 SetDlgItemText (dlg, IDC_FILE_SIG_SIGINF, _("Signature mode"));
286 SetDlgItemText (dlg, IDC_FILE_SIG_OPTINF, _("Options"));
287 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
288 CheckDlgButton (dlg, IDC_FILE_SIG_DETACH, BST_CHECKED);
289 kc = keycache_get_ctx (KEYCACHE_PUB);
290 if (!kc)
291 BUG (dlg);
292 sec_kc = keycache_get_ctx (KEYCACHE_PRV);
293 if (!sec_kc)
294 BUG (dlg);
295 lv = keylist_load (GetDlgItem (dlg, IDC_FILE_SIG_LIST), kc, sec_kc,
296 KEYLIST_SIGN, KEY_SORT_USERID);
297 SetForegroundWindow (dlg);
298 return TRUE;
299
300 case WM_DESTROY:
301 if (lv) {
302 listview_release (lv);
303 lv = NULL;
304 }
305 return FALSE;
306
307 case WM_SYSCOMMAND:
308 if (LOWORD (wparam) == SC_CLOSE)
309 EndDialog (dlg, TRUE);
310 return FALSE;
311
312 case WM_COMMAND:
313 switch (LOWORD (wparam)) {
314 case IDOK:
315 if (IsDlgButtonChecked (dlg, IDC_FILE_SIG_ARMOR))
316 gpgme_set_armor (c->ctx, 1);
317 if (IsDlgButtonChecked (dlg, IDC_FILE_SIG_NORMAL))
318 c->sigmode = GPGME_SIG_MODE_NORMAL;
319 else if (IsDlgButtonChecked (dlg, IDC_FILE_SIG_DETACH))
320 c->sigmode = GPGME_SIG_MODE_DETACH;
321 else if (IsDlgButtonChecked( dlg, IDC_FILE_SIG_CLEAR))
322 c->sigmode = GPGME_SIG_MODE_CLEAR;
323 else {
324 /* default is to produce detached signatures */
325 c->sigmode = GPGME_SIG_MODE_DETACH;
326 }
327 lv_idx = listview_get_selected_item (lv);
328 if (lv_idx == -1) {
329 if (listview_count_items (lv, 0) == 1)
330 lv_idx = 0;
331 else {
332 msg_box (dlg, _("Please select a key."), _("File Sign"), MB_ERR);
333 return FALSE;
334 }
335 }
336 listview_get_item_text( lv, lv_idx, 1, signer, sizeof signer-1 );
337 if( get_seckey( signer, &key ) )
338 BUG( NULL );
339 gpgme_signers_clear (c->ctx);
340 gpgme_signers_add (c->ctx, key);
341 free_if_alloc (c->opaque);
342 c->opaque = m_strdup (signer); /* store for later use */
343 c->cancel = 0;
344 if (!c->opaque)
345 BUG (0);
346 EndDialog (dlg, TRUE);
347 return TRUE;
348
349 case IDCANCEL:
350 c->cancel = 1;
351 EndDialog (dlg, FALSE);
352 return FALSE;
353 }
354 break;
355 }
356
357 return FALSE;
358 }
359
360
361 /* Setup status bar for the main window @dlg. */
362 static HWND
363 setup_status_bar (HWND dlg)
364 {
365 HWND statbar;
366 RECT r;
367 int partpos[3];
368 int i;
369
370 GetClientRect (dlg, &r);
371 for (i=1; i <= 3; i++)
372 partpos[i-1] = r.right/3*i;
373
374 statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM,
375 "", dlg, FM_SEPARATOR_ID);
376 ShowWindow (statbar, SW_SHOW);
377 SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos);
378 return statbar;
379 }
380
381
382 /* Refresh the status bar text with the selected item from @lv. */
383 static void
384 update_status_bar (HWND statbar, listview_ctrl_t lv)
385 {
386 struct stat st;
387 char buf[128];
388 int n;
389
390 if (!lv) { /* flush */
391 SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)"0 Byte");
392 SendMessage (statbar, SB_SETTEXT, 0, (LPARAM)_("0 Objects marked"));
393 return;
394 }
395 n = listview_count_items (lv, 1);
396 _snprintf (buf, sizeof (buf)-1, _("%d Object(s) marked"), n);
397 SendMessage (statbar, SB_SETTEXT, 0, (LPARAM)buf);
398 listview_get_item_text (lv, listview_get_curr_pos (lv), 1, buf, 127);
399 if (stat (buf, &st) == 0) {
400 if (st.st_size < 1024)
401 _snprintf (buf, sizeof (buf)-1, "%d Byte", st.st_size);
402 else if (st.st_size < 1048576)
403 _snprintf (buf, sizeof (buf)-1, "%d KB", st.st_size/1024);
404 else
405 _snprintf (buf, sizeof (buf)-1, "%d MB", st.st_size/1024/1024);
406 SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)buf);
407 }
408 else
409 SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)"0 Byte");
410 }
411
412
413 /* Subclass procedure to detect common hotkeys. */
414 static BOOL CALLBACK
415 filelist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
416 {
417 switch (msg) {
418 case WM_KEYUP:
419 int virt_key = (int)wparam;
420 if (virt_key == VK_DELETE)
421 send_cmd_id (filelist_proc.dlg, ID_FILEMISC_WIPE);
422 break;
423 }
424 return CallWindowProc (filelist_proc.old, dlg, msg, wparam, lparam);
425 }
426
427
428 /* Enable or disabled menu entries from the dialog window @hwnd.
429 @lv is used to find out the state of the selected file entry. */
430 static void
431 update_ui_items (HWND hwnd, listview_ctrl_t lv)
432 {
433 HMENU hm;
434 int pos;
435
436 hm = GetMenu (hwnd);
437
438 pos = listview_get_curr_pos (lv);
439 if (fm_check_file_type (lv, pos, FM_ENCRYPT)) {
440 set_menu_state (hm, ID_FILEMISC_DECRYPT, MF_GRAYED|MF_DISABLED);
441 set_menu_state (hm, ID_FILECTX_VERIFY, MF_GRAYED|MF_DISABLED);
442 }
443 if (fm_check_file_type (lv, pos, FM_DECRYPT)) {
444 set_menu_state (hm, ID_FILEMISC_ENCRYPT, MF_GRAYED|MF_DISABLED);
445 set_menu_state (hm, ID_FILEMISC_SIGN, MF_GRAYED|MF_DISABLED);
446 set_menu_state (hm, ID_FILEMISC_SIGNENC, MF_GRAYED|MF_DISABLED);
447 }
448 if (fm_check_file_type (lv, pos, FM_VERIFY)) {
449 set_menu_state (hm, ID_FILEMISC_VERIFY, MF_ENABLED);
450 set_menu_state (hm, ID_FILEMISC_SIGN, MF_GRAYED|MF_DISABLED);
451 set_menu_state (hm, ID_FILEMISC_SIGNENC, MF_GRAYED|MF_DISABLED);
452 }
453 }
454
455
456 /* Dialog box procedure for the File Manager. */
457 BOOL CALLBACK
458 file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
459 {
460 static HWND statbar;
461 static listview_ctrl_t lv = NULL;
462 static HMENU menu = NULL;
463 static int always_ontop = 0;
464 HWND fl;
465
466 switch (msg) {
467 case WM_INITDIALOG:
468 always_ontop = get_reg_winpt_flag ("AlwaysOnTop");
469 if (always_ontop == -1)
470 always_ontop = 0;
471 SetWindowText (dlg, _("File Manager (use drag & drop to add files)"));
472 menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC);
473 set_menu_text_bypos (menu, 0, _("File"));
474 set_menu_text_bypos (menu, 1, _("Edit"));
475 set_menu_text_bypos (menu, 2, _("View"));
476 set_menu_text (menu, ID_FILEMISC_OPEN, _("&Open...") );
477 set_menu_text (menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") );
478 set_menu_text (menu, ID_FILEMISC_ENCRYPT_ZIP, _("Encrypt into ZIP"));
479 set_menu_text (menu, ID_FILEMISC_DECRYPT, _("&Decrypt") );
480 set_menu_text (menu, ID_FILEMISC_SIGN, _("&Sign") );
481 set_menu_text (menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") );
482 set_menu_text (menu, ID_FILEMISC_VERIFY, _("&Verify") );
483 set_menu_text (menu, ID_FILEMISC_SYMENC, _("S&ymmetric") );
484 set_menu_text (menu, ID_FILEMISC_IMPORT, _("&Import") );
485 set_menu_text (menu, ID_FILEMISC_EXPORT, _("E&xport") );
486 set_menu_text (menu, ID_FILEMISC_QUIT, _("Exit"));
487 set_menu_text (menu, ID_FILEMISC_CLEAR, _("&Reset") );
488 set_menu_text (menu, ID_FILEMISC_ONTOP, _("Always on Top"));
489 set_menu_text (menu, ID_FILEMISC_PASTE, _("&Paste"));
490 set_menu_text (menu, ID_FILEMISC_SELALL, _("&Select All"));
491 set_menu_text (menu, ID_FILEMISC_PREFS, _("&Preferences"));
492 set_menu_text (menu, ID_FILEMISC_SEND, _("Send as Mail"));
493 set_menu_text (menu, ID_FILEMISC_LIST, _("&List Packets"));
494 set_menu_text (menu, ID_FILEMISC_WIPE_FREES, _("Wipe Free Space"));
495 set_menu_text (menu, ID_FILEMISC_WIPE, _("&Wipe"));
496
497 fl = GetDlgItem (dlg, IDC_FILE_LIST);
498 filelist_proc.dlg = dlg;
499 filelist_proc.current = (WNDPROC)filelist_subclass_proc;
500 filelist_proc.old = (WNDPROC)GetWindowLong (fl, GWL_WNDPROC);
501 if (filelist_proc.old) {
502 if (!SetWindowLong (fl, GWL_WNDPROC, (LONG)filelist_proc.current)) {
503 msg_box (dlg, "Could not set filelist window procedure.",
504 _("File Manager"), MB_ERR);
505 BUG (NULL);
506 }
507 }
508 SetMenu (dlg, menu);
509 if (!always_ontop)
510 set_menu_state (menu, ID_FILEMISC_ONTOP, MFS_UNCHECKED);
511 else
512 center_window2 (dlg, NULL, HWND_TOPMOST);
513 fm_build (&lv, GetDlgItem (dlg, IDC_FILE_LIST));
514 center_window (dlg, NULL);
515 SetForegroundWindow (dlg);
516 statbar = setup_status_bar (dlg);
517 filelist_proc.opaque = (void*)statbar;
518 return TRUE;
519
520 case WM_DESTROY:
521 if (lv) {
522 fm_delete (lv);
523 lv = NULL;
524 }
525 if (menu) {
526 DestroyMenu (menu);
527 menu = NULL;
528 }
529 set_reg_winpt_flag ("AlwaysOnTop", always_ontop);
530 return FALSE;
531
532 case WM_DROPFILES:
533 fm_add_dropped_files (lv, (HDROP)wparam);
534 return TRUE;
535
536 case WM_NOTIFY:
537 NMHDR *notify;
538 int pos;
539 HMENU hm;
540
541 notify = (NMHDR *)lparam;
542 if (notify && notify->code == NM_CLICK &&
543 notify->idFrom == IDC_FILE_LIST)
544 update_status_bar (statbar, lv);
545 if (notify && notify->code == NM_RCLICK
546 && notify->idFrom == IDC_FILE_LIST) {
547 POINT p;
548 HMENU popup;
549
550 GetCursorPos (&p);
551 hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_FILEMISC_CTX));
552 popup = GetSubMenu (hm, 0);
553 set_menu_text (popup, ID_FILECTX_ENCRYPT_ZIP, _("Encrypt into ZIP"));
554 set_menu_text (popup, ID_FILECTX_ENCRYPT, _("Encrypt"));
555 set_menu_text (popup, ID_FILECTX_DECRYPT, _("Decrypt"));
556 set_menu_text (popup, ID_FILECTX_SIGN, _("Sign"));
557 set_menu_text (popup, ID_FILECTX_SIGNENC, _("Sign && Encrypt"));
558 set_menu_text (popup, ID_FILECTX_VERIFY, _("Verify"));
559 set_menu_text (popup, ID_FILECTX_WIPE, _("Wipe"));
560 set_menu_text (popup, ID_FILECTX_SEND, _("Send as Mail"));
561 set_menu_text (popup, ID_FILECTX_LIST, _("List Packets"));
562 pos = listview_get_curr_pos (lv);
563 if (fm_check_file_type (lv, pos, FM_DECRYPT))
564 set_menu_state (popup, ID_FILECTX_SEND, MF_ENABLED);
565 if (fm_check_file_type (lv, pos, FM_ENCRYPT)) {
566 set_menu_state (popup, ID_FILECTX_DECRYPT, MF_GRAYED|MF_DISABLED);
567 set_menu_state (popup, ID_FILECTX_VERIFY, MF_GRAYED|MF_DISABLED);
568 }
569 if (fm_check_file_type (lv, pos, FM_DECRYPT)) {
570 set_menu_state (popup, ID_FILECTX_ENCRYPT_ZIP, MF_GRAYED|MF_DISABLED);
571 set_menu_state (popup, ID_FILECTX_ENCRYPT, MF_GRAYED|MF_DISABLED);
572 set_menu_state (popup, ID_FILECTX_SIGN, MF_GRAYED|MF_DISABLED);
573 set_menu_state (popup, ID_FILECTX_SIGNENC, MF_GRAYED|MF_DISABLED);
574 }
575 if (fm_check_file_type (lv, pos, FM_VERIFY)) {
576 set_menu_state (popup, ID_FILECTX_VERIFY, MF_ENABLED);
577 set_menu_state (popup, ID_FILECTX_SIGN, MF_GRAYED|MF_DISABLED);
578 set_menu_state (popup, ID_FILECTX_SIGNENC, MF_GRAYED|MF_DISABLED);
579 }
580
581 TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL);
582 DestroyMenu (popup);
583 DestroyMenu (hm);
584 }
585 if (notify && notify->code == NM_CLICK
586 && notify->idFrom == IDC_FILE_LIST) {
587 hm = GetMenu (dlg);
588 pos = listview_get_curr_pos (lv);
589 if (!fm_check_file_type (lv, pos, FM_DECRYPT))
590 set_menu_state (hm, ID_FILEMISC_SEND, MF_GRAYED|MF_DISABLED);
591 else
592 set_menu_state (hm, ID_FILEMISC_SEND, MF_ENABLED);
593 }
594 if (notify && notify->code == LVN_ITEMCHANGED &&
595 ((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */
596 update_ui_items (dlg, lv);
597 return TRUE;
598
599 case WM_SYSCOMMAND:
600 if (LOWORD (wparam) == SC_CLOSE)
601 EndDialog (dlg, TRUE);
602 return FALSE;
603
604 case WM_INITMENUPOPUP:
605 if ((UINT)LOWORD (lparam) == 0 &&
606 GetMenuItemCount ((HMENU)wparam) == 19) /* XXX: do not hard code values */
607 set_menu_text_bypos ((HMENU)wparam, 2, _("&Calc Digest"));
608 return FALSE;
609
610 case WM_COMMAND:
611 switch (LOWORD (wparam)) {
612 case IDCANCEL:
613 EndDialog (dlg, FALSE);
614 return TRUE;
615
616 case ID_FILEMISC_QUIT:
617 EndDialog (dlg, TRUE);
618 return TRUE;
619
620 case ID_FILEMISC_WIPE_FREES:
621 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL,
622 dlg, space_wipefrees_dlg_proc, 0);
623 break;
624
625 case ID_FILEMISC_SELALL:
626 listview_select_all (lv);
627 break;
628
629 case ID_FILEMISC_PASTE:
630 fm_verify_pasted_detsig (lv, dlg);
631 break;
632
633 case ID_FILEMISC_ONTOP:
634 always_ontop ^= 1;
635 set_menu_state (menu, ID_FILEMISC_ONTOP,
636 always_ontop == 0? MFS_UNCHECKED : MFS_CHECKED);
637 center_window2 (dlg, NULL,
638 always_ontop == 0? HWND_NOTOPMOST : HWND_TOPMOST);
639 break;
640
641 case ID_FILEMISC_SEND:
642 fm_send_file (lv);
643 break;
644
645 case ID_FILEMISC_PREFS:
646 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_FILE_PREFS, dlg,
647 file_preferences_dlg_proc, 0);
648 break;
649
650 case ID_FILEMISC_LIST:
651 case ID_FILEMISC_ENCRYPT:
652 case ID_FILEMISC_SYMENC:
653 case ID_FILEMISC_DECRYPT:
654 case ID_FILEMISC_SIGN:
655 case ID_FILEMISC_SIGNENC:
656 case ID_FILEMISC_VERIFY:
657 case ID_FILEMISC_WIPE:
658 case ID_FILEMISC_ENCRYPT_ZIP:
659 fm_parse_files (lv, dlg, LOWORD (wparam));
660 SetForegroundWindow (dlg);
661 return TRUE;
662
663 case ID_FILEMISC_MD_MD5:
664 case ID_FILEMISC_MD_SHA1:
665 case ID_FILEMISC_MD_RMD160:
666 case ID_FILEMISC_MD_SHA256:
667 int algo;
668
669 switch (LOWORD (wparam)) {
670 case ID_FILEMISC_MD_MD5: algo = GPGME_MD_MD5; break;
671 case ID_FILEMISC_MD_SHA1: algo = GPGME_MD_SHA1; break;
672 case ID_FILEMISC_MD_RMD160: algo = GPGME_MD_RMD160; break;
673 case ID_FILEMISC_MD_SHA256: algo = GPGME_MD_SHA256; break;
674 default: algo = GPGME_MD_SHA1; break;
675 }
676 fm_print_md (lv, dlg, algo);
677 SetForegroundWindow (dlg);
678 return TRUE;
679
680 case ID_FILEMISC_CLEAR:
681 listview_del_all_items (lv);
682 return TRUE;
683
684 case ID_FILEMISC_OPEN:
685 fm_add_opened_files( lv, dlg );
686 return TRUE;
687
688 /* context menu entries */
689 case ID_FILECTX_ENCRYPT: send_cmd_id (dlg, ID_FILEMISC_ENCRYPT); break;
690 case ID_FILECTX_DECRYPT: send_cmd_id (dlg, ID_FILEMISC_DECRYPT);break;
691 case ID_FILECTX_SIGN: send_cmd_id (dlg, ID_FILEMISC_SIGN); break;
692 case ID_FILECTX_SIGNENC: send_cmd_id (dlg, ID_FILEMISC_SIGNENC);break;
693 case ID_FILECTX_VERIFY: send_cmd_id (dlg, ID_FILEMISC_VERIFY); break;
694 case ID_FILECTX_WIPE: send_cmd_id (dlg, ID_FILEMISC_WIPE); break;
695 case ID_FILECTX_LIST: send_cmd_id (dlg, ID_FILEMISC_LIST); break;
696 case ID_FILECTX_SEND: send_cmd_id (dlg, ID_FILEMISC_SEND); break;
697 case ID_FILECTX_ENCRYPT_ZIP:send_cmd_id (dlg, ID_FILEMISC_ENCRYPT_ZIP); break;
698 }
699 break;
700 }
701
702 return FALSE;
703 }
704
705
706 /* Dialog box procedure for the FM preferences. */
707 BOOL CALLBACK
708 file_preferences_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
709 {
710 switch (msg) {
711 case WM_INITDIALOG:
712 CheckDlgButton (dlg, IDC_FPREFS_PROGRESS,
713 reg_prefs.fm.progress? BST_CHECKED : BST_UNCHECKED);
714 SetForegroundWindow (dlg);
715 center_window (dlg, NULL);
716 break;
717
718 case WM_COMMAND:
719 switch (LOWORD (wparam)) {
720 case IDOK:
721 reg_prefs.fm.progress = IsDlgButtonChecked (dlg, IDC_FPREFS_PROGRESS)? 1 : 0;
722 set_reg_winpt_prefs (&reg_prefs);
723 EndDialog (dlg, TRUE);
724 break;
725
726 case IDCANCEL:
727 EndDialog (dlg, FALSE);
728 break;
729 }
730 break;
731 }
732
733 return FALSE;
734 }
735
736
737 /* Add the selected items from @lv into the combo box. */
738 static void
739 add_files_from_lv (HWND dlg, listview_ctrl_t lv)
740 {
741 char fname[384+1];
742 int i;
743
744 for (i = 0; i < listview_count_items (lv, 0); i++) {
745 if (!listview_get_item_state (lv, i))
746 continue;
747 listview_get_item_text (lv, i, 1, fname, sizeof (fname)-1);
748 SendDlgItemMessage (dlg, IDC_SECDEL_FILES, LB_ADDSTRING,
749 0, (WPARAM)(char *)fname);
750 }
751 }
752
753
754 /* Dialog box procedure to confirm that files shall be deleted. */
755 BOOL CALLBACK
756 file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
757 {
758 static secdel_confirm_s * ctx;
759
760 switch (msg) {
761 case WM_INITDIALOG:
762 ctx = (struct secdel_confirm_s *)lparam;
763 if (!ctx)
764 BUG (NULL);
765 add_files_from_lv (dlg, ctx->lv_files);
766 SetWindowText (dlg, _("Are you sure you want to secure delete these files?"));
767 SetDlgItemText (dlg, IDYES, _("&Yes"));
768 SetDlgItemText (dlg, IDNO, _("&No"));
769 break;
770
771 case WM_COMMAND:
772 switch (LOWORD (wparam)) {
773 case IDYES:
774 ctx->yes = 1;
775 EndDialog (dlg, TRUE);
776 break;
777
778 case IDNO:
779 ctx->yes = 0;
780 EndDialog (dlg, FALSE);
781 break;
782 }
783 break;
784 }
785
786 return FALSE;
787 }
788
789
790 /* Wipe callback. @ctx is a window handle @off is the current offset
791 and @n is the total size. */
792 static void
793 wipe_cb (void *ctx, ui64 off, ui64 n)
794 {
795 SendDlgItemMessage ((HWND)ctx, IDC_SPACE_PROGRESS, PBM_SETPOS,
796 (WPARAM) (off*100/n), 0);
797 SetDlgItemInt ((HWND)ctx, IDC_SPACE_OFF, (UINT)(off/1024), FALSE);
798 SetDlgItemInt ((HWND)ctx, IDC_SPACE_N, (UINT)(n/1024), FALSE);
799 }
800
801
802 /* Call the wipe free space method asynchron. */
803 static DWORD WINAPI
804 wipe_thread (void *ctx)
805 {
806 thread_ctx_t a = (thread_ctx_t)ctx;
807 int rc;
808
809 rc = wipe_freespace (a->drive, &a->fd, wipe_cb, a->dlg);
810 SetDlgItemText (a->dlg, IDC_SPACE_INFO,
811 rc? _("Operation Status: Error") :
812 _("Operation Status: Done."));
813 if (rc)
814 msg_box (a->dlg, winpt_strerror (rc), _("Wipe Free Space"), MB_ERR);
815 else
816 MessageBeep (MB_OK);
817 ExitThread (0);
818 return 0;
819 }
820
821
822 static void
823 fill_drive_combobox (HWND dlg)
824 {
825 char buf[384], p[16];
826 int n, i, j = 0;
827
828 n = GetLogicalDriveStrings (DIM (buf)-1, buf);
829 while (j < n) {
830 for (i = 0; buf[j] != '\0'; i++, j++)
831 p[i] = buf[j];
832 p[i] = '\0';
833 j++;
834 if (GetDriveType (p) != DRIVE_CDROM)
835 SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_ADDSTRING,
836 0, (LPARAM)(const char *)p);
837 }
838 SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_SETCURSEL, 0, 0);
839 } /* fill_drive_combobox */
840
841
842 static void
843 update_disc_stats (HWND dlg)
844 {
845 ULARGE_INTEGER caller = {0}, total = {0}, free = {0};
846 char buf[128], drive[32], a_total[64] = {0}, a_free[64] = {0};
847 int idx;
848
849 idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0);
850 GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1);
851 if (GetDiskFreeSpaceEx (drive, &caller, &total, &free)) {
852 _ui64toa (total.QuadPart/1024, a_total, 10);
853 _ui64toa (free.QuadPart/1024, a_free, 10);
854 }
855 _snprintf (buf, DIM (buf)-1, _("Total Capacity: %12sk\n"
856 "Free Space : %12sk"), a_total, a_free);
857 SetDlgItemText(dlg, IDC_SPACE_DISC_INFO, buf);
858 SetDlgItemInt (dlg, IDC_SPACE_OFF, 0, FALSE);
859 SetDlgItemInt (dlg, IDC_SPACE_N, 0, FALSE);
860 } /* update_disc_stats */
861
862
863 BOOL CALLBACK
864 space_wipefrees_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
865 {
866 static HANDLE thread_hd = NULL;
867 static thread_ctx_s ctx;
868 char drive[32], * p;
869 int idx;
870 DWORD tid;
871
872 switch (msg) {
873 case WM_INITDIALOG:
874 fill_drive_combobox (dlg);
875 update_disc_stats (dlg);
876 center_window (dlg, NULL);
877 SetForegroundWindow (dlg);
878 break;
879
880 case WM_DESTROY:
881 thread_hd = NULL;
882 free_if_alloc (ctx.drive);
883 memset (&ctx, 0, sizeof ctx);
884 break;
885
886 case WM_COMMAND:
887 if (HIWORD (wparam) == CBN_SELCHANGE)
888 update_disc_stats (dlg);
889 switch (LOWORD (wparam)) {
890 case IDOK:
891 idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0);
892 if (idx != CB_ERR && !thread_hd) {
893 GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1);
894 ctx.dlg = dlg;
895 ctx.drive = m_strdup (drive);
896 ctx.fd = NULL;
897 thread_hd = CreateThread (NULL, 0, wipe_thread, &ctx, 0, &tid);
898 }
899 if (WaitForSingleObject (thread_hd, 0) == WAIT_OBJECT_0) {
900 CloseHandle (thread_hd);
901 thread_hd = NULL;
902 EndDialog (dlg, TRUE);
903 }
904 break;
905
906 case IDCANCEL:
907 if (thread_hd) {
908 WaitForSingleObject (thread_hd, 2000);
909 TerminateThread (thread_hd, 1);
910 CloseHandle (thread_hd);
911 CloseHandle (ctx.fd);
912 p = make_filename (ctx.drive, "temp_winpt.tmp", NULL);
913 if (p && !file_exist_check (p))
914 remove (p);
915 free_if_alloc (p);
916 }
917 EndDialog( dlg, FALSE );
918 break;
919 }
920 break;
921 }
922
923 return FALSE;
924 } /* space_wipefrees_dlg_proc */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26