diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-08-30 15:34:11 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-08-30 15:00:40 +0000 |
commit | 3ab2b0625bb8ab8447a508d654d6e8c95d50dbd5 (patch) | |
tree | d3780ed2527c3a244963f08f03d8c2332162ce90 /desktop | |
parent | a037f6338c19e16bcbc0674214666a786872c59d (diff) |
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@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 31 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 72 |
2 files changed, 73 insertions, 30 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index d3888ff94021..aa8286e7e437 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(testGetStyles); @@ -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; @@ -1441,6 +1443,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 1de564f88ad5..6ab1cf3bb6b4 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1820,45 +1820,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; } |