void ParserXmlVasttrafikSe::parseTimeTable(QNetworkReply *networkReply)
{
    qDebug() << "ParserXmlVasttrafikSe::parseTimeTable(networkReply.url()=" << networkReply->url().toString() << ")";

    TimetableEntriesList result;
    QTextStream ts(networkReply->readAll());
    ts.setCodec("UTF-8");
    const QString xmlRawtext = ts.readAll();

    QDomDocument doc("result");
    if (doc.setContent(xmlRawtext, false)) {
        bool isArrival = false;
        QDomNodeList nodeList = doc.elementsByTagName("Departure");
        if (nodeList.isEmpty()) {
            nodeList = doc.elementsByTagName("Arrival");
            isArrival = true;
        }
        for (unsigned int i = 0; i < nodeList.length(); ++i) {
            QDomNode node = nodeList.item(i);
            TimetableEntry item;

            item.destinationStation = getAttribute(node, isArrival ? "origin" : "direction");
            item.platform = getAttribute(node, "track");
            const QString connectionName = i18nConnectionType(getAttribute(node, "name"));
            const QString fgColor = getAttribute(node, "fgColor");
            const QString bgColor = getAttribute(node, "bgColor");
            if (!fgColor.isEmpty() && !bgColor.isEmpty())
                item.trainType = QString::fromLatin1("<span style=\"color:%2; background-color: %3;\">%1</span>").arg(connectionName).arg(fgColor).arg(bgColor);
            else
                item.trainType = connectionName;
            const QTime scheduledTime = QTime::fromString(getAttribute(node, "time"), QLatin1String("hh:mm"));
            item.time = scheduledTime;
            const QString realTimeStr = getAttribute(node, "rtTime");
            if (!realTimeStr.isEmpty()) {
                const QTime realTimeTime = QTime::fromString(realTimeStr, QLatin1String("hh:mm"));
                const int minutesTo = scheduledTime.msecsTo(realTimeTime) / 60000;
                if (minutesTo > 3)
                    item.miscInfo = tr("<span style=\"color:#b30;\">%1 min late</span>").arg(minutesTo);
                else
                    item.miscInfo = tr("<span style=\"color:#093; font-weight: normal;\">on time</span>");
            }

            result << item;
        }
    }

    emit timetableResult(result);
}
Exemplo n.º 2
0
void ParserHafasXml::parseTimeTableMode1(QNetworkReply *networkReply)
{
    TimetableEntriesList result;

    QString data = QString::fromLatin1(networkReply->readAll());

    //Add a root element, because its sometimes missing
    if (data.indexOf("StationTable") == -1) {
        data.prepend("<StationTable>");
        data.append("</StationTable>");
    }

    QXmlStreamReader xml;
    xml.addData(data);

    while (!xml.atEnd()) {
        xml.readNext();

        if (xml.isStartElement() && (xml.name() == "Err")) {
            QString errorMsg = xml.attributes().value("text").toString().simplified();
            emit errorOccured(tr("Backend returns an error: ") + errorMsg);
            qWarning()<<"ParserHafasXml::parseTimeTableMode1: "<<errorMsg;
        }

        if (xml.isStartElement() && (xml.name() == "Journey")) {
            TimetableEntry item;

            QString dest = xml.attributes().value("dir").toString().simplified();
            QString station = xml.attributes().value("depStation").toString().simplified();
            QString train = xml.attributes().value("hafasname").toString().simplified();

            if (dest.isEmpty()) {
                dest = xml.attributes().value("targetLoc").toString().simplified();
            }
            if (train.isEmpty()) {
                train = xml.attributes().value("prod").toString().simplified();

                if (train.indexOf("#")) {
                    train = train.left(train.indexOf("#"));
                }
            }

            //get delay infos,
            QString txtDelay = xml.attributes().value("delay").toString().simplified();
            //QString intDelay = xml.attributes().value("e_delay").toString().simplified();
            QString reasonDelay = xml.attributes().value("delayReason").toString().simplified();
            QString miscInfo = "";

            if (!txtDelay.isEmpty()) {
                if (txtDelay == "-") {
                    miscInfo = "";
                } else if (txtDelay == "0") {
                    miscInfo = tr("On-Time");
                } else {
                    miscInfo = txtDelay;
                }
            }

            if (!reasonDelay.isEmpty()) {
                if (!miscInfo.isEmpty()) {
                    miscInfo.append(": ");
                }
                miscInfo.append(reasonDelay);
            }

            item.currentStation = station;
            item.destinationStation = dest;
            item.trainType = train;
            item.platform = xml.attributes().value("platform").toString().simplified();
            item.time = QTime::fromString(xml.attributes().value("fpTime").toString(), "hh:mm");
            item.miscInfo = miscInfo;

            result << item;
        }

    }
    emit timetableResult(result);
}
Exemplo n.º 3
0
void ParserHafasXml::parseTimeTableMode0(QNetworkReply *networkReply)
{
    TimetableEntriesList result;

    QString data = QString::fromUtf8(networkReply->readAll());

    QXmlStreamReader xml;
    xml.addData(data);

    while (!xml.atEnd()) {
        xml.readNext();
        if (xml.isStartElement() && (xml.name() == "STBJourney")) {
            TimetableEntry item;

            while (!xml.atEnd()) {
                xml.readNext();
                if (xml.isStartElement() && xml.name() == "Station") {
                    item.currentStation = xml.attributes().value("name").toString().simplified();
                    item.latitude = xml.attributes().value("y").toString().toInt();
                    item.longitude = xml.attributes().value("x").toString().toInt();
                }

                if (xml.isStartElement() && (xml.name() == "Dep" || xml.name() == "Arr" )) {
                    while (!xml.atEnd()) {
                        xml.readNext();
                        if (xml.isStartElement() && xml.name() == "Time") {
                            xml.readNext();
                            item.time = QTime::fromString(xml.text().toString(), "hh:mm");
                        }

                        if (xml.isStartElement() && xml.name() == "Platform") {
                            while (!xml.atEnd()) {
                                xml.readNext();
                                if (xml.isStartElement() && xml.name() == "Text") {
                                    xml.readNext();
                                    item.platform = xml.text().toString().simplified();
                                }

                                if (xml.isEndElement() && xml.name() == "Platform") {
                                   break;
                                }
                            }
                        }

                        if (xml.isEndElement() && (xml.name() == "Dep" || xml.name() == "Arr" )) {
                           break;
                        }
                    }
                }

                if (xml.isStartElement() && xml.name() == "Attribute") {
                    QString currentAttributeType = xml.attributes().value("type").toString();
                    while (!xml.atEnd()) {
                        xml.readNext();
                        if (xml.isStartElement() && xml.name() == "Text") {
                            xml.readNext();

                            if (currentAttributeType == "DIRECTION") {
                                item.destinationStation = xml.text().toString().simplified();
                            }
                            if (currentAttributeType == "NAME") {
                                item.trainType = xml.text().toString().simplified();
                            }
                        }

                        if (xml.isEndElement() && xml.name() == "Attribute") {
                           break;
                        }
                    }
                }
                if (xml.isEndElement() && xml.name() == "STBJourney") {
                    result << item;
                    break;
                }
            }
        }
    }

    emit timetableResult(result);
}
Exemplo n.º 4
0
void FahrplanParserThread::run()
{
    ParserAbstract *m_parser;

    switch (i_parser) {
        default:
        case 0:
            m_parser = new ParserMobileBahnDe();
            break;
        case 1:
            m_parser = new ParserXmlOebbAt();
            break;
        case 2:
            m_parser = new ParserXmlRejseplanenDk();
            break;
        case 3:
            m_parser = new ParserXmlSbbCh();
            break;
        case 4:
            m_parser = new ParserXmlNri();
            break;
        case 5:
            m_parser = new ParserXmlVasttrafikSe();
            break;
        case 6:
            m_parser = new ParserPTVVicGovAu();
            break;
        case 7:
            m_parser = new ParserSydneyEFA();
            break;
        case 8:
            m_parser = new ParserSFBayEFA();
            break;
        case 9:
            m_parser = new ParserIrelandEFA();
            break;
        case 10:
            m_parser = new ParserDubaiEFA();
            break;
        case 11:
            m_parser = new ParserNinetwo();
            break;
        case 12:
            m_parser = new ParserMunichEFA();
            break;
        case 13:
            m_parser = new ParserSalzburgEFA();
            break;
        case 14:
            m_parser = new ParserResRobot();
            break;
        case 15:
            m_parser = new ParserFinlandMatka();
            break;
    }

    m_name = m_parser->name();
    m_short_name = m_parser->shortName();
    m_uid = m_parser->uid();
    m_trainrestrictions = m_parser->getTrainRestrictions();
    m_supports_gps = m_parser->supportsGps();
    m_supports_via = m_parser->supportsVia();
    m_supports_timetable = m_parser->supportsTimeTable();
    m_supports_timetabledirection = m_parser->supportsTimeTableDirection();

    qRegisterMetaType<ParserAbstract::Mode>("ParserAbstract::Mode");
    //Connect thread requests with actual parser
    connect(this, SIGNAL(requestCancelRequest()), m_parser, SLOT(cancelRequest()), Qt::QueuedConnection);
    connect(this, SIGNAL(requestFindStationsByName(QString)), m_parser, SLOT(findStationsByName(QString)), Qt::QueuedConnection);
    connect(this, SIGNAL(requestFindStationsByCoordinates(qreal,qreal)), m_parser, SLOT(findStationsByCoordinates(qreal,qreal)), Qt::QueuedConnection);
    connect(this, SIGNAL(requestGetJourneyDetails(QString)), m_parser, SLOT(getJourneyDetails(QString)), Qt::QueuedConnection);
    connect(this, SIGNAL(requestGetTimeTableForStation(Station,Station,QDateTime,ParserAbstract::Mode,int)), m_parser, SLOT(getTimeTableForStation(Station,Station,QDateTime,ParserAbstract::Mode,int)), Qt::QueuedConnection);
    connect(this, SIGNAL(requestSearchJourney(Station,Station,Station,QDateTime,ParserAbstract::Mode,int)), m_parser, SLOT(searchJourney(Station,Station,Station,QDateTime,ParserAbstract::Mode,int)), Qt::QueuedConnection);
    connect(this, SIGNAL(requestSearchJourneyEarlier()), m_parser, SLOT(searchJourneyEarlier()), Qt::QueuedConnection);
    connect(this, SIGNAL(requestSearchJourneyLater()), m_parser, SLOT(searchJourneyLater()), Qt::QueuedConnection);

    //Connect parser responses with threads corresponding results
    connect(m_parser, SIGNAL(errorOccured(QString)), this, SIGNAL(errorOccured(QString)), Qt::QueuedConnection);
    connect(m_parser, SIGNAL(journeyDetailsResult(JourneyDetailResultList*)), this, SIGNAL(journeyDetailsResult(JourneyDetailResultList*)), Qt::QueuedConnection);
    connect(m_parser, SIGNAL(journeyResult(JourneyResultList*)), this, SIGNAL(journeyResult(JourneyResultList*)), Qt::QueuedConnection);
    connect(m_parser, SIGNAL(stationsResult(StationsList)), this, SIGNAL(stationsResult(StationsList)), Qt::QueuedConnection);
    connect(m_parser, SIGNAL(timetableResult(TimetableEntriesList)), this, SIGNAL(timeTableResult(TimetableEntriesList)), Qt::QueuedConnection);

    m_ready = true;

    // Autodelete after thread finishes.
    connect(this, SIGNAL(finished()), SLOT(deleteLater()));

    exec();

    delete m_parser;
}