desktop/qa/desktop_lib/test_desktop_lib.cxx | 42 +++++++++++++++++++++++++-- desktop/source/lib/init.cxx | 43 ++++++++++++++++++++++++++-- include/LibreOfficeKit/LibreOfficeKit.hxx | 5 +++ 3 files changed, 85 insertions(+), 5 deletions(-)
New commits: commit cfa9404319ac5310dc772b3b4a9a3d05721e6940 Author: Jan Holesovsky <[email protected]> Date: Thu Feb 11 14:34:07 2016 +0100 lok: Extend the StatusModified unit test with Save As. Change-Id: Ie9bbce6892fe1dcf55e23028e68037f996d7c71f diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 705fa24..1d6c562 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -644,10 +644,10 @@ void DesktopLOKTest::testModifiedStatus() pDocument->pClass->initializeForRendering(pDocument, nullptr); pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); - // Set the document as modified. + // Type "t" and check that the document was set as modified + m_bModified = false; m_aStateChangedCondition.reset(); - uno::Reference<util::XModifiable> xModifiable(mxComponent, uno::UNO_QUERY); - xModifiable->setModified(true); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0); TimeValue aTimeValue = { 2 , 0 }; // 2 seconds max m_aStateChangedCondition.wait(aTimeValue); Scheduler::ProcessEventsToIdle(); @@ -655,6 +655,42 @@ void DesktopLOKTest::testModifiedStatus() // This was false, there was no callback about the modified status change. CPPUNIT_ASSERT(m_bModified); + // Perform SaveAs with "TakeOwnership" option set, and check that the + // modification state was reset + m_aStateChangedCondition.reset(); + utl::TempFile aTempFile; + //aTempFile.EnableKillingFile(); + CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "odt", "TakeOwnership")); + m_aStateChangedCondition.wait(aTimeValue); + Scheduler::ProcessEventsToIdle(); + + // There was no callback about the modified status change. + CPPUNIT_ASSERT(!m_bModified); + + // Modify the document again + m_bModified = false; + m_aStateChangedCondition.reset(); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 't', 0); + m_aStateChangedCondition.wait(aTimeValue); + Scheduler::ProcessEventsToIdle(); + + // There was no callback about the modified status change. + CPPUNIT_ASSERT(m_bModified); + + /* + // TODO: move this to a test where LOK is fully bootstrapped, so that we can + // get back the notification about ".uno:Save" too + // Now perform a normal "Save", and check the modified state was reset + // again + m_aStateChangedCondition.reset(); + pDocument->pClass->postUnoCommand(pDocument, ".uno:Save", nullptr, false); + m_aStateChangedCondition.wait(aTimeValue); + Scheduler::ProcessEventsToIdle(); + + // There was no callback about the modified status change. + CPPUNIT_ASSERT(!m_bModified); + */ + comphelper::LibreOfficeKit::setActive(false); } commit 645ec0a7498932d4f1767353a89576cdf33f9c23 Author: Jan Holesovsky <[email protected]> Date: Thu Feb 11 10:35:37 2016 +0100 lok: Only add interaction handler when LOK fully initialized. Necessary for unit testing. Change-Id: I8db8b4c469864a915a00f8d8c4932634d74f11a7 diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index c6e288e..e236595 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1128,7 +1128,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma std::vector<beans::PropertyValue> aPropertyValuesVector(jsonToPropertyValuesVector(pArguments)); // handle potential interaction - if (aCommand == ".uno:Save") + if (gImpl && aCommand == ".uno:Save") { rtl::Reference<LOKInteractionHandler> const pInteraction( new LOKInteractionHandler(::comphelper::getProcessComponentContext(), "save", gImpl, pDocument)); commit a121074cbd07939713e169586469b934aedbe594 Author: Jan Holesovsky <[email protected]> Date: Wed Feb 10 13:26:50 2016 +0100 lok: Introduce a "TakeOwnership" filter option for saveAs(). It is consumed by the saveAs() itself, and when provided, the document identity changes to the provided pUrl - meaning that '.uno:ModifiedStatus' is triggered as with the "Save As..." in the UI. This mode must not be used when saving to PNG or PDF. Change-Id: I11b5aa814476a8dcab9eac5202bd052828ebbd96 diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 4e75258..c6e288e 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -658,6 +658,30 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha OUString aFilterOptions = getUString(pFilterOptions); + // 'TakeOwnership' == this is a 'real' SaveAs (that is, the document + // gets a new name). When this is not provided, the meaning of + // saveAs() is more like save-a-copy, which allows saving to any + // random format like PDF or PNG. + // It is not a real filter option, so we have to filter it out. + bool bTakeOwnership = false; + int nIndex = -1; + if (aFilterOptions == "TakeOwnership") + { + bTakeOwnership = true; + aFilterOptions = ""; + } + else if ((nIndex = aFilterOptions.indexOf(",TakeOwnership")) >= 0 || (nIndex = aFilterOptions.indexOf("TakeOwnership,")) >= 0) + { + OUString aFiltered; + if (nIndex > 0) + aFiltered = aFilterOptions.copy(0, nIndex); + if (nIndex + 14 < aFilterOptions.getLength()) + aFiltered = aFiltered + aFilterOptions.copy(nIndex + 14); + + bTakeOwnership = true; + aFilterOptions = aFiltered; + } + MediaDescriptor aSaveMediaDescriptor; aSaveMediaDescriptor["Overwrite"] <<= sal_True; aSaveMediaDescriptor["FilterName"] <<= aFilterName; @@ -675,7 +699,11 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha } uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW); - xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList()); + + if (bTakeOwnership) + xStorable->storeAsURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList()); + else + xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList()); return true; } diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 7837904..9e18df0 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -48,6 +48,11 @@ public: * @param pUrl the location where to store the document * @param pFormat the format to use while exporting, when omitted, then deducted from pURL's extension * @param pFilterOptions options for the export filter, e.g. SkipImages. + * Another useful FilterOption is "TakeOwnership". It is consumed + * by the saveAs() itself, and when provided, the document identity + * changes to the provided pUrl - meaning that '.uno:ModifiedStatus' + * is triggered as with the "Save As..." in the UI. + * "TakeOwnership" mode must not be used when saving to PNG or PDF. */ inline bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL) { commit d11bf83b3f28fccdaac4c90dfb283b47f3617a7d Author: Jan Holesovsky <[email protected]> Date: Mon Feb 8 20:09:37 2016 +0100 lok: Interaction handler for saveAs() too. The LOK does not have to be fully initialized, eg. during the unit tests, don't use the interaction handler in such a case. Change-Id: I11bb8db37c92b05e2c1ad06e1a6632db7fb0ea60 diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index eaac992..4e75258 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -663,6 +663,17 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha aSaveMediaDescriptor["FilterName"] <<= aFilterName; aSaveMediaDescriptor[MediaDescriptor::PROP_FILTEROPTIONS()] <<= aFilterOptions; + // add interaction handler too + if (gImpl) + { + // gImpl does not have to exist when running from a unit test + rtl::Reference<LOKInteractionHandler> const pInteraction( + new LOKInteractionHandler(::comphelper::getProcessComponentContext(), "saveas", gImpl, pDocument)); + uno::Reference<task::XInteractionHandler2> const xInteraction(pInteraction.get()); + + aSaveMediaDescriptor[MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteraction; + } + uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW); xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList()); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
