Code

inkboard-session now sends all changes to the document
authordaleharvey <daleharvey@users.sourceforge.net>
Tue, 15 Aug 2006 14:00:14 +0000 (14:00 +0000)
committerdaleharvey <daleharvey@users.sourceforge.net>
Tue, 15 Aug 2006 14:00:14 +0000 (14:00 +0000)
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-node.cpp
src/jabber_whiteboard/inkboard-node.h [deleted file]
src/jabber_whiteboard/inkboard-session.cpp
src/jabber_whiteboard/inkboard-session.h

index e5470c045657e622f05e206372bd2e73ccee810a..b4ac480dede3bd224635bb6447063df4c5b135fc 100644 (file)
@@ -24,7 +24,6 @@ jabber_whiteboard_SOURCES = \
        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 \
index 8d9559c570fce36522fac98c155ce99b406ac4d9..a8843b9e758f40331275480cbb49d45e66652b67 100644 (file)
@@ -45,8 +45,23 @@ namespace Vars {
             "<wb xmlns='%4' session='%5'>%6</wb>"
         "</message>"); 
 
-    const std::string PROTOCOL_MESSAGE("<%1><%2 /></%1>");
-    const std::string NEW_MESSAGE("<new parent=\"%1\" id=\"%2\" target=\"%3\">%4</new>");
+    const std::string PROTOCOL_MESSAGE(
+        "<%1><%2 /></%1>");
+
+    const std::string NEW_MESSAGE(
+        "<new parent=\"%1\" id=\"%2\" target=\"%3\">%4</new>");
+
+    const std::string CONFIGURE_MESSAGE(
+        "<configure target=\"%1\" version=\"%2\" attribute=\"%3\" value=\"%4\" />");
+
+    const std::string CONFIGURE_TEXT_MESSAGE(
+        "<configure target=\"%1\" version=\"%2\"><text>%3</text></configure>");
+
+    const std::string MOVE_MESSAGE(
+        "<move target=\"%1\" n=\"%2\" />");
+
+    const std::string REMOVE_MESSAGE(
+        "<remove target=\"%1\" />");
 }
 
 namespace State {
index cff54916c38bbc735b8a0f392dbf2490cf2a0851..675e1313615ad24158dbf5258e79c029560e0694 100644 (file)
@@ -88,10 +88,19 @@ 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; 
     extern const std::string NEW_MESSAGE; 
+    extern const std::string CONFIGURE_MESSAGE; 
+    extern const std::string CONFIGURE_TEXT_MESSAGE; 
+    extern const std::string MOVE_MESSAGE; 
+    extern const std::string REMOVE_MESSAGE; 
+
+
+
 
 }
 
index 521e8d1b4b897de157c15ad7e9374fc1a450f7ca..60d4cdd27e15c532339fe084d7f006b38bfbab0d 100644 (file)
@@ -14,7 +14,6 @@
 
 #include "jabber_whiteboard/inkboard-document.h"
 
-
 #include "util/ucompose.hpp"
 
 #include "xml/simple-session.h"
@@ -243,36 +242,6 @@ 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 c7d325ab99bb468fc3b73df6eb5a6d2e5bc9b0ee..c463e461a2013b5206aa1596e3c0da66208bf4fd 100644 (file)
 #include <glib.h>
 #include <glibmm.h>
 
