You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
2.7 KiB
138 lines
2.7 KiB
14 years ago
|
#include "calculateconfig.h"
|
||
|
|
||
|
#include <QProcess>
|
||
|
#include <QDebug>
|
||
|
|
||
|
#include <QtXml>
|
||
|
|
||
|
|
||
|
CalculateConfig* CalculateConfig::_instance = 0;
|
||
|
|
||
|
CalculateConfig::CalculateConfig()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
CalculateConfig::~CalculateConfig()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
CalculateConfig* CalculateConfig::instance()
|
||
|
{
|
||
|
if ( !_instance )
|
||
|
_instance = new CalculateConfig();
|
||
|
return _instance;
|
||
|
}
|
||
|
|
||
|
bool CalculateConfig::getDefaultConfig()
|
||
|
{
|
||
|
// start cl-install -v and parse out
|
||
|
QProcess cl_install;
|
||
|
|
||
|
qDebug() << "Start cl-install -v --xml";
|
||
|
cl_install.start("cl-install", QStringList() << "-v" << "--xml");
|
||
|
|
||
|
if ( !cl_install.waitForStarted() )
|
||
|
return false;
|
||
|
|
||
|
if ( !cl_install.waitForFinished() )
|
||
|
return false;
|
||
|
|
||
|
QString outVars = cl_install.readAll();
|
||
|
|
||
|
QDomDocument xmlVars;
|
||
|
QString errMsg;
|
||
|
int errLine;
|
||
|
int errColumn;
|
||
|
|
||
|
if ( xmlVars.setContent(outVars, true, &errMsg, &errLine, &errColumn) )
|
||
|
{
|
||
|
QDomElement domRoot = xmlVars.documentElement();
|
||
|
if (domRoot.tagName() == "variables") {
|
||
|
parseVariables(domRoot);
|
||
|
} else {
|
||
|
qDebug() << "Section \"variables\" not found";
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void CalculateConfig::parseVariables(const QDomNode& node)
|
||
|
{
|
||
|
QDomNode domNode = node.firstChild();
|
||
|
while ( !domNode.isNull() )
|
||
|
{
|
||
|
if ( domNode.isElement() )
|
||
|
{
|
||
|
QDomElement domElement = domNode.toElement();
|
||
|
if ( !domElement.isNull() )
|
||
|
{
|
||
|
if (domElement.tagName() == "var")
|
||
|
{
|
||
|
if (domElement.attribute("type") == "var")
|
||
|
{
|
||
|
parseVar(domElement);
|
||
|
}
|
||
|
else if (domElement.attribute("type") == "list")
|
||
|
{
|
||
|
parseVarList(domElement);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
domNode = domNode.nextSibling();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void CalculateConfig::parseVar(const QDomNode& node)
|
||
|
{
|
||
|
QString name = node.toElement().attribute("name");
|
||
|
QDomNode domNode = node.firstChild();
|
||
|
|
||
|
while ( !domNode.isNull() )
|
||
|
{
|
||
|
if ( domNode.isElement() )
|
||
|
{
|
||
|
QDomElement domElement = domNode.toElement();
|
||
|
if ( !domElement.isNull() )
|
||
|
{
|
||
|
if (domElement.tagName() == "value")
|
||
|
{
|
||
|
//qDebug() << "var " << name << " = " << domElement.text();
|
||
|
m_Config[name] = QVariant( domElement.text() );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
domNode = domNode.nextSibling();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void CalculateConfig::parseVarList(const QDomNode& node)
|
||
|
{
|
||
|
QStringList resList;
|
||
|
QString name = node.toElement().attribute("name");
|
||
|
QDomNode domNode = node.firstChild();
|
||
|
|
||
|
while ( !domNode.isNull() )
|
||
|
{
|
||
|
if ( domNode.isElement() )
|
||
|
{
|
||
|
QDomElement domElement = domNode.toElement();
|
||
|
if ( !domElement.isNull() )
|
||
|
{
|
||
|
if (domElement.tagName() == "value")
|
||
|
{
|
||
|
//qDebug() << "list " << name << " = " << domElement.text();
|
||
|
resList << domElement.text();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
domNode = domNode.nextSibling();
|
||
|
}
|
||
|
if ( !resList.isEmpty() )
|
||
|
{
|
||
|
m_Config[name] = QVariant( resList );
|
||
|
}
|
||
|
}
|