[svn-upgrade] new version fosdem-schedule (0.4.1+svn262+ds)
[debian/fosdem-schedule.git] / src / sql / schedulexmlparser.cpp
index c1c65597a6fd3de94862d44955ff6b5e74a2b7c2..78a66331ec2fc50b54c511c82e486349df093e2b 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "schedulexmlparser.h"
 #include "sqlengine.h"
+#include "../gui/errormessage.h"
 
 #include <QDebug>
 
@@ -30,14 +31,21 @@ ScheduleXmlParser::ScheduleXmlParser(QObject *aParent)
 {
 }
 
-int ScheduleXmlParser::parseData(const QByteArray &aData)
+void ScheduleXmlParser::parseData(const QByteArray &aData, const QString& url)
 {
     QDomDocument document;
-    document.setContent (aData, false);
+    QString xml_error;
+    if (!document.setContent (aData, false, &xml_error)) {
+        error_message("Could not parse schedule: " + xml_error);
+        return;
+    }
 
     QDomElement scheduleElement = document.firstChildElement("schedule");
 
+    SqlEngine::beginTransaction();
+
     int confId = 0;
+    QString conference_title;
     if (!scheduleElement.isNull())
     {
         QDomElement conferenceElement = scheduleElement.firstChildElement("conference");
@@ -54,9 +62,11 @@ int ScheduleXmlParser::parseData(const QByteArray &aData)
             conference["days"] = conferenceElement.firstChildElement("days").text(); // int
             conference["day_change"] = conferenceElement.firstChildElement("day_change").text(); // time
             conference["timeslot_duration"] = conferenceElement.firstChildElement("timeslot_duration").text(); // time
+            conference["url"] = url;
             SqlEngine::addConferenceToDB(conference);
             confId = conference["id"].toInt();
-            emit(parsingSchedule(conference["title"]));
+            conference_title = conference["title"];
+            emit(parsingScheduleBegin());
         }
 
         // we need to get count of all events in order to emit 'progressStatus' signal
@@ -92,7 +102,7 @@ int ScheduleXmlParser::parseData(const QByteArray &aData)
                         room["name"] = roomElement.attribute("name");
                         room["event_id"] = eventElement.attribute("id");
                         room["conference_id"] = QString::number(confId,10);
-                        room["picture"] = "NOT DEFINED YET"; // TODO: implement some mapping to assign correct picture to specified room_name
+                        room["picture"] = ""; // TODO: implement some mapping to assign correct picture to specified room_name
                         SqlEngine::addRoomToDB(room);
 
                         // process event's nodes
@@ -144,7 +154,11 @@ int ScheduleXmlParser::parseData(const QByteArray &aData)
             } // parsing room elements
         } // parsing day elements
     } // schedule element
-
-    return confId;
+    SqlEngine::commitTransaction();
+    if (!conference_title.isNull()) {
+        emit parsingScheduleEnd(conference_title);
+    } else {
+        error_message("Could not parse schedule");
+    }
 }