summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authordaleharvey <daleharvey@users.sourceforge.net>2006-08-13 02:31:48 +0000
committerdaleharvey <daleharvey@users.sourceforge.net>2006-08-13 02:31:48 +0000
commitdd377b852d0024b927084c96e632a7a1d0687b6a (patch)
treef6828df98136c428613734f5ef9180f4d6e4139f /src
parentseparate invariant check from main logic for clarity (diff)
downloadinkscape-dd377b852d0024b927084c96e632a7a1d0687b6a.tar.gz
inkscape-dd377b852d0024b927084c96e632a7a1d0687b6a.zip
Changes to the document are registered through inkboard-session, inkboard-node extends simplenode and allows us to store whiteboard specific information for each node
(bzr r1593)
Diffstat (limited to 'src')
-rw-r--r--src/jabber_whiteboard/Makefile_insert4
-rw-r--r--src/jabber_whiteboard/defines.cpp3
-rw-r--r--src/jabber_whiteboard/defines.h1
-rw-r--r--src/jabber_whiteboard/inkboard-document.cpp49
-rw-r--r--src/jabber_whiteboard/inkboard-document.h12
-rw-r--r--src/jabber_whiteboard/inkboard-node.cpp41
-rw-r--r--src/jabber_whiteboard/inkboard-node.h71
-rw-r--r--src/jabber_whiteboard/inkboard-session.cpp64
-rw-r--r--src/jabber_whiteboard/inkboard-session.h57
-rw-r--r--src/jabber_whiteboard/keynode.cpp2
-rw-r--r--src/jabber_whiteboard/keynode.h3
-rw-r--r--src/jabber_whiteboard/message-utilities.cpp28
-rw-r--r--src/jabber_whiteboard/message-utilities.h4
13 files changed, 266 insertions, 73 deletions
diff --git a/src/jabber_whiteboard/Makefile_insert b/src/jabber_whiteboard/Makefile_insert
index bea89e803..e5470c045 100644
--- a/src/jabber_whiteboard/Makefile_insert
+++ b/src/jabber_whiteboard/Makefile_insert
@@ -23,6 +23,10 @@ jabber_whiteboard_SOURCES = \
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 \
diff --git a/src/jabber_whiteboard/defines.cpp b/src/jabber_whiteboard/defines.cpp
index 725391deb..8d9559c57 100644
--- a/src/jabber_whiteboard/defines.cpp
+++ b/src/jabber_whiteboard/defines.cpp
@@ -37,6 +37,7 @@ namespace Message {
namespace Vars {
+ const std::string DOCUMENT_ROOT_NODE("ROOT");
const std::string INKBOARD_XMLNS("http://inkscape.org/inkboard");
const std::string WHITEBOARD_MESSAGE(
@@ -45,7 +46,7 @@ namespace Vars {
"</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 {
diff --git a/src/jabber_whiteboard/defines.h b/src/jabber_whiteboard/defines.h
index ade33cc78..cff54916c 100644
--- a/src/jabber_whiteboard/defines.h
+++ b/src/jabber_whiteboard/defines.h
@@ -87,6 +87,7 @@ namespace Message {
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 644db8e2a..521e8d1b4 100644
--- a/src/jabber_whiteboard/inkboard-document.cpp
+++ b/src/jabber_whiteboard/inkboard-document.cpp
@@ -19,6 +19,7 @@
#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"
@@ -39,7 +40,7 @@ InkboardDocument::_initBindings()
this->sm = &SessionManager::instance();
this->state = State::INITIAL;
_bindDocument(*this);
- _bindLogger(*(new XML::SimpleSession()));
+ _bindLogger(*(new InkboardSession(this)));
}
void
@@ -107,7 +108,7 @@ InkboardDocument::recieve(Message::Wrapper &wrapper, Pedro::Element* data)
// 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
diff --git a/src/jabber_whiteboard/inkboard-document.h b/src/jabber_whiteboard/inkboard-document.h
index dfe001842..45a4178d4 100644
--- a/src/jabber_whiteboard/inkboard-document.h
+++ b/src/jabber_whiteboard/inkboard-document.h
@@ -25,7 +25,6 @@ namespace Inkscape {
namespace Whiteboard {
-
class InkboardDocument : public XML::SimpleNode, public XML::Document {
public:
@@ -36,6 +35,9 @@ public:
return Inkscape::XML::DOCUMENT_NODE;
}
+ State::SessionState state;
+ KeyNodeTable *tracker;
+
void setRecipient(Glib::ustring const& val);
Glib::ustring getRecipient() const;
@@ -48,13 +50,16 @@ public:
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.
@@ -79,12 +84,9 @@ private:
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
new file mode 100644
index 000000000..c7d325ab9
--- /dev/null
+++ b/src/jabber_whiteboard/inkboard-node.cpp
@@ -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
new file mode 100644
index 000000000..20787a597
--- /dev/null
+++ b/src/jabber_whiteboard/inkboard-node.h
@@ -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 e6ff67f4b..ea63c5f31 100644
--- a/src/jabber_whiteboard/inkboard-session.cpp
+++ b/src/jabber_whiteboard/inkboard-session.cpp
@@ -14,6 +14,9 @@
#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"
@@ -32,50 +35,50 @@ using XML::Node;
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));
}
@@ -84,8 +87,19 @@ void InkboardSession::notifyChildAdded(Node &parent,
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);
}
}
@@ -93,8 +107,9 @@ void InkboardSession::notifyChildRemoved(Node &parent,
Node &child,
Node *prev)
{
- if (_in_transaction) {
- }
+ if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
+ g_warning("child removed");
+ }
}
void InkboardSession::notifyChildOrderChanged(Node &parent,
@@ -102,24 +117,27 @@ 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) {
+
}
}
diff --git a/src/jabber_whiteboard/inkboard-session.h b/src/jabber_whiteboard/inkboard-session.h
index 9b1209e05..4ade2ca32 100644
--- a/src/jabber_whiteboard/inkboard-session.h
+++ b/src/jabber_whiteboard/inkboard-session.h
@@ -15,49 +15,37 @@
#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
@@ -86,7 +74,7 @@ public:
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);
@@ -111,8 +99,7 @@ private:
bool _in_transaction;
- std::bitset< NUM_FLAGS > status;
- Glib::ustring _name;
+ InkboardDocument *doc;
};
}
diff --git a/src/jabber_whiteboard/keynode.cpp b/src/jabber_whiteboard/keynode.cpp
index b338a91fe..6f0a5226f 100644
--- a/src/jabber_whiteboard/keynode.cpp
+++ b/src/jabber_whiteboard/keynode.cpp
@@ -47,7 +47,7 @@ void KeyNodeTable::put(const Glib::ustring &key, const XML::Node *node)
else
iter++;
}
-
+
//add new
KeyNodePair pair(key, node);
items.push_back(pair);
diff --git a/src/jabber_whiteboard/keynode.h b/src/jabber_whiteboard/keynode.h
index eb68f40b6..f727219d5 100644
--- a/src/jabber_whiteboard/keynode.h
+++ b/src/jabber_whiteboard/keynode.h
@@ -47,11 +47,12 @@ class KeyNodeTable
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 e18f27ae4..448cc23e1 100644
--- a/src/jabber_whiteboard/message-utilities.cpp
+++ b/src/jabber_whiteboard/message-utilities.cpp
@@ -14,6 +14,7 @@
#include "util/share.h"
#include "util/list.h"
+#include "util/ucompose.hpp"
#include "xml/node.h"
#include "xml/attribute-record.h"
@@ -37,6 +38,27 @@ namespace Whiteboard {
// 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,
@@ -271,7 +293,7 @@ MessageUtilities::objectDeleteMessage(Glib::ustring &msgbuf,
parentid = parent.attribute("id");
if (prev != NULL) {
previd = prev->attribute("id");
- }*/
+ }
Glib::ustring parentid, previd, childid;
@@ -361,7 +383,7 @@ MessageUtilities::childOrderChangeMessage(Glib::ustring& msgbuf,
msgbuf = msgbuf + "<" + MESSAGE_OLDVAL + ">";
msgbuf += (*oldprevid);
msgbuf = msgbuf + "</" + MESSAGE_OLDVAL + ">";
- */
+
// <MESSAGE_NEWVAL>newprevid</MESSAGE_NEWVAL>
msgbuf = msgbuf + "<" + MESSAGE_NEWVAL + ">";
@@ -451,7 +473,7 @@ MessageUtilities::makeTagWithContent(const Glib::ustring &tagname,
buf += "</" + tagname + ">";
return buf;
}
-
+*/
}
diff --git a/src/jabber_whiteboard/message-utilities.h b/src/jabber_whiteboard/message-utilities.h
index 2ea65acb8..5ca07a398 100644
--- a/src/jabber_whiteboard/message-utilities.h
+++ b/src/jabber_whiteboard/message-utilities.h
@@ -44,6 +44,8 @@ class XMLNodeTracker;
class MessageUtilities {
public:
// Message generation utilities
+ static Glib::ustring objectToString(Inkscape::XML::Node *element);
+/*
static void newObjectMessage(Glib::ustring &msgbuf,
KeyNodeTable& newnodesbuf,
NewChildObjectMessageList& childmsgbuf,
@@ -81,7 +83,7 @@ public:
// Message tag generation utilities
static Glib::ustring makeTagWithContent(const Glib::ustring &tagname,
const Glib::ustring &content);
-
+*/
private:
// noncopyable, nonassignable
MessageUtilities(MessageUtilities const&);