summaryrefslogtreecommitdiff
path: root/desktop/source/lib/init.cxx
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2019-10-20 10:06:20 -0400
committerHenry Castro <hcastro@collabora.com>2019-10-22 19:50:39 +0200
commit762ee9c8339695ff9471124b448a25a83638bfba (patch)
tree60ccee5d30b979aa4a1b0cb7d5171b96f6139fc8 /desktop/source/lib/init.cxx
parentc8671a691f6810566bc715bb8eb00cbae4ee17c3 (diff)
lok: convert JSON to StringMap in sent DialogEvent function
The StringMap type is used to the class UIObject methods to get state and execute actions. So the idea is the loleaflet client side send a raw JSON string: { ctrl: "id_control", cmd: "SELECT", ID: "item_id", ... // more parameters } Then it is transformed with a simple JSON to StringMap, finally it is dispatched to execute the actions. Change-Id: Icd628598fe46ae28b4afa3ca17ac75797c1b9308 Reviewed-on: https://gerrit.libreoffice.org/81167 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Henry Castro <hcastro@collabora.com>
Diffstat (limited to 'desktop/source/lib/init.cxx')
-rw-r--r--desktop/source/lib/init.cxx74
1 files changed, 30 insertions, 44 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 200be4cf465f..d316997bab46 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -413,6 +413,25 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char
return aArguments;
}
+
+static StringMap jsonToStringMap(const char* pJSON)
+{
+ StringMap aArgs;
+ if (pJSON && pJSON[0] != '\0')
+ {
+ std::stringstream aStream(pJSON);
+ boost::property_tree::ptree aTree;
+ boost::property_tree::read_json(aStream, aTree);
+
+ for (const auto& rPair : aTree)
+ {
+ aArgs[OUString::fromUtf8(rPair.first.c_str())] = OUString::fromUtf8(rPair.second.get_value<std::string>(".").c_str());
+ }
+ }
+ return aArgs;
+}
+
+
static boost::property_tree::ptree unoAnyToPropertyTree(const uno::Any& anyItem)
{
boost::property_tree::ptree aTree;
@@ -3272,34 +3291,14 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
{
SolarMutexGuard aGuard;
- char* pCopy = strdup(pArguments);
- if (!pCopy)
- {
- SetLastExceptionMsg("String copying error.");
- return;
- }
-
- char* pIdChar = strtok(pCopy, " ");
- char* pOptionalEventType = strtok(nullptr, " ");
- char* pOptionalData = strtok(nullptr, " ");
-
- if (!pIdChar)
- {
- SetLastExceptionMsg("Error parsing the command.");
- free(pCopy);
- return;
- }
-
- OUString sId = OUString::createFromAscii(pIdChar);
-
+ StringMap aMap(jsonToStringMap(pArguments));
VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nWindowId);
if (!pWindow)
{
SetLastExceptionMsg("Document doesn't support dialog rendering, or window not found.");
- free(pCopy);
return;
}
- else
+ else if (aMap.find("id") != aMap.end())
{
const OUString sClickAction("CLICK");
const OUString sSelectAction("SELECT");
@@ -3311,40 +3310,29 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
try
{
WindowUIObject aUIObject(pWindow);
- std::unique_ptr<UIObject> pUIWindow(aUIObject.get_child(sId));
+ std::unique_ptr<UIObject> pUIWindow(aUIObject.get_child(aMap["id"]));
if (pUIWindow) {
bool bIsClickAction = false;
- StringMap aMap;
- if (pOptionalEventType) {
- if (strcmp(pOptionalEventType, "selected") == 0 && pOptionalData)
+ if (aMap.find("cmd") != aMap.end()) {
+ if (aMap["cmd"] == "selected")
{
- char* pPos = strtok(pOptionalData, ";");
- char* pText = strtok(nullptr, ";");
-
- if (!pPos || !pText)
- {
- SetLastExceptionMsg("Error parsing the command.");
- free(pCopy);
- return;
- }
-
- aMap["POS"] = OUString::createFromAscii(pPos);
- aMap["TEXT"] = OUString::createFromAscii(pText);
+ aMap["POS"] = aMap["data"];
+ aMap["TEXT"] = aMap["data"];
pUIWindow->execute(sSelectAction, aMap);
}
- else if (strcmp(pOptionalEventType, "plus") == 0)
+ else if (aMap["cmd"] == "plus")
{
pUIWindow->execute(sUpAction, aMap);
}
- else if (strcmp(pOptionalEventType, "minus") == 0)
+ else if (aMap["cmd"] == "minus")
{
pUIWindow->execute(sDownAction, aMap);
}
- else if (pOptionalData)
+ else if (aMap["cmd"] == "set")
{
- aMap["TEXT"] = OUString::createFromAscii(pOptionalData);
+ aMap["TEXT"] = aMap["data"];
pUIWindow->execute(sClearAction, aMap);
pUIWindow->execute(sTypeAction, aMap);
@@ -3364,8 +3352,6 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin
pWindow->Hide();
pWindow->Show();
}
-
- free(pCopy);
}
static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished)