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

Annotation of /trunk/Src/wptFileSaveDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 247 - (hide annotations)
Fri Jul 21 08:19:24 2006 UTC (18 years, 7 months ago) by twoaday
File size: 4520 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26