[Libreoffice-commits] core.git: include/LibreOfficeKit libreofficekit/source sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Aug 19 14:46:17 UTC 2016


 include/LibreOfficeKit/LibreOfficeKitEnums.h   |   24 ++++++++++++++
 libreofficekit/source/gtk/lokdocview.cxx       |    6 +++
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   32 ++++++++++++++++++-
 sw/source/core/doc/docredln.cxx                |   42 +++++++++++++++++++++++++
 sw/source/core/inc/unoport.hxx                 |    3 +
 sw/source/core/unocore/unoredline.cxx          |    8 ++--
 6 files changed, 110 insertions(+), 5 deletions(-)

New commits:
commit 0bc553f3ef3c188a96ea4875f4722ad4d40da4a3
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Aug 19 15:27:59 2016 +0200

    sw lok: add callbacks for redline table insertion / removal
    
    An alternative would be to follow the Manage Changes dialog approach and
    subscribe to the SFX_HINT_DOCCHANGED notification in SwDocShell, cache
    the old redline table and find out the differences to the current one,
    but that way sound much more complex without benefits.
    
    Change-Id: I20a45285b88255ccea9d6646c0b5288ac1c91879

diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 651e9bc..2c3bcab 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -406,6 +406,30 @@ typedef enum
      */
     LOK_CALLBACK_VIEW_LOCK,
 
+    /**
+     * The size of the change tracking table has changed.
+     *
+     * The payload example:
+     * {
+     *     "redline": {
+     *         "action": "Remove",
+     *         "index": "1",
+     *         "author": "Unknown Author",
+     *         "type": "Delete",
+     *         "comment": "",
+     *         "dateTime": "2016-08-18T12:14:00"
+     *     }
+     * }
+     *
+     * The format is the same as an entry of
+     * lok::Document::getCommandValues('.uno:AcceptTrackedChanges'), extra
+     * fields:
+     *
+     * - 'action' is either 'Add' or 'Remove', depending on if this is an
+     *   insertion into the table or a removal.
+     */
+    LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED,
+
 }
 LibreOfficeKitCallbackType;
 
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 0156330..3af5d00 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -421,6 +421,8 @@ callbackTypeToString (int nType)
         return "LOK_CALLBACK_ERROR";
     case LOK_CALLBACK_VIEW_LOCK:
         return "LOK_CALLBACK_VIEW_LOCK";
+    case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
+        return "LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED";
     }
     g_assert(false);
     return nullptr;
@@ -1339,6 +1341,10 @@ callback (gpointer pData)
         gtk_widget_queue_draw(GTK_WIDGET(pDocView));
         break;
     }
+    case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
+    {
+        break;
+    }
     default:
         g_assert(false);
         break;
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index ad8deaf..a8b7bf9 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -68,6 +68,7 @@ public:
     void testShapeTextUndoShells();
     void testShapeTextUndoGroupShells();
     void testTrackChanges();
+    void testTrackChangesCallback();
 
     CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -101,6 +102,7 @@ public:
     CPPUNIT_TEST(testShapeTextUndoShells);
     CPPUNIT_TEST(testShapeTextUndoGroupShells);
     CPPUNIT_TEST(testTrackChanges);
+    CPPUNIT_TEST(testTrackChangesCallback);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -116,13 +118,15 @@ private:
     int m_nSelectionBeforeSearchResult;
     int m_nSelectionAfterSearchResult;
     int m_nInvalidations;
+    int m_nRedlineTableSizeChanged;
 };
 
 SwTiledRenderingTest::SwTiledRenderingTest()
     : m_bFound(true),
       m_nSelectionBeforeSearchResult(0),
       m_nSelectionAfterSearchResult(0),
-      m_nInvalidations(0)
+      m_nInvalidations(0),
+      m_nRedlineTableSizeChanged(0)
 {
 }
 
@@ -196,6 +200,11 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
         }
     }
     break;
+    case LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED:
+    {
+        ++m_nRedlineTableSizeChanged;
+    }
+    break;
     }
 }
 
@@ -1169,6 +1178,27 @@ void SwTiledRenderingTest::testTrackChanges()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void SwTiledRenderingTest::testTrackChangesCallback()
+{
+    // Load a document.
+    comphelper::LibreOfficeKit::setActive();
+    SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
+    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback, this);
+
+    // Turn on track changes and type "x".
+    uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY);
+    xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true));
+    m_nRedlineTableSizeChanged = 0;
+    pWrtShell->Insert("x");
+
+    // Assert that we get exactly one notification about the redline insert.
+    // This was 0, as LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED wasn't sent.
+    CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableSizeChanged);
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index da3b773..b93a39b 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -18,6 +18,8 @@
  */
 
 #include <libxml/xmlwriter.h>
+#include <boost/property_tree/json_parser.hpp>
+
 #include <tools/datetimeutils.hxx>
 #include <hintids.hxx>
 #include <svl/itemiter.hxx>
@@ -25,6 +27,10 @@
 #include <editeng/colritem.hxx>
 #include <editeng/udlnitem.hxx>
 #include <editeng/crossedoutitem.hxx>
+#include <comphelper/lok.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <unotools/datetime.hxx>
+#include <sfx2/viewsh.hxx>
 #include <swmodule.hxx>
 #include <doc.hxx>
 #include <docredln.hxx>
@@ -47,6 +53,7 @@
 #include <rootfrm.hxx>
 
 #include <comcore.hrc>
+#include <unoport.hxx>
 
 using namespace com::sun::star;
 
@@ -291,12 +298,41 @@ bool SwExtraRedlineTable::DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox&
     return bChg;
 }
 
