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

Diff of /trunk/Src/wptFileSaveDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 47 by werner, Mon Oct 31 14:04:59 2005 UTC revision 247 by twoaday, Fri Jul 21 08:19:24 2006 UTC
# Line 1  Line 1 
1  /* wptFileSaveDlg.cpp - Save a file  /* wptFileSaveDlg.cpp - Extract plaintext and save it to a file
2   *      Copyright (C) 2002, 2003 Timo Schulz   *      Copyright (C) 2002, 2003, 2005, 2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 17  Line 17 
17   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19   */   */
   
20  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
21  #include <config.h>  #include <config.h>
22  #endif  #endif
23    
24  #include <windows.h>  #include <windows.h>
 #include <windows.h>  
25    
26  #include "resource.h"  #include "resource.h"
27  #include "wptTypes.h"  #include "wptTypes.h"
# Line 32  Line 30 
30  #include "wptW32API.h"  #include "wptW32API.h"
31  #include "wptErrors.h"  #include "wptErrors.h"
32    
33    
34  static void  static void
35  switch_buttons( HWND dlg, int file )  switch_buttons (HWND dlg, int file)
36  {  {
37      int check1 = file? BST_CHECKED : BST_UNCHECKED;      int check1 = file? BST_CHECKED : BST_UNCHECKED;
38      int check2 = file? BST_UNCHECKED: BST_CHECKED;      int check2 = file? BST_UNCHECKED: BST_CHECKED;
39            
40      CheckDlgButton( dlg, IDC_FILE_SAVE_TOFILE, check1 );      CheckDlgButton (dlg, IDC_FILE_SAVE_TOFILE, check1);
41      CheckDlgButton( dlg, IDC_FILE_SAVE_CLIP, check2 );          CheckDlgButton (dlg, IDC_FILE_SAVE_CLIP, check2);
42  } /* switch_buttons */  }
43    
44    
45    /* Dialog box procedure to save the plaintext of a signature
46       plus some additional information. */
47  BOOL CALLBACK  BOOL CALLBACK
48  file_save_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  file_save_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
49  {      {    
50      gpgme_data_t sig, plain;      gpgme_data_t sig, plain;
51      gpgme_error_t err;      gpgme_error_t err;
52      const char *filename;      const char *filename;
53      int has_data;      int has_data;
54      char file[768];      char file[MAX_PATH+128];
55            
56      switch ( msg ) {      switch (msg) {
57      case WM_INITDIALOG:      case WM_INITDIALOG:
58          #ifndef LANG_DE          SetWindowText (dlg, _("Save Plaintext"));
59          SetWindowText( dlg, _("Save Plaintext") );          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
60          #endif          SetDlgItemText (dlg, IDC_FILE_SAVE, _("&Save additional information"));
61          switch_buttons( dlg, 0 );          SetDlgItemText (dlg, IDC_FILE_SAVE_TOFILE, _("Save to &file"));
62          SetForegroundWindow( dlg );          SetDlgItemText (dlg, IDC_FILE_SAVE_CLIP, _("Send to &clipboard"));
63            switch_buttons (dlg, 1);
64            center_window (dlg, NULL);
65            SetForegroundWindow (dlg);
66          return TRUE;          return TRUE;
67                    
     case WM_SYSCOMMAND:  
         if( LOWORD( wparam ) == SC_CLOSE )  
             EndDialog( dlg, TRUE );  
         return FALSE;  
           
68      case WM_COMMAND:      case WM_COMMAND:
69          switch ( LOWORD(wparam) ) {          switch (LOWORD (wparam)) {
70          case IDC_FILE_SAVE_SELECT:          case IDC_FILE_SAVE_SELECT:
71              filename = get_filesave_dlg( dlg, _("Destination for Plaintext"), NULL, NULL );              filename = get_filesave_dlg (dlg, _("Destination for Plaintext"), NULL, NULL);
72              if( filename ) {              if (filename) {
73                  SetDlgItemText( dlg, IDC_FILE_SAVE_FILE, filename );                  SetDlgItemText (dlg, IDC_FILE_SAVE_FILE, filename);
74                  switch_buttons( dlg, 1 );                  switch_buttons (dlg, 1);
75              }              }
76              return TRUE;              return TRUE;
77                            
78          case IDOK:          case IDOK:
79              if( IsDlgButtonChecked( dlg, IDC_FILE_SAVE_TOFILE ) ) {              if (IsDlgButtonChecked (dlg, IDC_FILE_SAVE_TOFILE)) {
80                  if( !GetDlgItemText( dlg, IDC_FILE_SAVE_FILE, file, sizeof file - 1 ) ) {                  if (!GetDlgItemText (dlg, IDC_FILE_SAVE_FILE, file, sizeof (file) - 1)) {
81                      msg_box( dlg, _("Please enter a filename."), _("Save Plaintext"), MB_INFO );                      msg_box (dlg, _("Please enter a filename."), _("Save Plaintext"), MB_INFO);
82                      return FALSE;                      return TRUE;
83                  }                  }
84                    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                  err = gpg_data_new_from_clipboard (&sig, 0);                  err = gpg_data_new_from_clipboard (&sig, 0);
90                  if( err ) {                  if (err) {
91                      msg_box( dlg, winpt_strerror( WPTERR_CLIP_GET ), _("Save Plaintext"), MB_ERR );                      msg_box (dlg, winpt_strerror (WPTERR_CLIP_GET),
92                      return FALSE;                               _("Save Plaintext"), MB_ERR);
93                        return TRUE;
94                    }
95                    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                  gpg_data_extract_plaintext( sig, &plain );                  gpgme_data_release (sig);
                 gpg_data_release_and_set_file( plain, file );  
                 gpgme_data_release( sig );  
                 msg_box( dlg, _("Finished"), _("Save Plaintext"), MB_OK );  
104              }              }
105              else if( IsDlgButtonChecked( dlg, IDC_FILE_SAVE_CLIP ) ) {              else if (IsDlgButtonChecked (dlg, IDC_FILE_SAVE_CLIP)) {
106                  if( !gpg_clip_istext_avail( &has_data ) && !has_data ) {                  if (!gpg_clip_istext_avail (&has_data) && !has_data) {
107                      msg_box( dlg, winpt_strerror( WPTERR_CLIP_ISEMPTY ), _("Save Plaintext"), MB_ERR );                      msg_box (dlg, winpt_strerror (WPTERR_CLIP_ISEMPTY),
108                                 _("Save Plaintext"), MB_ERR);
109                      return FALSE;                      return FALSE;
110                  }                  }
111                  err = gpg_data_new_from_clipboard (&sig, 0);                  err = gpg_data_new_from_clipboard (&sig, 0);
112                  if( err ) {                  if (err) {
113                      msg_box( dlg, winpt_strerror( WPTERR_CLIP_GET ), _("Save Plaintext"), MB_ERR );                      msg_box (dlg, winpt_strerror (WPTERR_CLIP_GET),
114                                 _("Save Plaintext"), MB_ERR);
115                      return FALSE;                      return FALSE;
116                  }                  }
117                  gpg_data_extract_plaintext( sig, &plain );                  gpg_data_extract_plaintext (sig, &plain);
118                  gpg_data_release_and_set_clipboard( plain, 0 );                  gpg_data_release_and_set_clipboard (plain, 0);
119                  gpgme_data_release( sig );                  gpgme_data_release (sig);
120                  msg_box( dlg, _("Finished"), _("Save Plaintext"), MB_OK );                  msg_box (dlg, _("Finished"), _("Save Plaintext"), MB_OK);
121              }              }
122              EndDialog( dlg, TRUE );              EndDialog (dlg, TRUE);
123              return TRUE;              return TRUE;
124                            
125          case IDCANCEL:          case IDCANCEL:
126              EndDialog( dlg, FALSE );              EndDialog (dlg, FALSE);
127              return FALSE;              return FALSE;
128          }          }
129          break;          break;
130      }      }
131            
132      return FALSE;      return FALSE;
133  } /* file_save_dlg_proc */  }

Legend:
Removed from v.47  
changed lines
  Added in v.247

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26