summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/QtUI/Whiteboard/GView.cpp85
-rw-r--r--Swift/QtUI/Whiteboard/GView.h8
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp47
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.h4
-rw-r--r--Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h19
-rw-r--r--Swiften/Elements/WhiteboardPayload.h10
-rw-r--r--Swiften/Parser/PayloadParsers/WhiteboardParser.cpp27
-rw-r--r--Swiften/Parser/PayloadParsers/WhiteboardParser.h3
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp18
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardElement.h2
-rw-r--r--Swiften/Whiteboard/IncomingWhiteboardSession.cpp24
-rw-r--r--Swiften/Whiteboard/IncomingWhiteboardSession.h8
-rw-r--r--Swiften/Whiteboard/OutgoingWhiteboardSession.cpp29
-rw-r--r--Swiften/Whiteboard/OutgoingWhiteboardSession.h6
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.cpp18
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.h11
16 files changed, 266 insertions, 53 deletions
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp
index 27197d0..92339ce 100644
--- a/Swift/QtUI/Whiteboard/GView.cpp
+++ b/Swift/QtUI/Whiteboard/GView.cpp
@@ -46,13 +46,35 @@ namespace Swift {
lastItem = 0;
}
- QGraphicsItem* GView::getItem(const QString id) const {
- return items_.value(id);
- }
+ void GView::addItem(QGraphicsItem* item, QString id, int pos) {
+// QList<QGraphicsItem*> items = scene()->items();
+// std::cout << "pos: " << pos << " size: " << items.size() << std::endl;
+// if (mousePressed && pos >= items_.size()) {
+// pos++;
+// }
+ if (pos > items_.size()) {
+ item->setZValue(zValue++);
+ scene()->addItem(item);
+ items_.append(item);
+ } else {
+ QList<QGraphicsItem*>::iterator it = items_.begin();
+ for (int i = 1; i < pos; i++) {
+ ++it;
+ }
+ // std::cout << id.toStdString() << " before: " << (*it)->data(100).toString().toStdString() << std::endl;
+ item->setZValue((*it)->zValue());
+ scene()->addItem(item);
+ item->stackBefore(*it);
+ // --it;
+ items_.insert(it, item);
+ }
- void GView::addItem(QGraphicsItem* item, QString id) {
- scene()->addItem(item);
- items_.insert(id, item);
+// items = scene()->items();
+ std::cout << "items:" << std::endl;
+ for (QList<QGraphicsItem*>::const_iterator it = items_.begin(); it != items_.end(); ++it) {
+ std::cout << (*it)->data(100).toString().toStdString() << std::endl;
+ }
+ std::cout << std::endl;
}
void GView::setIDPrefix(QString prefix) {
@@ -182,19 +204,23 @@ namespace Swift {
QPointF point = this->mapToScene(event->pos());
QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen);
QString id = getNewID();
- items_.insert(id, item);
- item->setZValue(zValue++);
+// items_.append(item);
+// item->setZValue(zValue++);
+ item->setZValue(10000000);
item->setData(100, id);
+ item->setData(101, items_.size());
lastItem = item;
}
else if (mode == Rect) {
QPointF point = this->mapToScene(event->pos());
QGraphicsRectItem* item = scene()->addRect(point.x(), point.y(), 0, 0, pen, brush);
QString id = getNewID();
- items_.insert(id, item);
- item->setZValue(zValue++);
+// items_.append(item);
+// item->setZValue(zValue++);
+ item->setZValue(10000000);
item->setData(0, point);
item->setData(100, id);
+ item->setData(101, items_.size());
lastItem = item;
}
else if (mode == Rubber) {
@@ -213,21 +239,25 @@ namespace Swift {
QPointF point = this->mapToScene(event->pos());
QGraphicsEllipseItem* item = scene()->addEllipse(point.x(), point.y(), 0, 0, pen, brush);
QString id = getNewID();
- items_.insert(id, item);
- item->setZValue(zValue++);
+// items_.append(item);
+// item->setZValue(zValue++);
+ item->setZValue(10000000);
item->setData(0, point);
item->setData(100, id);
+ item->setData(101, items_.size());
lastItem = item;
}
else if (mode == HandLine) {
QPointF point = this->mapToScene(event->pos());
FreehandLineItem* item = new FreehandLineItem;
QString id = getNewID();
- items_.insert(id, item);
+// items_.append(item);
item->setPen(pen);
item->setStartPoint(point);
- item->setZValue(zValue++);
+// item->setZValue(zValue++);
+ item->setZValue(10000000);
item->setData(100, id);
+ item->setData(101, items_.size());
scene()->addItem(item);
lastItem = item;
}
@@ -236,19 +266,22 @@ namespace Swift {
QPainterPath path;
QGraphicsPathItem* item = scene()->addPath(path, pen, brush);
QString id = getNewID();
- items_.insert(id, item);
- item->setZValue(zValue++);
+// items_.append(item);
+// item->setZValue(zValue++);
+ item->setZValue(10000000);
item->setData(0, point);
item->setData(100, id);
+ item->setData(101, items_.size());
lastItem = item;
}
else if (mode == Text) {
QPointF point = this->mapToScene(event->pos());
QGraphicsTextItem* item = scene()->addText("");
QString id = getNewID();
- items_.insert(id, item);
+ items_.append(item);
item->setZValue(zValue++);
item->setData(100, id);
+ item->setData(101, items_.size());
item->setDefaultTextColor(pen.color());
textDialog = new TextDialog(item, this);
connect(textDialog, SIGNAL(accepted(QGraphicsItem*)), this, SIGNAL(lastItemChanged(QGraphicsItem*)));
@@ -266,9 +299,11 @@ namespace Swift {
polygon.append(point);
item = scene()->addPolygon(polygon, pen, brush);
QString id = getNewID();
- items_.insert(id, item);
- item->setZValue(zValue++);
+// items_.append(item);
+// item->setZValue(zValue++);
+ item->setZValue(10000000);
item->setData(100, id);
+ item->setData(101, items_.size());
lastItem = item;
}
else {
@@ -302,7 +337,17 @@ namespace Swift {
void GView::mouseReleaseEvent(QMouseEvent *event)
{
mousePressed = false;
- lastItemChanged(lastItem);
+ zValue++;
+ lastItem->setZValue(zValue++);
+ items_.append(lastItem);
+// lastItemChanged(lastItem, lastItem->data(101).toInt());
+ std::cout << "items:" << std::endl;
+ for (QList<QGraphicsItem*>::const_iterator it = items_.begin(); it != items_.end(); ++it) {
+ std::cout << (*it)->data(100).toString().toStdString() << std::endl;
+ }
+ std::cout << std::endl;
+
+ lastItemChanged(lastItem, items_.size());
}
diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h
index 0069fb5..9428f3d 100644
--- a/Swift/QtUI/Whiteboard/GView.h
+++ b/Swift/QtUI/Whiteboard/GView.h
@@ -31,8 +31,7 @@ namespace Swift {
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
- QGraphicsItem* getItem(const QString id) const;
- void addItem(QGraphicsItem* item, QString id);
+ void addItem(QGraphicsItem* item, QString id, int pos);
void setIDPrefix(QString prefix);
void clear();
@@ -51,11 +50,12 @@ namespace Swift {
QGraphicsItem* lastItem;
QGraphicsRectItem* selectionRect;
TextDialog* textDialog;
- QMap<QString, QGraphicsItem*> items_;
+// QMap<QString, QGraphicsItem*> items_;
+ QList<QGraphicsItem*> items_;
SimpleIDGenerator idGenerator;
QString idPrefix;
signals:
- void lastItemChanged(QGraphicsItem* item);
+ void lastItemChanged(QGraphicsItem* item, int pos);
};
}
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
index 5afc382..5743d80 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -15,6 +15,7 @@
#include <Swiften/Elements/WhiteboardPayload.h>
#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h>
#include <Swiften/Whiteboard/Elements/WhiteboardRectElement.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardInsertOperation.h>
#include <Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h>
#include <QMessageBox>
@@ -35,7 +36,7 @@ namespace Swift {
graphicsView = new GView(scene, this);
graphicsView->setMode(GView::Line);
- connect(graphicsView, SIGNAL(lastItemChanged(QGraphicsItem*)), this, SLOT(handleLastItemChanged(QGraphicsItem*)));
+ connect(graphicsView, SIGNAL(lastItemChanged(QGraphicsItem*, int)), this, SLOT(handleLastItemChanged(QGraphicsItem*, int)));
widthBox = new QSpinBox(this);
connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int)));
@@ -132,8 +133,17 @@ namespace Swift {
}
void QtWhiteboardWindow::handleWhiteboardElementReceive(const WhiteboardElement::ref element) {
- WhiteboardElementDrawingVisitor visitor(graphicsView);
- element->accept(visitor);
+// WhiteboardElementDrawingVisitor visitor(graphicsView);
+// element->accept(visitor);
+ }
+
+ void QtWhiteboardWindow::handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation) {
+ WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos());
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation);
+ if (insertOp) {
+ insertOp->getElement()->accept(visitor);
+ lastOpID = insertOp->getID();
+ }
}
void QtWhiteboardWindow::changeLineWidth(int i)
@@ -210,6 +220,7 @@ namespace Swift {
whiteboardSession_ = session;
graphicsView->setIDPrefix(P2QSTRING(whiteboardSession_->getClientID()));
whiteboardSession_->onElementReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardElementReceive, this, _1));
+ whiteboardSession_->onOperationReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardOperationReceive, this, _1));
whiteboardSession_->onRequestAccepted.connect(boost::bind(&QWidget::show, this));
whiteboardSession_->onSessionTerminateReceived.connect(boost::bind(&QtWhiteboardWindow::handleSessionTerminate, this));
}
@@ -218,8 +229,8 @@ namespace Swift {
QWidget::activateWindow();
}
- void QtWhiteboardWindow::handleLastItemChanged(QGraphicsItem* item) {
- std::string serialized;
+ void QtWhiteboardWindow::handleLastItemChanged(QGraphicsItem* item, int pos) {
+ WhiteboardElement::ref el;
QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
if (lineItem != 0) {
QLine line = lineItem->line().toLine();
@@ -229,8 +240,8 @@ namespace Swift {
element->setPenWidth(lineItem->pen().width());
element->setID(lineItem->data(100).toString().toStdString());
- whiteboardSession_->sendElement(element);
-
+// whiteboardSession_->sendElement(element);
+ el = element;
}
FreehandLineItem* freehandLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
if (freehandLineItem != 0) {
@@ -247,7 +258,8 @@ namespace Swift {
element->setPoints(points);
element->setID(freehandLineItem->data(100).toString().toStdString());
- whiteboardSession_->sendElement(element);
+// whiteboardSession_->sendElement(element);
+ el = element;
}
QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
@@ -262,7 +274,8 @@ namespace Swift {
element->setPenWidth(rectItem->pen().width());
element->setID(rectItem->data(100).toString().toStdString());
- whiteboardSession_->sendElement(element);
+// whiteboardSession_->sendElement(element);
+ el = element;
}
QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
@@ -275,7 +288,8 @@ namespace Swift {
element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha()));
element->setID(rectItem->data(100).toString().toStdString());
- whiteboardSession_->sendElement(element);
+// whiteboardSession_->sendElement(element);
+ el = element;
}
QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
@@ -297,7 +311,8 @@ namespace Swift {
element->setPenWidth(polygonItem->pen().width());
element->setID(polygonItem->data(100).toString().toStdString());
- whiteboardSession_->sendElement(element);
+// whiteboardSession_->sendElement(element);
+ el = element;
}
QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
@@ -316,8 +331,16 @@ namespace Swift {
element->setPenWidth(ellipseItem->pen().width());
element->setID(ellipseItem->data(100).toString().toStdString());
- whiteboardSession_->sendElement(element);
+// whiteboardSession_->sendElement(element);
+ el = element;
}
+ WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>();
+ insertOp->setID(el->getID());
+ insertOp->setPos(pos);
+ insertOp->setElement(el);
+ insertOp->setParentID(lastOpID);
+ lastOpID = el->getID();
+ whiteboardSession_->sendOperation(insertOp);
}
void QtWhiteboardWindow::handleSessionTerminate() {
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
index fc55495..fbe98a7 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
@@ -49,11 +49,12 @@ namespace Swift {
void setTextMode();
void setPolygonMode();
void setSelectMode();
- void handleLastItemChanged(QGraphicsItem* item);
+ void handleLastItemChanged(QGraphicsItem* item, int pos);
private:
void handleSessionTerminate();
void handleWhiteboardElementReceive(const WhiteboardElement::ref element);
+ void handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation);
void closeEvent(QCloseEvent* event);
private:
@@ -79,6 +80,7 @@ namespace Swift {
QToolButton* polygonButton;
QToolButton* selectButton;
+ std::string lastOpID;
WhiteboardSession::ref whiteboardSession_;
};
}
diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
index 38ed676..d9809b5 100644
--- a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
+++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
@@ -18,7 +18,7 @@
namespace Swift {
class WhiteboardElementDrawingVisitor : public WhiteboardElementVisitor {
public:
- WhiteboardElementDrawingVisitor(GView* graphicsView) : graphicsView_(graphicsView) {}
+ WhiteboardElementDrawingVisitor(GView* graphicsView, int pos) : graphicsView_(graphicsView), pos_(pos) {}
void visit(WhiteboardLineElement& element) {
QGraphicsLineItem *item = new QGraphicsLineItem(element.x1(), element.y1(), element.x2(), element.y2());
@@ -29,7 +29,7 @@ namespace Swift {
item->setPen(pen);
QString id = P2QSTRING(element.getID());
item->setData(100, id);
- graphicsView_->addItem(item, id);
+ graphicsView_->addItem(item, id, pos_);
}
void visit(WhiteboardFreehandPathElement& element) {
@@ -48,7 +48,7 @@ namespace Swift {
QString id = P2QSTRING(element.getID());
item->setData(100, id);
- graphicsView_->addItem(item, id);
+ graphicsView_->addItem(item, id, pos_);
}
void visit(WhiteboardRectElement& element) {
@@ -64,11 +64,11 @@ namespace Swift {
item->setBrush(brush);
QString id = P2QSTRING(element.getID());
item->setData(100, id);
- graphicsView_->addItem(item, id);
+ graphicsView_->addItem(item, id, pos_);
}
void visit(WhiteboardPolygonElement& element) {
- QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ /* QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
if (item == 0) {
item = new QGraphicsPolygonItem();
QPen pen;
@@ -82,14 +82,14 @@ namespace Swift {
item->setBrush(brush);
QString id = P2QSTRING(element.getID());
item->setData(100, id);
- graphicsView_->addItem(item, id);
+ graphicsView_->addItem(item, id, pos_);
}
QPolygonF polygon;
std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin();
for (; it != element.getPoints().end(); ++it) {
polygon.append(QPointF(it->first, it->second));
}
- item->setPolygon(polygon);
+ item->setPolygon(polygon);*/
}
void visit(WhiteboardTextElement& element) {
@@ -103,7 +103,7 @@ namespace Swift {
QString id = P2QSTRING(element.getID());
item->setData(100, id);
- graphicsView_->addItem(item, id);
+ graphicsView_->addItem(item, id, pos_);
}
void visit(WhiteboardEllipseElement& element) {
@@ -124,10 +124,11 @@ namespace Swift {
item->setBrush(brush);
QString id = P2QSTRING(element.getID());
item->setData(100, id);
- graphicsView_->addItem(item, id);
+ graphicsView_->addItem(item, id, pos_);
}
private:
GView* graphicsView_;
+ int pos_;
};
}
diff --git a/Swiften/Elements/WhiteboardPayload.h b/Swiften/Elements/WhiteboardPayload.h
index c61e4a5..cf22f20 100644
--- a/Swiften/Elements/WhiteboardPayload.h
+++ b/Swiften/Elements/WhiteboardPayload.h
@@ -10,6 +10,7 @@
#include <Swiften/Elements/Payload.h>
#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardOperation.h>
namespace Swift {
class WhiteboardPayload : public Payload {
@@ -46,9 +47,18 @@ namespace Swift {
element_ = element;
}
+ WhiteboardOperation::ref getOperation() const {
+ return operation_;
+ }
+
+ void setOperation(WhiteboardOperation::ref operation) {
+ operation_ = operation;
+ }
+
private:
std::string data_;
Type type_;
WhiteboardElement::ref element_;
+ WhiteboardOperation::ref operation_;
};
}
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);
}
diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.h b/Swiften/Parser/PayloadParsers/WhiteboardParser.h
index 7c93de3..bc4ed2a 100644
--- a/Swiften/Parser/PayloadParsers/WhiteboardParser.h
+++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.h
@@ -9,6 +9,7 @@
#include <Swiften/Elements/WhiteboardPayload.h>
#include <Swiften/Parser/GenericPayloadParser.h>
#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardOperation.h>
namespace Swift {
class WhiteboardParser : public Swift::GenericPayloadParser<WhiteboardPayload> {
@@ -27,5 +28,7 @@ namespace Swift {
bool actualIsText;
int level_;
std::string data_;
+ WhiteboardElement::ref wbElement;
+ WhiteboardOperation::ref operation;
};
}
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
index a15d7ae..0cd4779 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
@@ -9,6 +9,7 @@
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/lexical_cast.hpp>
#include <Swiften/Serializer/XML/XMLTextNode.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardInsertOperation.h>
namespace Swift {
void WhiteboardElementSerializingVisitor::visit(WhiteboardLineElement& line) {
@@ -135,9 +136,22 @@ namespace Swift {
std::string WhiteboardSerializer::serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const {
XMLElement element("wb");
if (payload->getType() == WhiteboardPayload::Data) {
+ XMLElement::ref operationNode = boost::make_shared<XMLElement>("operation");
WhiteboardElementSerializingVisitor visitor;
- payload->getElement()->accept(visitor);
- element.addNode(visitor.getResult());
+// payload->getElement()->accept(visitor);
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(payload->getOperation());
+ if (insertOp) {
+ try {
+ operationNode->setAttribute("type", "insert");
+ operationNode->setAttribute("pos", boost::lexical_cast<std::string>(insertOp->getPos()));
+ operationNode->setAttribute("id", insertOp->getID());
+ operationNode->setAttribute("parentid", insertOp->getParentID());
+ } catch (boost::bad_lexical_cast&) {
+ }
+ insertOp->getElement()->accept(visitor);
+ operationNode->addNode(visitor.getResult());
+ }
+ element.addNode(operationNode);
}
element.setAttribute("type", typeToString(payload->getType()));
return element.serialize();
diff --git a/Swiften/Whiteboard/Elements/WhiteboardElement.h b/Swiften/Whiteboard/Elements/WhiteboardElement.h
index 5095506..2b84a04 100644
--- a/Swiften/Whiteboard/Elements/WhiteboardElement.h
+++ b/Swiften/Whiteboard/Elements/WhiteboardElement.h
@@ -17,5 +17,7 @@ namespace Swift {
public:
virtual ~WhiteboardElement() {}
virtual void accept(WhiteboardElementVisitor& visitor) = 0;
+ virtual std::string getID() const = 0;
+ virtual void setID(const std::string&) = 0;
};
}
diff --git a/Swiften/Whiteboard/IncomingWhiteboardSession.cpp b/Swiften/Whiteboard/IncomingWhiteboardSession.cpp
index 5cdba1a..60faa2e 100644
--- a/Swiften/Whiteboard/IncomingWhiteboardSession.cpp
+++ b/Swiften/Whiteboard/IncomingWhiteboardSession.cpp
@@ -23,4 +23,28 @@ namespace Swift {
std::string IncomingWhiteboardSession::getClientID() const {
return "b";
}
+
+ void IncomingWhiteboardSession::handleIncomingOperation(WhiteboardOperation::ref operation) {
+// std::cout << "incoming pos: " << operation->getPos() << std::endl;
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation);
+ if (insertOp) {
+ WhiteboardOperation::ref op = server.handleClientOperationReceived(insertOp);
+ //std::cout << "in1: " << operation->getID() << " " << operation->getPos() << " " << operation->getParentID() << std::endl;
+ //std::cout << "in2: " << op->getID() << " " << op->getPos() << " " << op->getParentID() << std::endl;
+ onOperationReceived(op);
+ WhiteboardPayload::ref payload = boost::make_shared<WhiteboardPayload>();
+ payload->setOperation(op);
+ sendPayload(payload);
+ } else {
+ std::cout << "unknown operation" << std::endl;
+ }
+ }
+
+ void IncomingWhiteboardSession::handleSendOperationRequest(WhiteboardOperation::ref operation) {
+ //std::cout << "out: " << operation->getID() << " " << operation->getPos() << " " << operation->getParentID()<< std::endl;
+ server.handleLocalOperationReceived(operation);
+ WhiteboardPayload::ref payload = boost::make_shared<WhiteboardPayload>();
+ payload->setOperation(operation);
+ sendPayload(payload);
+ }
}
diff --git a/Swiften/Whiteboard/IncomingWhiteboardSession.h b/Swiften/Whiteboard/IncomingWhiteboardSession.h
index 9971d75..33c1a78 100644
--- a/Swiften/Whiteboard/IncomingWhiteboardSession.h
+++ b/Swiften/Whiteboard/IncomingWhiteboardSession.h
@@ -7,7 +7,7 @@
#pragma once
#include <Swiften/Whiteboard/WhiteboardSession.h>
-
+#include <Swiften/Whiteboard/WhiteboardServer.h>
#include <boost/shared_ptr.hpp>
namespace Swift {
@@ -21,5 +21,11 @@ namespace Swift {
void accept();
std::string getClientID() const;
+
+ private:
+ void handleIncomingOperation(WhiteboardOperation::ref operation);
+ void handleSendOperationRequest(WhiteboardOperation::ref operation);
+
+ WhiteboardServer server;
};
}
diff --git a/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp b/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp
index f0b6d22..da4d3cf 100644
--- a/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp
+++ b/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp
@@ -33,4 +33,33 @@ namespace Swift {
onRequestRejected(toJID_);
}
}
+
+ void OutgoingWhiteboardSession::handleIncomingOperation(WhiteboardOperation::ref operation) {
+// std::cout << "incoming pos: " << operation->getPos() << std::endl;
+ WhiteboardClient::Result pairResult = client.handleServerOperationReceived(operation);
+ if (pairResult.client) {
+ onOperationReceived(pairResult.client);
+ //std::cout << "in1: " << operation->getID() << " " << operation->getPos() << " " << operation->getParentID() << std::endl;
+ //std::cout << "in2: " << pairResult.client->getID() << " " << pairResult.client->getPos() << " " << pairResult.client->getParentID() << std::endl;
+ }
+
+ if (pairResult.server) {
+ //std::cout << "outts: " << pairResult.server->getID() << " " << pairResult.server->getPos() << std::endl;
+ WhiteboardPayload::ref payload = boost::make_shared<WhiteboardPayload>();
+ payload->setOperation(pairResult.server);
+ sendPayload(payload);
+ }
+ }
+
+ void OutgoingWhiteboardSession::handleSendOperationRequest(WhiteboardOperation::ref operation) {
+ //std::cout << "out1: " << operation->getID() << " " << operation->getPos() << " " << operation->getParentID() << std::endl;
+ WhiteboardOperation::ref result = client.handleLocalOperationReceived(operation);
+
+ if (result) {
+ //std::cout << "out2: " << result->getID() << " " << result->getPos()<< " " << result->getParentID()<< std::endl;
+ WhiteboardPayload::ref payload = boost::make_shared<WhiteboardPayload>();
+ payload->setOperation(result);
+ sendPayload(payload);
+ }
+ }
}
diff --git a/Swiften/Whiteboard/OutgoingWhiteboardSession.h b/Swiften/Whiteboard/OutgoingWhiteboardSession.h
index 5cc0f42..fbd0f20 100644
--- a/Swiften/Whiteboard/OutgoingWhiteboardSession.h
+++ b/Swiften/Whiteboard/OutgoingWhiteboardSession.h
@@ -7,7 +7,7 @@
#pragma once
#include <Swiften/Whiteboard/WhiteboardSession.h>
-
+#include <Swiften/Whiteboard/WhiteboardClient.h>
#include <boost/shared_ptr.hpp>
#include <Swiften/Queries/GenericRequest.h>
@@ -24,5 +24,9 @@ namespace Swift {
private:
void handleRequestResponse(boost::shared_ptr<WhiteboardPayload> payload, ErrorPayload::ref error);
+ void handleIncomingOperation(WhiteboardOperation::ref operation);
+ void handleSendOperationRequest(WhiteboardOperation::ref operation);
+
+ WhiteboardClient client;
};
}
diff --git a/Swiften/Whiteboard/WhiteboardSession.cpp b/Swiften/Whiteboard/WhiteboardSession.cpp
index d9dc592..2828436 100644
--- a/Swiften/Whiteboard/WhiteboardSession.cpp
+++ b/Swiften/Whiteboard/WhiteboardSession.cpp
@@ -27,7 +27,9 @@ namespace Swift {
switch (payload->getType()) {
case WhiteboardPayload::Data:
- onElementReceived(payload->getElement());
+ //onElementReceived(payload->getElement());
+// onOperationReceived(payload->getOperation());
+ handleIncomingOperation(payload->getOperation());
break;
case WhiteboardPayload::SessionAccept:
onRequestAccepted(toJID_);
@@ -42,6 +44,20 @@ namespace Swift {
request->send();
}
+ void WhiteboardSession::sendOperation(const WhiteboardOperation::ref operation) {
+/* boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>();
+ // payload->setElement(operation->getElement());
+ payload->setOperation(operation);
+ boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
+ request->send();*/
+ handleSendOperationRequest(operation);
+ }
+
+ void WhiteboardSession::sendPayload(boost::shared_ptr<WhiteboardPayload> payload) {
+ boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
+ request->send();
+ }
+
void WhiteboardSession::cancel() {
boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>(WhiteboardPayload::SessionTerminate);
boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
diff --git a/Swiften/Whiteboard/WhiteboardSession.h b/Swiften/Whiteboard/WhiteboardSession.h
index 0d10af3..7fb03e6 100644
--- a/Swiften/Whiteboard/WhiteboardSession.h
+++ b/Swiften/Whiteboard/WhiteboardSession.h
@@ -12,6 +12,7 @@
#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+#include <Swiften/Whiteboard/Operations/WhiteboardOperation.h>
namespace Swift {
class IQRouter;
@@ -27,18 +28,26 @@ namespace Swift {
virtual ~WhiteboardSession();
void handleIncomingAction(boost::shared_ptr<WhiteboardPayload> payload);
void sendElement(const WhiteboardElement::ref element);
+ void sendOperation(WhiteboardOperation::ref operation);
void cancel();
const JID& getTo() const;
virtual std::string getClientID() const = 0;
public:
- boost::signal< void(const WhiteboardElement::ref element)> onElementReceived;
+ boost::signal< void(const WhiteboardElement::ref element)> onElementReceived;
+ boost::signal< void(const WhiteboardOperation::ref operation)> onOperationReceived;
boost::signal< void(const JID& contact)> onSessionTerminateReceived;
boost::signal< void(const JID& contact)> onRequestAccepted;
boost::signal< void(const JID& contact)> onSessionCancelled;
boost::signal< void(const JID& contact)> onRequestRejected;
+ private:
+ virtual void handleIncomingOperation(WhiteboardOperation::ref operation) = 0;
+ virtual void handleSendOperationRequest(WhiteboardOperation::ref operation) = 0;
+
protected:
+ void sendPayload(boost::shared_ptr<WhiteboardPayload> payload);
+
JID toJID_;
IQRouter* router_;
};