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