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

Contents of /trunk/Src/wptClipEditDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations)
Wed Oct 26 11:20:09 2005 UTC (19 years, 4 months ago) by twoaday
File size: 6741 byte(s)
2005-10-25  Timo Schulz  <twoaday@g10code.com>
                                                                                
        * wptGPGUtil.cpp (create_process): Hide window.
        * wptKeyPropsDlg.cpp (get_photo_tmpname): New.
        * wptClipSignEncDlg.cpp (clip_signenc_dlg_proc): Remove
        static var 'enable'.
        * wptKeygenDlg.cpp (keygen_dlg_proc): Likewise.
        (gpg_genkey_params): Make sure all primary keys are capable
        for signing and certification.
        * wptKeySigDlg.cpp (is_sig): If no item is selected, return 0.
        * wptGPG.cpp (gnupg_access_keyring): Check return value for
        NULL. Noted by Ralf.
        (get_gnupg_prog): Simplified.
        (check_homedir): Fixed. Return 0 when the dir is successfully created.
        * wptKeyManagerDlg.cpp (km_file_import): Use the hourglass to
        indicate a pending GPG process.
        * wptFileManager.cpp (op_begin, op_end): New. Indicate an start
        and and of an operation. For now just the cursor changes.
        (fm_parse_command_line): Remove debug output. Thanks to Ralf again.
        * WinPT.cpp (WinMain): Check if there is already an instance and
        set a variable early as possible.
        (load_gettext): If a previous instance was found, do not output
        any errors. Kudos to Ralf.


