src/mvc/mvc.pro: add network module.
[toast/confclerk.git] / src / sql / schedulexmlparser.cpp
index 15e3861..6f5e508 100644 (file)
@@ -27,6 +27,7 @@
 #include "../gui/errormessage.h"
 
 #include <QDebug>
+#include <stdexcept>
 
 ScheduleXmlParser::ScheduleXmlParser(SqlEngine* sqlEngine, QObject *aParent): QObject(aParent),sqlEngine(sqlEngine) {
 }
@@ -38,6 +39,15 @@ public:
 };
 
 
+void checkEvent(QHash<QString,QString>& event) {
+    QString event_id = event["id"];
+    if (event_id.trimmed().isEmpty()) throw ParseException(QObject::tr("The ID of event '%1' is missing.").arg(event["title"]));
+    bool ok;
+    event_id.toInt(&ok);
+    if (!ok) throw ParseException(QObject::tr("The ID '%2' of event '%1' is not numeric.").arg(event["title"]).arg(event_id));
+}
+
+
 void ScheduleXmlParser::parseDataImpl(const QByteArray &aData, const QString& url, int conferenceId) {
     QDomDocument document;
     QString xml_error;
@@ -115,7 +125,7 @@ void ScheduleXmlParser::parseDataImpl(const QByteArray &aData, const QString& ur
 
                         // process event's nodes
                         QHash<QString,QString> event;
-                        event["id"] = eventElement.attribute("id");;
+                        event["id"] = eventElement.attribute("id");
                         event["conference_id"] = QString::number(conferenceId, 10);
                         QTime event_start = QTime::fromString(eventElement.firstChildElement("start").text(), sqlEngine->TIME_FORMAT);
                         event["start"] = event_start.toString(sqlEngine->TIME_FORMAT); // time eg. 10:00
@@ -139,6 +149,7 @@ void ScheduleXmlParser::parseDataImpl(const QByteArray &aData, const QString& ur
                         event["language"] = eventElement.firstChildElement("language").text(); // language eg. "English"
                         event["abstract"] = eventElement.firstChildElement("abstract").text(); // string
                         event["description"] = eventElement.firstChildElement("description").text(); // string
+                        checkEvent(event);
                         sqlEngine->addEventToDB(event);
                         // process persons' nodes
                         QDomElement personsElement = eventElement.firstChildElement("persons");