20#include "xmlhandler.h"
28using namespace KoMacro;
36 class XMLHandler::Private
52 Private( Macro* const macro)
61 : d( new Private(macro) )
73 d->macro->clearItems();
77 if(element.tagName() != "macro") {
78 kdDebug() << TQString( "XMLHandler::parseXML() Invalid tagname \"%1\"").arg(element.tagName()) << endl;
85 if( element.attribute( "xmlversion") != "1"){
86 kdDebug() << TQString( "XMLHandler::parseXML() Invalid xml-version \"%1\"").arg(element.attribute( "xmlversion")) << endl;
95 for(TQDomNode itemnode = element.firstChild(); ! itemnode.isNull(); itemnode = itemnode.nextSibling()) {
97 if(itemnode.nodeName() == "item") {
99 const TQDomElement itemelem = itemnode.toElement();
102 TDESharedPtr<MacroItem> item = new MacroItem();
105 d->macro->addItem( item );
112 item->setAction(action);
116 item->setComment( itemelem.attribute( "comment") );
120 for(TQDomNode childnode = itemnode.firstChild(); ! childnode.isNull(); childnode = childnode.nextSibling()) {
122 if(childnode.nodeName() == "variable") {
124 const TQDomElement childelem = childnode.toElement();
127 const TQString name = childelem.attribute( "name");
129 const TQString value = childelem.text();
132 item->addVariable(name, value);
145 TQDomDocument document;
148 TQDomElement macroelem = document.createElement( "macro");
151 macroelem.setAttribute( "xmlversion", "1");
160 TQValueList<TDESharedPtr<MacroItem > > items = d->macro->items();
163 TQValueList<TDESharedPtr<MacroItem > >::ConstIterator it(items.constBegin()), end(items.constEnd());
165 for(;it != end; ++it) {
167 TDESharedPtr<MacroItem> item = *it;
174 TQDomElement itemelem = document.createElement( "item");
177 const TDESharedPtr<Action> action = item->action();
182 itemelem.setAttribute( "action", action->name());
187 TQMap<TQString, TDESharedPtr<Variable > > varmap = item->variables();
189 for(TQMap<TQString, TDESharedPtr<Variable > >::ConstIterator vit = varmap.constBegin(); vit != varmap.constEnd(); ++vit) {
190 const TDESharedPtr<Variable> v = vit.data();
197 TQDomElement varelement = document.createElement( "variable");
200 varelement.setAttribute( "name", vit.key());
203 varelement.appendChild(document.createTextNode(v->toString()));
206 itemelem.appendChild(varelement);
211 const TQString comment = item->comment();
212 if(! comment.isEmpty()) {
214 itemelem.setAttribute( "comment", item->comment());
219 macroelem.appendChild(itemelem);
The MacroItem class is an item in a Macro and represents one single execution step.
The Macro class implements all the action-handling.
TDESharedPtr< Action > action(const TQString &name) const
bool parseXML(const TQDomElement &element) Reads a given TQDomElement, extracts given Actions into the managed Macro-Instance.
~XMLHandler() Destructor to XMLHandler .
TQDomElement toXML() Converts the macro to a TQDomElement.
XMLHandler(Macro *const macro) Constructor to init a XMLHandler .
|