[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - include/LibreOfficeKit sd/qa sd/source
Jan Holesovsky
kendy at collabora.com
Thu Mar 3 11:18:45 UTC 2016
include/LibreOfficeKit/LibreOfficeKitEnums.h | 12 --
sd/qa/unit/tiledrendering/tiledrendering.cxx | 110 ++++++++++++++++++---------
sd/source/core/drawdoc2.cxx | 16 ---
3 files changed, 76 insertions(+), 62 deletions(-)
New commits:
commit 0ba1ebdd72f0612b61f28b11c7861121e7529f31
Author: Jan Holesovsky <kendy at collabora.com>
Date: Thu Mar 3 09:00:21 2016 +0100
sd lok: Remove LOK_CALLBACK_PARTS_COUNT_CHANGED from the API.
LOK_CALLBACK_PARTS_COUNT_CHANGED did not cover more complex scenarios, like
more pages deleted at the same time, etc.
Instead, we need to trigger the LOK_CALLBACK_DOCUMENT_SIZE_CHANGED, and the
client has to be smart enough to update the previews in a way that does not
consume too much resources - ie. it has to have a link between the part names
(which are unique) and the previews, and request only the missing ones.
Change-Id: I36ff5dc86f360e3c7bd2c55fae8aaa99e054b4eb
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 7e2cc30..343d169 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -280,18 +280,6 @@ typedef enum
* }
*/
LOK_CALLBACK_ERROR,
-
- /**
- * A part has been added to or removed from the document.
- *
- * {
- * "action" : "PartInserted" | "PartDeleted"
- * "part" : "Part Index"
- * }
- *
- * Note: this is currently emitted by Impress.
- */
- LOK_CALLBACK_PARTS_COUNT_CHANGED
}
LibreOfficeKitCallbackType;
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 8d19021..7c63bf2 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -27,6 +27,7 @@
#include <editeng/editids.hrc>
#include <editeng/editview.hxx>
#include <editeng/outliner.hxx>
+#include <osl/conditn.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <svl/srchitem.hxx>
@@ -100,9 +101,11 @@ private:
sal_Int32 m_nPart;
std::vector<OString> m_aSearchResultSelection;
std::vector<int> m_aSearchResultPart;
- std::vector<unsigned> m_aPageList;
int m_nSelectionBeforeSearchResult;
int m_nSelectionAfterSearchResult;
+
+ /// For document size changed callback.
+ osl::Condition m_aDocumentSizeCondition;
#endif
};
@@ -207,6 +210,11 @@ void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
m_bFound = false;
}
break;
+ case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
+ {
+ m_aDocumentSizeCondition.set();
+ }
+ break;
case LOK_CALLBACK_SET_PART:
{
OUString aPayload = OUString::createFromAscii(pPayload);
@@ -227,19 +235,6 @@ void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
}
}
break;
- case LOK_CALLBACK_PARTS_COUNT_CHANGED:
- {
- boost::property_tree::ptree aTree;
- std::stringstream aStream(pPayload);
- boost::property_tree::read_json(aStream, aTree);
- auto aAction = aTree.get<std::string>("action", "");
- auto aPart = aTree.get<std::string>("part", "");
- if (!aAction.empty() && !aPart.empty())
- {
- m_aPageList.push_back(std::atoi(aPart.data()));
- }
- }
- break;
}
}
@@ -515,6 +510,23 @@ void SdTiledRenderingTest::testSearchAllFollowedBySearch()
CPPUNIT_ASSERT_EQUAL(OString("match"), pXImpressDocument->getTextSelection("text/plain;charset=utf-8", aUsedFormat));
}
+namespace {
+
+std::vector<OUString> getCurrentParts(SdXImpressDocument* pDocument)
+{
+ int parts = pDocument->getParts();
+ std::vector<OUString> result;
+
+ for (int i = 0; i < parts; i++)
+ {
+ result.push_back(pDocument->getPartName(i));
+ }
+
+ return result;
+}
+
+}
+
void SdTiledRenderingTest::testInsertDeletePage()
{
comphelper::LibreOfficeKit::setActive();
@@ -524,59 +536,84 @@ void SdTiledRenderingTest::testInsertDeletePage()
SdDrawDocument *pDoc = pXImpressDocument->GetDocShell()->GetDoc();
CPPUNIT_ASSERT(pDoc);
+ std::vector<OUString> aInserted = {
+ "Slide 1", "Slide 2", "Slide 3", "Slide 4", "Slide 5",
+ "Slide 6", "Slide 7", "Slide 8", "Slide 9", "Slide 10", "Slide 11"
+ };
+
+ std::vector<OUString> aDeleted = {
+ "Slide 1"
+ };
+
// the document has 1 slide
CPPUNIT_ASSERT(pDoc->GetSdPageCount(PK_STANDARD) == 1);
uno::Sequence<beans::PropertyValue> aArgs;
// Insert slides
- for(unsigned it = 1; it <= 10; it++)
+ m_aDocumentSizeCondition.reset();
+ for (unsigned it = 1; it <= 10; it++)
comphelper::dispatchCommand(".uno:InsertPage", aArgs);
+ TimeValue aTimeValue = { 2 , 0 }; // 2 seconds max
+ osl::Condition::Result aResult = m_aDocumentSizeCondition.wait(&aTimeValue);
+ CPPUNIT_ASSERT_EQUAL(aResult, osl::Condition::result_ok);
+
// Verify inserted slides
- for(auto i: m_aPageList)
+ std::vector<OUString> aPageList(getCurrentParts(pXImpressDocument));
+ CPPUNIT_ASSERT_EQUAL(aPageList.size(), aInserted.size());
+
+ for (auto it1 = aPageList.begin(), it2 = aInserted.begin(); it1 != aPageList.end(); ++it1, ++it2)
{
- SdPage* pPage = pDoc->GetSdPage(i, PK_STANDARD);
- CPPUNIT_ASSERT(pPage);
+ CPPUNIT_ASSERT_EQUAL(*it1, *it2);
}
- m_aPageList.clear();
-
// Delete slides
- for(unsigned it = 1; it <= 10; it++)
+ m_aDocumentSizeCondition.reset();
+ for (unsigned it = 1; it <= 10; it++)
comphelper::dispatchCommand(".uno:DeletePage", aArgs);
+ aResult = m_aDocumentSizeCondition.wait(&aTimeValue);
+ CPPUNIT_ASSERT_EQUAL(aResult, osl::Condition::result_ok);
+
// Verify deleted slides
- for(auto i: m_aPageList)
+ aPageList = getCurrentParts(pXImpressDocument);
+ CPPUNIT_ASSERT_EQUAL(aPageList.size(), aDeleted.size());
+ for (auto it1 = aPageList.begin(), it2 = aDeleted.begin(); it1 != aPageList.end(); ++it1, ++it2)
{
- SdPage* pPage = pDoc->GetSdPage(i, PK_STANDARD);
- CPPUNIT_ASSERT(pPage == nullptr);
+ CPPUNIT_ASSERT_EQUAL(*it1, *it2);
}
- m_aPageList.clear();
-
// Undo deleted slides
- for(unsigned it = 1; it <= 10; it++)
+ m_aDocumentSizeCondition.reset();
+ for (unsigned it = 1; it <= 10; it++)
comphelper::dispatchCommand(".uno:Undo", aArgs);
+ aResult = m_aDocumentSizeCondition.wait(&aTimeValue);
+ CPPUNIT_ASSERT_EQUAL(aResult, osl::Condition::result_ok);
+
// Verify inserted slides
- for(auto i: m_aPageList)
+ aPageList = getCurrentParts(pXImpressDocument);
+ CPPUNIT_ASSERT_EQUAL(aPageList.size(), aInserted.size());
+ for (auto it1 = aPageList.begin(), it2 = aInserted.begin(); it1 != aPageList.end(); ++it1, ++it2)
{
- SdPage* pPage = pDoc->GetSdPage(i, PK_STANDARD);
- CPPUNIT_ASSERT(pPage);
+ CPPUNIT_ASSERT_EQUAL(*it1, *it2);
}
- m_aPageList.clear();
-
// Redo deleted slides
- for(unsigned it = 1; it <= 10; it++)
+ m_aDocumentSizeCondition.reset();
+ for (unsigned it = 1; it <= 10; it++)
comphelper::dispatchCommand(".uno:Redo", aArgs);
+ aResult = m_aDocumentSizeCondition.wait(&aTimeValue);
+ CPPUNIT_ASSERT_EQUAL(aResult, osl::Condition::result_ok);
+
// Verify deleted slides
- for(auto i: m_aPageList)
+ aPageList = getCurrentParts(pXImpressDocument);
+ CPPUNIT_ASSERT_EQUAL(aPageList.size(), aDeleted.size());
+ for (auto it1 = aPageList.begin(), it2 = aDeleted.begin(); it1 != aPageList.end(); ++it1, ++it2)
{
- SdPage* pPage = pDoc->GetSdPage(i, PK_STANDARD);
- CPPUNIT_ASSERT(pPage == nullptr);
+ CPPUNIT_ASSERT_EQUAL(*it1, *it2);
}
// the document has 1 slide
@@ -584,6 +621,7 @@ void SdTiledRenderingTest::testInsertDeletePage()
comphelper::LibreOfficeKit::setActive(false);
}
+
#endif
CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);
diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx
index a4510bb..b8e1ba4 100644
--- a/sd/source/core/drawdoc2.cxx
+++ b/sd/source/core/drawdoc2.cxx
@@ -386,13 +386,7 @@ void SdDrawDocument::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
if (comphelper::LibreOfficeKit::isActive() &&
static_cast<SdPage*>(pPage)->GetPageKind() == PK_STANDARD)
{
- boost::property_tree::ptree aTree;
- std::stringstream aStream;
- aTree.put("action", "PartInserted");
- aTree.put("part", OUString::number(nPos / 2).toUtf8().getStr());
- boost::property_tree::write_json(aStream, aTree);
- const OString aPayload = aStream.str().c_str();
- libreOfficeKitCallback(LOK_CALLBACK_PARTS_COUNT_CHANGED, aPayload.getStr());
+ libreOfficeKitCallback(LOK_CALLBACK_DOCUMENT_SIZE_CHANGED, "");
}
}
@@ -421,13 +415,7 @@ SdrPage* SdDrawDocument::RemovePage(sal_uInt16 nPgNum)
if (comphelper::LibreOfficeKit::isActive() &&
static_cast<SdPage*>(pPage)->GetPageKind() == PK_STANDARD)
{
- boost::property_tree::ptree aTree;
- std::stringstream aStream;
- aTree.put("action", "PartDeleted");
- aTree.put("part", OUString::number(nPgNum / 2).toUtf8().getStr());
- boost::property_tree::write_json(aStream, aTree);
- const OString aPayload = aStream.str().c_str();
- libreOfficeKitCallback(LOK_CALLBACK_PARTS_COUNT_CHANGED, aPayload.getStr());
+ libreOfficeKitCallback(LOK_CALLBACK_DOCUMENT_SIZE_CHANGED, "");
}
return pPage;
More information about the Libreoffice-commits
mailing list