+/// Emits LOK notification about one addition / removal of a redline item.
+static void lcl_RedlineNotification(bool bAdd, size_t nPos, SwRangeRedline* pRedline)
+{
+    if (!comphelper::LibreOfficeKit::isActive())
+        return;
+
+    boost::property_tree::ptree aRedline;
+    aRedline.put("action", (bAdd ? "Add" : "Remove"));
+    aRedline.put("index", nPos);
+    aRedline.put("author", pRedline->GetAuthorString(1).toUtf8().getStr());
+    aRedline.put("type", SwRedlineTypeToOUString(pRedline->GetRedlineData().GetType()).toUtf8().getStr());
+    aRedline.put("comment", pRedline->GetRedlineData().GetComment().toUtf8().getStr());
+    OUString sDateTime = utl::toISO8601(pRedline->GetRedlineData().GetTimeStamp().GetUNODateTime());
+    aRedline.put("dateTime", sDateTime.toUtf8().getStr());
+    boost::property_tree::ptree aTree;
+    aTree.add_child("redline", aRedline);
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aTree);
+    std::string aPayload = aStream.str();
+
+    SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+    while (pViewShell)
+    {
+        pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED, aPayload.c_str());
+        pViewShell = SfxViewShell::GetNext(*pViewShell);
+    }
+}
+
 bool SwRedlineTable::Insert( SwRangeRedline* p )
 {
     if( p->HasValidRange() )
     {
         std::pair<vector_type::const_iterator, bool> rv = maVector.insert( p );
         size_t nP = rv.first - begin();
+        lcl_RedlineNotification(/*bAdd=*/true, nP, p);
         p->CallDisplayFunc(nP);
         return rv.second;
     }
@@ -456,6 +492,7 @@ bool SwRedlineTable::Remove( const SwRangeRedline* p )
 
 void SwRedlineTable::Remove( sal_uInt16 nP )
 {
+    lcl_RedlineNotification(/*bAdd=*/false, nP, maVector[nP]);
     SwDoc* pDoc = nullptr;
     if( !nP && 1 == size() )
         pDoc = maVector.front()->GetDoc();
@@ -479,8 +516,13 @@ void SwRedlineTable::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )
     if( !nP && nL && nL == size() )
         pDoc = maVector.front()->GetDoc();
 
+    size_t nCount = 0;
     for( vector_type::const_iterator it = maVector.begin() + nP; it != maVector.begin() + nP + nL; ++it )
+    {
+        lcl_RedlineNotification(/*bAdd=*/false, nP + nCount, *it);
         delete *it;
+        ++nCount;
+    }
     maVector.erase( maVector.begin() + nP, maVector.begin() + nP + nL );
 
     SwViewShell* pSh;
diff --git a/sw/source/core/inc/unoport.hxx b/sw/source/core/inc/unoport.hxx
index d229d85..32b5e8e 100644
--- a/sw/source/core/inc/unoport.hxx
+++ b/sw/source/core/inc/unoport.hxx
@@ -42,6 +42,7 @@
 #include <unocrsr.hxx>
 #include <calbck.hxx>
 #include <unobaseclass.hxx>
+#include <IDocumentRedlineAccess.hxx>
 
 class SwFormatField;
 class SwFrameFormat;
@@ -309,6 +310,8 @@ public:
                 css::uno::RuntimeException, std::exception) override;
 };
 
+OUString SwRedlineTypeToOUString(RedlineType_t eType);
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unoredline.cxx b/sw/source/core/unocore/unoredline.cxx
index 20b9f4c..dc99aaf 100644
--- a/sw/source/core/unocore/unoredline.cxx
+++ b/sw/source/core/unocore/unoredline.cxx
@@ -189,7 +189,7 @@ SwXRedlinePortion::~SwXRedlinePortion()
 {
 }
 
-static OUString lcl_RedlineTypeToOUString(RedlineType_t eType)
+OUString SwRedlineTypeToOUString(RedlineType_t eType)
 {
     OUString sRet;
     switch(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)
@@ -221,7 +221,7 @@ static uno::Sequence<beans::PropertyValue> lcl_GetSuccessorProperties(const SwRa
         pValues[2].Name = UNO_NAME_REDLINE_COMMENT;
         pValues[2].Value <<= pNext->GetComment();
         pValues[3].Name = UNO_NAME_REDLINE_TYPE;
-        pValues[3].Value <<= lcl_RedlineTypeToOUString(pNext->GetType());
+        pValues[3].Value <<= SwRedlineTypeToOUString(pNext->GetType());
     }
     return aValues;
 }
@@ -289,7 +289,7 @@ uno::Any  SwXRedlinePortion::GetPropertyValue( const OUString& rPropertyName, co
         aRet <<= rRedline.GetComment();
     else if(rPropertyName == UNO_NAME_REDLINE_TYPE)
     {
-        aRet <<= lcl_RedlineTypeToOUString(rRedline.GetType());
+        aRet <<= SwRedlineTypeToOUString(rRedline.GetType());
     }
     else if(rPropertyName == UNO_NAME_REDLINE_SUCCESSOR_DATA)
     {
@@ -327,7 +327,7 @@ uno::Sequence< beans::PropertyValue > SwXRedlinePortion::CreateRedlineProperties
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_COMMENT;
     pRet[nPropIdx++].Value <<= rRedline.GetComment();
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_TYPE;
-    pRet[nPropIdx++].Value <<= lcl_RedlineTypeToOUString(rRedline.GetType());
+    pRet[nPropIdx++].Value <<= SwRedlineTypeToOUString(rRedline.GetType());
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_IDENTIFIER;
     pRet[nPropIdx++].Value <<= OUString::number(
         sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(&rRedline) ) );


More information about the Libreoffice-commits mailing list