00001 #include <QDomDocument>
00002 #include <QDomElement>
00003 #include <QDomNode>
00004 #include <QString>
00005 #include <QStringList>
00006 #include <QFile>
00007 #include <QIODevice>
00008 #include "manifestparser.h"
00009 #include "manifestdata.h"
00010 #include "manifestosinfo.h"
00011
00012 ManifestParser::ManifestParser()
00013 {
00014 }
00015
00018 bool ManifestParser::parse(ManifestData *data, QString path)
00019 {
00020 QDomDocument doc;
00021 QFile file(path);
00022 QList<ManifestOsInfo> *osInfo = data->operatingSystems();
00023
00024
00025 if(! file.open(QIODevice::ReadOnly))
00026 {
00027 emit customError(MANIFEST_IOERROR);
00028 return false;
00029 }
00030 if(! doc.setContent(&file))
00031 {
00032 emit customError(MANIFEST_XMLERROR);
00033 return false;
00034 }
00035
00036
00037 QDomElement root = doc.documentElement();
00038 if(root.nodeName() != "Allevo2")
00039 {
00040 emit customError(MANIFEST_FORMATERROR);
00041 return false;
00042 }
00043
00044 QDomNode node = root.firstChild();
00045 while(! node.isNull())
00046 {
00047 if(node.nodeName().toLower() == "version")
00048 {
00049 data->setVersion(node.firstChild().nodeValue().simplified());
00050 }
00051 if(node.nodeName().toLower() == "releasenotes")
00052 {
00053 data->setReleaseNotes(node.firstChild().nodeValue().simplified());
00054 }
00055 if(node.nodeName().toLower() == "releasedate")
00056 {
00057 QStringList parts = node.firstChild().nodeValue().simplified().split('-', QString::KeepEmptyParts);
00058 if(parts.count() == 3)
00059 {
00060 bool conversion1, conversion2, conversion3;
00061 int year, month, day;
00062
00063
00064 year = parts.value(0).toInt(&conversion1);
00065 month = parts.value(1).toInt(&conversion2);
00066 day = parts.value(2).toInt(&conversion3);
00067 if(conversion1 && conversion2 && conversion3)
00068 {
00069 data->setReleaseDate(QDate(year, month, day));
00070 }
00071 }
00072
00073 }
00074 if(node.nodeName().toLower() == "operatingsystem")
00075 {
00076 ManifestOsInfo osEntry;
00077
00078 if(node.attributes().contains("id"))
00079 {
00080 osEntry.setName(node.attributes().namedItem("id").nodeValue());
00081 }
00082
00083 QDomNode osNode = node.firstChild();
00084 while(! osNode.isNull())
00085 {
00086 if(osNode.nodeName().toLower() == "message")
00087 {
00088 osEntry.setMessage(osNode.firstChild().nodeValue().simplified());
00089 }
00090 if(osNode.nodeName().toLower() == "link")
00091 {
00092 osEntry.setLink(osNode.firstChild().nodeValue().simplified());
00093 if(osNode.attributes().contains("type"))
00094 {
00095
00096
00097 if(osNode.attributes().namedItem("type").nodeValue() == "0")
00098 {
00099 osEntry.setMessageOnly(true);
00100 }
00101 else
00102 {
00103 osEntry.setMessage(false);
00104 }
00105 }
00106 }
00107 osNode = osNode.nextSibling();
00108 }
00109 osInfo->append(osEntry);
00110 }
00111 node = node.nextSibling();
00112 }
00113
00114 return true;
00115 }