desktop/qa/data/BlankDrawDocument.odg |binary desktop/qa/desktop_lib/test_desktop_lib.cxx | 68 +++++++++++++++++++++++++++ desktop/source/lib/init.cxx | 52 ++++++++++++++++++++ sd/qa/unit/tiledrendering/data/dummy.odg |binary sd/qa/unit/tiledrendering/tiledrendering.cxx | 56 +++++++++++++++++++++- 5 files changed, 172 insertions(+), 4 deletions(-)
New commits: commit 68e5ff123e7bca884fcf23cf9f69422eb41fa0f7 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sun Jul 26 21:58:33 2020 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Aug 10 23:08:14 2020 +0200 allow to .uno:Save a PDF doc - divert to SaveAs to the doc. file To save PDF annotations, we need to allow a .uno:Save if the document was opened from a PDF file. When we get a .uno:Save command, we need to divert that to SaveAs into the same file as the current document was opened with. Change-Id: I0c511c4e5501de03ea8b0efb5aaf37cd09936e6e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99463 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 6f55a64f002d80a19201e2a9b0171725fb71a7fb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99883 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 906d3c4c6baa..fdd92d2d3430 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -105,6 +105,8 @@ #include <editeng/flstitem.hxx> #include <sfx2/app.hxx> #include <sfx2/objsh.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> #include <sfx2/viewsh.hxx> #include <sfx2/viewfrm.hxx> #include <sfx2/msgpool.hxx> @@ -721,6 +723,28 @@ std::string extractPrivateKey(const std::string & privateKey) return privateKey.substr(pos1, pos2); } +OUString lcl_getCurrentDocumentMimeType(LibLODocument_Impl* pDocument) +{ + OUString aMimeType; + SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(pDocument->mxComponent.get()); + if (!pBaseModel) + return aMimeType; + + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + if (!pObjectShell) + return aMimeType; + + SfxMedium* pMedium = pObjectShell->GetMedium(); + if (!pMedium) + return aMimeType; + + auto pFilter = pMedium->GetFilter(); + if (!pFilter) + return aMimeType; + + return pFilter->GetMimeType(); +} + // Gets an undo manager to enter and exit undo context. Needed by ToggleOrientation css::uno::Reference< css::document::XUndoManager > getUndoManager( const css::uno::Reference< css::frame::XFrame >& rxFrame ) { @@ -2463,6 +2487,9 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha OUString sFormat = getUString(pFormat); OUString aURL(getAbsoluteURL(sUrl)); + + uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW); + if (aURL.isEmpty()) { SetLastExceptionMsg("Filename to save to was not provided."); @@ -2603,7 +2630,6 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha aSaveMediaDescriptor[MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteraction; } - uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW); if (bTakeOwnership) xStorable->storeAsURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList()); @@ -3785,6 +3811,30 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma // handle potential interaction if (gImpl && aCommand == ".uno:Save") { + // Check if saving a PDF file + OUString aMimeType = lcl_getCurrentDocumentMimeType(pDocument); + if (aMimeType == "application/pdf") + { + // If we have a PDF file (for saving annotations for example), we need + // to run save-as to the same file as the opened document. Plain save + // doesn't work as the PDF is not a "native" format. + uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW); + OUString aURL = xStorable->getLocation(); + OString aURLUtf8 = OUStringToOString(aURL, RTL_TEXTENCODING_UTF8); + bool bResult = doc_saveAs(pThis, aURLUtf8.getStr(), "pdf", nullptr); + + // Send the result of save + boost::property_tree::ptree aTree; + aTree.put("commandName", pCommand); + aTree.put("success", bResult); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + OString aPayload = aStream.str().c_str(); + pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aPayload.getStr()); + return; + } + + rtl::Reference<LOKInteractionHandler> const pInteraction( new LOKInteractionHandler("save", gImpl, pDocument)); uno::Reference<task::XInteractionHandler2> const xInteraction(pInteraction.get()); commit b4d0b45ba6bce22501fbd623ac2ebf5da29ee356 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Jul 11 21:18:34 2020 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Aug 10 23:07:59 2020 +0200 add test for editing of annotations (using .uno:EditAnnotation) Change-Id: Ic798ab94bb63a3ae80882e77cf1582d875e27d4b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98583 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit fbecbb6872db7c40c8d632955589223a6c456475) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99882 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/desktop/qa/data/BlankDrawDocument.odg b/desktop/qa/data/BlankDrawDocument.odg new file mode 100644 index 000000000000..19ae49d63b36 Binary files /dev/null and b/desktop/qa/data/BlankDrawDocument.odg differ diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 864041b71d49..7acb50499ae9 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -55,6 +55,7 @@ #include <ostream> #include <config_features.h> #include <config_mpl.h> +#include <tools/json_writer.hxx> #include <lib/init.hxx> #include <svx/svxids.hrc> @@ -206,6 +207,7 @@ public: void testCommentsCalc(); void testCommentsImpress(); void testCommentsCallbacksWriter(); + void testCommentsAddEditDeleteDraw(); void testRunMacro(); void testExtractParameter(); void testGetSignatureState_NonSigned(); @@ -265,6 +267,7 @@ public: CPPUNIT_TEST(testCommentsCalc); CPPUNIT_TEST(testCommentsImpress); CPPUNIT_TEST(testCommentsCallbacksWriter); + CPPUNIT_TEST(testCommentsAddEditDeleteDraw); CPPUNIT_TEST(testRunMacro); CPPUNIT_TEST(testExtractParameter); CPPUNIT_TEST(testGetSignatureState_Signed); @@ -2346,6 +2349,71 @@ void DesktopLOKTest::testCommentsCallbacksWriter() CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), aTree.get_child("comments").size()); } +namespace +{ + +void addParameter(tools::JsonWriter& rJson, const char* sName, OString const & type, OString const & value) +{ + auto testNode = rJson.startNode(sName); + rJson.put("type", type); + rJson.put("value", value); +} + +} + +void DesktopLOKTest::testCommentsAddEditDeleteDraw() +{ + // Comments callback are emitted only if tiled annotations are off + comphelper::LibreOfficeKit::setTiledAnnotations(false); + LibLODocument_Impl* pDocument = loadDoc("BlankDrawDocument.odg"); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + ViewCallback aView1(pDocument); + + // Add a new comment + OString aCommandArgs; + { + tools::JsonWriter aJson; + addParameter(aJson, "Text", "string", "Comment"); + addParameter(aJson, "Author", "string", "LOK User1"); + aCommandArgs = aJson.extractAsOString(); + } + + pDocument->pClass->postUnoCommand(pDocument, ".uno:InsertAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action + CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView1.m_aCommentCallbackResult.get<std::string>("action")); + int nCommentId1 = aView1.m_aCommentCallbackResult.get<int>("id"); + + // Edit the previously added comment + { + tools::JsonWriter aJson; + addParameter(aJson, "Id", "string", OString::number(nCommentId1)); + addParameter(aJson, "Text", "string", "Edited comment"); + aCommandArgs = aJson.extractAsOString(); + } + + pDocument->pClass->postUnoCommand(pDocument, ".uno:EditAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Modify' action + CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get<std::string>("action")); + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get<int>("id")); + + // Delete Comment + { + tools::JsonWriter aJson; + addParameter(aJson, "Id", "string", OString::number(nCommentId1)); + aCommandArgs = aJson.extractAsOString(); + } + pDocument->pClass->postUnoCommand(pDocument, ".uno:DeleteAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Remove' action + CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView1.m_aCommentCallbackResult.get<std::string>("action")); + CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get<int>("id")); +} + void DesktopLOKTest::testRunMacro() { LibLibreOffice_Impl aOffice; diff --git a/sd/qa/unit/tiledrendering/data/dummy.odg b/sd/qa/unit/tiledrendering/data/dummy.odg new file mode 100644 index 000000000000..19ae49d63b36 Binary files /dev/null and b/sd/qa/unit/tiledrendering/data/dummy.odg differ diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index b6090961ebb7..d7c2719e105a 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -110,7 +110,8 @@ public: void testTdf81754(); void testTdf105502(); void testCommentCallbacks(); - void testCommentChange(); + void testCommentChangeImpress(); + void testCommentChangeDraw(); void testMultiViewInsertDeletePage(); void testDisableUndoRepair(); void testDocumentRepair(); @@ -160,7 +161,8 @@ public: CPPUNIT_TEST(testTdf81754); CPPUNIT_TEST(testTdf105502); CPPUNIT_TEST(testCommentCallbacks); - CPPUNIT_TEST(testCommentChange); + CPPUNIT_TEST(testCommentChangeImpress); + CPPUNIT_TEST(testCommentChangeDraw); CPPUNIT_TEST(testMultiViewInsertDeletePage); CPPUNIT_TEST(testDisableUndoRepair); CPPUNIT_TEST(testDocumentRepair); @@ -1781,7 +1783,7 @@ void SdTiledRenderingTest::testCommentCallbacks() comphelper::LibreOfficeKit::setTiledAnnotations(true); } -void SdTiledRenderingTest::testCommentChange() +void SdTiledRenderingTest::testCommentChangeImpress() { uno::Sequence<beans::PropertyValue> aArgs; @@ -1829,6 +1831,54 @@ void SdTiledRenderingTest::testCommentChange() comphelper::LibreOfficeKit::setTiledAnnotations(true); } +void SdTiledRenderingTest::testCommentChangeDraw() +{ + uno::Sequence<beans::PropertyValue> aArgs; + + // Load the document. + // Set the tiled annotations off + comphelper::LibreOfficeKit::setTiledAnnotations(false); + + createDoc("dummy.odg", comphelper::InitPropertySequence( + { + {".uno:Author", uno::makeAny(OUString("LOK User1"))}, + })); + + ViewCallback aView1; + + // Add a new comment + aArgs = comphelper::InitPropertySequence( + { + {"Text", uno::makeAny(OUString("Comment"))}, + }); + comphelper::dispatchCommand(".uno:InsertAnnotation", aArgs); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView1.m_aCommentCallbackResult.get<std::string>("action")); + + int nComment1 = aView1.m_aCommentCallbackResult.get<int>("id"); + + CPPUNIT_ASSERT(!aView1.m_aCommentCallbackResult.get<std::string>("parthash").empty()); + CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); + CPPUNIT_ASSERT_EQUAL(std::string("0, 0, 0, 0"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle")); + + // Edit this annotation now + aArgs = comphelper::InitPropertySequence( + { + {"Id", uno::makeAny(OUString::number(nComment1))}, + {"PositionX", uno::makeAny(sal_Int32(10))}, + {"PositionY", uno::makeAny(sal_Int32(20))} + }); + comphelper::dispatchCommand(".uno:EditAnnotation", aArgs); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get<std::string>("action")); + CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); + CPPUNIT_ASSERT_EQUAL(std::string("10, 20, 0, 0"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle")); + + comphelper::LibreOfficeKit::setTiledAnnotations(true); +} + void SdTiledRenderingTest::testMultiViewInsertDeletePage() { // Load the document. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits