[git] GpgOL - branch, master, updated. gpgol-1.3.0-23-gd1648f2

by Andre Heinecke cvs at cvs.gnupg.org
Fri Dec 4 17:19:00 CET 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG extension for MS Outlook".

The branch, master has been updated
       via  d1648f24e6abaaf9550671b0b6ddad56632a1cf3 (commit)
       via  50086fff3eb4c31cf4496463fcffa6f452fc19fe (commit)
       via  95736757ab809a9520215d300cf2fc71a918ebd4 (commit)
      from  79bd708bcc0ac5ffa110aa82db0437a7f422c5c6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d1648f24e6abaaf9550671b0b6ddad56632a1cf3
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Dec 4 17:02:35 2015 +0100

    Use callbacks for toggle btn state and refresh ui
    
    * src/application-events.cpp (ApplicationEvents::Invoke): Invalidate
      UI when a new Item is loaded.
    * src/gpgoladdin.cpp (GpgolRibbonExtender::Invoke): Store RibbonUI
      instances. Forward calls for new ID's.
      (GpgolRibbonExtender::GetCustomUI): Add callbacks.
      (GpgolRibbonExtender::GetIDsOfNames): Add CB ID's-
      (gpgoladdin_invalidate_ui): Invalidate UI. Invalidate causes
      all callback to be triggered again in their correct contexts.
    * src/gpgoladdin.h: Add prototype for gpgoladdin_invalidate_ui.
    * src/ribbon-callbacks.cpp (mark_mime_action): Work on base message.
      (get_crypt_pressed): Callback for toggle buttons.
    * src/ribbon-callbacks.h: Add ids and prototypes
    
    --
    This effectively is the first step to have a customised Ribbon UI
    for a mail context. Also fixes toggle button behavior in mime send
    mode and:
    
    GnuPG-Bug-Id: 2141

diff --git a/src/application-events.cpp b/src/application-events.cpp
index 4fe89cc..6b1ff4f 100644
--- a/src/application-events.cpp
+++ b/src/application-events.cpp
@@ -27,6 +27,7 @@
 #include "common.h"
 #include "oomhelp.h"
 #include "mail.h"
+#include "gpgoladdin.h"
 
 /* Application Events */
 BEGIN_EVENT_SINK(ApplicationEvents, IDispatch)
@@ -85,6 +86,8 @@ EVENT_SINK_INVOKE(ApplicationEvents)
           log_debug ("%s:%s: Creating mail object for item: %p",
                      SRCNAME, __func__, mailItem);
           new Mail (mailItem);
+          /* Ensure that all UI's are nicely updated for the new mail */
+          gpgoladdin_invalidate_ui ();
           break;
         }
       default:
diff --git a/src/gpgoladdin.cpp b/src/gpgoladdin.cpp
index 6599244..01c2084 100644
--- a/src/gpgoladdin.cpp
+++ b/src/gpgoladdin.cpp
@@ -1,5 +1,5 @@
 /* gpgoladdin.cpp - Connect GpgOL to Outlook as an addin
- *    Copyright (C) 2013 Intevation GmbH
+ *    Copyright (C) 2013, 2015 Intevation GmbH
  *
  * This file is part of GpgOL.
  *
@@ -51,6 +51,7 @@
 #include "mail.h"
 
 #include <gpg-error.h>
+#include <list>
 
 #define ICON_SIZE_LARGE  32
 #define ICON_SIZE_NORMAL 16
@@ -63,6 +64,8 @@ ULONG addinLocks = 0;
 
 bool can_unload = false;
 
+static std::list<LPDISPATCH> g_ribbon_uis;
+
 /* This is the main entry point for the addin
    Outlook uses this function to query for an Object implementing
    the IClassFactory interface.
@@ -504,6 +507,9 @@ GpgolRibbonExtender::GetIDsOfNames (REFIID riid, LPOLESTR *rgszNames,
       /* MIME support: */
       ID_MAPPER (L"encryptMime", ID_CMD_MIME_ENCRYPT)
       ID_MAPPER (L"signMime", ID_CMD_MIME_SIGN)
+      ID_MAPPER (L"getEncryptPressed", ID_GET_ENCRYPT_PRESSED)
+      ID_MAPPER (L"getSignPressed", ID_GET_SIGN_PRESSED)
+      ID_MAPPER (L"ribbonLoaded", ID_ON_LOAD);
     }
 
   if (cNames > 1)
