[svn] GpgOL - r312 - in trunk: po src

svn author wk cvs at cvs.gnupg.org
Thu Oct 29 19:49:32 CET 2009


Author: wk
Date: 2009-10-29 19:49:32 +0100 (Thu, 29 Oct 2009)
New Revision: 312

Added:
   trunk/src/decrypt-16.bmp
   trunk/src/decrypt-16m.bmp
   trunk/src/decrypt-verify-16.bmp
   trunk/src/decrypt-verify-16m.bmp
   trunk/src/encrypt-16.bmp
   trunk/src/key-manager-16.bmp
   trunk/src/key-manager-16m.bmp
   trunk/src/key-manager-32.bmp
   trunk/src/key-manager-32m.bmp
   trunk/src/sign-16.bmp
   trunk/src/sign-16m.bmp
   trunk/src/verify-16.bmp
   trunk/src/verify-16m.bmp
Removed:
   trunk/src/decrypt-mask.bmp
   trunk/src/decrypt-verify-mask.bmp
   trunk/src/decrypt-verify.bmp
   trunk/src/decrypt.bmp
   trunk/src/encrypt.bmp
   trunk/src/key-manager-mask.bmp
   trunk/src/key-manager.bmp
   trunk/src/sign-mask.bmp
   trunk/src/sign.bmp
   trunk/src/verify-mask.bmp
   trunk/src/verify.bmp
Modified:
   trunk/po/de.po
   trunk/po/sv.po
   trunk/src/ChangeLog
   trunk/src/Makefile.am
   trunk/src/cmdbarcontrols.cpp
   trunk/src/dialogs.h
   trunk/src/dialogs.rc
   trunk/src/explorers.cpp
   trunk/src/explorers.h
   trunk/src/ext-commands.cpp
   trunk/src/ext-commands.h
   trunk/src/inspectors.cpp
   trunk/src/inspectors.h
   trunk/src/oomhelp.cpp
   trunk/src/oomhelp.h
   trunk/src/revert.cpp
   trunk/src/revert.h
   trunk/src/util.h
Log:
All controls are now done via the OOM model.
Sign and encrypt buttons have no action yet.
Some other functions are not yet functional.
All 16px icons are integrated.
Prepared for other sized icons.


[The diff below has been truncated]

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/ChangeLog	2009-10-29 18:49:32 UTC (rev 312)
@@ -1,3 +1,9 @@
+2009-10-29  Werner Koch  <wk at g10code.com>
+
+	* ext-commands.cpp: Remove m_nCmdDebugN, m_nCmdRevertFolder,
+	m_nCmdSign, m_nCmdEncrypt and all related code.  Now handled in
+	inspectors.cpp.
+
 2009-10-28  Werner Koch  <wk at g10code.com>
 
 	* ext-commands.cpp: Remove m_nCmdCryptoState and all related code;

Modified: trunk/po/de.po  [not shown]
Modified: trunk/po/sv.po  [not shown]
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/Makefile.am	2009-10-29 18:49:32 UTC (rev 312)
@@ -15,15 +15,16 @@
 
 bin_PROGRAMS = gpgol 
 #treeview
-EXTRA_DIST = versioninfo.rc.in mapi32.def $(unused_sources) Outlook.gpl \
-	     logo.bmp encrypt.bmp  \
-             proto-auto.bmp proto-pgpmime.bmp proto-smime.bmp \
-             cryptostate.bmp \
-             key-manager.bmp key-manager-mask.bmp \
-             decrypt.bmp decrypt-mask.bmp \
-	     verify.bmp  verify-mask.bmp \
-             decrypt-verify.bmp decrypt-verify-mask.bmp \
-	     sign.bmp sign-mask.bmp
+EXTRA_DIST = \
+	versioninfo.rc.in mapi32.def $(unused_sources) Outlook.gpl \
+	encrypt-16.bmp encrypt-16m.bmp \
+	sign-16.bmp sign-16m.bmp \
+	key-manager-16.bmp key-manager-16m.bmp \
+	key-manager-32.bmp key-manager-32m.bmp \
+	decrypt-16.bmp decrypt-16m.bmp \
+	verify-16.bmp  verify-16m.bmp \
+	decrypt-verify-16.bmp decrypt-verify-16m.bmp \
+	logo.bmp
 
 EXEEXT = .dll
 

Modified: trunk/src/cmdbarcontrols.cpp
===================================================================
--- trunk/src/cmdbarcontrols.cpp	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/cmdbarcontrols.cpp	2009-10-29 18:49:32 UTC (rev 312)
@@ -28,6 +28,7 @@
 #include "oomhelp.h"
 #include "cmdbarcontrols.h"
 #include "inspectors.h"
+#include "explorers.h"
 #include "engine.h"
 
 #include "eventsink.h"
@@ -37,6 +38,7 @@
    Click event.  */
 BEGIN_EVENT_SINK(GpgolCommandBarButtonEvents, IOOMCommandBarButtonEvents)
   STDMETHOD (Click) (THIS_ LPDISPATCH, PBOOL);
