summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorAttila Szűcs <attila.szucs@collabora.com>2024-06-24 12:45:57 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-07-12 10:45:49 +0200
commitf8e7da23b64580d4bc45abb159651c63b578be8d (patch)
tree1d4ee73db8e475ded368e200a3a327ca68d25034 /desktop
parente2d82681a8055d0d4e7007b8dacf38f5675bc70f (diff)
SW: exctract document structure
It extract form controls, and write its data to JSON. It is a basic 1. version, for now it only recognize: -PlainText (and write its text) -CheckBox (and write its state) but it writes some common data for any type of controls: ID, alias, Tag, TabIndex, and its index. Change-Id: I9ff74cd013c6f1118942207059181678713504af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170381 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'desktop')
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx3
-rw-r--r--desktop/source/lib/init.cxx62
2 files changed, 64 insertions, 1 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 85cd7e47e4f2..c5d981ca6c58 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3590,10 +3590,11 @@ void DesktopLOKTest::testABI()
CPPUNIT_ASSERT_EQUAL(classOffset(19), offsetof(struct _LibreOfficeKitClass, stopURP));
CPPUNIT_ASSERT_EQUAL(classOffset(20), offsetof(struct _LibreOfficeKitClass, joinThreads));
CPPUNIT_ASSERT_EQUAL(classOffset(21), offsetof(struct _LibreOfficeKitClass, setForkedChild));
+ CPPUNIT_ASSERT_EQUAL(classOffset(22), offsetof(struct _LibreOfficeKitClass, extractDocumentStructureRequest));
// When extending LibreOfficeKit with a new function pointer, add new assert for the offsetof the
// new function pointer and bump this assert for the size of the class.
- CPPUNIT_ASSERT_EQUAL(classOffset(22), sizeof(struct _LibreOfficeKitClass));
+ CPPUNIT_ASSERT_EQUAL(classOffset(23), sizeof(struct _LibreOfficeKitClass));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(0), offsetof(struct _LibreOfficeKitDocumentClass, destroy));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(1), offsetof(struct _LibreOfficeKitDocumentClass, saveAs));
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 365947a43b9f..5a85758039ff 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2588,6 +2588,8 @@ static void lo_setOption(LibreOfficeKit* pThis, const char* pOption, const char*
static void lo_dumpState(LibreOfficeKit* pThis, const char* pOptions, char** pState);
+static char* lo_extractDocumentStructureRequest(LibreOfficeKit* pThis, const char* pFilePath);
+
LibLibreOffice_Impl::LibLibreOffice_Impl()
: m_pOfficeClass( gOfficeClass.lock() )
, maThread(nullptr)
@@ -2621,6 +2623,7 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
m_pOfficeClass->stopURP = lo_stopURP;
m_pOfficeClass->joinThreads = lo_joinThreads;
m_pOfficeClass->setForkedChild = lo_setForkedChild;
+ m_pOfficeClass->extractDocumentStructureRequest = lo_extractDocumentStructureRequest;
gOfficeClass = m_pOfficeClass;
}
@@ -3144,6 +3147,65 @@ static char* lo_extractRequest(LibreOfficeKit* /*pThis*/, const char* pFilePath)
return strdup("{ }");
}
+static char* lo_extractDocumentStructureRequest(LibreOfficeKit* /*pThis*/, const char* pFilePath)
+{
+ uno::Reference<frame::XDesktop2> xComponentLoader = frame::Desktop::create(xContext);
+ uno::Reference< css::lang::XComponent > xComp;
+ OUString aURL(getAbsoluteURL(pFilePath));
+ if (!aURL.isEmpty())
+ {
+ if (xComponentLoader.is())
+ {
+ try
+ {
+ uno::Sequence<css::beans::PropertyValue> aFilterOptions(comphelper::InitPropertySequence(
+ {
+ {u"Hidden"_ustr, css::uno::Any(true)},
+ {u"ReadOnly"_ustr, css::uno::Any(true)}
+ }));
+ xComp = xComponentLoader->loadComponentFromURL( aURL, u"_blank"_ustr, 0, aFilterOptions );
+ }
+ catch ( const lang::IllegalArgumentException& ex )
+ {
+ SAL_WARN("lok", "lo_extractDocumentStructureRequest: IllegalArgumentException: " << ex.Message);
+ }
+ catch (...)
+ {
+ SAL_WARN("lok", "lo_extractDocumentStructureRequest: Exception on loadComponentFromURL, url= " << aURL);
+ }
+
+ if (xComp.is())
+ {
+ ITiledRenderable* pDoc = dynamic_cast<ITiledRenderable*>(xComp.get());
+
+ auto pBaseModel = dynamic_cast<SfxBaseModel*>(xComp.get());
+ if (!pBaseModel)
+ return nullptr;
+
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ if (!pObjectShell)
+ return nullptr;
+
+ //if it is a writer document..
+ uno::Reference<lang::XServiceInfo> xDocument(xComp, uno::UNO_QUERY_THROW);
+ if (xDocument->supportsService(u"com.sun.star.text.TextDocument"_ustr) || xDocument->supportsService(u"com.sun.star.text.WebDocument"_ustr))
+ {
+ tools::JsonWriter aJson;
+ {
+ pDoc->getCommandValues(aJson, ".uno:ExtractDocumentStructure");
+ //auto aNode = aJson.startNode("Controls");
+ //extractLinks(xLTS->getLinks(), false, aJson);
+ }
+ return convertOString(aJson.finishAndGetAsOString());
+ }
+
+ xComp->dispose();
+ }
+ }
+ }
+ return strdup("{ }");
+}
+
static void lo_trimMemory(LibreOfficeKit* /* pThis */, int nTarget)
{
vcl::lok::trimMemory(nTarget);