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

Diff of /trunk/Src/wptMainProc.cpp

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

revision 72 by twoaday, Mon Nov 7 12:48:34 2005 UTC revision 225 by twoaday, Tue Jun 6 13:37:59 2006 UTC
# Line 1  Line 1 
1  /* wptMainProc.cpp - Main window procedure  /* wptMainProc.cpp - Main window procedure
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2006 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 44  Line 44 
44  #include "wptCard.h"  #include "wptCard.h"
45  #include "wptCryptdisk.h"  #include "wptCryptdisk.h"
46  #include "wptCardEdit.h"  #include "wptCardEdit.h"
 #include "wptCrypto.h"  
47    
48  extern HWND activ_hwnd;  
49    void update_keycache (HWND hwnd);
50    
51  static int cmd = 0;  static int cmd = 0;
52  static int wipe_contents = 0;  static int wipe_contents = 0;
53    
# Line 87  elgamal_warn_dlg_proc (HWND dlg, UINT ms Line 88  elgamal_warn_dlg_proc (HWND dlg, UINT ms
88  }  }
89    
90    
 /* @unused  
 static int  
 cleanup_tmp_files (void)  
 {  
     struct _finddata_t dat;  
     char tmp[384];  
     long hd;  
   
     if (GetTempPath (sizeof (tmp)-1, tmp) == FALSE ||  
         SetCurrentDirectory (tmp) == FALSE) {  
         winpt_errmsg ("GetTempPath", 0);  
         return WPTERR_GENERAL;  
     }  
     hd = _findfirst ("gpgmeOUT*", &dat);  
     if (hd == -1)  
         return 0;  
     do {  
         secure_unlink (dat.name, WIPE_MODE_SIMPLE);  
     } while (_findnext (hd, &dat) == 0);  
     _findclose (hd);  
     return 0;  
 }  
 */  
   
   
