diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-04-22 14:28:36 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-04-22 15:42:36 +0200 |
commit | 6a8719b12e2f24e926fccdfabc60b95c089320fc (patch) | |
tree | 6d16317f7bccb2132258ab4b7511ddad5c4ff460 /desktop/source | |
parent | 5dc81ae20145d66019d3853e033514a9b1bc9c57 (diff) |
lok::Document::postUnoCommand: allow passing arguments
Change-Id: I6c24a8e392473f3985d3bde9b76a3148fd03bc9a
Diffstat (limited to 'desktop/source')
-rw-r--r-- | desktop/source/lib/init.cxx | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index c1237ac1eca3..b783612ecb73 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -15,6 +15,7 @@ #include <boost/shared_ptr.hpp> #include <boost/weak_ptr.hpp> +#include <boost/property_tree/json_parser.hpp> #define LOK_USE_UNSTABLE_API #include <LibreOfficeKit/LibreOfficeKit.h> @@ -52,6 +53,7 @@ #include <unotools/syslocaleoptions.hxx> #include <unotools/mediadescriptor.hxx> #include <osl/module.hxx> +#include <comphelper/sequence.hxx> #include <app.hxx> @@ -207,7 +209,8 @@ static void doc_postMouseEvent (LibreOfficeKitDocument* pThis, int nY, int nCount); static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, - const char* pCommand); + const char* pCommand, + const char* pArguments); static void doc_setTextSelection (LibreOfficeKitDocument* pThis, int nType, int nX, @@ -701,11 +704,38 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar pDoc->postKeyEvent(nType, nCharCode, nKeyCode); } -static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand) +static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::PropertyValue>& rPropertyValues) +{ + boost::property_tree::ptree aTree; + std::stringstream aStream(pJSON); + boost::property_tree::read_json(aStream, aTree); + + std::vector<beans::PropertyValue> aArguments; + for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree) + { + const std::string& rType = rPair.second.get<std::string>("type"); + const std::string& rValue = rPair.second.get<std::string>("value"); + + beans::PropertyValue aValue; + aValue.Name = OUString::fromUtf8(rPair.first.c_str()); + if (rType == "string") + aValue.Value <<= OUString::fromUtf8(rValue.c_str()); + else if (rType == "boolean") + aValue.Value <<= OString(rValue.c_str()).toBoolean(); + else + SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'"); + aArguments.push_back(aValue); + } + rPropertyValues = comphelper::containerToSequence(aArguments); +} + +static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand, const char* pArguments) { OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8); - if (!comphelper::dispatchCommand(aCommand, uno::Sequence<beans::PropertyValue>())) + uno::Sequence<beans::PropertyValue> aPropertyValues; + jsonToPropertyValues(pArguments, aPropertyValues); + if (!comphelper::dispatchCommand(aCommand, aPropertyValues)) { gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command"; } |