#include "settings.h" Settings *Settings::_instance = 0; Settings *Settings::getInstance() { if (_instance == 0) { _instance = new Settings(); Q_CHECK_PTR(_instance); } return _instance; } Settings::Settings(QObject *parent) : QObject(parent) { m_layersNumber = 0; m_ui = false; } // 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 // - Audio device id // - Show the Ui or not 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").arg(file), QMessageBox::Ok); // Instead exit give the oportunity to load another file or define the settings qCritical("Load XML File Problem"); exit(1); } QXmlStreamReader* xmlReader = new QXmlStreamReader(xmlFile); while(!xmlReader->atEnd() && !xmlReader->hasError()) { QXmlStreamReader::TokenType token = xmlReader->readNext(); if(token == QXmlStreamReader::StartDocument) { continue; } if(token == QXmlStreamReader::StartElement) { if(xmlReader->name() == "lmsAudio") { m_ui = xmlReader->attributes().value("ui").toLocal8Bit().toInt(); m_layersNumber = xmlReader->attributes().value("layersNumber").toLocal8Bit().toInt(); m_pathmedia = xmlReader->attributes().value("path").toLocal8Bit(); continue; } if(xmlReader->name() == "audioDevice") { m_audioDeviceQty = xmlReader->attributes().value("devicesNumber").toLocal8Bit().toInt(); for (uint i = 0; i < m_audioDeviceQty; i++) { m_audioDeviceId[i] = xmlReader->attributes().value(QString("id%1").arg(i)).toLocal8Bit().toInt(); } } if(xmlReader->name() == "layer") { dmxSetting temp; temp.address = xmlReader->attributes().value("dmx").toLocal8Bit().toInt() - 1; temp.universe = xmlReader->attributes().value("universe").toLocal8Bit().toInt(); temp.layer = xmlReader->attributes().value("id").toLocal8Bit().toInt(); m_settings.append(temp); if (!m_universe.contains(temp.universe)) { m_universe.insert(temp.universe); } } } } if(xmlReader->hasError()) { QMessageBox::critical(NULL,"File xml Parse Error ", xmlReader->errorString(), QMessageBox::Ok); qWarning("File xml Parse Error %s", xmlReader->errorString().toLatin1().constData()); // ToDo: manage this, open a dialog to load a new file. } xmlReader->clear(); xmlFile->close(); delete xmlReader; delete xmlFile; this->printSettings(); } void Settings::printSettings() { qInfo() << "Settings read;\nShow Ui:" << m_ui << "Layers:" << m_layersNumber << "Path:" << m_pathmedia <<"Audio Device qty:" << m_audioDeviceQty; for (uint i = 0; i < m_audioDeviceQty; i++) qInfo() << "Audio device id:" << m_audioDeviceId[i]; for (int i = 0; i < m_layersNumber; i++) qInfo() << "Layer:" << m_settings[i].layer << "Address:" << m_settings[i].address << "Universe:" << m_settings[i].universe; } void Settings::readFile() { readFromFile(DEFAULT_FILE); }