#include "expxmldownloader.h" #include #include #include #include #include ExpXmlDownLoader::ExpXmlDownLoader(QObject *parent) : QObject(parent) { this->m_doc = NULL; } ExpXmlDownLoader::~ExpXmlDownLoader() { } bool ExpXmlDownLoader::parseXml(const QString &fileName) { QQueue nodes; nodes<<"RESOURCE"<<"TABLE"<<"DATA"<<"TABLEDATA"; if(m_doc!=NULL) delete m_doc; m_doc = new QDomDocument(fileName); QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) return false; if (!m_doc->setContent(&file)) { file.close(); return false; } file.close(); if(m_doc->isNull()) { delete m_doc; return false; } QDomElement docElem = m_doc->documentElement(); QDomNode n = docElem.firstChild(); while(!n.isNull() && !nodes.empty()) { if(n.toElement().tagName()==nodes.head()) { nodes.dequeue(); n=n.firstChild(); } else { n = n.nextSibling(); } } extractIntervals(n); makeDownloadList(); return true; } const QList &ExpXmlDownLoader::daysToDownload() { return m_FilesToDownload; } void ExpXmlDownLoader::extractIntervals(QDomNode n) { QDomNode inter; m_intervals.clear(); while(!n.isNull()) { if(n.toElement().tagName()=="TR") { ExpXmlDownLoaderIntervals interval; inter=n.firstChild(); if(inter.toElement().tagName()=="TD") { interval.start = inter.toElement().text(); } inter=inter.nextSibling(); if(inter.toElement().tagName()=="TD") { interval.stop = inter.toElement().text(); } m_intervals.append(interval); } n = n.nextSibling(); } } void ExpXmlDownLoader::makeDownloadList() { for(int i=0;i daysToDl; QDateTime start,stop; start=start.fromString(m_intervals[i].start,Qt::ISODate); stop=stop.fromString(m_intervals[i].stop,Qt::ISODate); int days=start.daysTo(stop); daysToDl.append(start.date()); if(days) { for(int j=0;j days) { for(int i=0;i