1 /**
2 * Inkscape::Whiteboard::InkboardDocument - Inkboard document implementation
3 *
4 * Authors:
5 * Dale Harvey <harveyd@gmail.com>
6 *
7 * Copyright (c) 2005 Authors
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #include <glib.h>
13 #include <glibmm.h>
15 #include "util/ucompose.hpp"
17 #include "pedro/pedrodom.h"
19 #include "xml/attribute-record.h"
20 #include "xml/element-node.h"
21 #include "xml/text-node.h"
23 #include "jabber_whiteboard/message-utilities.h"
24 #include "jabber_whiteboard/defines.h"
25 #include "jabber_whiteboard/inkboard-document.h"
28 namespace Inkscape {
30 namespace Whiteboard {
32 Glib::ustring
33 InkboardDocument::addNodeToTracker(Inkscape::XML::Node *node)
34 {
35 Glib::ustring rec = this->getRecipient();
36 Glib::ustring key = this->tracker->generateKey(rec);
37 this->tracker->put(key,node);
38 return key;
39 }
41 Message::Message
42 InkboardDocument::composeNewMessage(Inkscape::XML::Node *node)
43 {
44 Glib::ustring parentKey;
45 Glib::ustring key = this->tracker->get(node);
46 Inkscape::XML::Node *parent = node->parent();
48 Glib::ustring tempParentKey = this->tracker->get(node->parent());
49 if(tempParentKey.size() < 1)
50 parentKey = Vars::DOCUMENT_ROOT_NODE;
51 else
52 parentKey = tempParentKey;
54 unsigned int index = parent->_childPosition(*node);
56 Message::Message nodeMessage = MessageUtilities::objectToString(node);
57 Message::Message message = String::ucompose(Vars::NEW_MESSAGE,parentKey,key,index,0,nodeMessage);
59 return message;
60 }
62 void
63 InkboardDocument::changeConfigureText(Glib::ustring target, unsigned int version,
64 Glib::ustring text)
65 {
66 XML::Node *node = this->tracker->get(target);
67 unsigned int elementVersion = this->tracker->getVersion(node);
69 if(node)// && version == (elementVersion + 1))
70 {
71 this->tracker->incrementVersion(node);
72 this->tracker->addHistory(node, "text", text);
73 node->setContent(text.c_str());
74 }
75 }
77 void
78 InkboardDocument::changeConfigure(Glib::ustring target, unsigned int version,
79 Glib::ustring attribute, Glib::ustring value)
80 {
81 XML::Node *node = this->tracker->get(target);
82 unsigned int elementVersion = this->tracker->getVersion(node);
84 if(node)// && version == (elementVersion + 1))
85 {
86 this->tracker->incrementVersion(node);
87 this->tracker->addHistory(node, attribute, value.c_str());
89 if(attribute != "transform")
90 node->setAttribute(attribute.c_str(),value.c_str());
91 }
92 }
94 void
95 InkboardDocument::changeNew(Glib::ustring parentid, Glib::ustring id,
96 signed int index, Pedro::Element* data)
97 {
99 Glib::ustring name(data->getName());
101 if(name == "text")
102 {
103 XML::Node *parent = this->tracker->get(parentid);
104 XML::Node *node = new XML::TextNode(Util::share_string(data->getValue().c_str()));
106 if(parent && node)
107 {
108 this->tracker->put(id,node);
109 parent->appendChild(node);
110 }
111 }else
112 {
113 XML::Node *node = new XML::ElementNode(g_quark_from_string(name.c_str()));
114 this->tracker->put(id,node);
116 XML::Node *parent = (parentid != "ROOT")
117 ? this->tracker->get(parentid.c_str()) : this->root();
119 std::vector<Pedro::Attribute> attributes = data->getAttributes();
121 for (unsigned int i=0; i<attributes.size(); i++)
122 {
123 node->setAttribute(
124 (attributes[i].getName()).c_str(),
125 (attributes[i].getValue()).c_str());
126 }
128 if(parent != NULL)
129 parent->appendChild(node);
130 }
132 }
134 } // namespace Whiteboard
135 } // namespace Inkscape
138 /*
139 Local Variables:
140 mode:c++
141 c-file-style:"stroustrup"
142 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
143 indent-tabs-mode:nil
144 fill-column:99
145 End:
146 */
147 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :