96 lines
3.4 KiB
C++
96 lines
3.4 KiB
C++
#include "settings.h"
|
|
|
|
Settings::Settings(QObject *parent) :
|
|
QObject(parent)
|
|
{
|
|
readDefaultFile();
|
|
}
|
|
|
|
// Read the dmx settings for dmx.xml At the moment we need:
|
|
// - The path to the medias folder tree
|
|
// - The number of sources/layers controlled by DMX
|
|
// - The first DMX channel of each source/layer
|
|
// - The universe to bind in OLA
|
|
void Settings::readFromFile(QString file) {
|
|
|
|
QFile* xmlFile = new QFile(file);
|
|
if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QMessageBox::critical(NULL,"Load XML File Problem",
|
|
QString("Couldn't open %1 to load settings for olaInterface").arg(file),
|
|
QMessageBox::Ok);
|
|
return;
|
|
}
|
|
QXmlStreamReader* xmlReader = new QXmlStreamReader(xmlFile);
|
|
int counter = 0;
|
|
//Parse the XML until we reach end of it
|
|
while(!xmlReader->atEnd() && !xmlReader->hasError() && counter < LAYERS_NUMBER) {
|
|
// Read next element
|
|
QXmlStreamReader::TokenType token = xmlReader->readNext();
|
|
//If token is just StartDocument - go to next
|
|
if(token == QXmlStreamReader::StartDocument) {
|
|
continue;
|
|
}
|
|
//If token is StartElement - read it
|
|
if(token == QXmlStreamReader::StartElement) {
|
|
if(xmlReader->name() == "dmxSettings") {
|
|
int version = xmlReader->attributes().value("fileVersion").toLocal8Bit().toInt();
|
|
if(version == 1) {
|
|
int layers = xmlReader->attributes().value("layersNumber").toLocal8Bit().toInt();
|
|
emit layersNumber(layers);
|
|
MediaLibrary::getInstance()->setPath (xmlReader->attributes().value("path").toLocal8Bit());
|
|
continue;
|
|
}
|
|
}
|
|
QString add = "layer";
|
|
add.append(QString("%1").arg(counter));
|
|
if((xmlReader->name() == add)) {
|
|
dmxSetting temp;
|
|
temp.address = xmlReader->attributes().value("dmx").toLocal8Bit().toInt() - 1;
|
|
temp.universe = xmlReader->attributes().value("universe").toLocal8Bit().toInt();
|
|
temp.layer = counter;
|
|
emit DMXConf(temp);
|
|
}
|
|
counter++;
|
|
}
|
|
}
|
|
if(xmlReader->hasError()) {
|
|
QMessageBox::critical(NULL,"File xml Parse Error ", xmlReader->errorString(), QMessageBox::Ok);
|
|
}
|
|
//close reader and flush file
|
|
xmlReader->clear();
|
|
xmlFile->close();
|
|
|
|
delete xmlReader;
|
|
delete xmlFile;
|
|
}
|
|
|
|
/** Read the default file
|
|
*
|
|
*/
|
|
void Settings::readDefaultFile() {
|
|
readFromFile(DEFAULT_FILE);
|
|
}
|
|
|
|
void Settings::writeFile(QString filename)
|
|
{
|
|
/* QFile* xmlFile = new QFile(filename);
|
|
if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QMessageBox::critical(NULL,"Load XML File Problem",
|
|
QString("Couldn't open %1 to load settings for olaInterface").arg(file),
|
|
QMessageBox::Ok);
|
|
return;
|
|
}
|
|
QXmlStreamWriter* xmlWriter = new QXmlStreamWriter(xmlFile);
|
|
|
|
QXmlStreamWriter stream(&output);
|
|
stream.setAutoFormatting(true);
|
|
stream.writeStartDocument();
|
|
|
|
stream.writeStartElement("dmxSettings");
|
|
stream.writeAttribute("href", "http://qt.nokia.com/");
|
|
stream.writeTextElement("title", "Qt Home");
|
|
stream.writeEndElement();
|
|
|
|
stream.writeEndDocument();
|
|
*/
|
|
}
|