/[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 23 by twoaday, Fri Sep 30 10:10:16 2005 UTC revision 30 by twoaday, Sat Oct 22 10:17:59 2005 UTC
# Line 34  Line 34 
34  #include "wptVersion.h"  #include "wptVersion.h"
35  #include "wptImport.h"  #include "wptImport.h"
36    
 static HANDLE thread_hd = NULL;  
 static int dlg_init = 0;  
   
 struct data_callback_s {  
     listview_ctrl_t lv;  
     int is_revcert;  
     int has_seckeys;  
     const char * filename;  
     HWND root_dlg, dlg;  
 };  
 typedef struct data_callback_s *data_callback_t;  
   
   
   
 BOOL CALLBACK  
 data_cb_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  
 {      
     static data_callback_t ctx;  
     int rc;  
   
     switch( msg ) {  
     case WM_INITDIALOG:  
         ctx = (data_callback_t)lparam;  
         if (!ctx)  
             BUG (NULL);  
         SetForegroundWindow( dlg );  
         center_window( dlg, NULL );  
         dlg_init = 1;  
         ctx->dlg = dlg;  
         ShowWindow (ctx->root_dlg, SW_HIDE);  
         SetTimer (dlg, 0x123, 100, NULL);  
         break;  
   
     case WM_TIMER:  
         /* if the procedure is done, we make the callback window invisible  
            and the root dialog is forced to the forceground again. */  
         rc = implist_load (ctx->lv, ctx->filename, &ctx->is_revcert, &ctx->has_seckeys);  
         if (rc) {  
             KillTimer (dlg, 0x123);  
             PostQuitMessage (0);  
             EndDialog (dlg, FALSE);  
         }  
         SetForegroundWindow( ctx->root_dlg );  
         ShowWindow( ctx->root_dlg, SW_SHOW );  
         ShowWindow( dlg, SW_HIDE );  
         KillTimer( dlg, 0x123 );  
         break;  
     }  
     return FALSE;  
 } /* data_cb_dlg_proc */  
   
   
 DWORD WINAPI  
 data_cb_thread (void * opaque)  
 {  
     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_DATACB, glob_hwnd,  
                     data_cb_dlg_proc, (LPARAM)opaque);  
     ExitThread (0);  
     return 0;  
 } /* data_cb_thread */  
   
   
 int  
 data_cb_dlg_create (data_callback_t ctx)  
 {  
     DWORD tid;  
     SECURITY_ATTRIBUTES sec_attr;  
   
     if (dlg_init)  
         return 0;  
   
     memset (&sec_attr, 0, sizeof (sec_attr));  
     sec_attr.bInheritHandle = FALSE;  
     sec_attr.nLength = sizeof (sec_attr);  
     thread_hd = CreateThread( &sec_attr, 0, data_cb_thread, (void *)ctx, 0, &tid );  
     if( thread_hd == NULL ) {  
         msg_box( NULL, "Could not create data callback thread", _("WinPT"), MB_ERR );  
         return WPTERR_GENERAL;  
     }  
     return 0;  
 } /* data_cb_dlg_create */  
   
   
 void  
 data_cb_dlg_destroy( void )  
 {  
     if( dlg_init ) {  
         TerminateThread( thread_hd, 0 );  
         CloseHandle( thread_hd );  
         thread_hd = NULL;  
         dlg_init = 0;  
     }  
 } /* data_cb_dlg_destroy */  
   
   
   
   
 data_callback_t  
 data_cb_new( const char *filename, listview_ctrl_t lv, HWND dlg )  
 {  
     data_callback_t ctx;  
   
     ctx = new struct data_callback_s;    
     if( !ctx )  
         BUG( NULL );  
     ctx->filename = filename;  
     ctx->is_revcert = 0;  
     ctx->lv = lv;  
     ctx->root_dlg = dlg;  
     return ctx;  
 } /* data_cb_new */  
   
   
