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

Legend:
Removed from v.35  
changed lines
  Added in v.36

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26