summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f118e9d)
raw | patch | inline | side by side (parent: f118e9d)
author | daleharvey <daleharvey@users.sourceforge.net> | |
Sun, 13 Aug 2006 02:31:48 +0000 (02:31 +0000) | ||
committer | daleharvey <daleharvey@users.sourceforge.net> | |
Sun, 13 Aug 2006 02:31:48 +0000 (02:31 +0000) |
13 files changed:
index bea89e80378812ae59e48b43446ca40f12f3f92e..e5470c045657e622f05e206372bd2e73ccee810a 100644 (file)
jabber_whiteboard/message-tags.h \
jabber_whiteboard/message-utilities.cpp \
jabber_whiteboard/message-utilities.h \
+ jabber_whiteboard/inkboard-node.cpp \
+ jabber_whiteboard/inkboard-node.h \
+ jabber_whiteboard/inkboard-session.cpp \
+ jabber_whiteboard/inkboard-session.h \
jabber_whiteboard/inkboard-document.cpp \
jabber_whiteboard/inkboard-document.h \
jabber_whiteboard/invitation-confirm-dialog.cpp \
index 725391deb8ab810ec7f525cdc6a2002b0a568f60..8d9559c570fce36522fac98c155ce99b406ac4d9 100644 (file)
namespace Vars {
+ const std::string DOCUMENT_ROOT_NODE("ROOT");
const std::string INKBOARD_XMLNS("http://inkscape.org/inkboard");
const std::string WHITEBOARD_MESSAGE(
"</message>");
const std::string PROTOCOL_MESSAGE("<%1><%2 /></%1>");
-
+ const std::string NEW_MESSAGE("<new parent=\"%1\" id=\"%2\" target=\"%3\">%4</new>");
}
namespace State {
index ade33cc786ce77235d9617a58202ab697c3b5b23..cff54916c38bbc735b8a0f392dbf2490cf2a0851 100644 (file)
namespace Vars {
+ extern const std::string DOCUMENT_ROOT_NODE;
extern const std::string INKBOARD_XMLNS;
extern const std::string WHITEBOARD_MESSAGE;
extern const std::string PROTOCOL_MESSAGE;
diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp
index 644db8e2a3b1ca7d7f63a48e7cabbdee0b16eff6..521e8d1b4b897de157c15ad7e9374fc1a450f7ca 100644 (file)
#include "xml/simple-session.h"
#include "jabber_whiteboard/inkboard-session.h"
+#include "jabber_whiteboard/message-utilities.h"
#include "jabber_whiteboard/defines.h"
#include "jabber_whiteboard/session-manager.h"
#include "jabber_whiteboard/node-tracker.h"
this->sm = &SessionManager::instance();
this->state = State::INITIAL;
_bindDocument(*this);
- _bindLogger(*(new XML::SimpleSession()));
+ _bindLogger(*(new InkboardSession(this)));
}
void
// Send Document
this->tracker = new KeyNodeTable();
- this->sendDocument();
+ this->sendDocument(this->root());
this->send(getRecipient(),Message::PROTOCOL, Message::DOCUMENT_END);
@@ -150,9 +151,22 @@ InkboardDocument::send(const Glib::ustring &destJid, Message::Wrapper &wrapper,
}
void
-InkboardDocument::sendDocument()
+InkboardDocument::sendDocument(Inkscape::XML::Node* root)
{
+ for(Inkscape::XML::Node *child = root->firstChild();child!=NULL;child=child->next())
+ {
+ Glib::ustring parentKey,tempParentKey,key;
+
+ this->addNodeToTracker(child);
+ Message::Message message = this->composeNewMessage(child);
+ this->send(this->getRecipient(),Message::NEW,message);
+
+ if(child->childCount() != 0)
+ {
+ sendDocument(child);
+ }
+ }
}
bool
@@ -229,6 +243,35 @@ InkboardDocument::handleState(State::SessionState expectedState, State::SessionS
return false;
}
+Glib::ustring
+InkboardDocument::addNodeToTracker(Inkscape::XML::Node *node)
+{
+ Glib::ustring key = this->tracker->generateKey(this->getRecipient());
+ this->tracker->put(key,node);
+ return key;
+}
+
+Message::Message
+InkboardDocument::composeNewMessage(Inkscape::XML::Node *node)
+{
+ Glib::ustring parentKey;
+ Glib::ustring key = this->tracker->get(node);
+ Inkscape::XML::Node *parent = node->parent();
+
+ Glib::ustring tempParentKey = this->tracker->get(node->parent());
+ if(tempParentKey.size() < 1)
+ parentKey = Vars::DOCUMENT_ROOT_NODE;
+ else
+ parentKey = tempParentKey;
+
+ unsigned int index = parent->_childPosition(*node);
+
+ Message::Message nodeMessage = MessageUtilities::objectToString(node);
+ Message::Message message = String::ucompose(Vars::NEW_MESSAGE,parentKey,key,index,nodeMessage);
+
+ return message;
+}
+
} // namespace Whiteboard
} // namespace Inkscape
index dfe001842d10959fcdc4d1ca83cc7c893d4721ec..45a4178d46cbd6671bda13eb45afb76a01f74b54 100644 (file)
namespace Whiteboard {
-
class InkboardDocument : public XML::SimpleNode, public XML::Document {
public:
return Inkscape::XML::DOCUMENT_NODE;
}
+ State::SessionState state;
+ KeyNodeTable *tracker;
+
void setRecipient(Glib::ustring const& val);
Glib::ustring getRecipient() const;
void recieve(Message::Wrapper &wrapper, Pedro::Element* data);
bool send(const Glib::ustring &destJid, Message::Wrapper &mwrapper, Message::Message &message);
- void sendDocument();
+ void sendDocument(Inkscape::XML::Node* root);
bool handleOutgoingState(Message::Wrapper &wrapper,Glib::ustring const& message);
bool handleIncomingState(Message::Wrapper &wrapper,Pedro::Element* data);
bool handleState(State::SessionState expectedState, State::SessionState newstate);
+ Glib::ustring addNodeToTracker(Inkscape::XML::Node* node);
+ Message::Message composeNewMessage(Inkscape::XML::Node *node);
+
protected:
/**
* Copy constructor.
SessionManager *sm;
State::SessionType sessionType;
- State::SessionState state;
Glib::ustring sessionId;
Glib::ustring recipient;
-
- KeyNodeTable *tracker;
};
}
diff --git a/src/jabber_whiteboard/inkboard-node.cpp b/src/jabber_whiteboard/inkboard-node.cpp
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * Inkscape::Whiteboard::InkboardDocument - Inkboard document implementation
+ *
+ * Authors:
+ * Dale Harvey <harveyd@gmail.com>
+ *
+ * Copyright (c) 2005 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <glib.h>
+#include <glibmm.h>
+
+#include "jabber_whiteboard/inkboard-node.h"
+
+
+namespace Inkscape {
+
+namespace Whiteboard {
+
+InkboardNode::InkboardNode(int code, Inkscape::XML::NodeType type) :
+ XML::SimpleNode(code), version(0), nodetype(type)
+{
+
+}
+
+} // namespace Whiteboard
+} // namespace Inkscape
+
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/jabber_whiteboard/inkboard-node.h b/src/jabber_whiteboard/inkboard-node.h
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+ * Inkscape::Whiteboard::InkboardDocument - Inkboard document implementation
+ *
+ * Authors:
+ * Dale Harvey <harveyd@gmail.com>
+ *
+ * Copyright (c) 2005 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef __INKSCAPE_WHITEBOARD_INKBOARDNODE_H__
+#define __INKSCAPE_WHITEBOARD_INKBOARDNODE_H__
+
+#include <glibmm.h>
+
+#include "document.h"
+#include "xml/document.h"
+#include "xml/simple-node.h"
+
+namespace Inkscape {
+
+namespace Whiteboard {
+
+class InkboardNode : public XML::SimpleNode {
+public:
+
+ explicit InkboardNode(int code, Inkscape::XML::NodeType type);
+
+ XML::NodeType type() const
+ {
+ return this->nodetype;
+ }
+
+protected:
+
+ /**
+ * Copy constructor.
+ *
+ * \param orig Instance to copy.
+ */
+ InkboardNode(InkboardNode const& orig, Inkscape::XML::NodeType type) :
+ XML::Node(), XML::SimpleNode(orig), version(0), nodetype(type) {}
+
+ XML::SimpleNode* _duplicate() const
+ {
+ return new InkboardNode(*this,this->nodetype);
+ }
+
+private:
+
+ unsigned int version;
+ Inkscape::XML::NodeType nodetype;
+};
+
+}
+
+}
+
+#endif
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/jabber_whiteboard/inkboard-session.cpp b/src/jabber_whiteboard/inkboard-session.cpp
index e6ff67f4be6b7cbe873b70da0db252f7b35710d1..ea63c5f31e4c2e02b45b8f1225b431de91e71f22 100644 (file)
#include <glib/gquark.h>
#include "jabber_whiteboard/inkboard-session.h"
+#include "jabber_whiteboard/inkboard-document.h"
+#include "jabber_whiteboard/inkboard-node.h"
+#include "jabber_whiteboard/defines.h"
#include "xml/node.h"
#include "xml/event.h"
void
InkboardSession::beginTransaction()
{
- g_assert(!_in_transaction);
- _in_transaction = true;
+ g_assert(!_in_transaction);
+ _in_transaction = true;
}
void
InkboardSession::rollback()
{
- g_assert(_in_transaction);
- _in_transaction = false;
+ g_assert(_in_transaction);
+ _in_transaction = false;
}
void
InkboardSession::commit()
{
- g_assert(_in_transaction);
- _in_transaction = false;
+ g_assert(_in_transaction);
+ _in_transaction = false;
}
XML::Event*
InkboardSession::commitUndoable()
{
- g_assert(_in_transaction);
- _in_transaction = false;
- return NULL;
+ g_assert(_in_transaction);
+ _in_transaction = false;
+ return NULL;
}
XML::Node*
InkboardSession::createElementNode(char const* name)
{
- g_log(NULL, G_LOG_LEVEL_DEBUG, "InkboardSession::createElementNode");
- return new XML::ElementNode(g_quark_from_string(name));
+ g_log(NULL, G_LOG_LEVEL_DEBUG, "InkboardSession::createElementNode");
+ return new InkboardNode(g_quark_from_string(name),Inkscape::XML::ELEMENT_NODE);
}
XML::Node*
InkboardSession::createTextNode(char const* content)
{
- g_log(NULL, G_LOG_LEVEL_DEBUG, "InkboardSession::createTextNode");
+ g_log(NULL, G_LOG_LEVEL_DEBUG, "InkboardSession::createTextNode");
return new XML::TextNode(Util::share_string(content));
}
XML::Node*
InkboardSession::createCommentNode(char const* content)
{
- g_log(NULL, G_LOG_LEVEL_DEBUG, "InkboardSession::createCommentNode");
+ g_log(NULL, G_LOG_LEVEL_DEBUG, "InkboardSession::createCommentNode");
return new XML::CommentNode(Util::share_string(content));
}
Node &child,
Node *prev)
{
- if (_in_transaction) {
+ if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
+ InkboardNode *node = dynamic_cast< InkboardNode* >((XML::Node *)&child);
+ if(node == NULL)
+ {
+ g_warning("non inkboard node");
+ return;
+ }
+
+ this->doc->addNodeToTracker(node);
+ Message::Message message = this->doc->composeNewMessage(node);
+
+ this->doc->send(this->doc->getRecipient(),Message::NEW,message);
}
}
Node &child,
Node *prev)
{
- if (_in_transaction) {
- }
+ if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
+ g_warning("child removed");
+ }
}
void InkboardSession::notifyChildOrderChanged(Node &parent,
Node *old_prev,
Node *new_prev)
{
- if (_in_transaction) {
+ if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
+ g_warning("child reordered");
}
}
void InkboardSession::notifyContentChanged(Node &node,
- Util::SharedCStringPtr old_content,
- Util::SharedCStringPtr new_content)
+ Util::ptr_shared<char> old_content,
+ Util::ptr_shared<char> new_content)
{
- if (_in_transaction) {
+ if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
+ g_warning("content changed");
}
}
void InkboardSession::notifyAttributeChanged(Node &node,
GQuark name,
- Util::SharedCStringPtr old_value,
- Util::SharedCStringPtr new_value)
+ Util::ptr_shared<char> old_value,
+ Util::ptr_shared<char> new_value)
{
- if (_in_transaction) {
+ if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
+
}
}
index 9b1209e050a47df4770db288e340757f520f8f15..4ade2ca32d3a37322ba60cf611d690deab9efcf2 100644 (file)
#include <glibmm.h>
#include <bitset>
+#include "gc-managed.h"
+
+#include "xml/session.h"
+#include "xml/transaction-logger.h"
+#include "xml/log-builder.h"
+#include "xml/node-observer.h"
+#include "xml/simple-session.h"
+
#include "pedro/pedroxmpp.h"
+
+#include "jabber_whiteboard/inkboard-document.h"
+#include "jabber_whiteboard/inkboard-node.h"
+
#include "jabber_whiteboard/defines.h"
-#include "xml/simple-session.h"
#include "util/share.h"
namespace Inkscape {
namespace Whiteboard {
-class InkboardSession : public GC::Managed<>,
- public XML::Session,
- public XML::TransactionLogger
+class InkboardDocument;
+
+class InkboardSession : public GC::Managed<>, public XML::Session,
+ public XML::TransactionLogger
{
public:
- InkboardSession() : _in_transaction(false) { }
- InkboardSession(Glib::ustring const& name) : _in_transaction(false), _name(name) { }
- virtual ~InkboardSession() { }
-
- /**
- * Returns the name of this session.
- * \return The name of this session.
- */
- virtual Glib::ustring getName() const
- { return _name; }
-
- /**
- * Sets the name of this session.
- *
- * \param val The name to use.
- */
- virtual void setName(const Glib::ustring &val)
- { _name = val; }
-
- /**
- * Returns status attributes of this session.
- *
- * \return Status of this session.
- */
- virtual std::bitset< NUM_FLAGS > const& getStatus() const
- {
- return status;
- }
+
+ InkboardSession() : _in_transaction(false) { }
+ InkboardSession(InkboardDocument *document) : _in_transaction(false), doc(document) {}
+ virtual ~InkboardSession() { }
//
// XML::TransactionLogger methods
XML::Node* createCommentNode(char const* content);
//
- // XML::NodeObserver methods
+ // XML::NodeObserver methodscd ../
// (inherited from XML::TransactionLogger)
//
void notifyChildAdded(Inkscape::XML::Node &parent, Inkscape::XML::Node &child, Inkscape::XML::Node *prev);
bool _in_transaction;
- std::bitset< NUM_FLAGS > status;
- Glib::ustring _name;
+ InkboardDocument *doc;
};
}
index b338a91fe31dec552a4c07d7d93cc438592ad9b9..6f0a5226ff9841afa75fbdc23bed7cea8bb9df8c 100644 (file)
else
iter++;
}
-
+
//add new
KeyNodePair pair(key, node);
items.push_back(pair);
index eb68f40b6af2b3771b28944fb391e50cda5edf59..f727219d5c249b54ed68d5d9642a39ccfeddb09d 100644 (file)
public:
KeyNodeTable()
- {}
+ { this->counter = 0; }
KeyNodeTable(const KeyNodeTable &other)
{
items = other.items;
+ this->counter = 0;
}
virtual ~KeyNodeTable()
diff --git a/src/jabber_whiteboard/message-utilities.cpp b/src/jabber_whiteboard/message-utilities.cpp
index e18f27ae412cec9b2549cbaedfa049f8a95d559c..448cc23e16aa97db1a5f36a861f002e27577eb4c 100644 (file)
#include "util/share.h"
#include "util/list.h"
+#include "util/ucompose.hpp"
#include "xml/node.h"
#include "xml/attribute-record.h"
// in the maps referenced by newidsbuf and newnodesbuf. Passing NULL as the message buffer has the same effect.
//
// only_collect_nodes defaults to false because most invocations of this method also use the message string.
+
+Glib::ustring
+MessageUtilities::objectToString(Inkscape::XML::Node *element)
+{
+ if(element->type() == Inkscape::XML::TEXT_NODE)
+ return String::ucompose("<text>%1</text>",element->content());
+
+ Glib::ustring attributes;
+
+ for ( Inkscape::Util::List<Inkscape::XML::AttributeRecord const>
+ iter = element->attributeList() ; iter ; ++iter )
+ {
+ attributes.append(g_quark_to_string(iter->key));
+ attributes.append("=\"");
+ attributes.append(iter->value);
+ attributes.append("\" ");
+ }
+
+ return String::ucompose("<%1 %2/>",element->name(),attributes);
+}
+/*
void
MessageUtilities::newObjectMessage(Glib::ustring &msgbuf,
KeyNodeTable& newnodesbuf,
parentid = parent.attribute("id");
if (prev != NULL) {
previd = prev->attribute("id");
- }*/
+ }
Glib::ustring parentid, previd, childid;
msgbuf = msgbuf + "<" + MESSAGE_OLDVAL + ">";
msgbuf += (*oldprevid);
msgbuf = msgbuf + "</" + MESSAGE_OLDVAL + ">";
- */
+
// <MESSAGE_NEWVAL>newprevid</MESSAGE_NEWVAL>
msgbuf = msgbuf + "<" + MESSAGE_NEWVAL + ">";
buf += "</" + tagname + ">";
return buf;
}
-
+*/
}
index 2ea65acb85af84bca56ff23ec9cf733332899d2d..5ca07a398d5008e33d538072ba3dd3829c73a492 100644 (file)
class MessageUtilities {
public:
// Message generation utilities
+ static Glib::ustring objectToString(Inkscape::XML::Node *element);
+/*
static void newObjectMessage(Glib::ustring &msgbuf,
KeyNodeTable& newnodesbuf,
NewChildObjectMessageList& childmsgbuf,
// Message tag generation utilities
static Glib::ustring makeTagWithContent(const Glib::ustring &tagname,
const Glib::ustring &content);
-
+*/
private:
// noncopyable, nonassignable
MessageUtilities(MessageUtilities const&);