summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-06-15 10:48:54 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-06-15 10:48:54 (GMT)
commit1dc6b7f7a3d96df848edad85c0d07d99340e3a3e (patch)
treedb68d9c342293b18ce982a1eccbebde307ad0773
parent70de68383506430c297056cd3389595fc696df1e (diff)
downloadswift-contrib-1dc6b7f7a3d96df848edad85c0d07d99340e3a3e.zip
swift-contrib-1dc6b7f7a3d96df848edad85c0d07d99340e3a3e.tar.bz2
Moved serialization of elements to WhiteboardSerializer
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp9
-rw-r--r--Swiften/Elements/WhiteboardPayload.h11
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp27
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h14
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardElement.h21
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h17
-rw-r--r--Swiften/Whiteboard/Elements/WhiteboardLineElement.h47
-rw-r--r--Swiften/Whiteboard/IncomingWhiteboardSession.h4
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.cpp7
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.h2
10 files changed, 153 insertions, 6 deletions
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
index 3ea09ef..80c4447 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -9,9 +9,11 @@
#include <iostream>
#include <boost/bind.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Whiteboard/WhiteboardSession.h>
#include <Swiften/Elements/WhiteboardPayload.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h>
#include <QMessageBox>
using namespace std;
@@ -245,10 +247,13 @@ namespace Swift {
QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
if (lineItem != 0) {
QLine line = lineItem->line().toLine();
- std::stringstream stream;
+/* std::stringstream stream;
stream << "L";
stream << line.x1() << "," << line.y1() << "," << line.x2() << "," << line.y2();
- stream >> serialized;
+ stream >> serialized;*/
+ WhiteboardLineElement::ref element = boost::make_shared<WhiteboardLineElement>(line.x1(), line.y1(), line.x2(), line.y2());
+ whiteboardSession_->sendElement(element);
+
}
FreehandLineItem* freehandLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
if (freehandLineItem != 0) {
diff --git a/Swiften/Elements/WhiteboardPayload.h b/Swiften/Elements/WhiteboardPayload.h
index 3ad1706..c61e4a5 100644
--- a/Swiften/Elements/WhiteboardPayload.h
+++ b/Swiften/Elements/WhiteboardPayload.h
@@ -9,12 +9,14 @@
#include <string>
#include <Swiften/Elements/Payload.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
namespace Swift {
class WhiteboardPayload : public Payload {
public:
typedef boost::shared_ptr<WhiteboardPayload> ref;
+ public:
enum Type {Data, SessionRequest, SessionAccept, SessionTerminate};
WhiteboardPayload(Type type = WhiteboardPayload::Data) : type_(type) {
@@ -36,8 +38,17 @@ namespace Swift {
type_ = type;
}
+ WhiteboardElement::ref getElement() const {
+ return element_;
+ }
+
+ void setElement(WhiteboardElement::ref element) {
+ element_ = element;
+ }
+
private:
std::string data_;
Type type_;
+ WhiteboardElement::ref element_;
};
}
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
index 578b0ab..def21b1 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp
@@ -5,13 +5,36 @@
*/
#include <Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h>
-#include <Swiften/Serializer/XML/XMLElement.h>
+
+#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Serializer/XML/XMLTextNode.h>
namespace Swift {
+ void WhiteboardElementSerializingVisitor::visit(const WhiteboardLineElement* line) {
+ element = boost::make_shared<XMLElement>("line");
+ element->setAttribute("x1", intToStr(line->x1()));
+ element->setAttribute("y1", intToStr(line->y1()));
+ element->setAttribute("x2", intToStr(line->x2()));
+ element->setAttribute("y2", intToStr(line->y2()));
+ }
+
+ std::string WhiteboardElementSerializingVisitor::intToStr(const int t) {
+ std::stringstream ss;
+ ss << t;
+ return ss.str();
+ }
+
+ XMLElement::ref WhiteboardElementSerializingVisitor::getResult() const {
+ return element;
+ }
+
std::string WhiteboardSerializer::serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const {
XMLElement element("wb");
- element.addNode(XMLTextNode::ref(new XMLTextNode(payload->getData())));
+ if (payload->getType() == WhiteboardPayload::Data) {
+ WhiteboardElementSerializingVisitor visitor;
+ payload->getElement()->accept(visitor);
+ element.addNode(visitor.getResult());
+ }
element.setAttribute("type", typeToString(payload->getType()));
return element.serialize();
}
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
index 975d537..219ebcc 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
@@ -7,9 +7,23 @@
#pragma once
#include <Swiften/Elements/WhiteboardPayload.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h>
#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
namespace Swift {
+ class WhiteboardElementSerializingVisitor : public WhiteboardElementVisitor {
+ public:
+ void visit(const WhiteboardLineElement* line);
+ XMLElement::ref getResult() const;
+
+ private:
+ std::string intToStr(const int t);
+
+ XMLElement::ref element;
+ };
+
class WhiteboardSerializer : public GenericPayloadSerializer<WhiteboardPayload> {
public:
std::string serializePayload(boost::shared_ptr<WhiteboardPayload> payload) const;
diff --git a/Swiften/Whiteboard/Elements/WhiteboardElement.h b/Swiften/Whiteboard/Elements/WhiteboardElement.h
new file mode 100644
index 0000000..5095506
--- /dev/null
+++ b/Swiften/Whiteboard/Elements/WhiteboardElement.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+#include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h>
+
+namespace Swift {
+ class WhiteboardElement {
+ public:
+ typedef boost::shared_ptr<WhiteboardElement> ref;
+
+ public:
+ virtual ~WhiteboardElement() {}
+ virtual void accept(WhiteboardElementVisitor& visitor) = 0;
+ };
+}
diff --git a/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h b/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h
new file mode 100644
index 0000000..b5fd546
--- /dev/null
+++ b/Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+namespace Swift {
+ class WhiteboardLineElement;
+
+ class WhiteboardElementVisitor {
+ public:
+ virtual ~WhiteboardElementVisitor() {}
+ virtual void visit(const WhiteboardLineElement* /*element*/) = 0;
+ };
+}
diff --git a/Swiften/Whiteboard/Elements/WhiteboardLineElement.h b/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
new file mode 100644
index 0000000..b64e397
--- /dev/null
+++ b/Swiften/Whiteboard/Elements/WhiteboardLineElement.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
+
+namespace Swift {
+ class WhiteboardLineElement : public WhiteboardElement {
+ public:
+ typedef boost::shared_ptr<WhiteboardLineElement> ref;
+ public:
+ WhiteboardLineElement(int x1, int y1, int x2, int y2) {
+ x1_ = x1;
+ y1_ = y1;
+ x2_ = x2;
+ y2_ = y2;
+ }
+
+ int x1() const {
+ return x1_;
+ }
+
+ int y1() const {
+ return y1_;
+ }
+
+ int x2() const {
+ return x2_;
+ }
+
+ int y2() const {
+ return y2_;
+ }
+
+ void accept(WhiteboardElementVisitor& visitor) {
+ visitor.visit(this);
+ }
+
+ private:
+ int x1_, y1_, x2_, y2_;
+ std::string id;
+ };
+}
diff --git a/Swiften/Whiteboard/IncomingWhiteboardSession.h b/Swiften/Whiteboard/IncomingWhiteboardSession.h
index 3b15a49..a0d0b49 100644
--- a/Swiften/Whiteboard/IncomingWhiteboardSession.h
+++ b/Swiften/Whiteboard/IncomingWhiteboardSession.h
@@ -4,12 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+#pragma once
+
#include <Swiften/Whiteboard/WhiteboardSession.h>
#include <boost/shared_ptr.hpp>
-#pragma once
-
namespace Swift {
class IncomingWhiteboardSession : public WhiteboardSession {
public:
diff --git a/Swiften/Whiteboard/WhiteboardSession.cpp b/Swiften/Whiteboard/WhiteboardSession.cpp
index bfef7c3..9e4fd9f 100644
--- a/Swiften/Whiteboard/WhiteboardSession.cpp
+++ b/Swiften/Whiteboard/WhiteboardSession.cpp
@@ -42,6 +42,13 @@ namespace Swift {
request->send();
}
+ void WhiteboardSession::sendElement(const WhiteboardElement::ref element) {
+ boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>();
+ payload->setElement(element);
+ 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 7aa67ca..fb4305c 100644
--- a/Swiften/Whiteboard/WhiteboardSession.h
+++ b/Swiften/Whiteboard/WhiteboardSession.h
@@ -11,6 +11,7 @@
#include <Swiften/JID/JID.h>
#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/Queries/GenericRequest.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardElement.h>
namespace Swift {
class IQRouter;
@@ -26,6 +27,7 @@ namespace Swift {
virtual ~WhiteboardSession();
void handleIncomingAction(boost::shared_ptr<WhiteboardPayload> payload);
void sendData(const std::string& data);
+ void sendElement(const WhiteboardElement::ref element);
void cancel();
const JID& getTo() const;