+EVENT_SINK_DEFAULT_CTOR(GpgolCommandBarButtonEvents)
 EVENT_SINK_DEFAULT_DTOR(GpgolCommandBarButtonEvents)
 EVENT_SINK_INVOKE(GpgolCommandBarButtonEvents)
 {
@@ -69,34 +71,32 @@
 
 
 
-static int
-tagcmp (const char *a, const char *b)
-{
-  return strncmp (a, b, strlen (b));
-}
-
-
 /* This is the event sink for a button click.  */
 STDMETHODIMP
 GpgolCommandBarButtonEvents::Click (LPDISPATCH button, PBOOL cancel_default)
 {
   char *tag;
+  int instid;
 
   (void)cancel_default;
-  log_debug ("%s:%s: Called", SRCNAME, __func__);
 
+  tag = get_oom_string (button, "Tag");
+  instid = get_oom_int (button, "InstanceId");
   {
     char *tmp = get_object_name (button);
-    log_debug ("%s:%s: button is %p (%s)", 
-               SRCNAME, __func__, button, tmp? tmp:"(null)");
+    log_debug ("%s:%s: button is %p (%s) tag is (%s) instid %d", 
+               SRCNAME, __func__, button, 
+               tmp? tmp:"(null)",
+               tag? tag:"(null)", instid);
     xfree (tmp);
   }
 
-  tag = get_oom_string (button, "Tag");
-  log_debug ("%s:%s: button's tag is (%s)", 
-             SRCNAME, __func__, tag? tag:"(null)");
   if (!tag)
     ;
+  else if (!tagcmp (tag, "GpgOL_Inspector"))
+    {
+      proc_inspector_button_click (button, tag, instid);
+    }
   else if (!tagcmp (tag, "GpgOL_Start_Key_Manager"))
     {
       /* FIXME: We don't have the current window handle.  */
@@ -104,25 +104,9 @@
          MessageBox (NULL, _("Could not start certificate manager"),
                      _("GpgOL"), MB_ICONERROR|MB_OK);
     }
-  else if (!tagcmp (tag, "GpgOL_Inspector_Crypto_Info"))
+  else if (!tagcmp (tag, "GpgOL_Revert_Folder"))
     {
-      /* FIXME: We should invoke the decrypt/verify again. */
-      update_inspector_crypto_info (button);
-#if 0 /* This is the code we used to use.  */
-      log_debug ("%s:%s: command CryptoState called\n", SRCNAME, __func__);
-      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      if (SUCCEEDED (hr))
-        {
-          if (message_incoming_handler (message, hwnd, true))
-            message_display_handler (eecb, hwnd);
-	}
-      else
-        log_debug_w32 (hr, "%s:%s: command CryptoState failed", 
-                       SRCNAME, __func__);
-      ul_release (message, __func__, __LINE__);
-      ul_release (mdb, __func__, __LINE__);
-#endif
-
+      run_explorer_revert_folder (button);
     }
 
   xfree (tag);

Copied: trunk/src/decrypt-16.bmp (from rev 311, trunk/src/decrypt.bmp)
===================================================================
(Binary files differ)


Property changes on: trunk/src/decrypt-16.bmp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:mergeinfo
   + 

Copied: trunk/src/decrypt-16m.bmp (from rev 311, trunk/src/decrypt-mask.bmp)
===================================================================
(Binary files differ)


Property changes on: trunk/src/decrypt-16m.bmp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:mergeinfo
   + 

Deleted: trunk/src/decrypt-mask.bmp

Copied: trunk/src/decrypt-verify-16.bmp (from rev 311, trunk/src/decrypt-verify.bmp)
===================================================================
(Binary files differ)


Property changes on: trunk/src/decrypt-verify-16.bmp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:mergeinfo
   + 

Copied: trunk/src/decrypt-verify-16m.bmp (from rev 311, trunk/src/decrypt-verify-mask.bmp)
===================================================================
(Binary files differ)


Property changes on: trunk/src/decrypt-verify-16m.bmp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:mergeinfo
   + 

Deleted: trunk/src/decrypt-verify-mask.bmp

Deleted: trunk/src/decrypt-verify.bmp

Deleted: trunk/src/decrypt.bmp

Modified: trunk/src/dialogs.h
===================================================================
--- trunk/src/dialogs.h	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/dialogs.h	2009-10-29 18:49:32 UTC (rev 312)
@@ -7,29 +7,63 @@
 #define DIALOGS_H
 
 
-/* Ids used for bitmaps. 
-   Note: FOO_MASK must have a value of FOO + 1. */
-#define IDB_ENCRYPT                     3004
-#define IDB_SIGN                        3006
-#define IDB_SIGN_MASK                   3007
-#define IDB_ADD_KEYS                    3008
-#define IDB_KEY_MANAGER                 3010
-#define IDB_KEY_MANAGER_MASK            3011
-#define IDB_BANNER                      3012  /* The g10 Code logo.  */
-#define IDB_BANNER_HI                   3014  /* Not used.  */
-#define IDB_CRYPTO_STATE                3016  
-#define IDB_PROTO_AUTO                  3018  /* Not used.  */
-#define IDB_PROTO_PGPMIME               3020  /* Not used.  */
-#define IDB_PROTO_SMIME                 3022  /* Not used.  */
-#define IDB_PROTO_SMIME_MASK            3023  /* Not used.  */
-#define IDB_DECRYPT                     3024
-#define IDB_DECRYPT_MASK                3025
-#define IDB_VERIFY                      3026
-#define IDB_VERIFY_MASK                 3027
-#define IDB_DECRYPT_VERIFY              3028
-#define IDB_DECRYPT_VERIFY_MASK         3029
+/* Ids used for bitmaps.  There is some magic in the identifiers: In
+   the code we only use values like 3000, the icon code then uses the
+   current system pixel size to the Id and tries to load this one.
+   The mask is always the next id.  */
+#define IDB_ENCRYPT                     3000
+#define IDB_ENCRYPT_16                  3016
+#define IDB_ENCRYPT_16M                 3017
+#define IDB_ENCRYPT_32                  3032
+#define IDB_ENCRYPT_32M                 3033
+#define IDB_ENCRYPT_64                  3064
+#define IDB_ENCRYPT_64M                 3065
 
+#define IDB_SIGN                        3100
+#define IDB_SIGN_16                     3116
+#define IDB_SIGN_16M                    3117
+#define IDB_SIGN_32                     3132
+#define IDB_SIGN_32M                    3133
+#define IDB_SIGN_64                     3164
+#define IDB_SIGN_64M                    3165
 
+#define IDB_KEY_MANAGER                 3200
+#define IDB_KEY_MANAGER_16              3216
+#define IDB_KEY_MANAGER_16M             3217
+#define IDB_KEY_MANAGER_32              3232
+#define IDB_KEY_MANAGER_32M             3233
+#define IDB_KEY_MANAGER_64              3264
+#define IDB_KEY_MANAGER_64M             3265
+
+#define IDB_DECRYPT                     3300
+#define IDB_DECRYPT_16                  3316
+#define IDB_DECRYPT_16M                 3317
+#define IDB_DECRYPT_32                  3332
+#define IDB_DECRYPT_32M                 3333
+#define IDB_DECRYPT_64                  3364
+#define IDB_DECRYPT_64M                 3365
+
+#define IDB_VERIFY                      3400
+#define IDB_VERIFY_16                   3416
+#define IDB_VERIFY_16M                  3417
+#define IDB_VERIFY_32                   3432
+#define IDB_VERIFY_32M                  3433
+#define IDB_VERIFY_64                   3464
+#define IDB_VERIFY_64M                  3465
+
+#define IDB_DECRYPT_VERIFY              3500
+#define IDB_DECRYPT_VERIFY_16           3516
+#define IDB_DECRYPT_VERIFY_16M          3517
+#define IDB_DECRYPT_VERIFY_32           3532
+#define IDB_DECRYPT_VERIFY_32M          3533
+#define IDB_DECRYPT_VERIFY_64           3564
+#define IDB_DECRYPT_VERIFY_64M          3565
+
+
+/* Special */
+#define IDB_BANNER                      3900  /* The g10 Code logo.  */
+
+
 /* Ids used for the main config dialog.  */
 #define IDD_GPG_OPTIONS                 4001
 #define IDC_TIME_PHRASES                4010

Modified: trunk/src/dialogs.rc
===================================================================
--- trunk/src/dialogs.rc	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/dialogs.rc	2009-10-29 18:49:32 UTC (rev 312)
@@ -22,32 +22,56 @@
 
 #include "afxres.h"
 
-/* To create these bitmaps, you need to use an Outlook specific
-   palette.  A palette file for The Gimp is included as
-   Outlook.gpl.  */
 
-/*IDB_DECRYPT             BITMAP  DISCARDABLE     "decrypt.bmp"*/
-IDB_ENCRYPT             BITMAP  DISCARDABLE     "encrypt.bmp"
+IDB_ENCRYPT_16            BITMAP  DISCARDABLE  "encrypt-16.bmp"
+IDB_ENCRYPT_16M           BITMAP  DISCARDABLE  "encrypt-16m.bmp"      
+//IDB_ENCRYPT_32            BITMAP  DISCARDABLE        
+//IDB_ENCRYPT_32M           BITMAP  DISCARDABLE        
+//IDB_ENCRYPT_64            BITMAP  DISCARDABLE        
+//IDB_ENCRYPT_64M           BITMAP  DISCARDABLE        
+
+IDB_SIGN_16               BITMAP  DISCARDABLE  "sign-16.bmp"
+IDB_SIGN_16M              BITMAP  DISCARDABLE  "sign-16m.bmp"      
+//IDB_SIGN_32               BITMAP  DISCARDABLE        
+//IDB_SIGN_32M              BITMAP  DISCARDABLE        
+//IDB_SIGN_64               BITMAP  DISCARDABLE        
+//IDB_SIGN_64M              BITMAP  DISCARDABLE        
+
+IDB_KEY_MANAGER_16        BITMAP  DISCARDABLE  "key-manager-16.bmp"
+IDB_KEY_MANAGER_16M       BITMAP  DISCARDABLE  "key-manager-16m.bmp"     
+IDB_KEY_MANAGER_32        BITMAP  DISCARDABLE  "key-manager-32.bmp"      
+IDB_KEY_MANAGER_32M       BITMAP  DISCARDABLE  "key-manager-32m.bmp"      
+//IDB_KEY_MANAGER_64        BITMAP  DISCARDABLE        
+//IDB_KEY_MANAGER_64M       BITMAP  DISCARDABLE        
+
+IDB_DECRYPT_16            BITMAP  DISCARDABLE  "decrypt-16.bmp"     
+IDB_DECRYPT_16M           BITMAP  DISCARDABLE  "decrypt-16m.bmp"     
+//IDB_DECRYPT_32            BITMAP  DISCARDABLE        
+//IDB_DECRYPT_32M           BITMAP  DISCARDABLE        
+//IDB_DECRYPT_64            BITMAP  DISCARDABLE        
+//IDB_DECRYPT_64M           BITMAP  DISCARDABLE        
+
+IDB_VERIFY_16             BITMAP  DISCARDABLE  "verify-16.bmp"          
+IDB_VERIFY_16M            BITMAP  DISCARDABLE  "verify-16m.bmp"     
+//IDB_VERIFY_32             BITMAP  DISCARDABLE        
+//IDB_VERIFY_32M            BITMAP  DISCARDABLE        
+//IDB_VERIFY_64             BITMAP  DISCARDABLE        
+//IDB_VERIFY_64M            BITMAP  DISCARDABLE        
+
+IDB_DECRYPT_VERIFY_16     BITMAP  DISCARDABLE  "decrypt-verify-16.bmp" 
+IDB_DECRYPT_VERIFY_16M    BITMAP  DISCARDABLE  "decrypt-verify-16m.bmp"
+//IDB_DECRYPT_VERIFY_32     BITMAP  DISCARDABLE        
+//IDB_DECRYPT_VERIFY_32M    BITMAP  DISCARDABLE        
+//IDB_DECRYPT_VERIFY_64     BITMAP  DISCARDABLE        
+//IDB_DECRYPT_VERIFY_64M    BITMAP  DISCARDABLE        
+
+
+
+
 IDB_BANNER              BITMAP  DISCARDABLE     "logo.bmp"
-IDB_CRYPTO_STATE        BITMAP  DISCARDABLE     "cryptostate.bmp"
-IDB_PROTO_AUTO          BITMAP  DISCARDABLE     "proto-auto.bmp"
-IDB_PROTO_PGPMIME       BITMAP  DISCARDABLE     "proto-pgpmime.bmp"
-IDB_PROTO_SMIME         BITMAP  DISCARDABLE     "proto-smime.bmp"
-IDB_PROTO_SMIME_MASK    BITMAP  DISCARDABLE     "proto-smime-mask.bmp"
 
-IDB_KEY_MANAGER         BITMAP  DISCARDABLE     "key-manager.bmp"
-IDB_KEY_MANAGER_MASK    BITMAP  DISCARDABLE     "key-manager-mask.bmp"
-IDB_DECRYPT             BITMAP  DISCARDABLE     "decrypt.bmp"
-IDB_DECRYPT_MASK        BITMAP  DISCARDABLE     "decrypt-mask.bmp"
-IDB_VERIFY              BITMAP  DISCARDABLE     "verify.bmp"
-IDB_VERIFY_MASK         BITMAP  DISCARDABLE     "verify-mask.bmp"
-IDB_DECRYPT_VERIFY      BITMAP  DISCARDABLE     "decrypt-verify.bmp"
-IDB_DECRYPT_VERIFY_MASK BITMAP  DISCARDABLE     "decrypt-verify-mask.bmp"
-IDB_SIGN                BITMAP  DISCARDABLE     "sign.bmp"
-IDB_SIGN_MASK           BITMAP  DISCARDABLE     "sign-mask.bmp"
 
 
-
 IDD_GPG_OPTIONS  DIALOG DISCARDABLE  0, 0, 266, 274
 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "GpgOL"

Copied: trunk/src/encrypt-16.bmp (from rev 311, trunk/src/encrypt.bmp)
===================================================================
(Binary files differ)


Property changes on: trunk/src/encrypt-16.bmp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Name: svn:mergeinfo
   + 

Deleted: trunk/src/encrypt.bmp

Modified: trunk/src/explorers.cpp
===================================================================
--- trunk/src/explorers.cpp	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/explorers.cpp	2009-10-29 18:49:32 UTC (rev 312)
@@ -29,11 +29,13 @@
 #include "explorers.h"
 #include "dialogs.h"  /* IDB_xxx */
 #include "cmdbarcontrols.h"
+#include "revert.h"
 
 #include "eventsink.h"
 
 BEGIN_EVENT_SINK(GpgolExplorersEvents, IOOMExplorersEvents)
   STDMETHOD (NewExplorer) (THIS_ LPOOMEXPLORER);
+EVENT_SINK_DEFAULT_CTOR(GpgolExplorersEvents)
 EVENT_SINK_DEFAULT_DTOR(GpgolExplorersEvents)
 EVENT_SINK_INVOKE(GpgolExplorersEvents)
 {
@@ -77,7 +79,7 @@
 void
 add_explorer_controls (LPOOMEXPLORER explorer)
 {
-  LPDISPATCH pObj, pDisp, pTmp;
+  LPDISPATCH controls, button, obj;
 
   log_debug ("%s:%s: Enter", SRCNAME, __func__);
 
@@ -86,18 +88,18 @@
      called from a second thread.  */
 
   /* Check that our controls do not already exist.  */
-  pObj = get_oom_object (explorer, "CommandBars");
-  if (!pObj)
+  obj = get_oom_object (explorer, "CommandBars");
+  if (!obj)
     {
       log_debug ("%s:%s: CommandBars not found", SRCNAME, __func__);
       return;
     }
-  pDisp = get_oom_control_bytag (pObj, "GpgOL_Start_Key_Manager");
-  pObj->Release ();
-  pObj = NULL;
-  if (pDisp)
+  button = get_oom_control_bytag (obj, "GpgOL_Start_Key_Manager");
+  obj->Release ();
+  obj = NULL;
+  if (button)
     {
-      pDisp->Release ();
+      button->Release ();
       log_debug ("%s:%s: Leave (Controls are already added)",
                  SRCNAME, __func__);
       return;
@@ -108,57 +110,115 @@
      Outlooked crashed.  Quite likely my error but I was not able to
      find the problem.  */
 
-  /* Create the Start-Key-Manager menu entry.  */
-  pDisp = get_oom_object (explorer,
-                          "CommandBars.FindControl(,30007).get_Controls");
-  if (!pDisp)
+  /* Create the Start-Key-Manager menu entries.  */
+  controls = get_oom_object (explorer,
+                             "CommandBars.FindControl(,30007).get_Controls");
+  if (!controls)
     log_debug ("%s:%s: Menu Popup Extras not found\n", SRCNAME, __func__);
   else
     {
-      pTmp = add_oom_button (pDisp);
-      pDisp->Release ();
-      pDisp = pTmp;
-      if (pDisp)
+      button = add_oom_button (controls);
+      if (button)
         {
-          put_oom_string (pDisp, "Tag", "GpgOL_Start_Key_Manager");
-          put_oom_int (pDisp, "Style", msoButtonIconAndCaption );
-          put_oom_string (pDisp, "Caption", _("GnuPG Certificate &Manager"));
-          put_oom_string (pDisp, "TooltipText",
-                          _("Open the certificate manager"));
-          put_oom_icon (pDisp, IDB_KEY_MANAGER, 16);
+          put_oom_string (button, "Tag", "GpgOL_Start_Key_Manager");
+          put_oom_bool (button, "BeginGroup", true);
+          put_oom_int (button, "Style", msoButtonIconAndCaption );
+          put_oom_string (button, "Caption", _("GnuPG Certificate &Manager"));
+          put_oom_icon (button, IDB_KEY_MANAGER, 16);
           
-          install_GpgolCommandBarButtonEvents_sink (pDisp);
-          pDisp->Release ();
+          install_GpgolCommandBarButtonEvents_sink (button);
+          /* Fixme:  Save the returned object for an Unadvice.  */
+          button->Release ();
         }
+
+      button = add_oom_button (controls);
+      if (button)
+        {
+          put_oom_string (button, "Tag", "GpgOL_Revert_Folder");
+          put_oom_int (button, "Style", msoButtonCaption );
+          put_oom_string (button, "Caption",
+                          _("Remove GpgOL flags from this folder"));
+          
+          install_GpgolCommandBarButtonEvents_sink (button);
+          /* Fixme:  Save the returned object for an Unadvice.  */
+          button->Release ();
+        }
+
+      controls->Release ();
+      controls = NULL;
     }
 
   /* Create the Start-Key-Manager toolbar icon.  Not ethat we need to
      use a different tag name here.  If we won't do that event sink
      would be called twice.  */
-  pDisp = get_oom_object (explorer,
+  controls = get_oom_object (explorer,
                           "CommandBars.Item(Standard).get_Controls");
-  if (!pDisp)
+  if (!controls)
     log_debug ("%s:%s: CommandBar \"Standard\" not found\n",
                SRCNAME, __func__);
   else
     {
-      pTmp = add_oom_button (pDisp);
-      pDisp->Release ();
-      pDisp = pTmp;
-      if (pDisp)
+      button = add_oom_button (controls);
+      if (button)
         {
-          put_oom_string (pDisp, "Tag", "GpgOL_Start_Key_Manager at t");
-          put_oom_int (pDisp, "Style", msoButtonIcon );
-          put_oom_string (pDisp, "TooltipText",
+          put_oom_string (button, "Tag", "GpgOL_Start_Key_Manager at t");
+          put_oom_int (button, "Style", msoButtonIcon );
+          put_oom_string (button, "TooltipText",
                           _("Open the certificate manager"));
-          put_oom_icon (pDisp, IDB_KEY_MANAGER, 16);
+          put_oom_icon (button, IDB_KEY_MANAGER, 16);
           
-          install_GpgolCommandBarButtonEvents_sink (pDisp);
+          install_GpgolCommandBarButtonEvents_sink (button);
           /* Fixme:  store the event sink object somewhere.  */
-          pDisp->Release ();
+          button->Release ();
         }
+      controls->Release ();
     }
   
   log_debug ("%s:%s: Leave", SRCNAME, __func__);
 }
 
+
+
+void
+run_explorer_revert_folder (LPDISPATCH button)
+{
+  LPDISPATCH obj;
+
+  log_debug ("%s:%s: Enter", SRCNAME, __func__);
+
+  /* Notify the user that the general GpgOl function will be disabled
+     when calling this function.  */
+  if ( opt.disable_gpgol
+       || (MessageBox 
+           (NULL/* FIXME: need the hwnd */,
+            _("You are about to start the process of reversing messages "
+              "created by GpgOL to prepare deinstalling of GpgOL. "
+              "Running this command will put GpgOL into a disabled state "
+              "so that messages are not anymore processed by GpgOL.\n"
+              "\n"
+              "You should convert all folders one after the other with "
+              "this command, close Outlook and then deinstall GpgOL.\n"
+              "\n"
+              "Note that if you start Outlook again with GpgOL still "
+              "being installed, GpgOL will again process messages."),
+            _("GpgOL"), MB_ICONWARNING|MB_OKCANCEL) == IDOK))
+    {
+      if ( MessageBox 
+           (NULL /* Fixme: need hwnd */,
+            _("Do you want to revert this folder?"),
+            _("GpgOL"), MB_ICONQUESTION|MB_YESNO) == IDYES )
+        {
+          if (!opt.disable_gpgol)
+            opt.disable_gpgol = 1;
+
+          obj = get_oom_object (button, 
+                                "get_Parent.get_Parent.get_Parent.get_Parent"
+                                ".get_CurrentFolder");
+          if (obj)
+            {
+              gpgol_folder_revert (obj);
+              obj->Release ();
+            }
+        }
+    }
+}

Modified: trunk/src/explorers.h
===================================================================
--- trunk/src/explorers.h	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/explorers.h	2009-10-29 18:49:32 UTC (rev 312)
@@ -86,6 +86,8 @@
 
 void add_explorer_controls (LPOOMEXPLORER explorer);
 
+void run_explorer_revert_folder (LPDISPATCH button);
 
 
+
 #endif /*EXPLORERS_H*/

Modified: trunk/src/ext-commands.cpp
===================================================================
--- trunk/src/ext-commands.cpp	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/ext-commands.cpp	2009-10-29 18:49:32 UTC (rev 312)
@@ -38,8 +38,8 @@
 #include "ol-ext-callback.h"
 #include "message.h"
 #include "engine.h"
-#include "ext-commands.h"
 #include "revert.h"
+#include "ext-commands.h"
 #include "explorers.h"
 
 #define TRACEPOINT() do { log_debug ("%s:%s:%d: tracepoint\n", \
@@ -99,17 +99,7 @@
   m_pExchExt = pParentInterface; 
   m_lRef = 0; 
   m_lContext = 0; 
-  m_nCmdProtoAuto = 0;
-  m_nCmdProtoPgpmime = 0;
-  m_nCmdProtoSmime = 0;
-  m_nCmdEncrypt = 0;  
-  m_nCmdSign = 0; 
-  m_nCmdRevertFolder = 0;
-  m_nCmdDebug0 = 0;
-  m_nCmdDebug1 = 0;
-  m_nCmdDebug2 = 0;
-  m_nCmdDebug3 = 0;
-  m_toolbar_info = NULL; 
+    m_toolbar_info = NULL; 
   m_hWnd = NULL; 
 
   if (!bitmaps_initialized)
@@ -426,30 +416,9 @@
   /* Now install menu and toolbar items.  */
   if (m_lContext == EECONTEXT_READNOTEMESSAGE)
     {
-      add_menu (eecb, pnCommandIDBase,
-        "@", NULL,
-        (opt.enable_debug && !opt.disable_gpgol)?
-                "GpgOL Debug-1 (open_inspector)":"", &m_nCmdDebug1,
-        (opt.enable_debug && !opt.disable_gpgol)? 
-                "GpgOL Debug-2 (change msg class)":"", &m_nCmdDebug2,
-        opt.enable_debug? "GpgOL Debug-3 (revert message class)":"",
-                &m_nCmdDebug3,
-        NULL);
-
     }
   else if (m_lContext == EECONTEXT_SENDNOTEMESSAGE && !opt.disable_gpgol) 
     {
-      add_menu (eecb, pnCommandIDBase,
-        "@", NULL,
-        _("&encrypt message with GnuPG"), &m_nCmdEncrypt,
-        _("&sign message with GnuPG"), &m_nCmdSign,
-        NULL );
-
-        add_toolbar (pTBEArray, nTBECnt,
-                     "Encrypt", IDB_ENCRYPT, m_nCmdEncrypt,
-                     "Sign",    IDB_SIGN,    m_nCmdSign,
-                     NULL, 0, 0);
-      
       m_pExchExt->m_protoSelection = opt.default_protocol;
 
       if (draft_info && draft_info[0] == 'E')
@@ -468,15 +437,9 @@
 
       if (force_encrypt)
         m_pExchExt->m_gpgEncrypt = true;
-      check_menu (eecb, m_nCmdEncrypt, m_pExchExt->m_gpgEncrypt);
-      check_menu (eecb, m_nCmdSign, m_pExchExt->m_gpgSign);
     }
   else if (m_lContext == EECONTEXT_VIEWER) 
     {
-      add_menu (eecb, pnCommandIDBase, 
-        "@", NULL,
-        _("Remove GpgOL flags from this folder"), &m_nCmdRevertFolder,
-        NULL);
 
     }
 
@@ -575,109 +538,6 @@
         log_debug ("%s:%s: command Forward called\n", SRCNAME, __func__);
       return S_FALSE; /* Pass it on.  */
     }
-  else if (nCommandID == m_nCmdEncrypt
-           && m_lContext == EECONTEXT_SENDNOTEMESSAGE) 
-    {
-      log_debug ("%s:%s: command Encrypt called\n", SRCNAME, __func__);
-      m_pExchExt->m_gpgEncrypt = !m_pExchExt->m_gpgEncrypt;
-      check_menu (eecb, m_nCmdEncrypt, m_pExchExt->m_gpgEncrypt);
-    }
-  else if (nCommandID == m_nCmdSign
-           && m_lContext == EECONTEXT_SENDNOTEMESSAGE) 
-    {
-      log_debug ("%s:%s: command Sign called\n", SRCNAME, __func__);
-      m_pExchExt->m_gpgSign = !m_pExchExt->m_gpgSign;
-      check_menu (eecb, m_nCmdSign, m_pExchExt->m_gpgSign);
-    }
-  else if (nCommandID == m_nCmdRevertFolder
-           && m_lContext == EECONTEXT_VIEWER)
-    {
-      log_debug ("%s:%s: command ReverFoldert called\n", SRCNAME, __func__);
-      /* Notify the user that the general GpgOl fucntionaly will be
-         disabled when calling this function the first time.  */
-      if ( opt.disable_gpgol
-           || (MessageBox 
-               (hwnd,
-                _("You are about to start the process of reversing messages "
-                  "created by GpgOL to prepare deinstalling of GpgOL. "
-                  "Running this command will put GpgOL into a disabled state "
-                  "so that messages are not anymore processed by GpgOL.\n"
-                  "\n"
-                  "You should convert all folders one after the other with "
-                  "this command, close Outlook and then deinstall GpgOL.\n"
-                  "\n"
-                  "Note that if you start Outlook again with GpgOL still "
-                  "being installed, GpgOL will again process messages."),
-                _("GpgOL"), MB_ICONWARNING|MB_OKCANCEL) == IDOK))
-        {
-          if ( MessageBox 
-               (hwnd,
-                _("Do you want to revert this folder?"),
-                _("GpgOL"), MB_ICONQUESTION|MB_YESNO) == IDYES )
-            {
-              if (!opt.disable_gpgol)
-                opt.disable_gpgol = 1;
-          
-              gpgol_folder_revert (eecb);
-            }
-        }
-    }
-  else if (opt.enable_debug && nCommandID == m_nCmdDebug0
-           && m_lContext == EECONTEXT_READNOTEMESSAGE)
-    {
-      log_debug ("%s:%s: command Debug0 (showInfo) called\n",
-                 SRCNAME, __func__);
-      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      if (SUCCEEDED (hr))
-        {
-          message_show_info (message, hwnd);
-	}
-      ul_release (message, __func__, __LINE__);
-      ul_release (mdb, __func__, __LINE__);
-    }
-  else if (opt.enable_debug && nCommandID == m_nCmdDebug1
-           && m_lContext == EECONTEXT_READNOTEMESSAGE)
-    {
-      log_debug ("%s:%s: command Debug1 (open inspector) called\n",
-                 SRCNAME, __func__);
-      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      if (SUCCEEDED (hr))
-        {
-          open_inspector (eecb, message);
-	}
-      ul_release (message, __func__, __LINE__);
-      ul_release (mdb, __func__, __LINE__);
-    }
-  else if (opt.enable_debug && nCommandID == m_nCmdDebug2
-           && m_lContext == EECONTEXT_READNOTEMESSAGE)
-    {
-      log_debug ("%s:%s: command Debug2 (change message class) called\n", 
-                 SRCNAME, __func__);
-      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      if (SUCCEEDED (hr))
-        {
-          /* We sync here. */
-          mapi_change_message_class (message, 1);
-	}
-      ul_release (message, __func__, __LINE__);
-      ul_release (mdb, __func__, __LINE__);
-    }
-  else if (opt.enable_debug && nCommandID == m_nCmdDebug3
-           && m_lContext == EECONTEXT_READNOTEMESSAGE)
-    {
-      log_debug ("%s:%s: command Debug3 (revert_message_class) called\n", 
-                 SRCNAME, __func__);
-      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
-      if (SUCCEEDED (hr))
-        {
-          int rc = gpgol_message_revert (message, 1, 
-                                         KEEP_OPEN_READWRITE|FORCE_SAVE);
-          log_debug ("%s:%s: gpgol_message_revert returns %d\n", 
-                     SRCNAME, __func__, rc);
-	}
-      ul_release (message, __func__, __LINE__);
-      ul_release (mdb, __func__, __LINE__);
-    }
   else if (nCommandID == EECMDID_SaveMessage
            && m_lContext == EECONTEXT_SENDNOTEMESSAGE) 
     {
@@ -738,24 +598,7 @@
 
   show_event_object (eecb, __func__);
 
-  if (nCommandID == m_nCmdEncrypt 
-           && m_lContext == EECONTEXT_SENDNOTEMESSAGE) 
-    {
-      MessageBox (m_hWnd,
-                  _("Select this option to encrypt the message."),
-                  "GpgOL", MB_OK);	
-    } 
-  else if (nCommandID == m_nCmdSign
-           && m_lContext == EECONTEXT_SENDNOTEMESSAGE) 
-    {
-      MessageBox (m_hWnd,
-                  _("Select this option to sign the message."),
-                  "GpgOL", MB_OK);	
-    }
-  else
-    return S_FALSE;
-
-  return S_OK;
+  return S_FALSE;
 }
 
 
@@ -772,30 +615,7 @@
                                 LPTSTR pszText,  UINT nCharCnt)    
 {
 
-  if (nCommandID == m_nCmdEncrypt
-           && m_lContext == EECONTEXT_SENDNOTEMESSAGE) 
-    {
-      if (lFlags == EECQHT_STATUS)
-        lstrcpyn (pszText, ".", nCharCnt);
-      if (lFlags == EECQHT_TOOLTIP)
-        lstrcpyn (pszText,
-                  _("Encrypt message with GnuPG"),
-                  nCharCnt);
-    }
-  else if (nCommandID == m_nCmdSign
-           && m_lContext == EECONTEXT_SENDNOTEMESSAGE) 
-    {
-      if (lFlags == EECQHT_STATUS)
-        lstrcpyn (pszText, ".", nCharCnt);
-      if (lFlags == EECQHT_TOOLTIP)
-        lstrcpyn (pszText,
-                  _("Sign message with GnuPG"),
-                  nCharCnt);
-    }
-  else 
-    return S_FALSE;
-
-  return S_OK;
+  return S_FALSE;
 }
 
 
@@ -849,19 +669,6 @@
     n = description_size;
   lstrcpyn (description, tb_info->desc, n);
 
-  if (tb_info->cmd_id == m_nCmdEncrypt)
-    {
-      pTBB->fsStyle |= TBSTYLE_CHECK;
-      if (m_pExchExt->m_gpgEncrypt)
-        pTBB->fsState |= TBSTATE_CHECKED;
-    }
-  else if (tb_info->cmd_id == m_nCmdSign)
-    {
-      pTBB->fsStyle |= TBSTYLE_CHECK;
-      if (m_pExchExt->m_gpgSign)
-        pTBB->fsState |= TBSTATE_CHECKED;
-    }
-
   return S_OK;
 }
 

Modified: trunk/src/ext-commands.h
===================================================================
--- trunk/src/ext-commands.h	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/ext-commands.h	2009-10-29 18:49:32 UTC (rev 312)
@@ -40,17 +40,6 @@
   ULONG m_lRef;
   ULONG m_lContext;
   
-  UINT  m_nCmdProtoAuto;
-  UINT  m_nCmdProtoPgpmime;
-  UINT  m_nCmdProtoSmime;
-  UINT  m_nCmdEncrypt;
-  UINT  m_nCmdSign;
-  UINT  m_nCmdRevertFolder;
-  UINT  m_nCmdDebug0;
-  UINT  m_nCmdDebug1;
-  UINT  m_nCmdDebug2;
-  UINT  m_nCmdDebug3;
-
   /* A list of all active toolbar items.  */
   toolbar_info_t m_toolbar_info;
   

Modified: trunk/src/inspectors.cpp
===================================================================
--- trunk/src/inspectors.cpp	2009-10-28 19:26:06 UTC (rev 311)
+++ trunk/src/inspectors.cpp	2009-10-29 18:49:32 UTC (rev 312)
@@ -37,6 +37,7 @@
 /* Event sink for an Inspectors collection object.  */
 BEGIN_EVENT_SINK(GpgolInspectorsEvents, IOOMInspectorsEvents)
   STDMETHOD (NewInspector) (THIS_ LPOOMINSPECTOR);
+EVENT_SINK_DEFAULT_CTOR(GpgolInspectorsEvents)
 EVENT_SINK_DEFAULT_DTOR(GpgolInspectorsEvents)
 EVENT_SINK_INVOKE(GpgolInspectorsEvents)
 {
@@ -67,6 +68,11 @@
   STDMETHOD_ (void, Activate) (THIS_);
   STDMETHOD_ (void, Close) (THIS_);
   STDMETHOD_ (void, Deactivate) (THIS_);
+  bool m_first_activate_seen;
+EVENT_SINK_CTOR(GpgolInspectorEvents)
+{
+  m_first_activate_seen = false;
+}
 EVENT_SINK_DEFAULT_DTOR(GpgolInspectorEvents)
 EVENT_SINK_INVOKE(GpgolInspectorEvents)
 {
@@ -95,6 +101,18 @@
 
 
 
+/* A linked list as a simple collection of button.  */
+struct button_list_s
+{
+  struct button_list_s *next;
+  LPDISPATCH sink;
+  LPDISPATCH button;
+  int instid;
+  char tag[1];         /* Variable length string.  */
+};
+typedef struct button_list_s *button_list_t;
+
+
 /* To avoid messing around with the OOM (adding extra objects as user
    properties and such), we keep our own information structure about
    inspectors. */
@@ -110,8 +128,8 @@
      locate the inspector object.  */
   LPOOMINSPECTOREVENTS eventsink;
 
-  /* The event sink object for the crypto info button.  */
-  LPDISPATCH crypto_info_sink;
+  /* A list of all the buttons.  */
+  button_list_t buttons;
 
 };
 typedef struct inspector_info_s *inspector_info_t;
@@ -120,6 +138,11 @@
 static inspector_info_t all_inspectors;
 static HANDLE all_inspectors_lock;
 
+
+static void update_crypto_info (LPDISPATCH button);
+
+
+
 /* Initialize this module.  Returns 0 on success.  Called once by dllinit.  */
 int
 initialize_inspectors (void)
@@ -164,6 +187,34 @@
 }
 
 
+/* Add SINK and BUTTON to the list at LISTADDR.  The list takes
+   ownership of SINK and BUTTON, thus the caller may not use OBJ or
+   OBJ2 after this call.  If TAG is given it is stored as well.  */
+static void
+move_to_button_list (button_list_t *listaddr, 
+                     LPDISPATCH sink, LPDISPATCH button, const char *tag)
+{
+  button_list_t item;
+  int instid;
+
+  if (!tag)
+    tag = "";
+
+  instid = button? get_oom_int (button, "InstanceId"): 0;
+
+  // log_debug ("%s:%s: sink=%p btn=%p tag=(%s) instid=%d",
+  //            SRCNAME, __func__, sink, button, tag, instid);
+
+  item = (button_list_t)xcalloc (1, sizeof *item + strlen (tag));
+  item->sink = sink;
+  item->button = button;
+  item->instid = instid;
+  strcpy (item->tag, tag);
+  item->next = *listaddr;
+  *listaddr = item;
+}
+
+
 /* Register the inspector object INSPECTOR along with its event SINK.  */
 static void
 register_inspector (LPOOMINSPECTOR inspector, LPOOMINSPECTOREVENTS sink)
@@ -190,6 +241,7 @@
 deregister_inspector (LPOOMINSPECTOREVENTS sink)
 {
   inspector_info_t r, rprev;
+  button_list_t ol, ol2;
 
   if (!sink)
     return;
@@ -215,8 +267,17 @@
   r->eventsink = NULL;
   if (r->inspector)
     r->inspector->Release ();
-  if (r->crypto_info_sink)
-    r->crypto_info_sink->Release ();
+
+  for (ol = r->buttons; ol; ol = ol2)
+    {
+      ol2 = ol->next;
+      if (ol->sink)
+        ol->sink->Release ();
+      if (ol->button)
+        ol->button->Release ();
+      xfree (ol);
+    }
+
   xfree (r);
 }
 
@@ -242,7 +303,43 @@
 }
 
 
+/* Search through all objects and find the inspector which has a
+   button with the instanceId INSTID.  The find the button with TAG in
+   that inspector and return it.  Caller must release the returned
+   button.  Returns NULL if not found.  */
+static LPDISPATCH
+get_button_by_instid_and_tag (int instid, const char *tag)
+{
+  LPDISPATCH result = NULL;
+  inspector_info_t iinfo;
+  button_list_t ol;
 
+  // log_debug ("%s:%s: inst=%d tag=(%s)",SRCNAME, __func__, instid, tag);
+
+  lock_all_inspectors ();
+
+  for (iinfo = all_inspectors; iinfo; iinfo = iinfo->next)
+    for (ol = iinfo->buttons; ol; ol = ol->next)
+      if (ol->instid == instid)
+        {
+          /* Found the inspector.  Now look for the tag.  */
+          for (ol = iinfo->buttons; ol; ol = ol->next)
+            if (ol->tag && !strcmp (ol->tag, tag))
+              {
+                result = ol->button;
+                if (result)
+                  result->AddRef ();
+                break;
+              }
+          break;
+        }
+
+  unlock_all_inspectors ();
+  return result;
+}
+
+
+
 /* The method called by outlook for each new inspector.  Note that
    Outlook sometimes reuses Inspectro objects thus this event is not
    an indication for a newly opened Inspector.  */
@@ -261,7 +358,6 @@
     {
       register_inspector (inspector, (LPOOMINSPECTOREVENTS)obj);
       obj->Release ();
-      add_inspector_controls (inspector);
     }
   inspector->Release ();
   return S_OK;
@@ -284,6 +380,7 @@
 GpgolInspectorEvents::Activate (void)
 {
   LPDISPATCH obj, button;
+  LPOOMINSPECTOR inspector;
 
   log_debug ("%s:%s: Called", SRCNAME, __func__);
 
@@ -296,7 +393,18 @@
       log_error ("%s:%s: Object not set", SRCNAME, __func__);
       return;
     }
+  inspector = (LPOOMINSPECTOR)m_object;
 
+  /* If this is the first activate for the inspector, we add the
+     controls.  We do it only now to be sure that everything has been
+     initialized.  Doing that in GpgolInspectorsEvents::NewInspector
+     is not suggested due to claims from some mailing lists.  */ 
+  if (!m_first_activate_seen)
+    {
+      m_first_activate_seen = true;
+      add_inspector_controls (inspector);
+    }
+  
   /* Update the crypt info.  */
   obj = get_oom_object (m_object, "CommandBars");
   if (!obj)
@@ -307,7 +415,7 @@
       obj->Release ();
       if (button)
         {
-          update_inspector_crypto_info (button);
+          update_crypto_info (button);
           button->Release ();
         }
     }
@@ -323,14 +431,37 @@
 }
 
 
