kandy

commanditem.cpp

00001 /*
00002     This file is part of Kandy.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qdom.h>
00026 
00027 #include <kdebug.h>
00028 
00029 #include "atcommand.h"
00030 
00031 #include "commanditem.h"
00032 
00033 CommandItem::CommandItem(QListView *listView,ATCommand *command)
00034   : QListViewItem(listView)
00035 {
00036   mCommand = command;
00037   
00038   setItemText();
00039 }
00040 
00041 CommandItem::~CommandItem()
00042 {
00043 }
00044 
00045 ATCommand *CommandItem::command()
00046 {
00047   return mCommand;
00048 }
00049 
00050 void CommandItem::load(QDomElement *c)
00051 {
00052   mCommand->setCmdName(c->attribute("name","unknown"));
00053   mCommand->setCmdString(c->attribute("string","at"));
00054   mCommand->setHexOutput(c->attribute("hexoutput","n") == "y");
00055 
00056   QDomNode n = c->firstChild();
00057   while(!n.isNull()) {
00058     QDomElement e = n.toElement();
00059     if (!e.isNull()) {
00060       ATParameter *p = new ATParameter;
00061       p->setName(e.attribute("name","unnamed"));
00062       p->setValue(e.attribute("value","0"));
00063       p->setUserInput(e.attribute("userinput","n") == "y");
00064 
00065       mCommand->addParameter(p);
00066     }
00067     n = n.nextSibling();
00068   }
00069 
00070   setItemText();
00071 }
00072 
00073 void CommandItem::save(QDomDocument *doc,QDomElement *parent)
00074 {
00075   QDomElement c = doc->createElement("command");
00076   c.setAttribute("name",mCommand->cmdName());
00077   c.setAttribute("string",mCommand->cmdString());
00078   c.setAttribute("hexoutput",mCommand->hexOutput() ? "y" : "n");
00079   parent->appendChild(c);
00080   
00081   QPtrList<ATParameter> paras = mCommand->parameters();
00082   for(uint i=0;i<paras.count();++i) {
00083     saveParameter(paras.at(i),doc,&c);
00084   }
00085 }
00086 
00087 void CommandItem::saveParameter(ATParameter *p, QDomDocument *doc,
00088                                 QDomElement *parent)
00089 {
00090   QDomElement e = doc->createElement("parameter");
00091   e.setAttribute("name",p->name());
00092   e.setAttribute("value",p->value());
00093   e.setAttribute("userinput",p->userInput() ? "y" : "n");
00094   parent->appendChild(e);
00095 }
00096 
00097 void CommandItem::setItemText()
00098 {
00099   setText(0,mCommand->cmdName());
00100   setText(1,mCommand->cmdString());
00101   setText(2,mCommand->hexOutput() ? "y" : "n");
00102 }
KDE Home | KDE Accessibility Home | Description of Access Keys