This commit is contained in:
Max-Wilhelm Bruker
2009-10-30 13:18:25 +01:00
parent 1c2aa15b22
commit 6923c98dc2
12 changed files with 107 additions and 45 deletions

View File

@@ -11,47 +11,47 @@ ProtocolItem::ProtocolItem(const QString &_itemName)
{
}
bool ProtocolItem::read(QXmlStreamReader &xml)
bool ProtocolItem::read(QXmlStreamReader *xml)
{
while (!xml.atEnd()) {
xml.readNext();
if (xml.isStartElement()) {
qDebug() << "startElement: " << xml.name().toString();
} else if (xml.isEndElement()) {
qDebug() << "endElement: " << xml.name().toString();
if (xml.name() == getItemType()) {
while (!xml->atEnd()) {
xml->readNext();
if (xml->isStartElement()) {
qDebug() << "startElement: " << xml->name().toString();
} else if (xml->isEndElement()) {
qDebug() << "endElement: " << xml->name().toString();
if (xml->name() == getItemType()) {
extractParameters();
qDebug() << "FERTIG";
deleteLater();
return true;
} else {
QString tagName = xml.name().toString();
QString tagName = xml->name().toString();
if (!parameters.contains(tagName))
qDebug() << "unrecognized attribute";
else
parameters[tagName] = currentElementText;
}
} else if (xml.isCharacters() && !xml.isWhitespace()) {
currentElementText = xml.text().toString();
} else if (xml->isCharacters() && !xml->isWhitespace()) {
currentElementText = xml->text().toString();
qDebug() << "text: " << currentElementText;
}
}
return false;
}
void ProtocolItem::write(QXmlStreamWriter &xml)
void ProtocolItem::write(QXmlStreamWriter *xml)
{
xml.writeStartElement(getItemType());
xml->writeStartElement(getItemType());
if (!itemName.isEmpty())
xml.writeAttribute("name", itemName);
xml->writeAttribute("name", itemName);
QMapIterator<QString, QString> i(parameters);
while (i.hasNext()) {
i.next();
xml.writeTextElement(i.key(), i.value());
xml->writeTextElement(i.key(), i.value());
}
xml.writeEndElement();
xml->writeEndElement();
}
ProtocolItem *ProtocolItem::getNewItem(const QString &name)
@@ -118,6 +118,11 @@ void ProtocolResponse::initializeHash()
responseHash.insert("spectators_not_allowed", RespSpectatorsNotAllowed);
}
GenericEvent::GenericEvent(const QString &_eventName)
: ProtocolItem(_eventName)
{
}
void GameEvent::extractParameters()
{
bool ok;