summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-09-25 01:02:23 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-09-25 01:02:23 +0200
commit9b9f2ad9c819421c9f24bcbca98ee147f70d85b2 (patch)
treea43f26739f9a1e9602d7e6f5fd736a275349e77d /desktop
parent14ccaf915d09da23b07e8604b78c449c389a15cc (diff)
lok: add Office::getFilterTypes()
Change-Id: I3b1f4e11f2495e5ccb41f85802f243c0190695ee
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx39
1 files changed, 39 insertions, 0 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index fc5562022db2..0616d3bada0d 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -317,6 +317,8 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions (LibreOfficeKit* pThi
static void lo_registerCallback (LibreOfficeKit* pThis,
LibreOfficeKitCallback pCallback,
void* pData);
+static char* lo_getFilterTypes(LibreOfficeKit* pThis);
+
struct LibLibreOffice_Impl : public _LibreOfficeKit
{
OUString maLastExceptionMsg;
@@ -339,6 +341,7 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit
m_pOfficeClass->getError = lo_getError;
m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
m_pOfficeClass->registerCallback = lo_registerCallback;
+ m_pOfficeClass->getFilterTypes = lo_getFilterTypes;
gOfficeClass = m_pOfficeClass;
}
@@ -1095,6 +1098,42 @@ static char* lo_getError (LibreOfficeKit *pThis)
return pMemory;
}
+static char* lo_getFilterTypes(LibreOfficeKit* pThis)
+{
+ LibLibreOffice_Impl* pImpl = static_cast<LibLibreOffice_Impl*>(pThis);
+
+ if (!xSFactory.is())
+ xSFactory = comphelper::getProcessServiceFactory();
+
+ if (!xSFactory.is())
+ {
+ pImpl->maLastExceptionMsg = "Service factory is not available";
+ return 0;
+ }
+
+ uno::Reference<container::XNameAccess> xTypeDetection(xSFactory->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY);
+ uno::Sequence<OUString> aTypes = xTypeDetection->getElementNames();
+ boost::property_tree::ptree aTree;
+ for (const OUString& rType : aTypes)
+ {
+ uno::Sequence<beans::PropertyValue> aValues;
+ if (xTypeDetection->getByName(rType) >>= aValues)
+ {
+ auto it = std::find_if(aValues.begin(), aValues.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "MediaType"; });
+ OUString aValue;
+ if (it != aValues.end() && (it->Value >>= aValue) && !aValue.isEmpty())
+ {
+ boost::property_tree::ptree aChild;
+ aChild.put("MediaType", aValue.toUtf8());
+ aTree.add_child(rType.toUtf8().getStr(), aChild);
+ }
+ }
+ }
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ return strdup(aStream.str().c_str());
+}
+
static void force_c_locale()
{
// force locale (and resource files loaded) to en-US