91  /* Dialog box procedure to confirm to delete the clipboard contents. */  /* Dialog box procedure to confirm to delete the clipboard contents. */
92  static BOOL CALLBACK  static BOOL CALLBACK
93  confirm_delclipboard_dlg (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)  confirm_delclipboard_dlg (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
# Line 119  confirm_delclipboard_dlg (HWND dlg, UINT Line 95  confirm_delclipboard_dlg (HWND dlg, UINT
95      switch (msg) {      switch (msg) {
96      case WM_INITDIALOG:      case WM_INITDIALOG:
97          SetWindowText (dlg, _("Delete Clipboard Contents"));          SetWindowText (dlg, _("Delete Clipboard Contents"));
98            SetDlgItemText (dlg, IDC_CONFDELCLIP_BRAIN, _("&Remember the answer"));
99            SetDlgItemText (dlg, IDC_CONFDELCLIP_INFO, _("Do you want to delete the contents from the clipboard?"));
100            SetDlgItemText (dlg, IDYES, _("&Yes"));
101            SetDlgItemText (dlg, IDNO, _("&No"));
102          center_window (dlg, NULL);          center_window (dlg, NULL);
103          SetForegroundWindow (dlg);          SetForegroundWindow (dlg);
104          break;          break;
# Line 195  currwnd_gpg_dlg (HWND hwnd, UINT id, int Line 175  currwnd_gpg_dlg (HWND hwnd, UINT id, int
175              }              }
176          }          }
177          else if ((type & PGP_PUBKEY) && !(type & PGP_CLEARSIG))          else if ((type & PGP_PUBKEY) && !(type & PGP_CLEARSIG))
178              km_clip_import (GetDesktopWindow ());              km_clip_import (GetDesktopWindow (), NULL, NULL);
179          else {          else {
180              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd,              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd,
181                                clip_verify_dlg_proc, 0,                                clip_verify_dlg_proc, 0,
182                                _("Verify"), IDS_WINPT_VERIFY );                                _("Verify"), IDS_WINPT_VERIFY );
183              err  = gpg_error (GPG_ERR_EOF); /* make sure window is ot updated. */              err  = gpg_error (GPG_ERR_EOF); /* make sure window is not updated. */
184          }          }
185          break;          break;
186      }      }
# Line 215  clip_gpg_dlg (HWND hwnd, UINT id) Line 195  clip_gpg_dlg (HWND hwnd, UINT id)
195      gpgme_error_t err;      gpgme_error_t err;
196      int type;      int type;
197            
198      if( (id == ID_WINPT_SIGN || id == ID_WINPT_SIGNENCRYPT)      if ((id == ID_WINPT_SIGN || id == ID_WINPT_SIGNENCRYPT)
199          && gnupg_access_keyring (0) ) {          && gnupg_access_keyring (0)) {
200          msg_box( hwnd, _("Could not access secret keyring."), _("Sign"), MB_ERR );          msg_box (hwnd, _("Could not access secret keyring."), _("Sign"), MB_ERR);
201          return;          return;
202      }      }
203            
204      switch( id ) {      switch( id ) {
205      case ID_WINPT_SYMENC:      case ID_WINPT_SYMENC:
206          gpg_encrypt_symmetric();          gpg_encrypt_symmetric ();
207          break;          break;
208                    
209      case ID_WINPT_ENCRYPT:      case ID_WINPT_ENCRYPT:
# Line 262  clip_gpg_dlg (HWND hwnd, UINT id) Line 242  clip_gpg_dlg (HWND hwnd, UINT id)
242              text_input_s input;              text_input_s input;
243              gpgme_data_t sig;              gpgme_data_t sig;
244                            
245              memset( &input, 0, sizeof (input) );              memset (&input, 0, sizeof (input));
246              err = gpg_data_new_from_clipboard (&sig, 0);              err = gpg_data_new_from_clipboard (&sig, 0);
247              if( err ) {              if (err) {
248                  msg_box( hwnd, gpgme_strerror( err ),_("Verify"), MB_ERR );                  msg_box (hwnd, gpgme_strerror( err ),_("Verify"), MB_ERR);
249                  return;                  return;
250              }              }
251              input.type = 0;              input.type = 0;
252              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_TEXT, hwnd,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_TEXT, hwnd,
253                               text_input_dlg_proc, (LPARAM)&input,                                text_input_dlg_proc, (LPARAM)&input,
254                               _("Text Input"), IDS_WINPT_TEXT );                                _("Text Input"), IDS_WINPT_TEXT);
255                            
256              gpg_data_release_and_set_clipboard( sig, 0 );              /* the dialog might have changed the clipboard, so we restore
257              if( input.length ) {                 the original state (again). */
258                  dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd,              gpg_data_release_and_set_clipboard (sig, 0);
259                                   clip_verify_dlg_proc, (LPARAM)&input,              if (input.length > 0) {
260                                   _("Verify"), IDS_WINPT_VERIFY );                  dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd,
261                                      clip_verify_dlg_proc, (LPARAM)&input,
262                                      _("Verify"), IDS_WINPT_VERIFY);
263                  input.length = 0;                  input.length = 0;
264                  free_if_alloc( input.data );                  free_if_alloc (input.data);
265              }              }
266          }          }
267          else if (type & PGP_CLEARSIG) {          else if (type & PGP_CLEARSIG) {
# Line 288  clip_gpg_dlg (HWND hwnd, UINT id) Line 270  clip_gpg_dlg (HWND hwnd, UINT id)
270                                _("Verify"), IDS_WINPT_VERIFY );                                _("Verify"), IDS_WINPT_VERIFY );
271          }          }
272          else if ((type & PGP_PUBKEY) || (type & PGP_SECKEY))          else if ((type & PGP_PUBKEY) || (type & PGP_SECKEY))
273              km_clip_import (GetDesktopWindow ());              km_clip_import (GetDesktopWindow (), NULL, NULL);
274          else          else
275              msg_box (hwnd, _("Unknown OpenPGP type."), _("Clipboard"), MB_ERR);              msg_box (hwnd, _("Unknown OpenPGP type."), _("Clipboard"), MB_ERR);
276      }      }
277  }  }
278    
279    
 static bool  
 secret_key_available (void)  
 {  
     gpg_keycache_t sec = keycache_get_ctx (0);  
     if (!sec || gpg_keycache_get_size (sec) == 0)  
         return false;  
     return true;  
 }  
   
   
