Code

Changes to the document are registered through inkboard-session, inkboard-node extend...
authordaleharvey <daleharvey@users.sourceforge.net>
Sun, 13 Aug 2006 02:31:48 +0000 (02:31 +0000)
committerdaleharvey <daleharvey@users.sourceforge.net>
Sun, 13 Aug 2006 02:31:48 +0000 (02:31 +0000)
13 files changed:
src/jabber_whiteboard/Makefile_insert
src/jabber_whiteboard/defines.cpp
src/jabber_whiteboard/defines.h
src/jabber_whiteboard/inkboard-document.cpp
src/jabber_whiteboard/inkboard-document.h
src/jabber_whiteboard/inkboard-node.cpp [new file with mode: 0644]
src/jabber_whiteboard/inkboard-node.h [new file with mode: 0644]
src/jabber_whiteboard/inkboard-session.cpp
src/jabber_whiteboard/inkboard-session.h
src/jabber_whiteboard/keynode.cpp
src/jabber_whiteboard/keynode.h
src/jabber_whiteboard/message-utilities.cpp
src/jabber_whiteboard/message-utilities.h

index bea89e80378812ae59e48b43446ca40f12f3f92e..e5470c045657e622f05e206372bd2e73ccee810a 100644 (file)
@@ -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 \
index 725391deb8ab810ec7f525cdc6a2002b0a568f60..8d9559c570fce36522fac98c155ce99b406ac4d9 100644 (file)
@@ -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 {
index ade33cc786ce77235d9617a58202ab697c3b5b23..cff54916c38bbc735b8a0f392dbf2490cf2a0851 100644 (file)
@@ -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; 
index 644db8e2a3b1ca7d7f63a48e7cabbdee0b16eff6..521e8d1b4b897de157c15ad7e9374fc1a450f7ca 100644 (file)
@@ -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
index dfe001842d10959fcdc4d1ca83cc7c893d4721ec..45a4178d46cbd6671bda13eb45afb76a01f74b54 100644 (file)
@@ -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 (file)
index 0000000..c7d325a
--- /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
new file mode 100644 (file)
index 0000000..20787a5
--- /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 :
index e6ff67f4be6b7cbe873b70da0db252f7b35710d1..ea63c5f31e4c2e02b45b8f1225b431de91e71f22 100644 (file)
@@ -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) {
+
     }
 }
 
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
@@ -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;
 };
 
 }
index b338a91fe31dec552a4c07d7d93cc438592ad9b9..6f0a5226ff9841afa75fbdc23bed7cea8bb9df8c 100644 (file)
@@ -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);
index eb68f40b6af2b3771b28944fb391e50cda5edf59..f727219d5c249b54ed68d5d9642a39ccfeddb09d 100644 (file)
@@ -47,11 +47,12 @@ class KeyNodeTable
 public:
 
     KeyNodeTable()
-        {}
+        { this->counter = 0; }
 
     KeyNodeTable(const KeyNodeTable &other)
         {
         items = other.items;
+        this->counter = 0;
         }
 
     virtual ~KeyNodeTable()
index e18f27ae412cec9b2549cbaedfa049f8a95d559c..448cc23e16aa97db1a5f36a861f002e27577eb4c 100644 (file)
@@ -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;
 }
-
+*/
 
 }
 
index 2ea65acb85af84bca56ff23ec9cf733332899d2d..5ca07a398d5008e33d538072ba3dd3829c73a492 100644 (file)
@@ -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&);