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

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

    QDomDocument doc("result");
    if (doc.setContent(xmlRawtext, false)) {
        QDomNodeList locationList = doc.elementsByTagName("StopLocation");
        for (unsigned int i = 0; i < locationList.length(); ++i) {
            QDomNode locationNode = locationList.item(i);

            Station item;
            item.id = getAttribute(locationNode, "id");
            item.name = getAttribute(locationNode, "name");
            item.latitude = getAttribute(locationNode, "lat").toFloat();
            item.longitude = getAttribute(locationNode, "lon").toFloat();

            result << item;
        }
    }

    if (m_timeTableForStationParameters.isValid) {
        getTimeTableForStation(m_timeTableForStationParameters.currentStation, m_timeTableForStationParameters.directionStation, m_timeTableForStationParameters.dateTime, m_timeTableForStationParameters.mode, m_timeTableForStationParameters.trainrestrictions);
    } else if (m_searchJourneyParameters.isValid) {
        searchJourney(m_searchJourneyParameters.departureStation, m_searchJourneyParameters.arrivalStation, m_searchJourneyParameters.viaStation, m_searchJourneyParameters.dateTime, m_searchJourneyParameters.mode, m_searchJourneyParameters.trainrestrictions);
    } else {
        emit stationsResult(result);
    }
}
Пример #2
0
void ParserHafasXml::parseStationsByCoordinates(QNetworkReply *networkReply)
{
    //Normally hafas returns the data as Latin1, but here we get utf8.
    QString data = QString::fromUtf8(networkReply->readAll());
    const StationsList result = internalParseStationsByName(data);
    emit stationsResult(result);
}
Пример #3
0
void Parser131500ComAu::parseStationsByName(QNetworkReply *networkReply)
{
    StationsResultList result;

    QRegExp regexp = QRegExp("<select name=\"(.*)\" id=\"from\" size=\"6\" class=\"multiple\">(.*)</select>");
    regexp.setMinimal(true);

    regexp.indexIn(networkReply->readAll());

    QString element = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><html xmlns=\"http://www.w3.org/1999/xhtml\">\n<body>\n" + regexp.cap(0) + "\n</body>\n</html>\n";

    QBuffer readBuffer;
    readBuffer.setData(element.toAscii());
    readBuffer.open(QIODevice::ReadOnly);

    QXmlQuery query;
    query.bindVariable("path", &readBuffer);
    //Query for more than one result
    query.setQuery("declare default element namespace \"http://www.w3.org/1999/xhtml\"; declare variable $path external; doc($path)/html/body/select/option/string()");

    QStringList stationNames;
    if (!query.evaluateTo(&stationNames))
    {
        qDebug() << "parser131500ComAu::getStationsByName - Query 1 Failed";
    }

    for (int i = 0; i < stationNames.count(); i++) {
        //Remove unneeded stuff from the result
        stationNames[i].replace(" (Location)", "");
        StationsResultItem *item = new StationsResultItem();
        item->setStationName(stationNames[i].trimmed());
        result.appendItem(item);
    }

    emit stationsResult(&result);
}
Пример #4
0
void ParserHafasXml::parseStationsByName(QNetworkReply *networkReply)
{
    QString data = QString::fromLatin1(networkReply->readAll());
    const StationsList result = internalParseStationsByName(data);
    emit stationsResult(result);
}
Пример #5
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;
}