@@ -558,6 +564,16 @@ GpgolRibbonExtender::Invoke (DISPID dispid, REFIID riid, LCID lcid,
         return mime_sign (parms->rgvarg[1].pdispVal);
       case ID_CMD_MIME_ENCRYPT:
         return mime_encrypt (parms->rgvarg[1].pdispVal);
+      case ID_GET_ENCRYPT_PRESSED:
+        return get_crypt_pressed (parms->rgvarg[0].pdispVal, 1, result);
+      case ID_GET_SIGN_PRESSED:
+        return get_crypt_pressed (parms->rgvarg[0].pdispVal, 2, result);
+      case ID_ON_LOAD:
+          {
+            log_debug ("A new Ribbon control was born: %p",
+                       parms->rgvarg[0].pdispVal);
+            g_ribbon_uis.push_back (parms->rgvarg[0].pdispVal);
+          }
       case ID_BTN_CERTMANAGER:
       case ID_BTN_ENCRYPT:
       case ID_BTN_DECRYPT:
@@ -611,11 +627,11 @@ GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
   if (!wcscmp (RibbonID, L"Microsoft.Outlook.Mail.Compose"))
     {
       gpgrt_asprintf (&buffer,
-        "<customUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\">"
+        "<customUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\""
+        " onLoad=\"ribbonLoaded\">"
         " <ribbon>"
         "   <tabs>"
-        "    <tab id=\"gpgolTab\""
-        "         label=\"%s\">"
+        "    <tab idMso=\"TabNewMailMessage\">"
         "     <group id=\"general\""
         "            label=\"%s\">"
         "       <button id=\"CustomButton\""
@@ -625,30 +641,28 @@ GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
         "               screentip=\"%s\""
         "               supertip=\"%s\""
         "               onAction=\"startCertManager\"/>"
-        "     </group>"
-        "     <group id=\"textGroup\""
-        "            label=\"%s\">"
         "       <toggleButton id=\"mimeEncrypt\""
         "               getImage=\"btnEncryptLarge\""
         "               size=\"large\""
         "               label=\"%s\""
         "               screentip=\"%s\""
         "               supertip=\"%s\""
-        "               onAction=\"encryptMime\"/>"
+        "               onAction=\"encryptMime\""
+        "               getPressed=\"getEncryptPressed\"/>"
         "       <toggleButton id=\"mimeSign\""
         "               getImage=\"btnSignLarge\""
         "               size=\"large\""
         "               label=\"%s\""
         "               screentip=\"%s\""
         "               supertip=\"%s\""
-        "               onAction=\"signMime\"/>"
+        "               onAction=\"signMime\""
+        "               getPressed=\"getSignPressed\"/>"
         "     </group>"
         "    </tab>"
         "   </tabs>"
         " </ribbon>"
-        "</customUI>", _("GpgOL"), _("General"),
+        "</customUI>", _("GpgOL"),
         _("Start Certificate Manager"), certManagerTTip, certManagerSTip,
-        _("GnuPG"),
         _("Encrypt"), encryptTTip, encryptSTip,
         _("Sign"), signTTip, signSTip
         );
@@ -967,3 +981,27 @@ GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
   return S_OK;
 }
 #endif /* MIME_SEND */
+
+
+/* RibbonUi elements are created on demand but they are reused
+   in different inspectors. So far and from all documentation
+   I could find RibbonUi elments are never
+   deleted. When they are created the onLoad callback is called
+   to register them.
+   The callbacks registered in the XML description are only
+   executed on Load. So to have different information depending
+   on the available mails we have to invalidate the UI ourself.
+   This means that the callbacks will be reevaluated and the UI
+   Updated. Sadly we don't know which ribbon_ui needs updates
+   so we have to invalidate everything.
+*/
+void gpgoladdin_invalidate_ui ()
+{
+  std::list<LPDISPATCH>::iterator it;
+
+  for (it = g_ribbon_uis.begin(); it != g_ribbon_uis.end(); ++it)
+    {
+      log_debug ("Invalidating ribbon: %p", *it);
+      invoke_oom_method (*it, "Invalidate", NULL);
+    }
+}
diff --git a/src/gpgoladdin.h b/src/gpgoladdin.h
index 7b0c29a..c3fcfe6 100644
--- a/src/gpgoladdin.h
+++ b/src/gpgoladdin.h
@@ -206,6 +206,7 @@ private:
   LPDISPATCH m_application;
   LPDISPATCH m_addin;
   LPDISPATCH m_applicationEventSink;
+  LPDISPATCH m_ribbon_control;
   bool m_disabled;
 
 };
@@ -244,4 +245,7 @@ private:
 
 STDAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID* ppvObj);
 
+/* Invalidates the UI XML to trigger a reload of the UI Elements. */
+void gpgoladdin_invalidate_ui ();
+
 #endif /*GPGOLADDIN_H*/
