98 lines
3.7 KiB
C++
98 lines
3.7 KiB
C++
#include <QFileDialog>
|
|
#include <QFile>
|
|
#include <QXmlStreamReader>
|
|
#include <QMessageBox>
|
|
|
|
#include "settingsdialog.h"
|
|
#include "ui_settingsdialog.h"
|
|
|
|
settingsDialog::settingsDialog(QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::settingsDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
readXML();
|
|
connect(ui->choosePathButton,SIGNAL(clicked(QAbstractButton*)), this, SLOT(changeMediaPath()));
|
|
}
|
|
|
|
settingsDialog::~settingsDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void settingsDialog::readXML() {
|
|
// QFile xmlFile("conf.xml");
|
|
QFile* xmlFile = new QFile("conf.xlm");
|
|
Q_CHECK_PTR(xmlFile);
|
|
if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QMessageBox::critical(NULL,"Load XML File Problem",
|
|
"Couldn't open configuration file",
|
|
QMessageBox::Ok);
|
|
//return;
|
|
}
|
|
QXmlStreamReader* xmlReader = new QXmlStreamReader(xmlFile);
|
|
//Parse the XML until we reach end of it
|
|
while(!xmlReader->atEnd() && !xmlReader->hasError()) {
|
|
// 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() == "windowSettings") {
|
|
int version = xmlReader->attributes().value("fileVersion").toLocal8Bit().toInt();
|
|
if(version == 1) {
|
|
ui->winpositionx->setValue(xmlReader->attributes().value("XPos").toLocal8Bit().toInt());
|
|
ui->winpositiony->setValue(xmlReader->attributes().value("YPos").toLocal8Bit().toInt());
|
|
ui->winsizex->setValue(xmlReader->attributes().value("XSize").toLocal8Bit().toInt());
|
|
ui->winsizey->setValue(xmlReader->attributes().value("YSize").toLocal8Bit().toInt());
|
|
ui->fps->setValue(xmlReader->attributes().value("FPS").toLocal8Bit().toInt());
|
|
continue;
|
|
}
|
|
}
|
|
int counter = 0;
|
|
if(xmlReader->name() == "dmxSettings") {
|
|
int version = xmlReader->attributes().value("fileVersion").toLocal8Bit().toInt();
|
|
if(version == 1) {
|
|
// worker->m_layersNumber = xmlReader->attributes().value("layersNumber").toLocal8Bit().toInt();
|
|
emit pathChanged(xmlReader->attributes().value("path").toLocal8Bit());
|
|
continue;
|
|
}
|
|
}
|
|
// if (worker->m_layersNumber > MAX_SOURCE_DMX) {
|
|
// worker->m_layersNumber = MAX_SOURCE_DMX;
|
|
// }
|
|
QString add = "layer";
|
|
add.append(QString("%1").arg(counter));
|
|
if((xmlReader->name() == add)/* && (counter < worker->m_layersNumber)*/) {
|
|
emit dmxChanged(counter, (xmlReader->attributes().value("dmx").toLocal8Bit().toInt() - 1),xmlReader->attributes().value("universe").toLocal8Bit().toInt());
|
|
}
|
|
counter++;
|
|
}
|
|
}
|
|
if(xmlReader->hasError()) {
|
|
QMessageBox::critical(NULL,"xmlFile.xml Parse Error",xmlReader->errorString(), QMessageBox::Ok);
|
|
}
|
|
//close reader and flush file
|
|
xmlReader->clear();
|
|
xmlFile->close();
|
|
|
|
delete xmlReader;
|
|
delete xmlFile;
|
|
}
|
|
|
|
void settingsDialog::changeMediaPath(){
|
|
QFileDialog dialog(this);
|
|
dialog.setFileMode(QFileDialog::Directory);
|
|
QStringList fileNames;
|
|
if (!dialog.exec())
|
|
return;
|
|
fileNames = dialog.selectedFiles();
|
|
QString file = fileNames.at(0);
|
|
ui->currentPath->clear();
|
|
ui->currentPath->setText(file);
|
|
emit pathChanged(file);
|
|
// m_olaInterface->setPath(file); //Setear en olaInterface
|
|
}
|