include/sfx2/lokhelper.hxx     |    6 ++++++
 sfx2/source/view/lokhelper.cxx |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

New commits:
commit 6c09506d3da25f6f478c4f8ce94f7e5c0412b1fd
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Tue Jun 2 11:51:52 2020 +0530
Commit:     Dennis Francis <dennis.fran...@collabora.com>
CommitDate: Mon Jul 6 17:34:16 2020 +0200

    introduce property-tree versions of SfxLokHelper::notifyOtherView*()
    
    Change-Id: I4ebbc166da94eab6e35984c50220dde7daf7adde
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98055
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Dennis Francis <dennis.fran...@collabora.com>

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 032c656f1a4d..57aee1bb3a5d 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -39,6 +39,8 @@ struct SFX2_DLLPUBLIC LokMouseEventData
     {}
 };
 
+#include <boost/property_tree/ptree_fwd.hpp>
+
 class SFX2_DLLPUBLIC SfxLokHelper
 {
 public:
@@ -75,8 +77,12 @@ public:
     static void forEachOtherView(ViewShellType* pThisViewShell, FunctionType 
f);
     /// Invoke the LOK callback of all other views showing the same document 
as pThisView, with a payload of rKey-rPayload.
     static void notifyOtherViews(SfxViewShell* pThisView, int nType, const 
OString& rKey, const OString& rPayload);
+    /// Invoke the LOK callback of all views except pThisView, with a JSON 
payload created from the given property tree.
+    static void notifyOtherViews(SfxViewShell* pThisView, int nType, const 
boost::property_tree::ptree& rTree);
     /// Same as notifyOtherViews(), but works on a selected "other" view, not 
on all of them.
     static void notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* 
pOtherView, int nType, const OString& rKey, const OString& rPayload);
+    /// Same as notifyOtherViews(), the property-tree version, but works on a 
selected "other" view, not on all of them.
+    static void notifyOtherView(SfxViewShell* pThisView, SfxViewShell const* 
pOtherView, int nType, const boost::property_tree::ptree& rTree);
     /// Emits a LOK_CALLBACK_STATE_CHANGED
     static void sendUnoStatus(const SfxViewShell* pShell, const SfxPoolItem* 
pItem);
     /// Emits a LOK_CALLBACK_WINDOW
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 0b92060785bb..03241d065a78 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -30,6 +30,8 @@
 
 #include <shellimpl.hxx>
 
+#include <boost/property_tree/json_parser.hpp>
+
 using namespace com::sun::star;
 
 namespace {
@@ -288,6 +290,16 @@ static OString lcl_escapeQuotes(const OString &rStr)
     return aBuf.makeStringAndClear();
 }
 
+static OString lcl_generateJSON(SfxViewShell* pView, const 
boost::property_tree::ptree& rTree)
+{
+    boost::property_tree::ptree aMessageProps = rTree;
+    aMessageProps.put("viewId", SfxLokHelper::getView(pView));
+    aMessageProps.put("part", pView->getPart());
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aMessageProps, false /* pretty 
*/);
+    return OString(aStream.str().c_str()).trim();
+}
+
 void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell 
const* pOtherView, int nType, const OString& rKey, const OString& rPayload)
 {
     if (DisableCallbacks::disabled())
@@ -300,6 +312,15 @@ void SfxLokHelper::notifyOtherView(SfxViewShell* 
pThisView, SfxViewShell const*
     pOtherView->libreOfficeKitViewCallback(nType, aPayload.getStr());
 }
 
+void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell 
const* pOtherView, int nType,
+                                   const boost::property_tree::ptree& rTree)
+{
+    if (DisableCallbacks::disabled())
+        return;
+
+    pOtherView->libreOfficeKitViewCallback(nType, lcl_generateJSON(pThisView, 
rTree).getStr());
+}
+
 void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const 
OString& rKey, const OString& rPayload)
 {
     if (DisableCallbacks::disabled())
@@ -315,6 +336,24 @@ void SfxLokHelper::notifyOtherViews(SfxViewShell* 
pThisView, int nType, const OS
     }
 }
 
+void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const 
boost::property_tree::ptree& rTree)
+{
+    if (SfxLokHelper::getViewsCount() <= 1 || DisableCallbacks::disabled())
+        return;
+
+    // Payload is only dependent on pThisView.
+    OString aPayload = lcl_generateJSON(pThisView, rTree);
+
+    SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+    while (pViewShell)
+    {
+        if (pViewShell != pThisView)
+            pViewShell->libreOfficeKitViewCallback(nType, aPayload.getStr());
+
+        pViewShell = SfxViewShell::GetNext(*pViewShell);
+    }
+}
+
 namespace {
     OUString lcl_getNameForSlot(const SfxViewShell* pShell, sal_uInt16 nWhich)
     {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to