##// END OF EJS Templates
New register explorer WIP...
New register explorer WIP !!!!!!!!!!!!!!!!!!!!!!!!!!!!! REMOVED OLD genericPySysdriver interface Now the plugins are directly exposed to python. ABI not compatible with previous plugins. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

File last commit:

r66:a991e131f5a8 default
r79:3440ba47d0f1 default
Show More
xmldriver.cpp
105 lines | 2.6 KiB | text/x-c | CppLexer
Jeandet Alexis
First init of SocExplorer Repository.
r0 #include "xmldriver.h"
#include <socexplorerengine.h>
#include <QFile>
#include <QDebug>
XMLDriver::XMLDriver(QObject *parent) :
QObject(parent)
{
this->xmlFiles = new QList<xmlfile*>();
this->scanXmlFiles();
}
int XMLDriver::checkXmlFile(const QString &fileName)
{
QDomDocument document;
QFile file( fileName );
if( !file.open( QIODevice::ReadOnly ) )
return 0;
document.setContent(&file);
if(document.isNull())
return 0;
file.close();
return 1;
}
int XMLDriver::createXmlFile(const QString &fileName)
{
QDomDocument* xmlDoc=new QDomDocument();
QDomProcessingInstruction header = xmlDoc->createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"utf-8\"" );
xmlDoc->appendChild( header );
QDomElement rootnode= xmlDoc->createElement("socExplorerXml");
rootnode.setAttribute("name",fileName);
xmlDoc->appendChild(rootnode);
QFile file( fileName );
if(!file.exists())
{
if( !file.open( QIODevice::WriteOnly ) )
return 0;
QTextStream ts( &file );
ts << xmlDoc->toString();
file.close();
return 1;
}
return 0;
}
QList<xmlfile *> XMLDriver::getFileList(const QString &tagNameFilter)
{
QList<xmlfile*> list;
for(int i=0;i<xmlFiles->count();i++)
{
if(xmlFiles->at(i)->rootTagName()==tagNameFilter)
{
list.append(xmlFiles->at(i));
}
}
return list;
}
QList<QDomNodeList> XMLDriver::getAllNodes(const QString &tagName)
{
QList<QDomNodeList> list;
for(int i=0;i<xmlFiles->count();i++)
{
QDomNodeList nodes=xmlFiles->at(i)->getRootElement()->elementsByTagName(tagName);
if(!nodes.isEmpty())
{
list.append(nodes);
}
}
return list;
}
void XMLDriver::registerXmlFile(const QString &fileName)
{
for(int i=0;i<xmlFiles->count();i++)
{
if(xmlFiles->at(i)->fileName()==fileName)
{
return;
}
}
xmlFiles->append(new xmlfile(fileName));
}
void XMLDriver::scanXmlFiles()
{
Jeandet Alexis
Moved xml soc description in /usr/share/SocExplorer.
r66 QDir shareDir(SocExplorerEngine::sharePath());
QFileInfoList list = shareDir.entryInfoList();
Jeandet Alexis
First init of SocExplorer Repository.
r0 for (int i = 0; i < list.size(); ++i)
{
QFileInfo fileInfo = list.at(i);
if(fileInfo.isFile())
{
if(fileInfo.fileName().contains(".xml") && !fileInfo.fileName().contains(".xml~"))
{
qDebug()<<"Found " + fileInfo.fileName();
if(checkXmlFile(fileInfo.absoluteFilePath()))
{
registerXmlFile(fileInfo.absoluteFilePath());
}
}
}
}
}