280  /* Load the Card Manager with the current card. */  /* Load the Card Manager with the current card. */
281  static void  static void
282  load_smartcard (void)  load_card_manager (void)
283  {  {
284      gpg_card_t card;      gpg_card_t card;
285    
286      card = gpg_card_load ();      card = gpg_card_load ();
287      if (card) {      if (!card)
288          dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_EDIT,          return;
289                            GetDesktopWindow (), card_edit_dlg_proc,  
290                            (LPARAM)card,      dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_CARD_EDIT,
291                            _("Card Edit"), IDS_WINPT_CARD_EDIT);                        GetDesktopWindow (), card_edit_dlg_proc,
292          gpg_card_release (card);                        (LPARAM)card,
293          card = NULL;                             _("Card Edit"), IDS_WINPT_CARD_EDIT);
294      }      gpg_card_release (card);
295  }  }
296    
297    
# Line 338  add_taskbar_icon (HWND hwnd, NOTIFYICOND Line 310  add_taskbar_icon (HWND hwnd, NOTIFYICOND
310  }  }
311    
312    
313    static void
314    init_common_controls (void)
315    {
316        INITCOMMONCONTROLSEX cce;
317    
318        /* date control, toolbar, trackbar, ... */
319        cce.dwSize = sizeof (INITCOMMONCONTROLSEX);
320        cce.dwICC = ICC_DATE_CLASSES|ICC_BAR_CLASSES;
321        InitCommonControlsEx (&cce);
322    }
323    
324    
325  /* Main message loop for the tray window. */  /* Main message loop for the tray window. */
326  LRESULT CALLBACK  LRESULT CALLBACK
327  winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)  winpt_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
328  {                {              
329      static NOTIFYICONDATA NID;      static NOTIFYICONDATA NID;
330      static int use_hotkey = 0;          static DWORD cookie;
331      reminder_ctx_s ctx;      static int use_hotkey = 0;
332      LPARAM param;      static int manual_shutdown = 0;
333      curr_wnd_ctx currwnd = {0};      HWND wnd;
     int rc, set_wc = 0, has_data = 0;  
     INITCOMMONCONTROLSEX cce;  
334      gpgme_error_t err;      gpgme_error_t err;
335        curr_wnd_ctx currwnd = {0};
336        const char *s;
337        int rc, set_wc = 0, has_data = 0;
338    
339      switch (msg) {      switch (msg) {
340      case WM_CREATE:      case WM_CREATE:
# Line 367  winpt_main_proc (HWND hwnd, UINT msg, WP Line 352  winpt_main_proc (HWND hwnd, UINT msg, WP
352              msg_box (hwnd, _("Could not set current window mode hooks."),              msg_box (hwnd, _("Could not set current window mode hooks."),
353                       _("WinPT Error"), MB_OK);                       _("WinPT Error"), MB_OK);
354          mapi_init ();          mapi_init ();
355          /* init common controls: date control. */          init_common_controls ();
356          cce.dwSize = sizeof (INITCOMMONCONTROLSEX);          html_help_init (&cookie);
         cce.dwICC = ICC_DATE_CLASSES;  
         InitCommonControlsEx (&cce);  
357          LoadLibrary ("RichEd32.Dll");          LoadLibrary ("RichEd32.Dll");
358            manual_shutdown = 0;
359          break;          break;
360                    
361      case WM_ENDSESSION:      case WM_ENDSESSION:
362      case WM_DESTROY:      case WM_DESTROY:
363      case WM_CLOSE:      case WM_CLOSE:
364      case WM_QUIT:      case WM_QUIT:
         cryptdisk_cleanup ();  
365          mapi_deinit ();          mapi_deinit ();
366          wsock_end ();                  wsock_end ();        
367          keycache_release (1);          keycache_release (1);
368          gnupg_backup_keyrings ();          gnupg_backup_keyrings (reg_prefs.auto_backup,
369                                    reg_prefs.backup.mode,
370                                    reg_prefs.backup.include_secr);
371          free_reg_prefs ();          free_reg_prefs ();
372          free_gnupg_table ();          free_gnupg_table ();
373          hotkeys_unregister (hwnd);          hotkeys_unregister (hwnd);
         release_file_lock (&mo_file);  
374          PTD_delete ();          PTD_delete ();
375          agent_flush_cache ();          agent_flush_cache ();
376            html_help_deinit (cookie);
377          if (!gpg_clip_istext_avail (&has_data) && has_data) {          if (!gpg_clip_istext_avail (&has_data) && has_data) {
378              int chk = get_reg_winpt_flag ("WipeClipboard");              int chk = get_reg_winpt_flag ("WipeClipboard");
379              if (chk == -1)              if (chk == -1 && manual_shutdown)
380                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CONFDELCLIP,                  DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CONFDELCLIP,
381                                  GetDesktopWindow (), confirm_delclipboard_dlg,                                  GetDesktopWindow (), confirm_delclipboard_dlg,
382                                  0);                                  0);
# Line 400  winpt_main_proc (HWND hwnd, UINT msg, WP Line 385  winpt_main_proc (HWND hwnd, UINT msg, WP
385              wipe_contents = 0;              wipe_contents = 0;
386          }          }
387          debug_end ();          debug_end ();
         /*cleanup_tmp_files ();*/  
388          Shell_NotifyIcon (NIM_DELETE, &NID);          Shell_NotifyIcon (NIM_DELETE, &NID);
389          PostQuitMessage (0);          PostQuitMessage (0);
390          ExitProcess (0);          ExitProcess (0);
# Line 419  winpt_main_proc (HWND hwnd, UINT msg, WP Line 403  winpt_main_proc (HWND hwnd, UINT msg, WP
403              hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT));              hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT));
404              popup = GetSubMenu (hm, 0);              popup = GetSubMenu (hm, 0);
405    
406              set_menu_text( popup, ID_WINPT_FILE, _("File Manager") );              set_menu_text (popup, ID_WINPT_FILE, _("File Manager"));
407              set_menu_text( popup, ID_WINPT_KEY, _("Key Manager") );              set_menu_text (popup, ID_WINPT_KEY, _("Key Manager"));
408              set_menu_text( popup, ID_WINPT_CARD, _("Card Manager") );              set_menu_text (popup, ID_WINPT_CARD, _("Card Manager"));
409              if (!scard_support)              if (!scard_support)
410                  set_menu_state (popup, ID_WINPT_CARD, MF_DISABLED|MF_GRAYED);                  set_menu_state (popup, ID_WINPT_CARD, MF_DISABLED|MF_GRAYED);
             if (!cryptdisk_available ()) {  
                 set_menu_state (popup, ID_WINPT_CDISKNEW, MF_DISABLED|MF_GRAYED);  
                 set_menu_state (popup, ID_WINPT_CDISKMOUNT, MF_DISABLED|MF_GRAYED);  
                 set_menu_state (popup, ID_WINPT_CDISKUNMOUNT, MF_DISABLED|MF_GRAYED);  
             }  
   
