source: src/sql/schedulexmlparser.cpp @ ca90cb1

qt5
Last change on this file since ca90cb1 was ca90cb1, checked in by uzakmat <uzakmat@…>, 12 years ago

A header with the proper copyright/lincence statement was added into each source/header file.

  • Property mode set to 100644
File size: 8.1 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
4 * This file is part of fosdem-schedule.
5 *
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)
9 * any later version.
10 *
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
14 * more details.
15 *
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/>.
18 */
19
20#include <QDomDocument>
21#include <QHash>
22
23#include "schedulexmlparser.h"
24#include "sqlengine.h"
25
26#include <QDebug>
27
28ScheduleXmlParser::ScheduleXmlParser(QObject *aParent)
29    : QObject(aParent)
30{
31}
32
33int ScheduleXmlParser::parseData(const QByteArray &aData)
34{
35    QDomDocument document;
36    document.setContent (aData, false);
37
38    QDomElement scheduleElement = document.firstChildElement("schedule");
39
40    int confId = 0;
41    if (!scheduleElement.isNull())
42    {
43        QDomElement conferenceElement = scheduleElement.firstChildElement("conference");
44        if (!conferenceElement.isNull())
45        {
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"]));
60        }
61
62        // we need to get count of all events in order to emit 'progressStatus' signal
63        int totalEventsCount = scheduleElement.elementsByTagName("event").count();
64
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++)
69        {
70            QDomElement dayElement = dayList.at(i).toElement();
71            //QDate dayDate = QDate::fromString(dayElement.attribute("date"),DATE_FORMAT);
72            //int dayIndex = dayElement.attribute("index").toInt();
73
74            // parsing room elements
75            QDomNodeList roomList = dayElement.elementsByTagName("room");
76            for (int i=0; i<roomList.count(); i++)
77            {
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"))
82                {
83                    // parsing event elements
84                    QDomNodeList eventList = roomElement.elementsByTagName("event");
85                    for (int i=0; i<eventList.count(); i++)
86                    {
87                        currentEvent++;
88                        QDomElement eventElement = eventList.at(i).toElement();
89
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);
97
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);
127                        }
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);
138                        }
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
143                }
144            } // parsing room elements
145        } // parsing day elements
146    } // schedule element
147
148    return confId;
149}
150
Note: See TracBrowser for help on using the repository browser.