/[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 139 by twoaday, Wed Jan 11 12:19:41 2006 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 45  Line 45 
45  #include "wptCryptdisk.h"  #include "wptCryptdisk.h"
46  #include "wptCardEdit.h"  #include "wptCardEdit.h"
47    
48    
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 172  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 239  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 265  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_card_manager (void)  load_card_manager (void)
# Line 289  load_card_manager (void) Line 284  load_card_manager (void)
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 Edit"), IDS_WINPT_CARD_EDIT);
294        gpg_card_release (card);
295  }  }
296    
297    
# Line 314  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 DWORD cookie;
331      static int use_hotkey = 0;      static int use_hotkey = 0;
332      INITCOMMONCONTROLSEX cce;      static int manual_shutdown = 0;
     LPARAM param;  
333      HWND wnd;      HWND wnd;
334      gpgme_error_t err;      gpgme_error_t err;
335      curr_wnd_ctx currwnd = {0};      curr_wnd_ctx currwnd = {0};
# Line 344  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);
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 && msg != WM_ENDSESSION)              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 394  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 504  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              clip_gpg_dlg (hwnd, (int)wparam);              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 551  winpt_main_proc (HWND hwnd, UINT msg, WP Line 555  winpt_main_proc (HWND hwnd, UINT msg, WP
555              wnd = FindWindow (NULL, _("Key Manager"));              wnd = FindWindow (NULL, _("Key Manager"));
556              if (wnd && IsIconic (wnd))              if (wnd && IsIconic (wnd))
557                  ShowWindow (wnd, SW_RESTORE);                  ShowWindow (wnd, SW_RESTORE);
558              param = 0;              if (wnd)
559              if (cmd)                  SetForegroundWindow (wnd);
                 param = (LPARAM)cmd;  
560              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC,              dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYMISC,
561                                GetDesktopWindow(), keymanager_dlg_proc, param,                                GetDesktopWindow(), keymanager_dlg_proc,
562                                  cmd != 0? (LPARAM)cmd : 0,
563                                _("Key Manager"), IDS_WINPT_KEYMISC);                                _("Key Manager"), IDS_WINPT_KEYMISC);
564              cmd = 0;              cmd = 0;
565              break;              break;
# Line 583  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.139  
changed lines
  Added in v.225

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26