kandy Library API Documentation

commanditem.cpp

00001 // $Id: commanditem.cpp,v 1.3 2001/09/14 06:57:29 mlaurent Exp $
00002 
00003 #include <qdom.h>
00004 
00005 #include <kdebug.h>
00006 
00007 #include "atcommand.h"
00008 
00009 #include "commanditem.h"
00010 
00011 CommandItem::CommandItem(QListView *listView,ATCommand *command)
00012   : QListViewItem(listView)
00013 {
00014   mCommand = command;
00015   
00016   setItemText();
00017 }
00018 
00019 CommandItem::~CommandItem()
00020 {
00021 }
00022 
00023 ATCommand *CommandItem::command()
00024 {
00025   return mCommand;
00026 }
00027 
00028 void CommandItem::load(QDomElement *c)
00029 {
00030   mCommand->setCmdName(c->attribute("name","unknown"));
00031   mCommand->setCmdString(c->attribute("string","at"));
00032   mCommand->setHexOutput(c->attribute("hexoutput","n") == "y");
00033 
00034   QDomNode n = c->firstChild();
00035   while(!n.isNull()) {
00036     QDomElement e = n.toElement();
00037     if (!e.isNull()) {
00038       ATParameter *p = new ATParameter;
00039       p->setName(e.attribute("name","unnamed"));
00040       p->setValue(e.attribute("value","0"));
00041       p->setUserInput(e.attribute("userinput","n") == "y");
00042 
00043       mCommand->addParameter(p);
00044     }
00045     n = n.nextSibling();
00046   }
00047 
00048   setItemText();
00049 }
00050 
00051 void CommandItem::save(QDomDocument *doc,QDomElement *parent)
00052 {
00053   QDomElement c = doc->createElement("command");
00054   c.setAttribute("name",mCommand->cmdName());
00055   c.setAttribute("string",mCommand->cmdString());
00056   c.setAttribute("hexoutput",mCommand->hexOutput() ? "y" : "n");
00057   parent->appendChild(c);
00058   
00059   QPtrList<ATParameter> paras = mCommand->parameters();
00060   for(uint i=0;i<paras.count();++i) {
00061     saveParameter(paras.at(i),doc,&c);
00062   }
00063 }
00064 
00065 void CommandItem::saveParameter(ATParameter *p, QDomDocument *doc,
00066                                 QDomElement *parent)
00067 {
00068   QDomElement e = doc->createElement("parameter");
00069   e.setAttribute("name",p->name());
00070   e.setAttribute("value",p->value());
00071   e.setAttribute("userinput",p->userInput() ? "y" : "n");
00072   parent->appendChild(e);
00073 }
00074 
00075 void CommandItem::setItemText()
00076 {
00077   setText(0,mCommand->cmdName());
00078   setText(1,mCommand->cmdString());
00079   setText(2,mCommand->hexOutput() ? "y" : "n");
00080 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:40:32 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001