[72f6fe4] | 1 |
|
---|
| 2 | #include <QDomDocument>
|
---|
| 3 | #include <QHash>
|
---|
| 4 |
|
---|
| 5 | #include "schedulexmlparser.h"
|
---|
| 6 | #include "sqlengine.h"
|
---|
| 7 |
|
---|
| 8 | #include <QDebug>
|
---|
| 9 |
|
---|
| 10 | ScheduleXmlParser::ScheduleXmlParser(QObject *aParent)
|
---|
| 11 | : QObject(aParent)
|
---|
| 12 | {
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | void ScheduleXmlParser::parseData(const QByteArray &aData, SqlEngine *aDBEngine)
|
---|
| 16 | {
|
---|
| 17 | Q_ASSERT(NULL != aDBEngine);
|
---|
| 18 |
|
---|
| 19 | QDomDocument document;
|
---|
| 20 | document.setContent (aData, false);
|
---|
| 21 |
|
---|
| 22 | QDomElement scheduleElement = document.firstChildElement("schedule");
|
---|
| 23 |
|
---|
| 24 | if (!scheduleElement.isNull())
|
---|
| 25 | {
|
---|
| 26 | // TODO: assign conferenceID based on eg. title
|
---|
| 27 | int conferenceID = 1; // HARD-WIRED for now to '1' - only one Conference
|
---|
| 28 |
|
---|
| 29 | QDomElement conferenceElement = scheduleElement.firstChildElement("conference");
|
---|
| 30 | if (!conferenceElement.isNull())
|
---|
| 31 | {
|
---|
| 32 | QHash<QString,QString> conference;
|
---|
| 33 | conference["id"] = QString::number(conferenceID,10);
|
---|
| 34 | conference["title"] = conferenceElement.firstChildElement("title").text();
|
---|
| 35 | conference["subtitle"] = conferenceElement.firstChildElement("subtitle").text();
|
---|
| 36 | conference["venue"] = conferenceElement.firstChildElement("venue").text();
|
---|
| 37 | conference["city"] = conferenceElement.firstChildElement("city").text();
|
---|
| 38 | conference["start"] = conferenceElement.firstChildElement("start").text(); // date
|
---|
| 39 | conference["end"] = conferenceElement.firstChildElement("end").text(); // date
|
---|
| 40 | conference["days"] = conferenceElement.firstChildElement("days").text(); // int
|
---|
| 41 | conference["day_change"] = conferenceElement.firstChildElement("day_change").text(); // time
|
---|
| 42 | conference["timeslot_duration"] = conferenceElement.firstChildElement("timeslot_duration").text(); // time
|
---|
| 43 | aDBEngine->addConferenceToDB(conference);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | // we need to get count of all events in order to emit 'progressStatus' signal
|
---|
| 47 | int totalEventsCount = scheduleElement.elementsByTagName("event").count();
|
---|
| 48 |
|
---|
| 49 | // parsing day elements
|
---|
| 50 | int currentEvent = 0; // hold global idx of processed event
|
---|
| 51 | QDomNodeList dayList = scheduleElement.elementsByTagName("day");
|
---|
| 52 | for (int i=0; i<dayList.count(); i++)
|
---|
| 53 | {
|
---|
| 54 | QDomElement dayElement = dayList.at(i).toElement();
|
---|
| 55 | //QDate dayDate = QDate::fromString(dayElement.attribute("date"),DATE_FORMAT);
|
---|
| 56 | //int dayIndex = dayElement.attribute("index").toInt();
|
---|
| 57 |
|
---|
| 58 | // parsing room elements
|
---|
| 59 | QDomNodeList roomList = dayElement.elementsByTagName("room");
|
---|
| 60 | for (int i=0; i<roomList.count(); i++)
|
---|
| 61 | {
|
---|
| 62 | QDomElement roomElement = roomList.at(i).toElement();
|
---|
| 63 | // roomElement has to be 'Element' and it has to have 'name' attribute
|
---|
| 64 | // TODO: 'event' has also 'room' node, so it can be unstable if that node has also 'name' attribute
|
---|
| 65 | if(roomElement.hasAttribute("name"))
|
---|
| 66 | {
|
---|
| 67 | // parsing event elements
|
---|
| 68 | QDomNodeList eventList = roomElement.elementsByTagName("event");
|
---|
| 69 | for (int i=0; i<eventList.count(); i++)
|
---|
| 70 | {
|
---|
| 71 | currentEvent++;
|
---|
| 72 | QDomElement eventElement = eventList.at(i).toElement();
|
---|
| 73 |
|
---|
| 74 | // now we have all info to create ROOM/EVENT_ROOM record(s)
|
---|
| 75 | QHash<QString,QString> room;
|
---|
| 76 | room["name"] = roomElement.attribute("name");
|
---|
| 77 | room["event_id"] = eventElement.attribute("id");
|
---|
| 78 | room["conference_id"] = QString::number(conferenceID,10);
|
---|
| 79 | room["picture"] = "NOT DEFINED YET"; // TODO: implement some mapping to assign correct picture to specified room_name
|
---|
| 80 | aDBEngine->addRoomToDB(room);
|
---|
| 81 |
|
---|
| 82 | // process event's nodes
|
---|
| 83 | QHash<QString,QString> event;
|
---|
| 84 | event["id"] = eventElement.attribute("id");
|
---|
| 85 | event["conference_id"] = QString::number(conferenceID,10);
|
---|
| 86 | event["start"] = eventElement.firstChildElement("start").text(); // time eg. 10:00
|
---|
| 87 | event["date"] = dayElement.attribute("date"); // date eg. 2009-02-07
|
---|
| 88 | event["duration"] = eventElement.firstChildElement("duration").text(); // time eg. 00:30
|
---|
| 89 | event["room_name"] = eventElement.firstChildElement("room").text(); // string eg. "Janson"
|
---|
| 90 | event["tag"] = eventElement.firstChildElement("tag").text(); // string eg. "welcome"
|
---|
| 91 | event["title"] = eventElement.firstChildElement("title").text(); // string eg. "Welcome"
|
---|
| 92 | event["subtitle"] = eventElement.firstChildElement("subtitle").text(); // string
|
---|
| 93 | event["track"] = eventElement.firstChildElement("track").text(); // string eg. "Keynotes"
|
---|
| 94 | event["type"] = eventElement.firstChildElement("type").text(); // string eg. "Podium"
|
---|
| 95 | event["language"] = eventElement.firstChildElement("language").text(); // language eg. "English"
|
---|
| 96 | event["abstract"] = eventElement.firstChildElement("abstract").text(); // string
|
---|
| 97 | event["description"] = eventElement.firstChildElement("description").text(); // string
|
---|
| 98 | aDBEngine->addEventToDB(event);
|
---|
| 99 |
|
---|
| 100 | // process persons' nodes
|
---|
| 101 | QList<QString> persons;
|
---|
| 102 | QDomElement personsElement = eventElement.firstChildElement("persons");
|
---|
| 103 | QDomNodeList personList = personsElement.elementsByTagName("person");
|
---|
| 104 | for (int i=0; i<personList.count(); i++)
|
---|
| 105 | {
|
---|
| 106 | QHash<QString,QString> person;
|
---|
| 107 | person["id"] = personList.at(i).toElement().attribute("id");
|
---|
| 108 | person["name"] = personList.at(i).toElement().text();
|
---|
| 109 | person["event_id"] = eventElement.attribute("id");
|
---|
| 110 | person["conference_id"] = QString::number(conferenceID,10);
|
---|
| 111 | //qDebug() << "adding Person: " << person["name"];
|
---|
| 112 | aDBEngine->addPersonToDB(person);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | // process links' nodes
|
---|
| 116 | QDomElement linksElement = eventElement.firstChildElement("links");
|
---|
| 117 | QDomNodeList linkList = linksElement.elementsByTagName("link");
|
---|
| 118 | for (int i=0; i<linkList.count(); i++)
|
---|
| 119 | {
|
---|
| 120 | QHash<QString,QString> link;
|
---|
| 121 | link["name"] = linkList.at(i).toElement().text();
|
---|
| 122 | link["url"] = linkList.at(i).toElement().attribute("href");
|
---|
| 123 | link["event_id"] = eventElement.attribute("id");
|
---|
| 124 | link["conference_id"] = QString::number(conferenceID,10);
|
---|
| 125 | aDBEngine->addLinkToDB(link);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | // emit signal to inform the user about the current status (how many events are parsed so far - expressed in %)
|
---|
| 129 | int status=currentEvent*100/totalEventsCount;
|
---|
| 130 | emit progressStatus(status);
|
---|
| 131 | } // parsing event elements
|
---|
| 132 | }
|
---|
| 133 | } // parsing room elements
|
---|
| 134 | } // parsing day elements
|
---|
| 135 | } // schedule element
|
---|
| 136 | }
|
---|
| 137 |
|
---|