summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/WhiteboardParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/WhiteboardParser.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
index 0f2734c..037eae2 100644
--- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
+++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
@@ -12,6 +12,7 @@
#include <Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h>
#include <Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h>
#include <Swiften/Whiteboard/Elements/Color.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardInsertOperation.h>
#include <boost/optional.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/lexical_cast.hpp>
@@ -24,6 +25,18 @@ namespace Swift {
if (level_ == 0) {
getPayloadInternal()->setType(stringToType(attributes.getAttributeValue("type").get_value_or("")));
} else if (level_ == 1) {
+ std::string type = attributes.getAttributeValue("type").get_value_or("");
+ if (type == "insert") {
+ WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>();
+ try {
+ insertOp->setID(attributes.getAttributeValue("id").get_value_or(""));
+ insertOp->setParentID(attributes.getAttributeValue("parentid").get_value_or(""));
+ insertOp->setPos(boost::lexical_cast<int>(attributes.getAttributeValue("pos").get_value_or("0")));
+ } catch (boost::bad_lexical_cast&) {
+ }
+ operation = insertOp;
+ }
+ } else if (level_ == 2) {
if (element == "line") {
int x1 = 0;
int y1 = 0;
@@ -50,6 +63,7 @@ namespace Swift {
whiteboardElement->setPenWidth(penWidth);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "path") {
WhiteboardFreehandPathElement::ref whiteboardElement = boost::make_shared<WhiteboardFreehandPathElement>();
std::string pathData = attributes.getAttributeValue("d").get_value_or("");
@@ -98,6 +112,7 @@ namespace Swift {
whiteboardElement->setColor(color);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "rect") {
int x = 0;
int y = 0;
@@ -128,6 +143,7 @@ namespace Swift {
whiteboardElement->setBrushColor(brushColor);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "polygon") {
WhiteboardPolygonElement::ref whiteboardElement = boost::make_shared<WhiteboardPolygonElement>();
@@ -166,6 +182,7 @@ namespace Swift {
whiteboardElement->setBrushColor(brushColor);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "text") {
int x = 0;
int y = 0;
@@ -190,6 +207,7 @@ namespace Swift {
whiteboardElement->setSize(fontSize);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
} else if (element == "ellipse") {
int cx = 0;
int cy = 0;
@@ -220,6 +238,7 @@ namespace Swift {
whiteboardElement->setBrushColor(brushColor);
whiteboardElement->setID(attributes.getAttributeValue("id").get_value_or(""));
getPayloadInternal()->setElement(whiteboardElement);
+ wbElement = whiteboardElement;
}
}
++level_;
@@ -230,6 +249,12 @@ namespace Swift {
if (level_ == 0) {
getPayloadInternal()->setData(data_);
} else if (level_ == 1) {
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation);
+ if (insertOp) {
+ insertOp->setElement(wbElement);
+ }
+ getPayloadInternal()->setOperation(operation);
+ } else if (level_ == 2) {
if (element == "text") {
actualIsText = false;
}
@@ -237,7 +262,7 @@ namespace Swift {
}
void WhiteboardParser::handleCharacterData(const std::string& data) {
- if (level_ == 2 && actualIsText) {
+ if (level_ == 3 && actualIsText) {
WhiteboardTextElement::ref element = boost::dynamic_pointer_cast<WhiteboardTextElement>(getPayloadInternal()->getElement());
element->setText(data);
}