411              set_menu_text (popup, ID_WINPT_EDIT, _("Edit Clipboard"));              set_menu_text (popup, ID_WINPT_EDIT, _("Edit Clipboard"));
412              set_menu_text (popup, ID_WINPT_ABOUT, _("About..."));              set_menu_text (popup, ID_WINPT_ABOUT, _("About..."));
413              set_menu_text (popup, ID_WINPT_QUIT, _("Exit"));              set_menu_text (popup, ID_WINPT_QUIT, _("Exit"));
# Line 461  winpt_main_proc (HWND hwnd, UINT msg, WP Line 439  winpt_main_proc (HWND hwnd, UINT msg, WP
439              break;              break;
440                            
441          case WM_LBUTTONDBLCLK:          case WM_LBUTTONDBLCLK:
442              SendMessage( hwnd, WM_COMMAND, ID_WINPT_KEY, 0 );              gpg_read_only = gpg_check_permissions (0) == 0? 0 : 1;
443                SendMessage (hwnd, WM_COMMAND, ID_WINPT_KEY, 0);
444              break;              break;
445          }          }
446          break;          break;
# Line 528  winpt_main_proc (HWND hwnd, UINT msg, WP Line 507  winpt_main_proc (HWND hwnd, UINT msg, WP
507          case ID_WINPT_SIGN:          case ID_WINPT_SIGN:
508          case ID_WINPT_SIGNENCRYPT:          case ID_WINPT_SIGNENCRYPT:
509          case ID_WINPT_DECRYPT_VERIFY:          case ID_WINPT_DECRYPT_VERIFY:
510              err = gpg_clip_istext_avail( &has_data );              err = gpg_clip_istext_avail (&has_data);
511              if( err ) {              if (err) {
512                  msg_box( hwnd, gpgme_strerror( err ),_("Clipboard"), MB_ERR );                  msg_box (hwnd, gpgme_strerror (err),_("Clipboard"), MB_ERR);
513                  break;                  break;
514              }              }
515              if( !has_data ) {              if (!has_data) {
516                  msg_box( hwnd, winpt_strerror (WPTERR_CLIP_EMPTY),_("Clipboard"), MB_ERR );                  msg_box (hwnd, winpt_strerror (WPTERR_CLIP_EMPTY),
517                             _("Clipboard"), MB_ERR);
518                  break;                  break;
519              }              }
520              ctx.msecs = 500;              clip_gpg_dlg (hwnd, (int)wparam);
             window_reminder( &ctx );                      
             clip_gpg_dlg( hwnd, (int)wparam );  