+/* Check whether we are in composer or read mode.  */
+static bool
+is_inspector_in_composer_mode (LPDISPATCH inspector)
+{
+  LPDISPATCH obj;
+  bool in_composer;
+  
+  obj = get_oom_object (inspector, "get_CurrentItem");
+  if (obj)
+    {
+      /* We are in composer mode if the "Sent" property is false and
+         the class is 43.  */
+      in_composer = (!get_oom_bool (obj, "Sent") 
+                     && get_oom_int (obj, "Class") == 43);
+      obj->Release ();
+    }
+  else
+    in_composer = false;
+  return in_composer;
+}
 
 
-
+/* Add all the controls.  */
 void
 add_inspector_controls (LPOOMINSPECTOR inspector)
 {
-  LPDISPATCH pObj, pDisp, pTmp;
+  LPDISPATCH obj, controls, button;
   inspector_info_t inspinfo;
+  button_list_t buttonlist = NULL;
+  const char *tag;
+  int in_composer;
 
   log_debug ("%s:%s: Enter", SRCNAME, __func__);
 
@@ -341,75 +472,206 @@
      to keep a lock per inspector. */
 
   /* Check that our controls do not already exist.  */
-  pObj = get_oom_object (inspector, "CommandBars");
-  if (!pObj)
+  obj = get_oom_object (inspector, "CommandBars");
+  if (!obj)
     {
-      log_debug ("%s:%s: CommandBars not found", SRCNAME, __func__);
+      log_error ("%s:%s: CommandBars not found", SRCNAME, __func__);
       return;
     }
-  pDisp = get_oom_control_bytag (pObj, "GpgOL_Inspector_Crypto_Info");
-  pObj->Release ();
-  pObj = NULL;
-  if (pDisp)
+  button= get_oom_control_bytag (obj, "GpgOL_Inspector_Crypto_Info");
+  obj->Release ();
+  if (button)
     {
-      pDisp->Release ();
+      button->Release ();
       log_debug ("%s:%s: Leave (Controls are already added)",
                  SRCNAME, __func__);
       return;
     }
 
-  /* Create our controls.  */
-  pDisp = get_oom_object (inspector,
-                          "CommandBars.Item(Standard).get_Controls");
-  if (!pDisp)
-    log_debug ("%s:%s: CommandBar \"Standard\" not found\n",
-               SRCNAME, __func__);
-  else
+  /* Check whether we are in composer or read mode.  */
+  in_composer = is_inspector_in_composer_mode (inspector);
+
+  /* Add buttons to the Format menu but only in composer mode.  */
+  if (in_composer)
     {
-      pTmp = add_oom_button (pDisp);
-      pDisp->Release ();
-      pDisp = pTmp;
-      if (pDisp)
+      controls = get_oom_object 
+        (inspector, "CommandBars.FindControl(,30006).get_Controls");
+      if (!controls)
+        log_debug ("%s:%s: Menu Popup Format not found\n", SRCNAME, __func__);
+      else
         {
-          put_oom_string (pDisp, "Tag", "GpgOL_Inspector_Crypto_Info");
-          put_oom_int (pDisp, "Style", msoButtonIcon );
-          put_oom_string (pDisp, "TooltipText",
-                          _("Indicates the crypto status of the message"));
-          put_oom_icon (pDisp, IDB_SIGN, 16);
-          
-          pObj = install_GpgolCommandBarButtonEvents_sink (pDisp);
-          pDisp->Release ();
-          inspinfo = get_inspector_info (inspector);
-          if (inspinfo)
+          button = opt.disable_gpgol? NULL : add_oom_button (controls);
+          if (button)
             {
-              inspinfo->crypto_info_sink = pObj;
-              unlock_all_inspectors ();
+              put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Encrypt"));
+              put_oom_bool (button, "BeginGroup", true);
+              put_oom_int (button, "Style", msoButtonIconAndCaption );
+              put_oom_string (button, "Caption",
+                              _("&encrypt message with GnuPG"));
+              put_oom_icon (button, IDB_ENCRYPT, 16);
+              
+              obj = install_GpgolCommandBarButtonEvents_sink (button);
+              move_to_button_list (&buttonlist, obj, button, tag);
             }
-          else
+          
+          button = opt.disable_gpgol? NULL : add_oom_button (controls);
+          if (button)
             {
-              log_error ("%s:%s: inspector not registered", SRCNAME, __func__);
-              pObj->Release (); /* Get rid of the sink.  */
+              put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Sign"));
+              put_oom_int (button, "Style", msoButtonIconAndCaption );
+              put_oom_string (button, "Caption", _("&sign message with GnuPG"));
+              put_oom_icon (button, IDB_SIGN, 16);
+              
+              obj = install_GpgolCommandBarButtonEvents_sink (button);
+              move_to_button_list (&buttonlist, obj, button, tag);
             }
+          
+          controls->Release ();
         }
     }
+  
 
-  /* FIXME: Menuswe need to add: */
-        // (opt.disable_gpgol || not_a_gpgol_message)?
-        //         "" : _("GpgOL Decrypt/Verify"), &m_nCmdCryptoState,
-        // opt.enable_debug? "GpgOL Debug-0 (display crypto info)":"", 
-        //         &m_nCmdDebug0,
+  /* Add buttons to the Extra menu.  */
+  controls = get_oom_object (inspector,
+                             "CommandBars.FindControl(,30007).get_Controls");
+  if (!controls)
+    log_debug ("%s:%s: Menu Popup Extras not found\n", SRCNAME, __func__);
+  else
+    {
+      button = in_composer? NULL : add_oom_button (controls);
+      if (button)
+        {
+          put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Verify"));
+          put_oom_int (button, "Style", msoButtonIconAndCaption );
+          put_oom_string (button, "Caption", _("GpgOL Decrypt/Verify"));
+          put_oom_icon (button, IDB_DECRYPT_VERIFY, 16);
+          
+          obj = install_GpgolCommandBarButtonEvents_sink (button);
+          move_to_button_list (&buttonlist, obj, button, tag);
+        }
 
+      button = opt.enable_debug? add_oom_button (controls) : NULL;
+      if (button)
+        {
+          put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Debug-0"));
+          put_oom_int (button, "Style", msoButtonCaption );
+          put_oom_string (button, "Caption",
+                          "GpgOL Debug-0 (display crypto info)");
+          
+          obj = install_GpgolCommandBarButtonEvents_sink (button);
+          move_to_button_list (&buttonlist, obj, button, tag);
+        }
 
+      button = opt.enable_debug? add_oom_button (controls) : NULL;
+      if (button)
+        {
+          put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Debug-1"));
+          put_oom_int (button, "Style", msoButtonCaption );
+          put_oom_string (button, "Caption",
+                          "GpgOL Debug-1 (open_inspector)");
+          
+          obj = install_GpgolCommandBarButtonEvents_sink (button);
+          move_to_button_list (&buttonlist, obj, button, tag);
+        }
+
+      button = opt.enable_debug? add_oom_button (controls) : NULL;
+      if (button)
+        {
+          put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Debug-2"));
+          put_oom_int (button, "Style", msoButtonCaption );
+          put_oom_string (button, "Caption",
+                          "GpgOL Debug-2 (change message class)");
+          
+          obj = install_GpgolCommandBarButtonEvents_sink (button);
+          move_to_button_list (&buttonlist, obj, button, tag);
+        }
+
+      controls->Release ();
+    }
+
+
+  /* Create the toolbar buttons.  */
+  controls = get_oom_object (inspector,
+                             "CommandBars.Item(Standard).get_Controls");
+  if (!controls)
+    log_error ("%s:%s: CommandBar \"Standard\" not found\n",
+               SRCNAME, __func__);
+  else
+    {
+      button = (opt.disable_gpgol || !in_composer
+                ? NULL : add_oom_button (controls));
+      if (button)
+        {
+          put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Encrypt at t"));
+          put_oom_int (button, "Style", msoButtonIcon );
+          put_oom_string (button, "Caption", _("Encrypt message with GnuPG"));
+          put_oom_icon (button, IDB_ENCRYPT, 16);
+          put_oom_int (button, "State", msoButtonMixed );
+          
+          obj = install_GpgolCommandBarButtonEvents_sink (button);
+          move_to_button_list (&buttonlist, obj, button, tag);
+        }
+
+      button = (opt.disable_gpgol || !in_composer
+                ? NULL : add_oom_button (controls));
+      if (button)
+        {
+          put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Sign at t"));
+          put_oom_int (button, "Style", msoButtonIcon);
+          put_oom_string (button, "Caption", _("Sign message with GnuPG"));
+          put_oom_icon (button, IDB_SIGN, 16);
+          put_oom_int (button, "State", msoButtonDown);
+          
+          obj = install_GpgolCommandBarButtonEvents_sink (button);
+          move_to_button_list (&buttonlist, obj, button, tag);
+        }
+
+      button = in_composer? NULL : add_oom_button (controls);
+      if (button)
+        {
+          put_oom_string (button, "Tag", (tag = "GpgOL_Inspector_Crypto_Info"));
+          put_oom_int (button, "Style", msoButtonIcon);
+          
+          obj = install_GpgolCommandBarButtonEvents_sink (button);
+          move_to_button_list (&buttonlist, obj, button, tag);
+        }
+
+      controls->Release ();
+    }
+
+
+  /* Save the buttonlist.  */
+  inspinfo = get_inspector_info (inspector);
+  if (inspinfo)
+    {
+      inspinfo->buttons = buttonlist;
+      unlock_all_inspectors ();
+    }
+  else
+    {
+      button_list_t ol, ol2;
+
+      log_error ("%s:%s: inspector not registered", SRCNAME, __func__);
+      for (ol = buttonlist; ol; ol = ol2)
+        {
+          ol2 = ol->next;
+          if (ol->sink)
+            ol->sink->Release ();
+          if (ol->button)
+            ol->button->Release ();
+          xfree (ol);
+        }
+    }
     
   log_debug ("%s:%s: Leave", SRCNAME, __func__);
 }
 
 
 /* Update the crypto info icon.  */