-#include "jabber_whiteboard/inkboard-node.h"
+#include "util/ucompose.hpp"
+
+#include "jabber_whiteboard/message-utilities.h"
+#include "jabber_whiteboard/defines.h"
+#include "jabber_whiteboard/inkboard-document.h"
 
 
 namespace Inkscape {
 
 namespace Whiteboard {
 
-InkboardNode::InkboardNode(int code, Inkscape::XML::NodeType type) :
-       XML::SimpleNode(code), version(0), nodetype(type)
+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
diff --git a/src/jabber_whiteboard/inkboard-node.h b/src/jabber_whiteboard/inkboard-node.h
deleted file mode 100644 (file)
index 20787a5..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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 ea63c5f31e4c2e02b45b8f1225b431de91e71f22..6601d5d879b43ffe762eb346e79bbc8907f7d852 100644 (file)
@@ -15,7 +15,6 @@
 
 #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"
@@ -25,6 +24,7 @@
 #include "xml/comment-node.h"
 
 #include "util/share.h"
+#include "util/ucompose.hpp"
 
 namespace Inkscape {
 
@@ -64,21 +64,18 @@ InkboardSession::commitUndoable()
 XML::Node*
 InkboardSession::createElementNode(char const* name)
 {
-    g_log(NULL, G_LOG_LEVEL_DEBUG, "InkboardSession::createElementNode");
-    return new InkboardNode(g_quark_from_string(name),Inkscape::XML::ELEMENT_NODE);
+    return new XML::ElementNode(g_quark_from_string(name));
 }
 
 XML::Node*
 InkboardSession::createTextNode(char const* content)
 {
-    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");
     return new XML::CommentNode(Util::share_string(content));
 }
 
@@ -89,12 +86,7 @@ void InkboardSession::notifyChildAdded(Node &parent,
 {
     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;
-        }
+        XML::Node *node = (XML::Node *)&child;
 
         this->doc->addNodeToTracker(node);
         Message::Message message = this->doc->composeNewMessage(node);
@@ -107,8 +99,14 @@ void InkboardSession::notifyChildRemoved(Node &parent,
                                        Node &child,
                                        Node *prev)
 {
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
-        g_warning("child removed");
+    if (_in_transaction && doc->state == State::IN_WHITEBOARD) 
+    {
+        XML::Node *element = (XML::Node *)&child;
+
+        Message::Message message = String::ucompose(Vars::REMOVE_MESSAGE,
+            this->doc->tracker->get(element));
+
+        this->doc->send(this->doc->getRecipient(),Message::REMOVE,message);
    }
 }
 
@@ -117,8 +115,17 @@ void InkboardSession::notifyChildOrderChanged(Node &parent,
                                             Node *old_prev,
                                             Node *new_prev)
 {
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
-        g_warning("child reordered");
+    if (_in_transaction && doc->state == State::IN_WHITEBOARD) 
+    {
+        XML::Node *element = (XML::Node *)&child;
+        XML::Node *parentElement = (XML::Node *)&parent;
+
+        unsigned int index = parentElement->_childPosition(*element);
+
+        Message::Message message = String::ucompose(Vars::MOVE_MESSAGE,
+                this->doc->tracker->get(element),index);
+
+        this->doc->send(this->doc->getRecipient(),Message::MOVE,message);
     }
 }
 
@@ -126,8 +133,17 @@ void InkboardSession::notifyContentChanged(Node &node,
                                          Util::ptr_shared<char> old_content,
                                          Util::ptr_shared<char> new_content)
 {
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
-        g_warning("content changed");
+    if (_in_transaction && doc->state == State::IN_WHITEBOARD) 
+    {
+        XML::Node *element = (XML::Node *)&node;
+
+        if(new_content.pointer())
+        {
+            Message::Message message = String::ucompose(Vars::CONFIGURE_TEXT_MESSAGE,
+                this->doc->tracker->get(element),"0",new_content.pointer());
+
+            this->doc->send(this->doc->getRecipient(),Message::CONFIGURE,message);
+        }
     }
 }
 
@@ -136,8 +152,17 @@ void InkboardSession::notifyAttributeChanged(Node &node,
                                            Util::ptr_shared<char> old_value,
                                            Util::ptr_shared<char> new_value)
 {
-    if (_in_transaction && doc->state == State::IN_WHITEBOARD) {
+    if (_in_transaction && doc->state == State::IN_WHITEBOARD) 
+    {
+        XML::Node *element = (XML::Node *)&node;
+
+        if(name && new_value.pointer())
+        {
+            Message::Message message = String::ucompose(Vars::CONFIGURE_MESSAGE,
+                this->doc->tracker->get(element),"0",g_quark_to_string(name),new_value.pointer());
 
+            this->doc->send(this->doc->getRecipient(),Message::CONFIGURE,message);
+        }
     }
 }
 
index 4ade2ca32d3a37322ba60cf611d690deab9efcf2..10eeb63223674e24591eaf1fa438b313f403284f 100644 (file)
@@ -26,8 +26,6 @@
 #include "pedro/pedroxmpp.h"
 
 #include "jabber_whiteboard/inkboard-document.h"
-#include "jabber_whiteboard/inkboard-node.h"
-
 #include "jabber_whiteboard/defines.h"
 
 #include "util/share.h"