kexi

events.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqdom.h>
21#include <kdebug.h>
22
23#include "events.h"
24
25namespace KFormDesigner {
26
27Connection::Connection(const TQString &sender, const TQString &signal,
28 const TQString &receiver, const TQString &slot)
29{
30 m_sender = sender;
31 m_signal = signal;
32 m_receiver = receiver;
33 m_slot = slot;
34}
35
37
38ConnectionBuffer::ConnectionBuffer()
39{
40 setAutoDelete(true);
41}
42
43void
44ConnectionBuffer::fixName(const TQString &oldName, const TQString &newName)
45{
46 for(Connection *c = first(); c; c = next())
47 {
48 if(c->sender() == oldName)
49 c->setSender(newName);
50 if(c->receiver() == oldName)
51 c->setReceiver(newName);
52 }
53}
54
55ConnectionBuffer*
56ConnectionBuffer::allConnectionsForWidget(const TQString &widget)
57{
58 ConnectionBuffer *list = new ConnectionBuffer();
59 list->setAutoDelete(false); // or it will delete all our connections
60 for(Connection *c = first(); c; c = next())
61 {
62 if((c->sender() == widget) || (c->receiver() == widget))
63 list->append(c);
64 }
65
66 return list;
67}
68
69void
70ConnectionBuffer::save(TQDomNode &parentNode)
71{
72 if(isEmpty())
73 return;
74
75 TQDomDocument domDoc = parentNode.ownerDocument();
76 TQDomElement connections;
77 if(!parentNode.namedItem("connections").isNull())
78 connections = parentNode.namedItem("connections").toElement();
79 else
80 connections = domDoc.createElement("connections");
81 parentNode.appendChild(connections);
82
83 for(Connection *c = first(); c; c = next())
84 {
85 TQDomElement connection = domDoc.createElement("connection");
86 connection.setAttribute("language", "C++");
87 connections.appendChild(connection);
88
89 TQDomElement sender = domDoc.createElement("sender");
90 connection.appendChild(sender);
91 TQDomText senderText = domDoc.createTextNode(c->sender());
92 sender.appendChild(senderText);
93
94 TQDomElement signal = domDoc.createElement("signal");
95 connection.appendChild(signal);
96 TQDomText signalText = domDoc.createTextNode(c->signal());
97 signal.appendChild(signalText);
98
99 TQDomElement receiver = domDoc.createElement("receiver");
100 connection.appendChild(receiver);
101 TQDomText receiverText = domDoc.createTextNode(c->receiver());
102 receiver.appendChild(receiverText);
103
104 TQDomElement slot = domDoc.createElement("slot");
105 connection.appendChild(slot);
106 TQDomText slotText = domDoc.createTextNode(c->slot());
107 slot.appendChild(slotText);
108 }
109}
110
111void
112ConnectionBuffer::saveAllConnectionsForWidget(const TQString &widget, TQDomNode parentNode)
113{
114 ConnectionBuffer *buff = allConnectionsForWidget(widget);
115 buff->save(parentNode);
116 delete buff;
117}
118
119void
120ConnectionBuffer::load(TQDomNode node)
121{
122 for(TQDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
123 {
124 Connection *conn = new Connection();
125 conn->setSender(n.namedItem("sender").toElement().text());
126 conn->setSignal(n.namedItem("signal").toElement().text());
127 conn->setReceiver(n.namedItem("receiver").toElement().text());
128 conn->setSlot(n.namedItem("slot").toElement().text());
129 append(conn);
130 }
131}
132
133void
134ConnectionBuffer::removeAllConnectionsForWidget(const TQString &widget)
135{
136 for(Connection *c = first(); c; c = next())
137 {
138 if((c->sender() == widget) || (c->receiver() == widget))
139 removeRef(c);
140 }
141}
142
143}
144
145//#include "events.moc"