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, node->attribute(attribute.c_str()));
88 node->setAttribute(attribute.c_str(),value.c_str());
89 }
90 }
92 void
93 InkboardDocument::changeNew(Glib::ustring parentid, Glib::ustring id,
94 signed int index, Pedro::Element* data)
95 {
97 Glib::ustring name(data->getName());
99 if(name == "text")
100 {
101 XML::Node *parent = this->tracker->get(parentid);
102 XML::Node *node = new XML::TextNode(Util::share_string(data->getValue().c_str()));
104 if(parent && node)
105 {
106 this->tracker->put(id,node);
107 parent->appendChild(node);
108 }
109 }else
110 {
111 XML::Node *node = new XML::ElementNode(g_quark_from_string(name.c_str()));
112 this->tracker->put(id,node);
114 XML::Node *parent = (parentid != "ROOT")
115 ? this->tracker->get(parentid.c_str()) : this->root();
117 std::vector<Pedro::Attribute> attributes = data->getAttributes();
119 for (unsigned int i=0; i<attributes.size(); i++)
120 {
121 node->setAttribute(
122 (attributes[i].getName()).c_str(),
123 (attributes[i].getValue()).c_str());
124 }
126 if(parent != NULL)
127 parent->appendChild(node);
128 }
130 }
132 } // namespace Whiteboard
133 } // namespace Inkscape
136 /*
137 Local Variables:
138 mode:c++
139 c-file-style:"stroustrup"
140 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
141 indent-tabs-mode:nil
142 fill-column:99
143 End:
144 */
145 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :