1 |
twoaday |
247 |
/* wptFileSaveDlg.cpp - Extract plaintext and save it to a file |
2 |
|
|
* Copyright (C) 2002, 2003, 2005, 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 |
|
|
#ifdef HAVE_CONFIG_H |
17 |
|
|
#include <config.h> |
18 |
|
|
#endif |
19 |
|
|
|
20 |
|
|
#include <windows.h> |
21 |
|
|
|
22 |
werner |
47 |
#include "resource.h" |
23 |
werner |
36 |
#include "wptTypes.h" |
24 |
|
|
#include "wptNLS.h" |
25 |
|
|
#include "wptGPG.h" |
26 |
|
|
#include "wptW32API.h" |
27 |
|
|
#include "wptErrors.h" |
28 |
|
|
|
29 |
twoaday |
247 |
|
30 |
werner |
36 |
static void |
31 |
twoaday |
105 |
switch_buttons (HWND dlg, int file) |
32 |
werner |
36 |
{ |
33 |
|
|
int check1 = file? BST_CHECKED : BST_UNCHECKED; |
34 |
|
|
int check2 = file? BST_UNCHECKED: BST_CHECKED; |
35 |
|
|
|
36 |
twoaday |
105 |
CheckDlgButton (dlg, IDC_FILE_SAVE_TOFILE, check1); |
37 |
|
|
CheckDlgButton (dlg, IDC_FILE_SAVE_CLIP, check2); |
38 |
|
|
} |
39 |
werner |
36 |
|
40 |
|
|
|
41 |
twoaday |
105 |
/* Dialog box procedure to save the plaintext of a signature |
42 |
|
|
plus some additional information. */ |
43 |
werner |
36 |
BOOL CALLBACK |
44 |
twoaday |
105 |
file_save_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
45 |
werner |
36 |
{ |
46 |
|
|
gpgme_data_t sig, plain; |
47 |
|
|
gpgme_error_t err; |
48 |
|
|
const char *filename; |
49 |
|
|
int has_data; |
50 |
twoaday |
247 |
char file[MAX_PATH+128]; |
51 |
werner |
36 |
|
52 |
twoaday |
105 |
switch (msg) { |
53 |
werner |
36 |
case WM_INITDIALOG: |
54 |
twoaday |
105 |
SetWindowText (dlg, _("Save Plaintext")); |
55 |
|
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
56 |
|
|
SetDlgItemText (dlg, IDC_FILE_SAVE, _("&Save additional information")); |
57 |
|
|
SetDlgItemText (dlg, IDC_FILE_SAVE_TOFILE, _("Save to &file")); |
58 |
|
|
SetDlgItemText (dlg, IDC_FILE_SAVE_CLIP, _("Send to &clipboard")); |
59 |
twoaday |
247 |
switch_buttons (dlg, 1); |
60 |
|
|
center_window (dlg, NULL); |
61 |
twoaday |
105 |
SetForegroundWindow (dlg); |
62 |
werner |
36 |
return TRUE; |
63 |
|
|
|
64 |
|
|
case WM_COMMAND: |
65 |
twoaday |
247 |
switch (LOWORD (wparam)) { |
66 |
werner |
36 |
case IDC_FILE_SAVE_SELECT: |
67 |
twoaday |
328 |
filename = get_filesave_dlg (dlg, _("Destination for Plaintext"), |
68 |
|
|
NULL, NULL); |
69 |
twoaday |
247 |
if (filename) { |
70 |
|
|
SetDlgItemText (dlg, IDC_FILE_SAVE_FILE, filename); |
71 |
|
|
switch_buttons (dlg, 1); |
72 |
werner |
36 |
} |
73 |
|
|
return TRUE; |
74 |
|
|
|
75 |
|
|
case IDOK: |
76 |
twoaday |
247 |
if (IsDlgButtonChecked (dlg, IDC_FILE_SAVE_TOFILE)) { |
77 |
|
|
if (!GetDlgItemText (dlg, IDC_FILE_SAVE_FILE, file, sizeof (file) - 1)) { |
78 |
|
|
msg_box (dlg, _("Please enter a filename."), _("Save Plaintext"), MB_INFO); |
79 |
|
|
return TRUE; |
80 |
werner |
36 |
} |
81 |
twoaday |
247 |
if (check_file_name (file, IS_PATH)) { |
82 |
|
|
msg_box (dlg, _("The file name contains one or more illegal characters."), |
83 |
|
|
_("Save Plaintext"), MB_ERR); |
84 |
|
|
return TRUE; |
85 |
|
|
} |
86 |
werner |
36 |
err = gpg_data_new_from_clipboard (&sig, 0); |
87 |
twoaday |
247 |
if (err) { |
88 |
|
|
msg_box (dlg, winpt_strerror (WPTERR_CLIP_GET), |
89 |
|
|
_("Save Plaintext"), MB_ERR); |
90 |
|
|
return TRUE; |
91 |
werner |
36 |
} |
92 |
twoaday |
247 |
gpg_data_extract_plaintext (sig, &plain); |
93 |
|
|
err = gpg_data_release_and_set_file (plain, file); |
94 |
|
|
if (!err) |
95 |
|
|
msg_box (dlg, _("Finished"), _("Save Plaintext"), MB_OK); |
96 |
|
|
else { |
97 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Save Plaintext"), MB_ERR); |
98 |
|
|
gpgme_data_release (plain); |
99 |
|
|
} |
100 |
|
|
gpgme_data_release (sig); |
101 |
werner |
36 |
} |
102 |
twoaday |
247 |
else if (IsDlgButtonChecked (dlg, IDC_FILE_SAVE_CLIP)) { |
103 |
|
|
if (!gpg_clip_istext_avail (&has_data) && !has_data) { |
104 |
|
|
msg_box (dlg, winpt_strerror (WPTERR_CLIP_ISEMPTY), |
105 |
|
|
_("Save Plaintext"), MB_ERR); |
106 |
werner |
36 |
return FALSE; |
107 |
|
|
} |
108 |
|
|
err = gpg_data_new_from_clipboard (&sig, 0); |
109 |
twoaday |
247 |
if (err) { |
110 |
|
|
msg_box (dlg, winpt_strerror (WPTERR_CLIP_GET), |
111 |
|
|
_("Save Plaintext"), MB_ERR); |
112 |
werner |
36 |
return FALSE; |
113 |
|
|
} |
114 |
twoaday |
247 |
gpg_data_extract_plaintext (sig, &plain); |
115 |
twoaday |
328 |
gpg_data_release_to_clipboard (plain, 0); |
116 |
twoaday |
247 |
gpgme_data_release (sig); |
117 |
|
|
msg_box (dlg, _("Finished"), _("Save Plaintext"), MB_OK); |
118 |
werner |
36 |
} |
119 |
twoaday |
247 |
EndDialog (dlg, TRUE); |
120 |
werner |
36 |
return TRUE; |
121 |
|
|
|
122 |
|
|
case IDCANCEL: |
123 |
twoaday |
247 |
EndDialog (dlg, FALSE); |
124 |
werner |
36 |
return FALSE; |
125 |
|
|
} |
126 |
|
|
break; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
return FALSE; |
130 |
twoaday |
105 |
} |