source: src/sql/schedulexmlparser.cpp @ 6df32f2

qt5
Last change on this file since 6df32f2 was 6df32f2, checked in by gregor herrmann <gregoa@…>, 10 years ago

Update GPL blurb in source files.

  • Property mode set to 100644
File size: 8.6 KB
RevLine 
[ca90cb1]1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
[6df32f2]4 * This file is part of ConfClerk.
[ca90cb1]5 *
[6df32f2]6 * ConfClerk is free software: you can redistribute it and/or modify it
[ca90cb1]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 *
[6df32f2]11 * ConfClerk is distributed in the hope that it will be useful, but
[ca90cb1]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
[6df32f2]17 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[ca90cb1]18 */
[30e2bdf]19
20#include <QDomDocument>
21#include <QHash>
22
23#include "schedulexmlparser.h"
24#include "sqlengine.h"
[3329d39]25#include "../gui/errormessage.h"
[30e2bdf]26
27#include <QDebug>
28
29ScheduleXmlParser::ScheduleXmlParser(QObject *aParent)
30    : QObject(aParent)
31{
32}
33
[f299a08]34void ScheduleXmlParser::parseData(const QByteArray &aData, const QString& url)
[30e2bdf]35{
36    QDomDocument document;
[3329d39]37    QString xml_error;
38    if (!document.setContent (aData, false, &xml_error)) {
39        error_message("Could not parse schedule: " + xml_error);
[f299a08]40        return;
[3329d39]41    }
[30e2bdf]42
43    QDomElement scheduleElement = document.firstChildElement("schedule");
44
[1bad318]45    SqlEngine::beginTransaction();
46
[c15be10]47    int confId = 0;
[b431d47]48    QString conference_title;
[30e2bdf]49    if (!scheduleElement.isNull())
50    {
51        QDomElement conferenceElement = scheduleElement.firstChildElement("conference");
52        if (!conferenceElement.isNull())
53        {
54            QHash<QString,QString> conference;
[1735f55]55            conference["id"] = QString::number(0); // conference ID is assigned automatically, or obtained from the DB
[30e2bdf]56            conference["title"] = conferenceElement.firstChildElement("title").text();
57            conference["subtitle"] = conferenceElement.firstChildElement("subtitle").text();
58            conference["venue"] = conferenceElement.firstChildElement("venue").text();
59            conference["city"] = conferenceElement.firstChildElement("city").text();
60            conference["start"] = conferenceElement.firstChildElement("start").text(); // date
61            conference["end"] = conferenceElement.firstChildElement("end").text(); // date
62            conference["days"] = conferenceElement.firstChildElement("days").text(); // int
63            conference["day_change"] = conferenceElement.firstChildElement("day_change").text(); // time
64            conference["timeslot_duration"] = conferenceElement.firstChildElement("timeslot_duration").text(); // time
[d06ae27]65            conference["url"] = url;
[3a8dc71]66            SqlEngine::addConferenceToDB(conference);
[1735f55]67            confId = conference["id"].toInt();
[b431d47]68            conference_title = conference["title"];
69            emit(parsingScheduleBegin());
[30e2bdf]70        }
71
72        // we need to get count of all events in order to emit 'progressStatus' signal
73        int totalEventsCount = scheduleElement.elementsByTagName("event").count();
74
75        // parsing day elements
76        int currentEvent = 0; // hold global idx of processed event
77        QDomNodeList dayList = scheduleElement.elementsByTagName("day");
78        for (int i=0; i<dayList.count(); i++)
79        {
80            QDomElement dayElement = dayList.at(i).toElement();
81            //QDate dayDate = QDate::fromString(dayElement.attribute("date"),DATE_FORMAT);
82            //int dayIndex = dayElement.attribute("index").toInt();
83
84            // parsing room elements
85            QDomNodeList roomList = dayElement.elementsByTagName("room");
86            for (int i=0; i<roomList.count(); i++)
87            {
88                QDomElement roomElement = roomList.at(i).toElement();
89                // roomElement has to be 'Element' and it has to have 'name' attribute
90                // TODO: 'event' has also 'room' node, so it can be unstable if that node has also 'name' attribute
91                if(roomElement.hasAttribute("name"))
92                {
93                    // parsing event elements
94                    QDomNodeList eventList = roomElement.elementsByTagName("event");
95                    for (int i=0; i<eventList.count(); i++)
96                    {
97                        currentEvent++;
98                        QDomElement eventElement = eventList.at(i).toElement();
99
100                        // now we have all info to create ROOM/EVENT_ROOM record(s)
101                        QHash<QString,QString> room;
102                        room["name"] = roomElement.attribute("name");
103                        room["event_id"] = eventElement.attribute("id");
[1735f55]104                        room["conference_id"] = QString::number(confId,10);
[58eb7cc]105                        room["picture"] = ""; // TODO: implement some mapping to assign correct picture to specified room_name
[3a8dc71]106                        SqlEngine::addRoomToDB(room);
[30e2bdf]107
108                        // process event's nodes
[72cd3af]109                        QHash<QString,QString> event;
110                        event["id"] = eventElement.attribute("id");;
[1735f55]111                        event["conference_id"] = QString::number(confId, 10);
[30e2bdf]112                        event["start"] = eventElement.firstChildElement("start").text(); // time eg. 10:00
[72cd3af]113                        event["date"] = dayElement.attribute("date"); // date eg. 2009-02-07
114                        event["duration"] = eventElement.firstChildElement("duration").text(); // time eg. 00:30
115                        event["room_name"] = eventElement.firstChildElement("room").text(); // string eg. "Janson"
116                        event["tag"] = eventElement.firstChildElement("tag").text(); // string eg. "welcome"
117                        event["title"] = eventElement.firstChildElement("title").text(); // string eg. "Welcome"
118                        event["subtitle"] = eventElement.firstChildElement("subtitle").text(); // string
[30e2bdf]119                        event["track"] = eventElement.firstChildElement("track").text(); // string eg. "Keynotes"
[72cd3af]120                        event["type"] = eventElement.firstChildElement("type").text(); // string eg. "Podium"
121                        event["language"] = eventElement.firstChildElement("language").text(); // language eg. "English"
122                        event["abstract"] = eventElement.firstChildElement("abstract").text(); // string
123                        event["description"] = eventElement.firstChildElement("description").text(); // string
[3a8dc71]124                        SqlEngine::addEventToDB(event);
[72cd3af]125                        // process persons' nodes
126                        QList<QString> persons;
127                        QDomElement personsElement = eventElement.firstChildElement("persons");
128                        QDomNodeList personList = personsElement.elementsByTagName("person");
129                        for(int i = 0;i < personList.count();i++){
130                            QHash<QString,QString> person;
131                            person["id"] = personList.at(i).toElement().attribute("id");
132                            person["name"] = personList.at(i).toElement().text();
133                            person["event_id"] = eventElement.attribute("id");
[1735f55]134                            person["conference_id"] = QString::number(confId, 10);
[72cd3af]135                            //qDebug() << "adding Person: " << person["name"];
[3a8dc71]136                            SqlEngine::addPersonToDB(person);
[72cd3af]137                        }
138                        // process links' nodes
139                        QDomElement linksElement = eventElement.firstChildElement("links");
140                        QDomNodeList linkList = linksElement.elementsByTagName("link");
141                        for(int i = 0;i < linkList.count();i++){
142                            QHash<QString,QString> link;
143                            link["name"] = linkList.at(i).toElement().text();
144                            link["url"] = linkList.at(i).toElement().attribute("href");
145                            link["event_id"] = eventElement.attribute("id");
[1735f55]146                            link["conference_id"] = QString::number(confId, 10);
[3a8dc71]147                            SqlEngine::addLinkToDB(link);
[72cd3af]148                        }
149                        // emit signal to inform the user about the current status (how many events are parsed so far - expressed in %)
150                        int status = currentEvent * 100 / totalEventsCount;
[30e2bdf]151                        progressStatus(status);
152                    } // parsing event elements
153                }
154            } // parsing room elements
155        } // parsing day elements
156    } // schedule element
[1bad318]157    SqlEngine::commitTransaction();
[f299a08]158    if (!conference_title.isNull()) {
159        emit parsingScheduleEnd(conference_title);
160    } else {
161        error_message("Could not parse schedule");
162    }
[30e2bdf]163}
164
Note: See TracBrowser for help on using the repository browser.