521              break;              break;
522                
523              /** Current window operations **/              /** Current window operations **/
524          case ID_WINPT_CURRWND_SYMENC:          case ID_WINPT_CURRWND_SYMENC:
525          case ID_WINPT_CURRWND_ENCRYPT:          case ID_WINPT_CURRWND_ENCRYPT:
# Line 556  winpt_main_proc (HWND hwnd, UINT msg, WP Line 534  winpt_main_proc (HWND hwnd, UINT msg, WP
534                          winpt_strerror( WPTERR_CURR_WND ) );                          winpt_strerror( WPTERR_CURR_WND ) );
535                  break;                  break;
536              }              }
537              ctx.msecs = 500;              rc = currwnd_gpg_dlg (hwnd, (UINT)wparam, &set_wc);
538              window_reminder( &ctx );              if (!rc && set_wc)
539              rc = currwnd_gpg_dlg( hwnd, (UINT)wparam, &set_wc );                  set_window_contents (hwnd, &currwnd);
             if( !rc && set_wc )  
                 set_window_contents( hwnd, &currwnd );  
540              break;              break;
541                            
542              /** File handling **/              /** File handling **/
543          case ID_WINPT_FILE:          case ID_WINPT_FILE:
544              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_FILE,              s = _("File Manager (use drag & drop to add files)");
545                                GetDesktopWindow(), file_manager_dlg_proc, 0,              wnd = FindWindow (NULL, s);
546                                _("File Manager (use drag & drop to add files)"), IDS_WINPT_FILE );              if (wnd && IsIconic (wnd))
547                    ShowWindow (wnd, SW_RESTORE);
548                dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_FILE,
549                                  GetDesktopWindow (), file_manager_dlg_proc, 0,
550                                  s, IDS_WINPT_FILE);
551              break;              break;
552                            
553              /** Misc **/              /** Misc **/
554          case ID_WINPT_KEY:          case ID_WINPT_KEY:
555              param = NULL;              wnd = FindWindow (NULL, _("Key Manager"));
556              if( cmd )              if (wnd && IsIconic (wnd))
557                  param = (LPARAM)cmd;                  ShowWindow (wnd, SW_RESTORE);
558              dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC,              if (wnd)
559                                GetDesktopWindow(), keymanager_dlg_proc, param,                  SetForegroundWindow (wnd);
560                                _("Key Manager"), IDS_WINPT_KEYMISC );              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC,
561                                  GetDesktopWindow(), keymanager_dlg_proc,
562                                  cmd != 0? (LPARAM)cmd : 0,
563                                  _("Key Manager"), IDS_WINPT_KEYMISC);
564              cmd = 0;              cmd = 0;
565              break;              break;
566    
567          case ID_WINPT_CARD:          case ID_WINPT_CARD:
568              load_smartcard ();              load_card_manager ();
569              break;              break;
570                            
571          case ID_WINPT_EDIT:          case ID_WINPT_EDIT:
# Line 604  winpt_main_proc (HWND hwnd, UINT msg, WP Line 587  winpt_main_proc (HWND hwnd, UINT msg, WP
587              break;              break;
588                            
589          case ID_WINPT_GPGPREFS:          case ID_WINPT_GPGPREFS:
590              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, GetDesktopWindow(),              rc = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS,
591                                gpgprefs_dlg_proc, 0,                                      GetDesktopWindow(), gpgprefs_dlg_proc, 0,
592                                _("GnuPG Preferences"), IDS_WINPT_GPGPREFS);                                _("GnuPG Preferences"), IDS_WINPT_GPGPREFS);
593                if (rc == TRUE)
594                    update_keycache (GetDesktopWindow ());
595              break;              break;
   
         case ID_WINPT_CDISKNEW:  
             DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CDISK_NEW,  
                         GetDesktopWindow (), cryptdisk_new_dlg_proc, 0);  
             break;  
   
         case ID_WINPT_CDISKMOUNT:  
             DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CDISK_MOUNT,  
                         GetDesktopWindow (), cryptdisk_mount_dlg_proc, 0);  
             break;  
   
         case ID_WINPT_CDISKUNMOUNT:  
             DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_CDISK_UMOUNT,  
                         GetDesktopWindow (), cryptdisk_umount_dlg_proc, 0);  
             break;  
   
         case ID_WINPT_CDISKUMOUNTALL:  
             cryptdisk_unmount (0, 0);  
             break;  
596                            
597          case ID_WINPT_QUIT:          case ID_WINPT_QUIT:
598                manual_shutdown = 1;
599              SendMessage (hwnd, WM_DESTROY, 0, 0);              SendMessage (hwnd, WM_DESTROY, 0, 0);
600              break;              break;
601          }          }

Legend:
Removed from v.72  
changed lines
  Added in v.225

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26