From 69fb6a307172e244497bc618a102afccdd7c93b7 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 17 Aug 2016 12:17:19 +0200 Subject: lok::Document::getCommandValues: expose redline info Index is added as a property for each item, so that later changes can be identified by the index when they are accepted/rejected. Change-Id: I9362d208fdbed1f46d64558d44498d2b19150c81 --- desktop/qa/desktop_lib/test_desktop_lib.cxx | 25 ++++++++++++++ desktop/source/lib/init.cxx | 53 +++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) (limited to 'desktop') diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 017439160ef7..a1e7cc04df93 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -92,6 +92,7 @@ public: void testContextMenuWriter(); void testContextMenuImpress(); void testNotificationCompression(); + void testRedlineWriter(); CPPUNIT_TEST_SUITE(DesktopLOKTest); CPPUNIT_TEST(testGetStyles); @@ -119,6 +120,7 @@ public: CPPUNIT_TEST(testContextMenuWriter); CPPUNIT_TEST(testContextMenuImpress); CPPUNIT_TEST(testNotificationCompression); + CPPUNIT_TEST(testRedlineWriter); CPPUNIT_TEST_SUITE_END(); uno::Reference mxComponent; @@ -1380,6 +1382,29 @@ void DesktopLOKTest::testNotificationCompression() CPPUNIT_ASSERT_EQUAL(std::string("1"), std::get<1>(notifs[i++])); } +void DesktopLOKTest::testRedlineWriter() +{ + // Load a Writer document, enable change recording and press a key. + comphelper::LibreOfficeKit::setActive(); + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + uno::Reference 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); + + // 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(1), aTree.get_child("redlines").size()); + + 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 0d4fb4f42f4a..17955e850197 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -80,6 +81,7 @@ #include #include #include +#include #include @@ -1810,8 +1812,55 @@ static char* getUndoOrRedo(LibreOfficeKitDocument* pThis, UndoOrRedo eCommand) return pJson; } +/// Returns the JSON representation of the redline stack. +static char* getTrackedChanges(LibreOfficeKitDocument* pThis) +{ + LibLODocument_Impl* pDocument = static_cast(pThis); + + uno::Reference xRedlinesSupplier(pDocument->mxComponent, uno::UNO_QUERY); + if (!xRedlinesSupplier.is()) + return nullptr; + + uno::Reference xRedlines = xRedlinesSupplier->getRedlines()->createEnumeration(); + boost::property_tree::ptree aRedlines; + for (size_t nIndex = 0; xRedlines->hasMoreElements(); ++nIndex) + { + uno::Reference 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 sType; + xRedline->getPropertyValue("RedlineType") >>= sType; + aRedline.put("type", sType.toUtf8().getStr()); + + OUString sComment; + xRedline->getPropertyValue("RedlineComment") >>= sComment; + aRedline.put("comment", sComment.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)); + } + + 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; +} + static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand) { + SolarMutexGuard aGuard; + OString aCommand(pCommand); static const OString aViewRowColumnHeaders(".uno:ViewRowColumnHeaders"); static const OString aCellCursor(".uno:CellCursor"); @@ -1832,6 +1881,10 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo { return getUndoOrRedo(pThis, UndoOrRedo::REDO); } + else if (aCommand == ".uno:AcceptTrackedChanges") + { + return getTrackedChanges(pThis); + } else if (aCommand.startsWith(aViewRowColumnHeaders)) { ITiledRenderable* pDoc = getTiledRenderable(pThis); -- cgit