2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
20 #include <QDomDocument>
23 #include "schedulexmlparser.h"
24 #include "sqlengine.h"
28 ScheduleXmlParser::ScheduleXmlParser(QObject *aParent)
33 int ScheduleXmlParser::parseData(const QByteArray &aData)
35 QDomDocument document;
36 document.setContent (aData, false);
38 QDomElement scheduleElement = document.firstChildElement("schedule");
41 if (!scheduleElement.isNull())
43 QDomElement conferenceElement = scheduleElement.firstChildElement("conference");
44 if (!conferenceElement.isNull())
46 QHash<QString,QString> conference;
47 conference["id"] = QString::number(0); // conference ID is assigned automatically, or obtained from the DB
48 conference["title"] = conferenceElement.firstChildElement("title").text();
49 conference["subtitle"] = conferenceElement.firstChildElement("subtitle").text();
50 conference["venue"] = conferenceElement.firstChildElement("venue").text();
51 conference["city"] = conferenceElement.firstChildElement("city").text();
52 conference["start"] = conferenceElement.firstChildElement("start").text(); // date
53 conference["end"] = conferenceElement.firstChildElement("end").text(); // date
54 conference["days"] = conferenceElement.firstChildElement("days").text(); // int
55 conference["day_change"] = conferenceElement.firstChildElement("day_change").text(); // time
56 conference["timeslot_duration"] = conferenceElement.firstChildElement("timeslot_duration").text(); // time
57 SqlEngine::addConferenceToDB(conference);
58 confId = conference["id"].toInt();
59 emit(parsingSchedule(conference["title"]));
62 // we need to get count of all events in order to emit 'progressStatus' signal
63 int totalEventsCount = scheduleElement.elementsByTagName("event").count();
65 // parsing day elements
66 int currentEvent = 0; // hold global idx of processed event
67 QDomNodeList dayList = scheduleElement.elementsByTagName("day");
68 for (int i=0; i<dayList.count(); i++)
70 QDomElement dayElement = dayList.at(i).toElement();
71 //QDate dayDate = QDate::fromString(dayElement.attribute("date"),DATE_FORMAT);
72 //int dayIndex = dayElement.attribute("index").toInt();
74 // parsing room elements
75 QDomNodeList roomList = dayElement.elementsByTagName("room");
76 for (int i=0; i<roomList.count(); i++)
78 QDomElement roomElement = roomList.at(i).toElement();
79 // roomElement has to be 'Element' and it has to have 'name' attribute
80 // TODO: 'event' has also 'room' node, so it can be unstable if that node has also 'name' attribute
81 if(roomElement.hasAttribute("name"))
83 // parsing event elements
84 QDomNodeList eventList = roomElement.elementsByTagName("event");
85 for (int i=0; i<eventList.count(); i++)
88 QDomElement eventElement = eventList.at(i).toElement();
90 // now we have all info to create ROOM/EVENT_ROOM record(s)
91 QHash<QString,QString> room;
92 room["name"] = roomElement.attribute("name");
93 room["event_id"] = eventElement.attribute("id");
94 room["conference_id"] = QString::number(confId,10);
95 room["picture"] = "NOT DEFINED YET"; // TODO: implement some mapping to assign correct picture to specified room_name
96 SqlEngine::addRoomToDB(room);
98 // process event's nodes
99 QHash<QString,QString> event;
100 event["id"] = eventElement.attribute("id");;
101 event["conference_id"] = QString::number(confId, 10);
102 event["start"] = eventElement.firstChildElement("start").text(); // time eg. 10:00
103 event["date"] = dayElement.attribute("date"); // date eg. 2009-02-07
104 event["duration"] = eventElement.firstChildElement("duration").text(); // time eg. 00:30
105 event["room_name"] = eventElement.firstChildElement("room").text(); // string eg. "Janson"
106 event["tag"] = eventElement.firstChildElement("tag").text(); // string eg. "welcome"
107 event["title"] = eventElement.firstChildElement("title").text(); // string eg. "Welcome"
108 event["subtitle"] = eventElement.firstChildElement("subtitle").text(); // string
109 event["track"] = eventElement.firstChildElement("track").text(); // string eg. "Keynotes"
110 event["type"] = eventElement.firstChildElement("type").text(); // string eg. "Podium"
111 event["language"] = eventElement.firstChildElement("language").text(); // language eg. "English"
112 event["abstract"] = eventElement.firstChildElement("abstract").text(); // string
113 event["description"] = eventElement.firstChildElement("description").text(); // string
114 SqlEngine::addEventToDB(event);
115 // process persons' nodes
116 QList<QString> persons;
117 QDomElement personsElement = eventElement.firstChildElement("persons");
118 QDomNodeList personList = personsElement.elementsByTagName("person");
119 for(int i = 0;i < personList.count();i++){
120 QHash<QString,QString> person;
121 person["id"] = personList.at(i).toElement().attribute("id");
122 person["name"] = personList.at(i).toElement().text();
123 person["event_id"] = eventElement.attribute("id");
124 person["conference_id"] = QString::number(confId, 10);
125 //qDebug() << "adding Person: " << person["name"];
126 SqlEngine::addPersonToDB(person);
128 // process links' nodes
129 QDomElement linksElement = eventElement.firstChildElement("links");
130 QDomNodeList linkList = linksElement.elementsByTagName("link");
131 for(int i = 0;i < linkList.count();i++){
132 QHash<QString,QString> link;
133 link["name"] = linkList.at(i).toElement().text();
134 link["url"] = linkList.at(i).toElement().attribute("href");
135 link["event_id"] = eventElement.attribute("id");
136 link["conference_id"] = QString::number(confId, 10);
137 SqlEngine::addLinkToDB(link);
139 // emit signal to inform the user about the current status (how many events are parsed so far - expressed in %)
140 int status = currentEvent * 100 / totalEventsCount;
141 progressStatus(status);
142 } // parsing event elements
144 } // parsing room elements
145 } // parsing day elements
146 } // schedule element