1 /* wptClipEditDlg.cpp - Clipboard Editor dialog
2 * Copyright (C) 2000-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 #include <windows.h>
22 #include <stdio.h>
23
24 #include "wptTypes.h"
25 #include "wptW32API.h"
26 #include "wptVersion.h"
27 #include "wptErrors.h"
28 #include "wptGPG.h"
29 #include "wptNLS.h"
30 #include "../resource.h"
31
32
33 /* Load the clipboard contents into the text field in @dlg.
34 Return value: 0 on success. */
35 static int
36 load_clipboard (HWND dlg)
37 {
38 HANDLE clipmem;
39 char *cliptext;
40 char *p;
41
42 CloseClipboard (); /* make sure it is closed. */
43 if (OpenClipboard (NULL) == FALSE) {
44 msg_box (dlg, winpt_strerror (WPTERR_CLIP_OPEN), _("Clipboard"), MB_ERR);
45 return -1;
46 }
47 clipmem = GetClipboardData (CF_TEXT);
48 if (clipmem == NULL) {
49 CloseClipboard ();
50 return -1;
51 }
52
53 cliptext = (char *) GlobalLock (clipmem);
54 if (cliptext == NULL || !strlen (cliptext)) {
55 CloseClipboard ();
56 return -1;
57 }
58
59 p = new char [strlen (cliptext)+2];
60 if (!p)
61 BUG (0);
62 strcpy (p, cliptext);
63
64 GlobalUnlock (clipmem);
65 CloseClipboard ();
66 SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);
67 free_if_alloc (p);
68
69 return 0;
70 }
71
72
73 /* Load the clipboard from the selected file. */
74 static int
75 load_clipboard_from_file (HWND dlg)
76 {
77 OPENFILENAME open;
78 FILE *fp;
79 char *p;
80 char file[300] = "";
81 DWORD size;
82 int id;
83
84 memset (&open, 0, sizeof (open));
85 open.lStructSize = sizeof (OPENFILENAME);
86 open.hInstance = glob_hinst;
87 open.lpstrTitle = _("File Open");
88 open.lpstrFilter = (char *)_("All Files (*.*)\0*.*\0\0");
89 open.hwndOwner = dlg;
90 open.lpstrFile = file;
91 open.nMaxFile = sizeof (file)-1;
92 open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
93
94 if (GetOpenFileName (&open)) {
95 if( (size=get_file_size (file)) > MAX_CLIPTEXT_SIZE) {
96 id = msg_box (dlg, _("The file you want to add is very large.\n"
97 "Still proceed?"), _("Clipboard"), MB_INFO|MB_YESNO);
98 if (id == IDNO)
99 return -1;
100 }
101 fp = fopen (file, "rb");
102 if (!fp) {
103 msg_box (dlg, winpt_strerror (WPTERR_FILE_OPEN), _("Clipboard"), MB_ERR);
104 return FALSE;
105 }
106 p = new char[size+1];
107 if (!p)
108 BUG (0);
109 fread (p, 1, size, fp);
110 p[size] = '\0';
111 fclose (fp);
112 SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p);
113 free_if_alloc (p);
114 }
115 return 0;
116 }
117
118
119 /* Save the contents of the clipboard to the selected file. */
120 static int
121 save_clipboard_to_file (HWND dlg)
122 {
123 OPENFILENAME save;
124 FILE *fp;
125 char *p;
126 char file[300] = "";
127 DWORD nbytes;
128 int id;
129
130 memset (&save, 0, sizeof (save));
131 save.lStructSize = sizeof (OPENFILENAME);
132 save.hInstance = glob_hinst;
133 save.lpstrTitle = _("File Save");
134 save.lpstrFile = (char *)_("All Files (*.*)\0*.*\0\0");
135 save.hwndOwner = dlg;
136 save.lpstrFile = file;
137 save.nMaxFile = sizeof (file) - 1;
138 save.Flags = OFN_OVERWRITEPROMPT;
139
140 if( GetSaveFileName( &save ) ) {
141 if( file_exist_check( file ) == 0 ) {
142 id = log_box (_("Clipboard"), MB_YESNO,
143 _("\"%s\" already exists.\n"
144 "Replace existing file?"), file);
145 if( id == IDNO )
146 return FALSE;
147 }
148 fp = fopen (file, "wb");
149 if (!fp) {
150 msg_box (dlg, winpt_strerror (WPTERR_FILE_CREAT), _("Clipboard"), MB_ERR);
151 return FALSE;
152 }
153 /* XXX: there is a NUL-byte at the end. */
154 nbytes = SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_GETTEXTLENGTH, 0, 0);
155 if (nbytes > 0) {
156 p = new char[nbytes+1];
157 if (!p)
158 BUG (NULL);
159 GetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, p, nbytes);
160 fwrite (p, 1, nbytes, fp);
161 }
162 fclose (fp);
163 free_if_alloc (p);
164 }
165 return 0;
166 }
167
168
169 /* Dialog box procedure for the clipboard editor. */
170 BOOL CALLBACK
171 clip_edit_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
172 {
173 switch (msg) {
174 case WM_INITDIALOG:
175 SetWindowText (dlg, _("Clipboard Editor"));
176 SetDlgItemText (dlg, IDC_CLIPEDIT_SEND, _("&Copy"));
177 SetDlgItemText (dlg, IDC_CLIPEDIT_CLEAR, _("Clea&r"));
178 SetDlgItemText (dlg, IDC_CLIPEDIT_LOAD, _("&Load"));
179 SetDlgItemText (dlg, IDC_CLIPEDIT_SAVE, _("&Save"));
180
181 load_clipboard (dlg);
182 center_window (dlg, NULL);
183 SetForegroundWindow (dlg);
184 return TRUE;
185
186 case WM_SYSCOMMAND:
187 if (LOWORD (wparam) == SC_CLOSE)
188 EndDialog (dlg, TRUE);
189 return TRUE;
190
191 case WM_COMMAND:
192 switch (LOWORD (wparam)) {
193 case IDOK:
194 EndDialog (dlg, TRUE);
195 return TRUE;
196
197 case IDC_CLIPEDIT_SEND:
198 if (IsDlgButtonChecked (dlg, IDC_CLIPEDIT_QUOTE)) {
199 gpgme_data_t txt;
200 gpg_data_new_from_clipboard (&txt, 0);
201 gpg_data_mail_quote (&txt);
202 gpg_data_release_and_set_clipboard (txt, 0);
203 SendMessage (dlg, WM_INITDIALOG, 0, 0);
204 return TRUE;
205 }
206 SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, EM_SETSEL, 0, -1);
207 SendDlgItemMessage (dlg, IDC_CLIPEDIT_CLIPTEXT2, WM_COPY, 0, 0);
208 return TRUE;
209
210 case IDC_CLIPEDIT_CLEAR:
211 if (OpenClipboard (NULL) == FALSE) {
212 msg_box (dlg, winpt_strerror (WPTERR_CLIP_OPEN),
213 _("Clipboard"), MB_ERR);
214 return TRUE;
215 }
216 if (EmptyClipboard () == FALSE)
217 msg_box (dlg, winpt_strerror (WPTERR_CLIP_EMPTY),
218 _("Clipboard"), MB_ERR);
219 else
220 SetDlgItemText (dlg, IDC_CLIPEDIT_CLIPTEXT2, "");
221 CloseClipboard ();
222 return TRUE;
223
224 case IDC_CLIPEDIT_LOAD:
225 if (!load_clipboard_from_file (dlg)) {
226 /* XXX: for some files the code produces a crash! */
227 PostMessage (dlg, WM_COMMAND, MAKEWPARAM(IDC_CLIPEDIT_SEND, 0), NULL);
228 }
229 return TRUE;
230
231 case IDC_CLIPEDIT_SAVE:
232 save_clipboard_to_file (dlg);
233 return TRUE;
234 }
235 break;
236 }
237
238 return FALSE;
239 }
240

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26