mirror of
https://github.com/AntiMicroX/antimicrox.git
synced 2026-01-25 15:28:57 -05:00
Initial import of project into repository
This commit is contained in:
committed by
Travis Nickles
parent
26c56beeb6
commit
dd901c1918
136
xmlconfigreader.cpp
Normal file
136
xmlconfigreader.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
#include "xmlconfigreader.h"
|
||||
|
||||
XMLConfigReader::XMLConfigReader(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
fileName = QString(PadderCommon::configPath + "/dudeman.xml");
|
||||
configFile = new QFile(fileName);
|
||||
xml = new QXmlStreamReader();
|
||||
joystick = 0;
|
||||
}
|
||||
|
||||
void XMLConfigReader::setJoystick(Joystick *joystick)
|
||||
{
|
||||
this->joystick = joystick;
|
||||
}
|
||||
|
||||
void XMLConfigReader::setFileName(QString filename)
|
||||
{
|
||||
QFile *temp = new QFile(filename);
|
||||
if (temp->exists())
|
||||
{
|
||||
configFile = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete temp;
|
||||
temp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLConfigReader::configJoystick(Joystick *joystick)
|
||||
{
|
||||
this->joystick = joystick;
|
||||
read();
|
||||
}
|
||||
|
||||
bool XMLConfigReader::read()
|
||||
{
|
||||
if (configFile->exists() && joystick)
|
||||
{
|
||||
xml->clear();
|
||||
|
||||
if (!configFile->isOpen())
|
||||
{
|
||||
configFile->open(QFile::ReadOnly | QFile::Text);
|
||||
xml->setDevice(configFile);
|
||||
}
|
||||
|
||||
xml->readNextStartElement();
|
||||
if (xml->name() != "joystick")
|
||||
{
|
||||
xml->raiseError("Root node is not a joystick");
|
||||
}
|
||||
else
|
||||
{
|
||||
xml->readNextStartElement();
|
||||
}
|
||||
|
||||
while (!xml->atEnd())
|
||||
{
|
||||
if (xml->name() == "button" && xml->isStartElement())
|
||||
{
|
||||
int index = xml->attributes().value("index").toString().toInt();
|
||||
JoyButton *button = joystick->getJoyButton(index-1);
|
||||
if (button)
|
||||
{
|
||||
button->readConfig(xml);
|
||||
}
|
||||
else
|
||||
{
|
||||
xml->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
else if (xml->name() == "axis" && xml->isStartElement())
|
||||
{
|
||||
int index = xml->attributes().value("index").toString().toInt();
|
||||
JoyAxis *axis = joystick->getJoyAxis(index-1);
|
||||
if (axis)
|
||||
{
|
||||
axis->readConfig(xml);
|
||||
}
|
||||
else
|
||||
{
|
||||
xml->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
else if (xml->name() == "dpad" && xml->isStartElement())
|
||||
{
|
||||
int index = xml->attributes().value("index").toString().toInt();
|
||||
JoyDPad *dpad = joystick->getJoyDPad(index-1);
|
||||
if (dpad)
|
||||
{
|
||||
dpad->readConfig(xml);
|
||||
}
|
||||
else
|
||||
{
|
||||
xml->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If none of the above, skip the element
|
||||
xml->skipCurrentElement();
|
||||
}
|
||||
|
||||
xml->readNextStartElement();
|
||||
}
|
||||
|
||||
configFile->close();
|
||||
}
|
||||
|
||||
return !xml->error();
|
||||
}
|
||||
|
||||
XMLConfigReader::~XMLConfigReader()
|
||||
{
|
||||
if (configFile)
|
||||
{
|
||||
if (configFile->isOpen())
|
||||
{
|
||||
configFile->close();
|
||||
}
|
||||
|
||||
delete configFile;
|
||||
configFile = 0;
|
||||
}
|
||||
|
||||
if (xml)
|
||||
{
|
||||
delete xml;
|
||||
xml = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user