diff --git a/src/ribbon-callbacks.cpp b/src/ribbon-callbacks.cpp
index 76487d3..9079086 100644
--- a/src/ribbon-callbacks.cpp
+++ b/src/ribbon-callbacks.cpp
@@ -1308,7 +1308,7 @@ mark_mime_action (LPDISPATCH ctrl, int flags)
       goto done;
     }
 
-  message = get_oom_message (mailitem);
+  message = get_oom_base_message (mailitem);
 
   if (!message)
     {
@@ -1346,3 +1346,62 @@ HRESULT mime_encrypt (LPDISPATCH ctrl)
 {
   return mark_mime_action (ctrl, OP_ENCRYPT);
 }
+
+/* Get the state of encrypt / sign toggle buttons.
+  flag values: 1 get the state of the encrypt button.
+               2 get the state of the sign button. */
+HRESULT get_crypt_pressed (LPDISPATCH ctrl, int flags, VARIANT *result)
+{
+  HRESULT hr;
+  LPDISPATCH context = NULL,
+             mailitem = NULL;
+  LPMESSAGE message = NULL;
+
+  /* First the usual defensive check about our parameters */
+  if (!ctrl || !result)
+    {
+      log_error ("%s:%s:%i", SRCNAME, __func__, __LINE__);
+      return E_FAIL;
+    }
+
+  result->vt = VT_BOOL | VT_BYREF;
+  result->pboolVal = (VARIANT_BOOL*) xmalloc (sizeof (VARIANT_BOOL));
+
+  hr = getContext (ctrl, &context);
+
+  if (hr)
+    {
+      log_error ("%s:%s:%i : hresult %lx", SRCNAME, __func__, __LINE__,
+                 hr);
+      return E_FAIL;
+    }
+
+  mailitem = get_oom_object (context, "CurrentItem");
+
+  if (!mailitem)
+    {
+      log_error ("%s:%s: Failed to get mailitem.",
+                 SRCNAME, __func__);
+      goto done;
+    }
+
+  message = get_oom_base_message (mailitem);
+
+  if (!message)
+    {
+      log_error ("%s:%s: No message found.",
+                 SRCNAME, __func__);
+      goto done;
+    }
+
+  *(result->pboolVal) = get_gpgol_draft_info_flags (message) & flags ?
+                                                        VARIANT_TRUE :
+                                                        VARIANT_FALSE;
+
+done:
+  RELDISP (context);
+  RELDISP (mailitem);
+  RELDISP (message);
+
+  return S_OK;
+}
diff --git a/src/ribbon-callbacks.h b/src/ribbon-callbacks.h
index 8c4762d..571d36c 100644
--- a/src/ribbon-callbacks.h
+++ b/src/ribbon-callbacks.h
@@ -38,6 +38,9 @@
 #define ID_CMD_VERIFY_BODY      12
 #define ID_CMD_MIME_SIGN        13
 #define ID_CMD_MIME_ENCRYPT     14
+#define ID_GET_SIGN_PRESSED     15
+#define ID_GET_ENCRYPT_PRESSED  16
+#define ID_ON_LOAD              17
 
 #define ID_BTN_CERTMANAGER       IDI_KEY_MANAGER_64_PNG
 #define ID_BTN_DECRYPT           IDI_DECRYPT_16_PNG
@@ -64,4 +67,8 @@ HRESULT verifyBody (LPDISPATCH ctrl);
 HRESULT mime_encrypt (LPDISPATCH ctrl);
 /* Mark the mail to be mime signed on send. */
 HRESULT mime_sign (LPDISPATCH ctrl);
+/* Get the toggle state of a crypt button. Flag value 1: encrypt, 2: sign */
+HRESULT get_crypt_pressed (LPDISPATCH ctrl, int flags, VARIANT *result);
+/* Callback to get our own control reference */
+HRESULT ribbon_loaded (LPDISPATCH ctrl);
 #endif

commit 50086fff3eb4c31cf4496463fcffa6f452fc19fe
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Dec 4 16:59:32 2015 +0100

    Move blocking multitry save code into mapihelp
    
    * src/revert.cpp (finalize_mapi): Remove wait code.
    * src/mapihelp.cpp (mapi_do_save_changes): Try multiple times.
    
    --
    I randomly don't get failures saving back to mapi. Just happens
    in encryption for send. Blocking the UI is not nice but usally
    saving works after 1-5 tries. I've seen it as early as one try
    and as much as 5.

diff --git a/src/mapihelp.cpp b/src/mapihelp.cpp
index 8815b08..83d8faf 100644
--- a/src/mapihelp.cpp
+++ b/src/mapihelp.cpp
@@ -315,7 +315,17 @@ mapi_do_save_changes (LPMESSAGE message, ULONG flags, int only_del_body,
 
   if (!only_del_body || any)
     {
-      hr = message->SaveChanges (flags);
+      int i;
+      for (i = 0, hr = 0; hr && i < 10; i++)
+        {
+          hr = message->SaveChanges (flags);
+          if (hr)
+            {
+              log_debug ("%s:%s: Failed try to save.",
+                         SRCNAME, __func__);
+              Sleep (1000);
+            }
+        }
       if (hr)
         {
           log_error ("%s:%s: SaveChanges(%lu) failed: hr=%#lx\n",
diff --git a/src/revert.cpp b/src/revert.cpp
index 80876e3..23f2f8c 100644
--- a/src/revert.cpp
+++ b/src/revert.cpp
@@ -241,8 +241,6 @@ static int finalize_mapi (LPMESSAGE message)
   HRESULT hr;
   SPropTagArray proparray;
   ULONG tag_id;
-  int save_tries;
-  int rc;
 
   if (get_gpgollastdecrypted_tag (message, &tag_id))
     {
@@ -260,24 +258,7 @@ static int finalize_mapi (LPMESSAGE message)
       return -1;
     }
 
-  /* Save the changes. */
-  for (save_tries = 0, rc = 1; rc && save_tries < 10; save_tries++)
-    {
-      rc = mapi_save_changes (message, FORCE_SAVE);
-      if (rc)
-        {
-          log_debug ("Failed try to save.");
-          Sleep (1000);
-        }
-    }
-  if (save_tries == 5)
-    {
-      log_error ("%s:%s: Saving restored message failed.",
-                 SRCNAME, __func__);
-      return -1;
-    }
-
-  return 0;
+  return mapi_save_changes (message, FORCE_SAVE);
 }
 
 /* Similar to gpgol_message_revert but works on OOM and is

commit 95736757ab809a9520215d300cf2fc71a918ebd4
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri Dec 4 11:00:59 2015 +0100

    Revert "Add Tracepoints for issue 1837"
    
    This reverts commit 7016fec9aef7be53f164829f7c76e28c6a83e228.
    
    * src/gpgoladdin.cpp (getCustomUI): Fix conflicts.
    
    --
    The trace information is no longer useful the underlying problem
    was the unload of the dll caused by the wrong behavior of
    DLLCanUnloadNow

diff --git a/src/gpgoladdin.cpp b/src/gpgoladdin.cpp
index 5496eed..6599244 100644
--- a/src/gpgoladdin.cpp
+++ b/src/gpgoladdin.cpp
@@ -675,7 +675,6 @@ GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
 STDMETHODIMP
 GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
 {
-  TRACEPOINT
   char *buffer = NULL;
   const char *certManagerTTip =
     _("Start the Certificate Management Software");
@@ -713,17 +712,14 @@ GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
       "The combination of the signed message text and your signature is "
       "added below the plain text. "
       "The message will not be encrypted!");
-  TRACEPOINT
 
   log_debug ("%s:%s: GetCustomUI for id: %ls", SRCNAME, __func__, RibbonID);
 
   if (!RibbonXml)
     return E_POINTER;
 
-  TRACEPOINT
   if (!wcscmp (RibbonID, L"Microsoft.Outlook.Mail.Compose"))
     {
-      TRACEPOINT
       gpgrt_asprintf (&buffer,
         "<customUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\">"
         " <ribbon>"
@@ -816,7 +812,6 @@ GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
     }
   else if (!wcscmp (RibbonID, L"Microsoft.Outlook.Mail.Read"))
     {
-      TRACEPOINT
       gpgrt_asprintf (&buffer,
         "<customUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\">"
         " <ribbon>"
@@ -890,7 +885,6 @@ GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
     }
   else if (!wcscmp (RibbonID, L"Microsoft.Outlook.Explorer"))
     {
-      TRACEPOINT
       gpgrt_asprintf (&buffer,
         "<customUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\">"
         " <ribbon>"
@@ -959,23 +953,17 @@ GpgolRibbonExtender::GetCustomUI (BSTR RibbonID, BSTR * RibbonXml)
         _("GpgOL"), _("Save and decrypt"),/*_("Decrypt"), */
         _("Save and decrypt"));
     }
-  TRACEPOINT
 
   if (buffer)
     {
-      TRACEPOINT
       wchar_t *wbuf = utf8_to_wchar2 (buffer, strlen(buffer));
       xfree (buffer);
-      TRACEPOINT
       *RibbonXml = SysAllocString (wbuf);
-      TRACEPOINT
       xfree (wbuf);
-      TRACEPOINT
     }
   else
     *RibbonXml = NULL;
 
-  TRACEPOINT
   return S_OK;
 }
 #endif /* MIME_SEND */
diff --git a/src/ribbon-callbacks.cpp b/src/ribbon-callbacks.cpp
index 8414f83..76487d3 100644
--- a/src/ribbon-callbacks.cpp
+++ b/src/ribbon-callbacks.cpp
@@ -919,7 +919,6 @@ do_reader_action (LPDISPATCH ctrl, int flags)
 HRESULT
 getIcon (int id, VARIANT* result)
 {
-  TRACEPOINT
   PICTDESC pdesc;
   LPDISPATCH pPict;
   HRESULT hr;
@@ -935,7 +934,6 @@ getIcon (int id, VARIANT* result)
   pdesc.cbSizeofstruct = sizeof pdesc;
   pdesc.picType = PICTYPE_BITMAP;
 
-  TRACEPOINT
   if (!result)
     {
       log_error ("getIcon called without result variant.");
@@ -950,7 +948,6 @@ getIcon (int id, VARIANT* result)
   GdiplusStartup (&gdiplusToken, &gdiplusStartupInput, NULL);
 
   /* Get the image from the resource file */
-  TRACEPOINT
   hResource = FindResource (glob_hinst, MAKEINTRESOURCE(id), RT_RCDATA);
   if (!hResource)
     {
@@ -959,12 +956,10 @@ getIcon (int id, VARIANT* result)
       return E_FAIL;
     }
 
-  TRACEPOINT
   imageSize = SizeofResource (glob_hinst, hResource);
   if (!imageSize)
     return E_FAIL;
 
-  TRACEPOINT
   pResourceData = LockResource (LoadResource(glob_hinst, hResource));
 
   if (!pResourceData)
@@ -974,47 +969,36 @@ getIcon (int id, VARIANT* result)
       return E_FAIL;
     }
 
-  TRACEPOINT
   hBuffer = GlobalAlloc (GMEM_MOVEABLE, imageSize);
 
-  TRACEPOINT
   if (hBuffer)
     {
       void* pBuffer = GlobalLock (hBuffer);
       if (pBuffer)
         {
-          TRACEPOINT
           IStream* pStream = NULL;
           CopyMemory (pBuffer, pResourceData, imageSize);
 
-          TRACEPOINT
           if (CreateStreamOnHGlobal (hBuffer, FALSE, &pStream) == S_OK)
             {
-              TRACEPOINT
               pbitmap = Gdiplus::Bitmap::FromStream (pStream);
               pStream->Release();
               if (!pbitmap || pbitmap->GetHBITMAP (0, &pdesc.bmp.hbitmap))
                 {
-                  TRACEPOINT
                   log_error ("%s:%s: failed to get PNG.",
                              SRCNAME, __func__);
                 }
             }
         }
-      TRACEPOINT
       GlobalUnlock (pBuffer);
     }
-  TRACEPOINT
   GlobalFree (hBuffer);
 
-  TRACEPOINT
   Gdiplus::GdiplusShutdown (gdiplusToken);
-  TRACEPOINT
 
   /* Wrap the image into an OLE object.  */
   hr = OleCreatePictureIndirect (&pdesc, IID_IPictureDisp,
                                  TRUE, (void **) &pPict);
-  TRACEPOINT
   if (hr != S_OK || !pPict)
     {
       log_error ("%s:%s: OleCreatePictureIndirect failed: hr=%#lx\n",
@@ -1022,10 +1006,8 @@ getIcon (int id, VARIANT* result)
       return -1;
     }
 
-  TRACEPOINT
   result->pdispVal = pPict;
   result->vt = VT_DISPATCH;
-  TRACEPOINT
 
   return S_OK;
 }

-----------------------------------------------------------------------

Summary of changes:
 src/application-events.cpp |  3 ++
 src/gpgoladdin.cpp         | 72 ++++++++++++++++++++++++++++--------------
 src/gpgoladdin.h           |  4 +++
 src/mapihelp.cpp           | 12 ++++++-
 src/revert.cpp             | 21 +-----------
 src/ribbon-callbacks.cpp   | 79 +++++++++++++++++++++++++++++++++++-----------
 src/ribbon-callbacks.h     |  7 ++++
 7 files changed, 135 insertions(+), 63 deletions(-)


hooks/post-receive
-- 
GnuPG extension for MS Outlook
http://git.gnupg.org




More information about the Gnupg-commits mailing list