kandy

commanditem.cpp
1 /*
2  This file is part of Kandy.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <tqdom.h>
26 
27 #include <kdebug.h>
28 
29 #include "atcommand.h"
30 
31 #include "commanditem.h"
32 
33 CommandItem::CommandItem(TQListView *listView,ATCommand *command)
34  : TQListViewItem(listView)
35 {
36  mCommand = command;
37 
38  setItemText();
39 }
40 
41 CommandItem::~CommandItem()
42 {
43 }
44 
45 ATCommand *CommandItem::command()
46 {
47  return mCommand;
48 }
49 
50 void CommandItem::load(TQDomElement *c)
51 {
52  mCommand->setCmdName(c->attribute("name","unknown"));
53  mCommand->setCmdString(c->attribute("string","at"));
54  mCommand->setHexOutput(c->attribute("hexoutput","n") == "y");
55 
56  TQDomNode n = c->firstChild();
57  while(!n.isNull()) {
58  TQDomElement e = n.toElement();
59  if (!e.isNull()) {
60  ATParameter *p = new ATParameter;
61  p->setName(e.attribute("name","unnamed"));
62  p->setValue(e.attribute("value","0"));
63  p->setUserInput(e.attribute("userinput","n") == "y");
64 
65  mCommand->addParameter(p);
66  }
67  n = n.nextSibling();
68  }
69 
70  setItemText();
71 }
72 
73 void CommandItem::save(TQDomDocument *doc,TQDomElement *parent)
74 {
75  TQDomElement c = doc->createElement("command");
76  c.setAttribute("name",mCommand->cmdName());
77  c.setAttribute("string",mCommand->cmdString());
78  c.setAttribute("hexoutput",mCommand->hexOutput() ? "y" : "n");
79  parent->appendChild(c);
80 
81  TQPtrList<ATParameter> paras = mCommand->parameters();
82  for(uint i=0;i<paras.count();++i) {
83  saveParameter(paras.at(i),doc,&c);
84  }
85 }
86 
87 void CommandItem::saveParameter(ATParameter *p, TQDomDocument *doc,
88  TQDomElement *parent)
89 {
90  TQDomElement e = doc->createElement("parameter");
91  e.setAttribute("name",p->name());
92  e.setAttribute("value",p->value());
93  e.setAttribute("userinput",p->userInput() ? "y" : "n");
94  parent->appendChild(e);
95 }
96 
97 void CommandItem::setItemText()
98 {
99  setText(0,mCommand->cmdName());
100  setText(1,mCommand->cmdString());
101  setText(2,mCommand->hexOutput() ? "y" : "n");
102 }
This class provides an abstraction of an AT command.
Definition: atcommand.h:54