27 #include <tqtextstream.h>
31 #include "atcommand.h"
33 #include "commandset.h"
35 CommandSet::CommandSet()
37 mList.setAutoDelete(
true);
40 CommandSet::~CommandSet()
44 void CommandSet::addCommand(
ATCommand *command)
46 mList.append(command);
49 void CommandSet::deleteCommand(
ATCommand *command)
51 mList.removeRef(command);
54 bool CommandSet::loadFile(
const TQString& filename)
58 TQDomDocument doc(
"Kandy");
60 if (!f.open(IO_ReadOnly))
62 if (!doc.setContent(&f)) {
68 TQDomNodeList commands = doc.elementsByTagName(
"command");
69 for(uint i=0;i<commands.count();++i) {
70 TQDomElement c = commands.item(i).toElement();
81 bool CommandSet::saveFile(
const TQString& filename)
83 kdDebug(5960) <<
"CommandSet::saveFile(): " << filename << endl;
85 TQDomDocument doc(
"Kandy");
86 TQDomElement set = doc.createElement(
"commandset");
89 for(uint i=0; i<mList.count();++i) {
90 saveCommand(mList.at(i),&doc,&set);
93 TQFile xmlfile(filename);
94 if (!xmlfile.open(IO_WriteOnly)) {
95 kdDebug(5960) <<
"Error opening file for write." << endl;
98 TQTextStream ts(&xmlfile);
99 doc.documentElement().save(ts,2);
105 void CommandSet::clear()
110 void CommandSet::loadCommand(
ATCommand *command,TQDomElement *c)
112 command->setCmdName(c->attribute(
"name",
"unknown"));
113 command->setCmdString(c->attribute(
"string",
"at"));
114 command->setHexOutput(c->attribute(
"hexoutput",
"n") ==
"y");
116 TQDomNode n = c->firstChild();
118 TQDomElement e = n.toElement();
120 ATParameter *p =
new ATParameter;
121 p->setName(e.attribute(
"name",
"unnamed"));
122 p->setValue(e.attribute(
"value",
"0"));
123 p->setUserInput(e.attribute(
"userinput",
"n") ==
"y");
125 command->addParameter(p);
131 void CommandSet::saveCommand(
ATCommand *command,TQDomDocument *doc,
132 TQDomElement *parent)
134 TQDomElement c = doc->createElement(
"command");
135 c.setAttribute(
"name",command->cmdName());
136 c.setAttribute(
"string",command->cmdString());
137 c.setAttribute(
"hexoutput",command->hexOutput() ?
"y" :
"n");
138 parent->appendChild(c);
140 TQPtrList<ATParameter> paras = command->parameters();
141 for(uint i=0;i<paras.count();++i) {
142 saveParameter(paras.at(i),doc,&c);
146 void CommandSet::saveParameter(ATParameter *p, TQDomDocument *doc,
147 TQDomElement *parent)
149 TQDomElement e = doc->createElement(
"parameter");
150 e.setAttribute(
"name",p->name());
151 e.setAttribute(
"value",p->value());
152 e.setAttribute(
"userinput",p->userInput() ?
"y" :
"n");
153 parent->appendChild(e);
This class provides an abstraction of an AT command.