~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/jabber_whiteboard/inkboard-node.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
11
 
 
12
#include <glib.h>
 
13
#include <glibmm.h>
 
14
 
 
15
#include "util/ucompose.hpp"
 
16
 
 
17
#include "pedro/pedrodom.h"
 
18
 
 
19
#include "xml/attribute-record.h"
 
20
#include "xml/element-node.h"
 
21
#include "xml/text-node.h"
 
22
 
 
23
#include "jabber_whiteboard/message-utilities.h"
 
24
#include "jabber_whiteboard/defines.h"
 
25
#include "jabber_whiteboard/inkboard-document.h"
 
26
 
 
27
 
 
28
namespace Inkscape {
 
29
 
 
30
namespace Whiteboard {
 
31
 
 
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
}
 
40
 
 
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();
 
47
 
 
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;
 
53
 
 
54
    unsigned int index = parent->_childPosition(*node);
 
55
 
 
56
    Message::Message nodeMessage = MessageUtilities::objectToString(node);
 
57
    Message::Message message = String::ucompose(Vars::NEW_MESSAGE,parentKey,key,index,0,nodeMessage);
 
58
 
 
59
    return message;
 
60
}
 
61
 
 
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);
 
68
 
 
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
}
 
76
 
 
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);
 
83
 
 
84
    if(node)// && version == (elementVersion + 1))
 
85
    {
 
86
        this->tracker->incrementVersion(node);
 
87
        this->tracker->addHistory(node, attribute, value.c_str());
 
88
 
 
89
        if(attribute != "transform")
 
90
            node->setAttribute(attribute.c_str(),value.c_str());
 
91
    }
 
92
}
 
93
 
 
94
void 
 
95
InkboardDocument::changeNew(Glib::ustring parentid, Glib::ustring id, 
 
96
        signed int index, Pedro::Element* data)
 
97
{
 
98
 
 
99
    Glib::ustring name(data->getName());
 
100
 
 
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()));
 
105
 
 
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);
 
115
 
 
116
        XML::Node *parent = (parentid != "ROOT") 
 
117
            ? this->tracker->get(parentid.c_str()) : this->root();
 
118
 
 
119
        std::vector<Pedro::Attribute> attributes = data->getAttributes();
 
120
 
 
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
        }
 
127
 
 
128
        if(parent != NULL)
 
129
            parent->appendChild(node);
 
130
    }
 
131
 
 
132
}
 
133
 
 
134
} // namespace Whiteboard
 
135
} // namespace Inkscape
 
136
 
 
137
 
 
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 :