[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - 2 commits - desktop/qa desktop/source include/vcl libreofficekit/qa sc/inc sc/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Aug 31 07:49:16 UTC 2016


 desktop/qa/desktop_lib/test_desktop_lib.cxx         |   31 ++++++++
 desktop/source/lib/init.cxx                         |   72 +++++++++++---------
 include/vcl/ITiledRenderable.hxx                    |    8 ++
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |    3 
 sc/inc/chgtrack.hxx                                 |    2 
 sc/inc/docuno.hxx                                   |    3 
 sc/source/core/tool/chgtrack.cxx                    |   52 ++++++++++++++
 sc/source/ui/unoobj/docuno.cxx                      |   14 +++
 8 files changed, 155 insertions(+), 30 deletions(-)

New commits:
commit 312d3add7970144d2312f0c5968a2b73f6064da2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Aug 30 15:34:11 2016 +0200

    sc lok: implement getCommandValues(.uno:AcceptTrackedChanges) API
    
    Unlike in Writer, there doesn't seem to be an existing UNO API that can
    be reused here.
    
    Change-Id: I011a2f34d4d09ad604991637322ceadf6b2eb181
    Reviewed-on: https://gerrit.libreoffice.org/28498
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 3ab2b0625bb8ab8447a508d654d6e8c95d50dbd5)

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index d715329..5485da3 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -98,6 +98,7 @@ public:
     void testNotificationCompression();
     void testRedlineWriter();
     void testTrackChanges();
+    void testRedlineCalc();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testModifiedStatus);
@@ -127,6 +128,7 @@ public:
     CPPUNIT_TEST(testNotificationCompression);
     CPPUNIT_TEST(testRedlineWriter);
     CPPUNIT_TEST(testTrackChanges);
+    CPPUNIT_TEST(testRedlineCalc);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -1210,6 +1212,35 @@ void DesktopLOKTest::testRedlineWriter()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void DesktopLOKTest::testRedlineCalc()
+{
+    // Load a Writer document, enable change recording and press a key.
+    comphelper::LibreOfficeKit::setActive();
+    LibLODocument_Impl* pDocument = loadDoc("sheets.ods");
+    uno::Reference<beans::XPropertySet> xPropertySet(mxComponent, uno::UNO_QUERY);
+    xPropertySet->setPropertyValue("RecordChanges", uno::makeAny(true));
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 't', 0);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
+    pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 0, KEY_RETURN);
+
+    // Get redline info.
+    boost::property_tree::ptree aTree;
+    char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:AcceptTrackedChanges");
+    std::stringstream aStream(pJSON);
+    free(pJSON);
+    CPPUNIT_ASSERT(!aStream.str().empty());
+    boost::property_tree::read_json(aStream, aTree);
+    // Make sure that pressing a key creates exactly one redline.
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aTree.get_child("redlines").size());
+
+    for (boost::property_tree::ptree::value_type& rRedline : aTree.get_child("redlines"))
+        // This failed with boost::property_tree::ptree_bad_path, as there were no description field.
+        CPPUNIT_ASSERT_EQUAL(std::string("Cell B4 changed from '5' to 't'"), rRedline.second.get<std::string>("description"));
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b18e4d6..616521d 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1835,45 +1835,57 @@ static char* getTrackedChanges(LibreOfficeKitDocument* pThis)
     LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
 
     uno::Reference<document::XRedlinesSupplier> xRedlinesSupplier(pDocument->mxComponent, uno::UNO_QUERY);
