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

Contents of /trunk/Src/wptFileManagerDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 197 - (show annotations)
Mon Apr 10 07:38:06 2006 UTC (18 years, 10 months ago) by twoaday
File size: 28235 byte(s)
2006-04-09  Timo Schulz  <ts@g10code.de>
 
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Only return true
        if the homedir value was changed.
        * wptGPG.cpp (default_key_from_cache): Only return secret key
        if public part is available.
        (set_gnupg_default_key): Fix NULL problem.
        * wptKeyEditDlgs.cpp (do_editkey_clean): Set update flag.
        * wptFileCBS.cpp (write_cb, read_cb): Better error handling.
        * wptFileManagerDlg.cpp (file_manager_dlg_proc): Handle
        'always-on-top' correctly.
        * wptKeylist.cpp (keylist_get_recipients): Allocate enough
        mem to hold all possible keys.
        (keylist_enum_keys): Likewise.


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 ID_FILEMISC_QUIT:
613 EndDialog (dlg, TRUE);
614 return TRUE;
615
616 case ID_FILEMISC_WIPE_FREES:
617 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL,
618 dlg, space_wipefrees_dlg_proc, 0);
619 break;
620
621 case ID_FILEMISC_SELALL:
622 listview_select_all (lv);
623 break;
624
625 case ID_FILEMISC_PASTE:
626 fm_verify_pasted_detsig (lv, dlg);
627 break;
628
629 case ID_FILEMISC_ONTOP:
630 always_ontop ^= 1;
631 set_menu_state (menu, ID_FILEMISC_ONTOP,
632 always_ontop == 0? MFS_UNCHECKED : MFS_CHECKED);
633 center_window2 (dlg, NULL,
634 always_ontop == 0? HWND_NOTOPMOST : HWND_TOPMOST);
635 break;
636
637 case ID_FILEMISC_SEND:
638 fm_send_file (lv);
639 break;
640
641 case ID_FILEMISC_PREFS:
642 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_FILE_PREFS, dlg,
643 file_preferences_dlg_proc, 0);
644 break;
645
646 case ID_FILEMISC_LIST:
647 case ID_FILEMISC_ENCRYPT:
648 case ID_FILEMISC_SYMENC:
649 case ID_FILEMISC_DECRYPT:
650 case ID_FILEMISC_SIGN:
651 case ID_FILEMISC_SIGNENC:
652 case ID_FILEMISC_VERIFY:
653 case ID_FILEMISC_WIPE:
654 case ID_FILEMISC_ENCRYPT_ZIP:
655 fm_parse_files (lv, dlg, LOWORD (wparam));
656 SetForegroundWindow (dlg);
657 return TRUE;
658
659 case ID_FILEMISC_MD_MD5:
660 case ID_FILEMISC_MD_SHA1:
661 case ID_FILEMISC_MD_RMD160:
662 case ID_FILEMISC_MD_SHA256:
663 int algo;
664
665 switch (LOWORD (wparam)) {
666 case ID_FILEMISC_MD_MD5: algo = GPGME_MD_MD5; break;
667 case ID_FILEMISC_MD_SHA1: algo = GPGME_MD_SHA1; break;
668 case ID_FILEMISC_MD_RMD160: algo = GPGME_MD_RMD160; break;
669 case ID_FILEMISC_MD_SHA256: algo = GPGME_MD_SHA256; break;
670 default: algo = GPGME_MD_SHA1; break;
671 }
672 fm_print_md (lv, dlg, algo);
673 SetForegroundWindow (dlg);
674 return TRUE;
675
676 case ID_FILEMISC_CLEAR:
677 listview_del_all_items (lv);
678 return TRUE;
679
680 case ID_FILEMISC_OPEN:
681 fm_add_opened_files( lv, dlg );
682 return TRUE;
683
684 /* context menu entries */
685 case ID_FILECTX_ENCRYPT: send_cmd_id (dlg, ID_FILEMISC_ENCRYPT); break;
686 case ID_FILECTX_DECRYPT: send_cmd_id (dlg, ID_FILEMISC_DECRYPT);break;
687 case ID_FILECTX_SIGN: send_cmd_id (dlg, ID_FILEMISC_SIGN); break;
688 case ID_FILECTX_SIGNENC: send_cmd_id (dlg, ID_FILEMISC_SIGNENC);break;
689 case ID_FILECTX_VERIFY: send_cmd_id (dlg, ID_FILEMISC_VERIFY); break;
690 case ID_FILECTX_WIPE: send_cmd_id (dlg, ID_FILEMISC_WIPE); break;
691 case ID_FILECTX_LIST: send_cmd_id (dlg, ID_FILEMISC_LIST); break;
692 case ID_FILECTX_SEND: send_cmd_id (dlg, ID_FILEMISC_SEND); break;
693 case ID_FILECTX_ENCRYPT_ZIP:send_cmd_id (dlg, ID_FILEMISC_ENCRYPT_ZIP); break;
694 }
695 break;
696 }
697
698 return FALSE;
699 }
700
701
702 /* Dialog box procedure for the FM preferences. */
703 BOOL CALLBACK
704 file_preferences_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
705 {
706 switch (msg) {
707 case WM_INITDIALOG:
708 CheckDlgButton (dlg, IDC_FPREFS_PROGRESS,
709 reg_prefs.fm.progress? BST_CHECKED : BST_UNCHECKED);
710 SetForegroundWindow (dlg);
711 center_window (dlg, NULL);
712 break;
713
714 case WM_COMMAND:
715 switch (LOWORD (wparam)) {
716 case IDOK:
717 reg_prefs.fm.progress = IsDlgButtonChecked (dlg, IDC_FPREFS_PROGRESS)? 1 : 0;
718 set_reg_winpt_prefs (&reg_prefs);
719 EndDialog (dlg, TRUE);
720 break;
721
722 case IDCANCEL:
723 EndDialog (dlg, FALSE);
724 break;
725 }
726 break;
727 }
728
729 return FALSE;
730 }
731
732
733 /* Add the selected items from @lv into the combo box. */
734 static void
735 add_files_from_lv (HWND dlg, listview_ctrl_t lv)
736 {
737 char fname[384+1];
738 int i;
739
740 for (i = 0; i < listview_count_items (lv, 0); i++) {
741 if (!listview_get_item_state (lv, i))
742 continue;
743 listview_get_item_text (lv, i, 1, fname, sizeof (fname)-1);
744 SendDlgItemMessage (dlg, IDC_SECDEL_FILES, LB_ADDSTRING,
745 0, (WPARAM)(char *)fname);
746 }
747 }
748
749
750 /* Dialog box procedure to confirm that files shall be deleted. */
751 BOOL CALLBACK
752 file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
753 {
754 static secdel_confirm_s * ctx;
755
756 switch (msg) {
757 case WM_INITDIALOG:
758 ctx = (struct secdel_confirm_s *)lparam;
759 if (!ctx)
760 BUG (NULL);
761 add_files_from_lv (dlg, ctx->lv_files);
762 SetWindowText (dlg, _("Are you sure you want to secure delete these files?"));
763 SetDlgItemText (dlg, IDYES, _("&Yes"));
764 SetDlgItemText (dlg, IDNO, _("&No"));
765 break;
766
767 case WM_COMMAND:
768 switch (LOWORD (wparam)) {
769 case IDYES:
770 ctx->yes = 1;
771 EndDialog (dlg, TRUE);
772 break;
773
774 case IDNO:
775 ctx->yes = 0;
776 EndDialog (dlg, FALSE);
777 break;
778 }
779 break;
780 }
781
782 return FALSE;
783 }
784
785
786 /* Wipe callback. @ctx is a window handle @off is the current offset
787 and @n is the total size. */
788 static void
789 wipe_cb (void *ctx, ui64 off, ui64 n)
790 {
791 SendDlgItemMessage ((HWND)ctx, IDC_SPACE_PROGRESS, PBM_SETPOS,
792 (WPARAM) (off*100/n), 0);
793 SetDlgItemInt ((HWND)ctx, IDC_SPACE_OFF, (UINT)(off/1024), FALSE);
794 SetDlgItemInt ((HWND)ctx, IDC_SPACE_N, (UINT)(n/1024), FALSE);
795 }
796
797
798 /* Call the wipe free space method asynchron. */
799 static DWORD WINAPI
800 wipe_thread (void *ctx)
801 {
802 thread_ctx_t a = (thread_ctx_t)ctx;
803 int rc;
804
805 rc = wipe_freespace (a->drive, &a->fd, wipe_cb, a->dlg);
806 SetDlgItemText (a->dlg, IDC_SPACE_INFO,
807 rc? _("Operation Status: Error") :
808 _("Operation Status: Done."));
809 if (rc)
810 msg_box (a->dlg, winpt_strerror (rc), _("Wipe Free Space"), MB_ERR);
811 else
812 MessageBeep (MB_OK);
813 ExitThread (0);
814 return 0;
815 }
816
817
818 static void
819 fill_drive_combobox (HWND dlg)
820 {
821 char buf[384], p[16];
822 int n, i, j = 0;
823
824 n = GetLogicalDriveStrings (DIM (buf)-1, buf);
825 while (j < n) {
826 for (i = 0; buf[j] != '\0'; i++, j++)
827 p[i] = buf[j];
828 p[i] = '\0';
829 j++;
830 if (GetDriveType (p) != DRIVE_CDROM)
831 SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_ADDSTRING,
832 0, (LPARAM)(const char *)p);
833 }
834 SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_SETCURSEL, 0, 0);
835 } /* fill_drive_combobox */
836
837
838 static void
839 update_disc_stats (HWND dlg)
840 {
841 ULARGE_INTEGER caller = {0}, total = {0}, free = {0};
842 char buf[128], drive[32], a_total[64] = {0}, a_free[64] = {0};
843 int idx;
844
845 idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0);
846 GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1);
847 if (GetDiskFreeSpaceEx (drive, &caller, &total, &free)) {
848 _ui64toa (total.QuadPart/1024, a_total, 10);
849 _ui64toa (free.QuadPart/1024, a_free, 10);
850 }
851 _snprintf (buf, DIM (buf)-1, _("Total Capacity: %12sk\n"
852 "Free Space : %12sk"), a_total, a_free);
853 SetDlgItemText(dlg, IDC_SPACE_DISC_INFO, buf);
854 SetDlgItemInt (dlg, IDC_SPACE_OFF, 0, FALSE);
855 SetDlgItemInt (dlg, IDC_SPACE_N, 0, FALSE);
856 } /* update_disc_stats */
857
858
859 BOOL CALLBACK
860 space_wipefrees_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
861 {
862 static HANDLE thread_hd = NULL;
863 static thread_ctx_s ctx;
864 char drive[32], * p;
865 int idx;
866 DWORD tid;
867
868 switch (msg) {
869 case WM_INITDIALOG:
870 fill_drive_combobox (dlg);
871 update_disc_stats (dlg);
872 center_window (dlg, NULL);
873 SetForegroundWindow (dlg);
874 break;
875
876 case WM_DESTROY:
877 thread_hd = NULL;
878 free_if_alloc (ctx.drive);
879 memset (&ctx, 0, sizeof ctx);
880 break;
881
882 case WM_COMMAND:
883 if (HIWORD (wparam) == CBN_SELCHANGE)
884 update_disc_stats (dlg);
885 switch (LOWORD (wparam)) {
886 case IDOK:
887 idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0);
888 if (idx != CB_ERR && !thread_hd) {
889 GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1);
890 ctx.dlg = dlg;
891 ctx.drive = m_strdup (drive);
892 ctx.fd = NULL;
893 thread_hd = CreateThread (NULL, 0, wipe_thread, &ctx, 0, &tid);
894 }
895 if (WaitForSingleObject (thread_hd, 0) == WAIT_OBJECT_0) {
896 CloseHandle (thread_hd);
897 thread_hd = NULL;
898 EndDialog (dlg, TRUE);
899 }
900 break;
901
902 case IDCANCEL:
903 if (thread_hd) {
904 WaitForSingleObject (thread_hd, 2000);
905 TerminateThread (thread_hd, 1);
906 CloseHandle (thread_hd);
907 CloseHandle (ctx.fd);
908 p = make_filename (ctx.drive, "temp_winpt.tmp", NULL);
909 if (p && !file_exist_check (p))
910 remove (p);
911 free_if_alloc (p);
912 }
913 EndDialog( dlg, FALSE );
914 break;
915 }
916 break;
917 }
918
919 return FALSE;
920 } /* space_wipefrees_dlg_proc */

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26