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