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

Diff of /trunk/Src/wptClipImportDlg.cpp

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

revision 34 by twoaday, Wed Oct 26 11:20:09 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 2005 UTC
# Line 1  Line 1 
1  /* wptClipImportDlg.cpp - WinPT key import dialog  /* wptClipImportDlg.cpp - WinPT key import dialog
2   *      Copyright (C) 2001-2005 Timo Schulz   *      Copyright (C) 2001-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 <config.h>
24  #include "../resource.h"  #endif
25  #include "wptCrypto.h"  
26  #include "wptGPG.h"  #include <windows.h>
27  #include "wptCommonCtl.h"  #include <windows.h>
28  #include "wptKeylist.h"  
29  #include "wptNLS.h"  #include "../resource.h"
30  #include "wptErrors.h"  #include "wptCrypto.h"
31  #include "wptTypes.h"  #include "wptGPG.h"
32  #include "wptContext.h" /* for passphrase_s */  #include "wptCommonCtl.h"
33  #include "wptDlgs.h"  #include "wptKeylist.h"
34  #include "wptW32API.h"  #include "wptNLS.h"
35  #include "wptVersion.h"  #include "wptErrors.h"
36  #include "wptImport.h"  #include "wptTypes.h"
37    #include "wptContext.h" /* for passphrase_s */
38    #include "wptDlgs.h"
39  /* Import the PGP key data from the clipboard.  #include "wptW32API.h"
40     Return value: 0 on success. */  #include "wptVersion.h"
41  gpgme_error_t  #include "wptImport.h"
42  gpgme_op_clip_import (gpgme_ctx_t ctx)  
43  {  
44      gpgme_error_t err = 0;  /* Import the PGP key data from the clipboard.
45      gpgme_data_t keydata = NULL;     Return value: 0 on success. */
46        gpgme_error_t
47      err = gpg_data_new_from_clipboard (&keydata, 0);  gpgme_op_clip_import (gpgme_ctx_t ctx)
48      if (!err)  {
49          err = gpgme_op_import (ctx, keydata);      gpgme_error_t err = 0;
50        gpgme_data_t keydata = NULL;
51      gpgme_data_release (keydata);      
52      return err;      err = gpg_data_new_from_clipboard (&keydata, 0);
53  }      if (!err)
54            err = gpgme_op_import (ctx, keydata);
55    
56  /* Load the import statistics dialog with the results from @res. */        gpgme_data_release (keydata);
57  void      return err;
58  print_import_status (gpgme_import_result_t res)  }
59  {  
60      int rc = 0;  
61    /* Load the import statistics dialog with the results from @res. */  
62      dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT_STAT, glob_hwnd,  void
63                        import_status_dlg_proc, (LPARAM)res,  print_import_status (gpgme_import_result_t res)
64                        _("Key Import Statistics"), IDS_WINPT_IMPORT_STAT);  {
65      if (res->imported || res->secret_imported)      int rc = 0;
66          keycache_set_reload (1); /* XXX: update flag */  
67  }      dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT_STAT, glob_hwnd,
68                          import_status_dlg_proc, (LPARAM)res,
69                          _("Key Import Statistics"), IDS_WINPT_IMPORT_STAT);
70  /* Dialog procedure for importing key clipboard data. */      if (res->imported || res->secret_imported)
71  BOOL CALLBACK          keycache_set_reload (1); /* XXX: update flag */
72  clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  }
73  {  
74      static listview_ctrl_t lv = NULL;  
75      static int is_revcert;  /* Dialog procedure for importing key clipboard data. */
76      static int has_seckeys;  BOOL CALLBACK
77      int rc = 0, id = 0;      clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
78      gpgme_error_t err;  {
79      gpgme_ctx_t ctx;      static listview_ctrl_t lv = NULL;
80      gpgme_import_result_t res;      static int is_revcert;
81      gpgme_key_t *selkeys = NULL;      static int has_seckeys;
82            int rc = 0, id = 0;    
83      switch( msg ) {      gpgme_error_t err;
84      case WM_INITDIALOG:      gpgme_ctx_t ctx;
85          SetWindowText (dlg, _("Key Import"));      gpgme_import_result_t res;
86          SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import"));      gpgme_key_t *selkeys = NULL;
87        
88          rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST));      switch( msg ) {
89          if (rc)      case WM_INITDIALOG:
90              BUG (NULL);          SetWindowText (dlg, _("Key Import"));
91          SetForegroundWindow (dlg);          SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import"));
92          center_window (dlg, NULL);  
93          rc = implist_load (lv, NULL, &is_revcert, &has_seckeys);          rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST));
94          return TRUE;          if (rc)
95                        BUG (NULL);
96      case WM_DESTROY:          SetForegroundWindow (dlg);
97          if( lv ) {          center_window (dlg, NULL);
98              implist_delete(lv);          rc = implist_load (lv, NULL, &is_revcert, &has_seckeys);
99              lv = NULL;          return TRUE;
100          }          
101          return FALSE;      case WM_DESTROY:
102                    if( lv ) {
103      case WM_SYSCOMMAND:              implist_delete(lv);
104          if( LOWORD (wparam) == SC_CLOSE )              lv = NULL;
105              EndDialog( dlg, TRUE );          }
106          return FALSE;          return FALSE;
107                    
108      case WM_COMMAND:      case WM_SYSCOMMAND:
109          switch( LOWORD( wparam ) ) {          if( LOWORD (wparam) == SC_CLOSE )
110          case IDCANCEL:              EndDialog( dlg, TRUE );
111              EndDialog (dlg, TRUE);          return FALSE;
112              return TRUE;          
113                    case WM_COMMAND:
114          case IDC_IMPORT_DOIT:          switch( LOWORD( wparam ) ) {
115              if (has_seckeys > 0) {          case IDCANCEL:
116                  msg_box (dlg, _("Some of the imported keys are secret keys.\n\n"              EndDialog (dlg, TRUE);
117                                  "The ownertrust values of these keys must be\n"              return TRUE;
118                                  "set manually via the Key Properties dialog."),              
119                           _("Import"), MB_INFO);          case IDC_IMPORT_DOIT:
120              }              if (has_seckeys > 0) {
121              SetForegroundWindow (dlg);                  msg_box (dlg, _("Some of the imported keys are secret keys.\n\n"
122              center_window (dlg, NULL);                                  "The ownertrust values of these keys must be\n"
123                                    "set manually via the Key Properties dialog."),
124              /* XXX: support interactive and only import some keys. */                           _("Import"), MB_INFO);
125              /*              }
126              int n;              SetForegroundWindow (dlg);
127              char keyid[32];              center_window (dlg, NULL);
128              n = listview_count_items (lv, 0);        
129              if( n > 1 && listview_count_items( lv, 1 ) > 0 ) {              /* XXX: support interactive and only import some keys. */
130                  selkeys = calloc (n+1, sizeof (gpgme_key_t));              /*
131                  if (!selkeys)              int n;
132                      BUG (NULL);              char keyid[32];
133                  for (id = 0; id < n; id++) {              n = listview_count_items (lv, 0);      
134                      if (listview_get_item_state (lv, id)) {              if( n > 1 && listview_count_items( lv, 1 ) > 0 ) {
135                          listview_get_item_text (lv, id, 2, keyid, DIM (keyid)-1);                  selkeys = calloc (n+1, sizeof (gpgme_key_t));
136                          // XXX: set the keyid??                  if (!selkeys)
137                          // ( selkeys, keyid+2 );                      BUG (NULL);
138                      }                  for (id = 0; id < n; id++) {
139                  }                      if (listview_get_item_state (lv, id)) {
140              }                          listview_get_item_text (lv, id, 2, keyid, DIM (keyid)-1);
141              */                          // XXX: set the keyid??
142                            // ( selkeys, keyid+2 );
143              err = gpgme_new (&ctx);                      }
144              if (err)                  }
145                  BUG (NULL);              }
146              err = gpgme_op_clip_import (ctx);              */
147              if (err) {  
148                  msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR);              err = gpgme_new (&ctx);
149                  gpgme_release (ctx);              if (err)
150                  return FALSE;                  BUG (NULL);
151              }              err = gpgme_op_clip_import (ctx);
152              res = gpgme_op_import_result (ctx);              if (err) {
153              print_import_status (res);                  msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR);
154              if (res->no_user_id > 0) {                              gpgme_release (ctx);
155                  msg_box (dlg, _("Key without a self signature was dectected!\n"                  return FALSE;
156                                  "(This key is NOT usable for encryption, etc)\n"              }
157                                  "\n"              res = gpgme_op_import_result (ctx);
158                                  "Cannot import these key(s)."), _("Import"), MB_INFO);              print_import_status (res);
159              }              if (res->no_user_id > 0) {            
160              gpgme_release (ctx);                  msg_box (dlg, _("Key without a self signature was dectected!\n"
161              EndDialog (dlg, TRUE);                                  "(This key is NOT usable for encryption, etc)\n"
162              return TRUE;                                  "\n"
163          }                                  "Cannot import these key(s)."), _("Import"), MB_INFO);
164          break;              }
165      }              gpgme_release (ctx);
166                    EndDialog (dlg, TRUE);
167      return FALSE;              return TRUE;
168  }          }
169            break;
170        }
171        
172        return FALSE;
173    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26