-void
-update_inspector_crypto_info (LPDISPATCH button)
+static void
+update_crypto_info (LPDISPATCH button)
 {
-  LPDISPATCH obj;
+  LPDISPATCH inspector;
   char *msgcls = NULL;;
   const char *s;
   int in_composer = 0;
@@ -422,13 +684,13 @@
      versions via mapi_get_message_type and mapi_test_sig_status
      in UserProperties and use them instead of a direct lookup of
      the messageClass.  */
-  obj = get_oom_object (button, "get_Parent.get_Parent.get_CurrentItem");
-  if (obj)
+
+  inspector = get_oom_object (button, "get_Parent.get_Parent.get_CurrentItem");
+  if (inspector)
     {
-      msgcls = get_oom_string (obj, "MessageClass");
-      /* If "Sent" is false we are in composer mode  */
-      in_composer = !get_oom_bool (obj, "Sent");
-      obj->Release ();
+      msgcls = get_oom_string (inspector, "MessageClass");
+      in_composer = is_inspector_in_composer_mode (inspector);
+      inspector->Release ();
     }
   if (msgcls)
     {
@@ -494,3 +756,131 @@
     }
 }
 
+
+/* Toggle a button and return the new state.  */
+static int
+toggle_button (LPDISPATCH button, const char *tag, int instid)
+{
+  int state = get_oom_int (button, "State");
+  char tag2[256];
+  LPDISPATCH button2;
+
+  log_debug ("%s:%s: button `%s' state is %d", SRCNAME, tag, __func__, state);
+  state = (state == msoButtonUp)? msoButtonDown : msoButtonUp;
+  put_oom_int (button, "State", state);
+
+  /* Toggle the other button.  */
+  mem2str (tag2, tag, sizeof tag2 - 2);
+  if (*tag2 && tag2[1] && !strcmp (tag2+strlen(tag2)-2, "@t"))
+    tag2[strlen(tag2)-2] = 0; /* Remove the "@t".  */
+  else
+    strcat (tag2, "@t");      /* Append a "@t".  */
+
+  button2 = get_button_by_instid_and_tag (instid, tag2);
+  if (!button2)
+    log_debug ("%s:%s: button `%s' not found", SRCNAME, __func__, tag2);
+  else
+    {
+      put_oom_int (button2, "State", state);
+      button2->Release ();
+    }
+  return state;
+}
+
+
+/* Called for a click on an inspector button.  BUTTON is the button
+   object and TAG is the tag value (which is guaranteed not to be
+   NULL).  INSTID is the instance ID of the button. */
+void
+proc_inspector_button_click (LPDISPATCH button, const char *tag, int instid)
+{
+  if (!tagcmp (tag, "GpgOL_Inspector_Encrypt"))
+    {  
+      toggle_button (button, tag, instid);
+    }
+  else if (!tagcmp (tag, "GpgOL_Inspector_Sign"))
+    {  
+      toggle_button (button, tag, instid);
+    }
+  else if (!tagcmp (tag, "GpgOL_Inspector_Verify"))
+    {
+      /* FIXME: We need to invoke decrypt/verify again. */
+    }
+  else if (!tagcmp (tag, "GpgOL_Inspector_Crypto_Info"))
+    {
+      /* FIXME: We should invoke the decrypt/verify again. */
+      update_crypto_info (button);
+#if 0 /* This is the code we used to use.  */
+      log_debug ("%s:%s: command CryptoState called\n", SRCNAME, __func__);
+      hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
+      if (SUCCEEDED (hr))
+        {
+          if (message_incoming_handler (message, hwnd, true))
+            message_display_handler (eecb, hwnd);
+	}
+      else
+        log_debug_w32 (hr, "%s:%s: command CryptoState failed", 
+                       SRCNAME, __func__);
+      ul_release (message, __func__, __LINE__);
+      ul_release (mdb, __func__, __LINE__);
+#endif
+    }
+  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-0"))
+    {
+      /* Show crypto info.  */
+      log_debug ("%s:%s: command Debug0 (showInfo) called\n",
+                 SRCNAME, __func__);
+      // hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
+      // if (SUCCEEDED (hr))
+      //   {
+      //     message_show_info (message, hwnd);
+      //   }
+      // ul_release (message, __func__, __LINE__);
+      // ul_release (mdb, __func__, __LINE__);
+    }
+  else if (!tagcmp (tag, "GpgOL_Inspector_Debug-1"))
+    {
+      /* Open inspector.  */
+      log_debug ("%s:%s: command Debug1 (open inspector) called\n",
+                 SRCNAME, __func__);
+      // hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&message);
+      // if (SUCCEEDED (hr))
+      //   {
+      //     open_inspector (eecb, message);
+      //   }
+      // ul_release (message, __func__, __LINE__);
+      // ul_release (mdb, __func__, __LINE__);
+    }




More information about the Gnupg-commits mailing list