From: daleharvey Date: Tue, 15 Aug 2006 14:00:14 +0000 (+0000) Subject: inkboard-session now sends all changes to the document X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ea62aa3dbb676cf0bb7b01daef378985591bbc85;p=inkscape.git inkboard-session now sends all changes to the document --- diff --git a/src/jabber_whiteboard/Makefile_insert b/src/jabber_whiteboard/Makefile_insert index e5470c045..b4ac480de 100644 --- a/src/jabber_whiteboard/Makefile_insert +++ b/src/jabber_whiteboard/Makefile_insert @@ -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 \ diff --git a/src/jabber_whiteboard/defines.cpp b/src/jabber_whiteboard/defines.cpp index 8d9559c57..a8843b9e7 100644 --- a/src/jabber_whiteboard/defines.cpp +++ b/src/jabber_whiteboard/defines.cpp @@ -45,8 +45,23 @@ namespace Vars { "%6" ""); - const std::string PROTOCOL_MESSAGE("<%1><%2 />"); - const std::string NEW_MESSAGE("%4"); + const std::string PROTOCOL_MESSAGE( + "<%1><%2 />"); + + const std::string NEW_MESSAGE( + "%4"); + + const std::string CONFIGURE_MESSAGE( + ""); + + const std::string CONFIGURE_TEXT_MESSAGE( + "%3"); + + const std::string MOVE_MESSAGE( + ""); + + const std::string REMOVE_MESSAGE( + ""); } namespace State { diff --git a/src/jabber_whiteboard/defines.h b/src/jabber_whiteboard/defines.h index cff54916c..675e13136 100644 --- a/src/jabber_whiteboard/defines.h +++ b/src/jabber_whiteboard/defines.h @@ -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; + + + } diff --git a/src/jabber_whiteboard/inkboard-document.cpp b/src/jabber_whiteboard/inkboard-document.cpp index 521e8d1b4..60d4cdd27 100644 --- a/src/jabber_whiteboard/inkboard-document.cpp +++ b/src/jabber_whiteboard/inkboard-document.cpp @@ -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 diff --git a/src/jabber_whiteboard/inkboard-node.cpp b/src/jabber_whiteboard/inkboard-node.cpp index c7d325ab9..c463e461a 100644 --- a/src/jabber_whiteboard/inkboard-node.cpp +++ b/src/jabber_whiteboard/inkboard-node.cpp @@ -12,17 +12,44 @@ #include #include -#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 index 20787a597..000000000 --- a/src/jabber_whiteboard/inkboard-node.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Inkscape::Whiteboard::InkboardDocument - Inkboard document implementation - * - * Authors: - * Dale Harvey - * - * 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 - -#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 ea63c5f31..6601d5d87 100644 --- a/src/jabber_whiteboard/inkboard-session.cpp +++ b/src/jabber_whiteboard/inkboard-session.cpp @@ -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 old_content, Util::ptr_shared 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 old_value, Util::ptr_shared 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); + } } } diff --git a/src/jabber_whiteboard/inkboard-session.h b/src/jabber_whiteboard/inkboard-session.h index 4ade2ca32..10eeb6322 100644 --- a/src/jabber_whiteboard/inkboard-session.h +++ b/src/jabber_whiteboard/inkboard-session.h @@ -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"