37    
38  /* Import the PGP key data from the clipboard.  /* Import the PGP key data from the clipboard.
39     Return value: 0 on success. */     Return value: 0 on success. */
# Line 164  gpgme_op_clip_import (gpgme_ctx_t ctx) Line 51  gpgme_op_clip_import (gpgme_ctx_t ctx)
51      return err;      return err;
52  }  }
53    
54    
55  /* Load the import statistics dialog with the results from @res. */    /* Load the import statistics dialog with the results from @res. */  
56  void  void
57  print_import_status (gpgme_import_result_t res)  print_import_status (gpgme_import_result_t res)
# Line 183  BOOL CALLBACK Line 71  BOOL CALLBACK
71  clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
72  {  {
73      static listview_ctrl_t lv = NULL;      static listview_ctrl_t lv = NULL;
74      static data_callback_t cb;      static int is_revcert;
75      int rc = 0, id = 0;      static int has_seckeys;
76      //int n;      int rc = 0, id = 0;    
     //char keyid[32];  
77      gpgme_error_t err;      gpgme_error_t err;
78      gpgme_ctx_t ctx;      gpgme_ctx_t ctx;
79      gpgme_import_result_t res;      gpgme_import_result_t res;
# Line 194  clip_import_dlg_proc (HWND dlg, UINT msg Line 81  clip_import_dlg_proc (HWND dlg, UINT msg
81            
82      switch( msg ) {      switch( msg ) {
83      case WM_INITDIALOG:      case WM_INITDIALOG:
84  #ifndef LANG_DE      #ifndef LANG_DE
85          SetWindowText( dlg, _("Key Import") );          SetWindowText (dlg, _("Key Import"));
86          SetDlgItemText( dlg, IDC_IMPORT_DOIT, _("&Import") );          SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import"));
87  #endif      #endif
88          rc = implist_build( &lv, GetDlgItem( dlg, IDC_IMPORT_KEYLIST ) );          rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST));
89          if( rc )          if (rc)
90              BUG( NULL );              BUG (NULL);
91          SetForegroundWindow( dlg );          SetForegroundWindow (dlg);
92          center_window( dlg, NULL );          center_window (dlg, NULL);
93          //ctx = data_cb_new( NULL, lv, dlg );          rc = implist_load (lv, NULL, &is_revcert, &has_seckeys);
         //data_cb_dlg_create( ctx );  
         cb = new data_callback_s;  
         memset (cb, 0, sizeof (data_callback_s));  
         rc = implist_load (lv, NULL, &cb->is_revcert, &cb->has_seckeys);  
94          return TRUE;          return TRUE;
95                    
96      case WM_DESTROY:      case WM_DESTROY:
97          if( lv ) {          if( lv ) {
98              implist_delete( lv );              implist_delete(lv);
99              lv = NULL;              lv = NULL;
100          }          }
         free_if_alloc (cb);  
101          return FALSE;          return FALSE;
102                    
103      case WM_SYSCOMMAND:      case WM_SYSCOMMAND:
# Line 226  clip_import_dlg_proc (HWND dlg, UINT msg Line 108  clip_import_dlg_proc (HWND dlg, UINT msg
108      case WM_COMMAND:      case WM_COMMAND:
109          switch( LOWORD( wparam ) ) {          switch( LOWORD( wparam ) ) {
110          case IDCANCEL:          case IDCANCEL:
111              data_cb_dlg_destroy();              EndDialog (dlg, TRUE);
             EndDialog( dlg, TRUE );  
112              return TRUE;              return TRUE;
113                            
114          case IDC_IMPORT_DOIT:          case IDC_IMPORT_DOIT:
115              ShowWindow (cb->dlg, SW_SHOW );              if (has_seckeys > 0) {
             if (cb->has_seckeys) {  
116                  msg_box (dlg, _("Some of the imported keys are secret keys.\n\n"                  msg_box (dlg, _("Some of the imported keys are secret keys.\n\n"
117                                  "The ownertrust values of these keys must be\n"                                  "The ownertrust values of these keys must be\n"
118                                  "set manually via the Key Properties dialog."),                                  "set manually via the Key Properties dialog."),
119                           _("Import"), MB_INFO);                           _("Import"), MB_INFO);
120              }              }
121              SetForegroundWindow (cb->dlg);              SetForegroundWindow (dlg);
122              center_window (cb->dlg, NULL );              center_window (dlg, NULL);
123    
124                /* XXX: support interactive and only import some keys. */
125              /*              /*
126                int n;
127                char keyid[32];
128              n = listview_count_items (lv, 0);                    n = listview_count_items (lv, 0);      
129              if( n > 1 && listview_count_items( lv, 1 ) > 0 ) {              if( n > 1 && listview_count_items( lv, 1 ) > 0 ) {
130                  selkeys = calloc (n+1, sizeof (gpgme_key_t));                  selkeys = calloc (n+1, sizeof (gpgme_key_t));
# Line 256  clip_import_dlg_proc (HWND dlg, UINT msg Line 140  clip_import_dlg_proc (HWND dlg, UINT msg
140              }              }
141              */              */
142    
             /* XXX: support interactive and only import some keys. */  
143              err = gpgme_new (&ctx);              err = gpgme_new (&ctx);
144              if (err)              if (err)
145                  BUG (NULL);                  BUG (NULL);
146              err = gpgme_op_clip_import (ctx);              err = gpgme_op_clip_import (ctx);
147              if (err) {              if (err) {
148                  msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR);                  msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR);
149                    gpgme_release (ctx);
150                  return FALSE;                  return FALSE;
151              }              }
152              res = gpgme_op_import_result (ctx);              res = gpgme_op_import_result (ctx);
# Line 282  clip_import_dlg_proc (HWND dlg, UINT msg Line 166  clip_import_dlg_proc (HWND dlg, UINT msg
166            
167      return FALSE;      return FALSE;
168  }  }
   

Legend:
Removed from v.23  
changed lines
  Added in v.30

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26