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);
47 Glib::ustring tempParentKey = this->tracker->get(node->parent());
48 if(tempParentKey.size() < 1)
49 parentKey = Vars::DOCUMENT_ROOT_NODE;
50 else
51 parentKey = tempParentKey;
53 unsigned int index = node->position();
55 Message::Message nodeMessage = MessageUtilities::objectToString(node);
56 Message::Message message = String::ucompose(Vars::NEW_MESSAGE,parentKey,key,index,0,nodeMessage);
58 return message;
59 }
61 void
62 InkboardDocument::changeConfigureText(Glib::ustring target,
63 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,
79 unsigned int /*version*/,
80 Glib::ustring attribute,
81 Glib::ustring value)
82 {
83 XML::Node *node = this->tracker->get(target);
84 //unsigned int elementVersion = this->tracker->getVersion(node);
86 if(node)// && version == (elementVersion + 1))
87 {
88 this->tracker->incrementVersion(node);
89 this->tracker->addHistory(node, attribute, value.c_str());
91 if(attribute != "transform")
92 node->setAttribute(attribute.c_str(),value.c_str());
93 }
94 }
96 void
97 InkboardDocument::changeNew(Glib::ustring parentid, Glib::ustring id,
98 signed int /*index*/, Pedro::Element* data)
99 {
101 Glib::ustring name(data->getName());
103 if(name == "text")
104 {
105 XML::Node *parent = this->tracker->get(parentid);
106 XML::Node *node = new XML::TextNode(Util::share_string(data->getValue().c_str()), this);
108 if(parent && node)
109 {
110 this->tracker->put(id,node);
111 parent->appendChild(node);
112 }
113 }else
114 {
115 XML::Node *node = new XML::ElementNode(g_quark_from_string(name.c_str()), this);
116 this->tracker->put(id,node);
118 XML::Node *parent = (parentid != "ROOT")
119 ? this->tracker->get(parentid.c_str()) : this->root();
121 std::vector<Pedro::Attribute> attributes = data->getAttributes();
123 for (unsigned int i=0; i<attributes.size(); i++)
124 {
125 node->setAttribute(
126 (attributes[i].getName()).c_str(),
127 (attributes[i].getValue()).c_str());
128 }
130 if(parent != NULL)
131 parent->appendChild(node);
132 }
134 }
136 } // namespace Whiteboard
137 } // namespace Inkscape
140 /*
141 Local Variables:
142 mode:c++
143 c-file-style:"stroustrup"
144 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
145 indent-tabs-mode:nil
146 fill-column:99
147 End:
148 */
149 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :