[Libreoffice-commits] core.git: 2 commits - desktop/inc desktop/source include/LibreOfficeKit
Miklos Vajna
vmiklos at collabora.co.uk
Thu Sep 24 16:07:27 PDT 2015
desktop/inc/lib/init.hxx | 12 ++++
desktop/source/lib/init.cxx | 86 +++++++++++++++++++-----------
include/LibreOfficeKit/LibreOfficeKit.h | 3 +
include/LibreOfficeKit/LibreOfficeKit.hxx | 21 +++++++
4 files changed, 93 insertions(+), 29 deletions(-)
New commits:
commit 14a9a7d52074104afa24278a7a350f05d6df572a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri Sep 25 01:06:31 2015 +0200
desktop: make LibLibreOffice_Impl visible to testcases
Change-Id: I345a6cab57cc594614e348700bb3c1c9a0673989
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index 186964f..da31adc 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -15,6 +15,7 @@
#include <com/sun/star/lang/XComponent.hpp>
#include <memory>
#include "../../source/inc/desktopdllapi.h"
+#include <osl/thread.h>
namespace desktop {
struct DESKTOP_DLLPUBLIC LibLODocument_Impl : public _LibreOfficeKitDocument
@@ -25,6 +26,17 @@ namespace desktop {
explicit LibLODocument_Impl(const css::uno::Reference <css::lang::XComponent> &xComponent);
~LibLODocument_Impl();
};
+
+ struct DESKTOP_DLLPUBLIC LibLibreOffice_Impl : public _LibreOfficeKit
+ {
+ OUString maLastExceptionMsg;
+ std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
+ oslThread maThread;
+ LibreOfficeKitCallback mpCallback;
+ void *mpCallbackData;
+
+ LibLibreOffice_Impl();
+ };
}
#endif
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0616d3b..b581bca 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -85,8 +85,6 @@ using namespace vcl;
using namespace desktop;
using namespace utl;
-struct LibLibreOffice_Impl;
-
static LibLibreOffice_Impl *gImpl = NULL;
static std::weak_ptr< LibreOfficeKitClass > gOfficeClass;
static std::weak_ptr< LibreOfficeKitDocumentClass > gDocumentClass;
@@ -319,36 +317,27 @@ static void lo_registerCallback (LibreOfficeKit* pThis,
void* pData);
static char* lo_getFilterTypes(LibreOfficeKit* pThis);
-struct LibLibreOffice_Impl : public _LibreOfficeKit
+LibLibreOffice_Impl::LibLibreOffice_Impl()
+ : maThread(0)
+ , mpCallback(nullptr)
+ , mpCallbackData(nullptr)
{
- OUString maLastExceptionMsg;
- std::shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
- oslThread maThread;
- LibreOfficeKitCallback mpCallback;
- void *mpCallbackData;
-
- LibLibreOffice_Impl()
- : maThread(0)
- , mpCallback(nullptr)
- , mpCallbackData(nullptr)
- {
- if(!(m_pOfficeClass = gOfficeClass.lock())) {
- m_pOfficeClass.reset(new LibreOfficeKitClass);
- m_pOfficeClass->nSize = sizeof(LibreOfficeKitClass);
-
- m_pOfficeClass->destroy = lo_destroy;
- m_pOfficeClass->documentLoad = lo_documentLoad;
- m_pOfficeClass->getError = lo_getError;
- m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
- m_pOfficeClass->registerCallback = lo_registerCallback;
- m_pOfficeClass->getFilterTypes = lo_getFilterTypes;
-
- gOfficeClass = m_pOfficeClass;
- }
-
- pClass = m_pOfficeClass.get();
+ if(!(m_pOfficeClass = gOfficeClass.lock())) {
+ m_pOfficeClass.reset(new LibreOfficeKitClass);
+ m_pOfficeClass->nSize = sizeof(LibreOfficeKitClass);
+
+ m_pOfficeClass->destroy = lo_destroy;
+ m_pOfficeClass->documentLoad = lo_documentLoad;
+ m_pOfficeClass->getError = lo_getError;
+ m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
+ m_pOfficeClass->registerCallback = lo_registerCallback;
+ m_pOfficeClass->getFilterTypes = lo_getFilterTypes;
+
+ gOfficeClass = m_pOfficeClass;
}
-};
+
+ pClass = m_pOfficeClass.get();
+}
namespace
{
commit 9b9f2ad9c819421c9f24bcbca98ee147f70d85b2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri Sep 25 01:02:23 2015 +0200
lok: add Office::getFilterTypes()
Change-Id: I3b1f4e11f2495e5ccb41f85802f243c0190695ee
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index fc55620..0616d3b 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
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 4c3e1fa..d5094bd 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -54,6 +54,9 @@ struct _LibreOfficeKitClass
void (*registerCallback) (LibreOfficeKit* pThis,
LibreOfficeKitCallback pCallback,
void* pData);
+
+ /// @see lok::Office::getFilterTypes().
+ char* (*getFilterTypes) (LibreOfficeKit* pThis);
#endif
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 7f96e19..207a9ce 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -353,6 +353,27 @@ public:
{
return mpThis->pClass->getError(mpThis);
}
+
+#ifdef LOK_USE_UNSTABLE_API
+ /**
+ * Returns details of filter types.
+ *
+ * Example returned string:
+ *
+ * {
+ * "writer8": {
+ * "MediaType": "application/vnd.oasis.opendocument.text"
+ * },
+ * "calc8": {
+ * "MediaType": "application/vnd.oasis.opendocument.spreadsheet"
+ * }
+ * }
+ */
+ inline char* getFilterTypes()
+ {
+ return mpThis->pClass->getFilterTypes(mpThis);
+ }
+#endif // LOK_USE_UNSTABLE_API
};
/// Factory method to create a lok::Office instance.
More information about the Libreoffice-commits
mailing list