-    if (!xRedlinesSupplier.is())
-        return nullptr;
-
-    uno::Reference<container::XEnumeration> xRedlines = xRedlinesSupplier->getRedlines()->createEnumeration();
-    boost::property_tree::ptree aRedlines;
-    for (size_t nIndex = 0; xRedlines->hasMoreElements(); ++nIndex)
+    std::stringstream aStream;
+    if (xRedlinesSupplier.is())
     {
-        uno::Reference<beans::XPropertySet> xRedline(xRedlines->nextElement(), uno::UNO_QUERY);
-        boost::property_tree::ptree aRedline;
-        aRedline.put("index", nIndex);
+        uno::Reference<container::XEnumeration> xRedlines = xRedlinesSupplier->getRedlines()->createEnumeration();
+        boost::property_tree::ptree aRedlines;
+        for (size_t nIndex = 0; xRedlines->hasMoreElements(); ++nIndex)
+        {
+            uno::Reference<beans::XPropertySet> xRedline(xRedlines->nextElement(), uno::UNO_QUERY);
+            boost::property_tree::ptree aRedline;
+            aRedline.put("index", nIndex);
+
+            OUString sAuthor;
+            xRedline->getPropertyValue("RedlineAuthor") >>= sAuthor;
+            aRedline.put("author", sAuthor.toUtf8().getStr());
 
-        OUString sAuthor;
-        xRedline->getPropertyValue("RedlineAuthor") >>= sAuthor;
-        aRedline.put("author", sAuthor.toUtf8().getStr());
+            OUString sType;
+            xRedline->getPropertyValue("RedlineType") >>= sType;
+            aRedline.put("type", sType.toUtf8().getStr());
 
-        OUString sType;
-        xRedline->getPropertyValue("RedlineType") >>= sType;
-        aRedline.put("type", sType.toUtf8().getStr());
+            OUString sComment;
+            xRedline->getPropertyValue("RedlineComment") >>= sComment;
+            aRedline.put("comment", sComment.toUtf8().getStr());
 
-        OUString sComment;
-        xRedline->getPropertyValue("RedlineComment") >>= sComment;
-        aRedline.put("comment", sComment.toUtf8().getStr());
+            OUString sDescription;
+            xRedline->getPropertyValue("RedlineDescription") >>= sDescription;
+            aRedline.put("description", sDescription.toUtf8().getStr());
 
-        OUString sDescription;
-        xRedline->getPropertyValue("RedlineDescription") >>= sDescription;
-        aRedline.put("description", sDescription.toUtf8().getStr());
+            util::DateTime aDateTime;
+            xRedline->getPropertyValue("RedlineDateTime") >>= aDateTime;
+            OUString sDateTime = utl::toISO8601(aDateTime);
+            aRedline.put("dateTime", sDateTime.toUtf8().getStr());
 
-        util::DateTime aDateTime;
-        xRedline->getPropertyValue("RedlineDateTime") >>= aDateTime;
-        OUString sDateTime = utl::toISO8601(aDateTime);
-        aRedline.put("dateTime", sDateTime.toUtf8().getStr());
+            aRedlines.push_back(std::make_pair("", aRedline));
+        }
 
-        aRedlines.push_back(std::make_pair("", aRedline));
+        boost::property_tree::ptree aTree;
+        aTree.add_child("redlines", aRedlines);
+        boost::property_tree::write_json(aStream, aTree);
+    }
+    else
+    {
+        ITiledRenderable* pDoc = getTiledRenderable(pThis);
+        if (!pDoc)
+        {
+            gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+            return nullptr;
+        }
+        OUString aTrackedChanges = pDoc->getTrackedChanges();
+        aStream << aTrackedChanges.toUtf8();
     }
 
-    boost::property_tree::ptree aTree;
-    aTree.add_child("redlines", aRedlines);
-    std::stringstream aStream;
-    boost::property_tree::write_json(aStream, aTree);
     char* pJson = strdup(aStream.str().c_str());
     return pJson;
 }
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 0c90ed3..3a8a697 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -199,6 +199,14 @@ public:
     virtual void setClientVisibleArea(const Rectangle& /*rRectangle*/)
     {
     }
+
+    /// Implementation for
+    /// lok::Document::getCommandValues(".uno:AcceptTrackedChanges") when there
+    /// is no matching UNO API.
+    virtual OUString getTrackedChanges()
+    {
+        return OUString();
+    }
 };
 
 } // namespace vcl
diff --git a/sc/inc/chgtrack.hxx b/sc/inc/chgtrack.hxx
index 2cdc14b..ca71ca5 100644
--- a/sc/inc/chgtrack.hxx
+++ b/sc/inc/chgtrack.hxx
@@ -1199,6 +1199,8 @@ public:
     void AppendCloned( ScChangeAction* pAppend );
     SC_DLLPUBLIC ScChangeTrack* Clone( ScDocument* pDocument ) const;
     static void MergeActionState( ScChangeAction* pAct, const ScChangeAction* pOtherAct );
+    /// Get info about all ScChangeAction elements.
+    OUString GetChangeTrackInfo();
 };
 
 #endif
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index 617d553..81b0924 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -419,6 +419,9 @@ public:
 
     /// @see vcl::ITiledRenderable::getPointer().
     virtual Pointer getPointer() override;
