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

Diff of /trunk/Src/wptOwnertrustDlg.cpp

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

revision 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 48 by werner, Mon Oct 31 21:14:11 2005 UTC
# Line 1  Line 1 
1  /* wptOwnertrust.cpp - Ownertrust im- and export  /* wptOwnertrust.cpp - Ownertrust im- and export
2   *      Copyright (C) 2001, 2002, 2003 Timo Schulz   *      Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3   *   *      Copyright (C) 2005 g10 Code GmbH
4   * This file is part of WinPT.   *
5   *   * This file is part of WinPT.
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   * WinPT is free software; you can redistribute it and/or modify
8   * the Free Software Foundation; either version 2 of the License, or   * it under the terms of the GNU General Public License as published by
9   * (at your option) any later version.   * the Free Software Foundation; either version 2 of the License, or
10   *   * (at your option) any later version.
11   * WinPT is distributed in the hope that it will be useful,   *
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * WinPT is distributed in the hope that it will be useful,
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * GNU General Public License for more details.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   *   * GNU General Public License for more details.
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,   * You should have received a copy of the GNU General Public License
18   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA   * along with WinPT; if not, write to the Free Software Foundation,
19   */   * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20     */
21  #include <windows.h>  
22    #ifdef HAVE_CONFIG_H
23  #include "../resource.h"  #include <config.h>
24  #include "wptTypes.h"  #endif
25  #include "wptGPG.h"  
26  #include "wptErrors.h"  #include <windows.h>
27  #include "wptNLS.h"  #include <sys/stat.h>
28  #include "wptW32API.h"  
29    #include "resource.h"
30    #include "wptTypes.h"
31  BOOL CALLBACK  #include "wptGPG.h"
32  ownertrust_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  #include "wptErrors.h"
33  {  #include "wptNLS.h"
34      gpgme_error_t err;  #include "wptW32API.h"
35      char fname[256];  
36        
37      switch( msg ) {  /* Export the ownertrust to the file @fname.
38      case WM_INITDIALOG:     Return value: 0 on success. */
39  #ifndef LANG_DE  static gpgme_error_t
40          SetWindowText( dlg, _("Ownertrust") );  gpg_export_ownertrust (const char *fname)
41          SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") );  {
42          SetDlgItemText( dlg, IDC_OWNERTRUST_DESC,      gpgme_error_t err;
43                         _("Here it is possible to save or restore the ownertrust from the "      char *ot_data = NULL;
44                           "'trustdb' file. This could be very useful because the values are NOT "      FILE *f;
45                           "stored in the keyring.") );  
46  #endif      err = gpg_manage_ownertrust (&ot_data, 1);
47          center_window( dlg );      if (err)
48          SetForegroundWindow( dlg );          return err;
49          return TRUE;      f = fopen (fname, "wb");
50                if (f) {
51      case WM_SYSCOMMAND:          fwrite (ot_data, 1, strlen (ot_data), f);
52          if( LOWORD (wparam) == SC_CLOSE )          fclose (f);
53              EndDialog( dlg, TRUE );      }
54          return FALSE;      else
55                    err = gpg_error (GPG_ERR_ENOENT);
56      case WM_COMMAND:      free (ot_data);
57          switch ( LOWORD( wparam ) ) {      return 0;
58          case IDC_OWNERTRUST_SELFILE:  }
59              const char * s;  
60              s = get_filename_dlg( dlg, 1, _("Please select a filename"), NULL, NULL );  
61              if( s && *s )  /* Import the ownertrust from file @fname.
62                  SetDlgItemText( dlg, IDC_OWNERTRUST_FILE, s );     Return value: 0 on success. */
63              break;  static gpgme_error_t
64    gpg_import_ownertrust (const char *fname)
65          case IDC_OWNERTRUST_EXPORT:  {
66              if( !GetDlgItemText( dlg, IDC_OWNERTRUST_FILE, fname, sizeof fname -1 ) ) {      gpgme_error_t err;
67                  msg_box( dlg, _("Please enter the filename."), _("Ownertrust"), MB_ERR );      FILE *f;
68                  return FALSE;      struct stat st;
69              }      char *ot_data;
70              err = gpgme_op_ownertrust_export_file( fname );  
71              if( err ) {      if (stat (fname, &st))
72                  msg_box( dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );          return gpg_error (GPG_ERR_ENOENT);
73                  return FALSE;      f = fopen (fname, "rb");
74              }      if (!f)
75              status_box( dlg, _("Ownertrust successfully exported."), _("GnuPG Status") );          return gpg_error (GPG_ERR_ENOENT);
76              EndDialog( dlg, TRUE );      ot_data = (char*)calloc (1, st.st_size+1);
77              return TRUE;      if (!ot_data)
78            BUG (NULL);
79          case IDC_OWNERTRUST_IMPORT:      fread (ot_data, 1, st.st_size, f);
80              if( !GetDlgItemText( dlg, IDC_OWNERTRUST_FILE, fname, sizeof fname-1 ) ) {      fclose (f);
81                  msg_box( dlg, _("Please enter the filename."), _("Ownertrust"), MB_ERR );  
82                  return FALSE;      err = gpg_manage_ownertrust (&ot_data, 0);
83              }  
84              err = gpgme_op_ownertrust_import_file( fname );                  free (ot_data);
85              if( err ) {      return 0;
86                  msg_box( dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );  }
87                  return FALSE;  
88              }  
89              status_box( dlg, _("Ownertrust succefully imported."), _("GnuPG Status") );  /* Dialog procedure to manage the ownertrust. */
90              EndDialog( dlg, TRUE );  BOOL CALLBACK
91              return TRUE;  ownertrust_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
92                {
93          case IDCANCEL:      gpgme_error_t err;
94              EndDialog( dlg, FALSE );      const char *fname;
95              return FALSE;      
96          }      switch( msg ) {
97          break;      case WM_INITDIALOG:
98      }      #ifndef LANG_DE
99                SetWindowText( dlg, _("Ownertrust") );
100      return FALSE;          SetDlgItemText( dlg, IDC_OWNERTRUST_INFO, _("File") );
101  } /* ownertrust_dlg_proc */          SetDlgItemText( dlg, IDC_OWNERTRUST_DESC,
102                           _("Here it is possible to save or restore the ownertrust from the "
103                             "'trustdb' file. This could be very useful because the values are NOT "
104                             "stored in the keyring.") );
105        #endif
106            center_window( dlg, NULL );
107            SetForegroundWindow( dlg );
108            return TRUE;
109            
110        case WM_SYSCOMMAND:
111            if (LOWORD (wparam) == SC_CLOSE)
112                EndDialog (dlg, TRUE);
113            return TRUE;
114            
115        case WM_COMMAND:
116            switch (LOWORD (wparam)) {
117            case IDC_OWNERTRUST_EXPORT:
118                fname = get_filesave_dlg (dlg, _("Select file name for output"), NULL, NULL);
119                if (!fname)
120                    return TRUE;
121                err = gpg_export_ownertrust (fname);
122                if (err) {
123                    msg_box (dlg, gpgme_strerror( err ), _("Ownertrust"), MB_ERR );
124                    return TRUE;
125                }
126                status_box (dlg, _("Ownertrust successfully exported."), _("GnuPG Status"));
127                return TRUE;
128    
129            case IDC_OWNERTRUST_IMPORT:
130                fname = get_fileopen_dlg (dlg, _("Select file name for input"), NULL, NULL);
131                if (!fname)
132                    return TRUE;
133                err = gpg_import_ownertrust (fname);
134                if (err) {
135                    msg_box (dlg, gpgme_strerror (err), _("Ownertrust"), MB_ERR);
136                    return TRUE;
137                }
138                status_box (dlg, _("Ownertrust succefully imported."), _("GnuPG Status"));
139                return TRUE;
140                
141            case IDCANCEL:
142                EndDialog (dlg, FALSE);
143                return TRUE;
144            }
145            break;
146        }
147        
148        return FALSE;
149    }

Legend:
Removed from v.2  
changed lines
  Added in v.48

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26