+
+    /// @see vcl::ITiledRenderable::getTrackedChanges().
+    OUString getTrackedChanges() override;
 };
 
 class ScDrawPagesObj : public cppu::WeakImplHelper<
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index 076a34c..1c0b447 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -41,8 +41,10 @@
 #include <svl/itempool.hxx>
 #include <sfx2/app.hxx>
 #include <unotools/useroptions.hxx>
+#include <unotools/datetime.hxx>
 #include <sfx2/sfxsids.hrc>
 #include <memory>
+#include <boost/property_tree/json_parser.hpp>
 
 IMPL_FIXEDMEMPOOL_NEWDEL( ScChangeActionCellListEntry )
 IMPL_FIXEDMEMPOOL_NEWDEL( ScChangeActionLinkEntry )
@@ -4712,4 +4714,54 @@ void ScChangeTrack::MergeActionState( ScChangeAction* pAct, const ScChangeAction
     }
 }
 
+/// Get info about a single ScChangeAction element.
+static void lcl_getTrackedChange(ScDocument* pDoc, int nIndex, ScChangeAction* pAction, boost::property_tree::ptree& rRedlines)
+{
+    if (pAction->GetType() == SC_CAT_CONTENT)
+    {
+        boost::property_tree::ptree aRedline;
+        aRedline.put("index", nIndex);
+
+        const OUString& sAuthor = pAction->GetUser();
+        aRedline.put("author", sAuthor.toUtf8().getStr());
+
+        aRedline.put("type", "Modify");
+
+        aRedline.put("comment", pAction->GetComment().toUtf8().getStr());
+
+        OUString aDescription;
+        pAction->GetDescription(aDescription, pDoc, true);
+        aRedline.put("description", aDescription);
+
+        OUString sDateTime = utl::toISO8601(pAction->GetDateTimeUTC().GetUNODateTime());
+        aRedline.put("dateTime", sDateTime.toUtf8().getStr());
+
+        rRedlines.push_back(std::make_pair("", aRedline));
+    }
+}
+
+OUString ScChangeTrack::GetChangeTrackInfo()
+{
+    boost::property_tree::ptree aRedlines;
+
+    ScChangeAction* pAction = GetFirst();
+    if (pAction)
+    {
+        int i = 0;
+        lcl_getTrackedChange(pDoc, i++, pAction, aRedlines);
+        ScChangeAction* pLastAction = GetLast();
+        while (pAction != pLastAction)
+        {
+            pAction = pAction->GetNext();
+            lcl_getTrackedChange(pDoc, i++, pAction, aRedlines);
+        }
+    }
+
+    boost::property_tree::ptree aTree;
+    aTree.add_child("redlines", aRedlines);
+    std::stringstream aStream;
+    boost::property_tree::write_json(aStream, aTree);
+    return OUString::fromUtf8(aStream.str().c_str());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 06f2774..b75bc52 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -115,6 +115,7 @@
 #include "drawsh.hxx"
 #include "drtxtob.hxx"
 #include "transobj.hxx"
+#include "chgtrack.hxx"
 
 #include "sc.hrc"
 
@@ -946,6 +947,19 @@ Pointer ScModelObj::getPointer()
     return pGridWindow->GetPointer();
 }
 
+OUString ScModelObj::getTrackedChanges()
+{
+    OUString aRet;
+
+    if (pDocShell)
+    {
+        if (ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack())
+            aRet = pChangeTrack->GetChangeTrackInfo();
+    }
+
+    return aRet;
+}
+
 void ScModelObj::initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& /*rArguments*/)
 {
     SolarMutexGuard aGuard;
commit a60d3309627bc1f69af9faf77171031e297e91b5
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Aug 30 15:15:42 2016 +0200

    gtktiledviewer: don't crash on unimplemented tracked change list
    
    As it's currently implemented only for Writer.
    
    Change-Id: I8c281b2294564472f2c2c5b7de5dd3f86a11a94a
    (cherry picked from commit 30b84816eb5c6cd44bdee459cac1bb9f90859aec)

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 5ad2059..01290d4 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -462,6 +462,9 @@ static void documentRedline(GtkWidget* pButton, gpointer /*pItem*/)
     // Get the data.
     LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pDocView);
     char* pValues = pDocument->pClass->getCommandValues(pDocument, ".uno:AcceptTrackedChanges");
+    if (!pValues)
+        return;
+
     std::stringstream aInfo;
     aInfo << "lok::Document::getCommandValues('.uno:AcceptTrackedChanges') returned '" << pValues << "'" << std::endl;
     g_info("%s", aInfo.str().c_str());


More information about the Libreoffice-commits mailing list