Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- parser_abstract.h:
- /*******************************************************************************
- This file is a part of Fahrplan for maemo 2009-2010
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- #ifndef PARSER_ABSTRACT_H
- #define PARSER_ABSTRACT_H
- #include <QObject>
- #include <QtNetwork>
- //#include <QNetworkAccessManager>
- //#include "mainwindow.h"
- struct DetailResultItem
- {
- QString fromStation;
- QString fromInfo;
- QDateTime fromTime;
- QString toStation;
- QString toInfo;
- QDateTime toTime;
- QString train;
- QString info;
- };
- struct DetailResultInfo
- {
- QString duration;
- QString info;
- QList<DetailResultItem> items;
- };
- struct ResultItem
- {
- QString id;
- QString fromTime;
- QString toTime;
- QString trainType;
- QString duration;
- QString changes;
- QString state;
- QString detailsUrl;
- QDate tripDate;
- DetailResultInfo detailsInfo;
- };
- struct ResultInfo
- {
- QString errorMsg;
- QString fromStation;
- QString toStation;
- QString timeInfo;
- QString earlierUrl;
- QString laterUrl;
- QList<ResultItem> items;
- };
- class parserAbstract : public QObject
- {
- Q_OBJECT
- public:
- virtual QStringList getStationsByName(QString stationName);
- virtual QStringList getTrainRestrictions();
- virtual QStringList getStationsByGPS(qreal latitude, qreal longitude);
- virtual ResultInfo getJourneyData(QString destinationStation, QString arrivalStation, QString viaStation, QDate date, QTime time, int mode, int trainrestrictions);
- virtual ResultInfo getJourneyData(QString queryUrl);
- virtual DetailResultInfo getJourneyDetailsData(QString queryUrl);
- virtual void httpRequestTimeout();
- // void NetworkManagerInit(void);
- virtual bool supportsGps();
- signals:
- public slots:
- protected:
- int currentRequestId;
- QEventLoop loop;
- public:
- int progress;
- int progressTotal;
- private slots:
- void httpRequestFinished(int requestId, bool error);
- void httpDataReadProgress(int done, int total);
- // void replyFinished(QNetworkReply*);
- };
- #endif // PARSER_ABSTRACT_H
- parser_abstract.cpp:
- /*******************************************************************************
- This file is a part of Fahrplan for maemo 2009-2010
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- #include "parser_abstract.h"
- void parserAbstract::httpDataReadProgress(int done, int total)
- {
- qDebug() << "httpDataReadProgress:" << done << "/" << total;
- progress = done;
- progressTotal = total;
- }
- void parserAbstract::httpRequestFinished(int requestId, bool error)
- {
- Q_UNUSED(error);
- if(currentRequestId != requestId) return;
- loop.exit();
- }
- void parserAbstract::httpRequestTimeout()
- {
- loop.exit();
- }
- //void parserAbstract::NetworkManagerInit(void)
- //{
- // qDebug() << "NetworkManager init";
- //}
- //void parserAbstract::replyFinished(QNetworkReply*)
- //{
- // qDebug() << "NetworkManager reply finished";
- // loop.exit();
- //}
- bool parserAbstract::supportsGps()
- {
- return false;
- }
- QStringList parserAbstract::getStationsByName(QString stationName)
- {
- Q_UNUSED(stationName);
- QStringList result;
- return result;
- }
- QStringList parserAbstract::getTrainRestrictions()
- {
- QStringList result;
- return result;
- }
- QStringList parserAbstract::getStationsByGPS(qreal latitude, qreal longitude)
- {
- Q_UNUSED(latitude);
- Q_UNUSED(longitude);
- QStringList result;
- return result;
- }
- ResultInfo parserAbstract::getJourneyData(QString destinationStation, QString arrivalStation, QString viaStation, QDate date, QTime time, int mode, int trainrestrictions)
- {
- Q_UNUSED(destinationStation);
- Q_UNUSED(arrivalStation);
- Q_UNUSED(viaStation);
- Q_UNUSED(date);
- Q_UNUSED(time);
- Q_UNUSED(mode);
- Q_UNUSED(trainrestrictions);
- ResultInfo result;
- return result;
- }
- ResultInfo parserAbstract::getJourneyData(QString queryUrl)
- {
- Q_UNUSED(queryUrl);
- ResultInfo result;
- return result;
- }
- DetailResultInfo parserAbstract::getJourneyDetailsData(QString queryUrl)
- {
- Q_UNUSED(queryUrl);
- DetailResultInfo result;
- return result;
- }
- parser_translink.h:
- /*******************************************************************************
- This file is a part of Fahrplan for maemo 2009-2010
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- #ifndef PARSER_TRANSLINK_H
- #define PARSER_TRANSLINK_H
- #include <QObject>
- #include <QtNetwork>
- #include <qjson/parser.h>
- #include "fahrplanutils.h"
- #include "parser_abstract.h"
- class parserTranslink : public parserAbstract
- {
- Q_OBJECT
- public:
- explicit parserTranslink(QObject *parent = 0);
- QStringList getStationsByName(QString stationName);
- QStringList getTrainRestrictions();
- QStringList getStationsByGPS(qreal latitude, qreal longitude);
- ResultInfo getJourneyData(QString destinationStation, QString arrivalStation, QString viaStation, QDate date, QTime time, int mode, int trainrestrictions);
- ResultInfo getJourneyData(QString queryUrl);
- DetailResultInfo getJourneyDetailsData(QString queryUrl);
- bool supportsGps();
- signals:
- public slots:
- private:
- QHttp *http;
- QBuffer *filebuffer;
- ResultInfo parseJourneyData(QByteArray data);
- };
- #endif // PARSER_TRANSLINK_H
- parser_translink.cpp:
- /*******************************************************************************
- This file is a part of Fahrplan for maemo 2009-2010
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- #include "parser_translink.h"
- parserTranslink::parserTranslink(QObject *parent)
- {
- Q_UNUSED(parent);
- http = new QHttp(this);
- connect(http, SIGNAL(requestFinished(int,bool)),
- this, SLOT(httpRequestFinished(int,bool)));
- }
- bool parserTranslink::supportsGps()
- {
- return true;
- }
- QStringList parserTranslink::getStationsByName(QString stationName)
- {
- QByteArray postData = "location=";
- postData.append(stationName);
- qDebug() << "Translink: getStationsByName";
- QUrl url("https://app.jp.translink.com.au/plan-your-journey/location/find-location");
- http->setHost(url.host(), QHttp::ConnectionModeHttps, url.port() == -1 ? 0 : url.port());
- filebuffer = new QBuffer();
- if (!filebuffer->open(QIODevice::WriteOnly))
- {
- qDebug() << "Can't open Buffer";
- }
- QHttpRequestHeader header;
- header.setRequest("POST", url.path());
- header.setValue("User-Agent", "Wget/1.10.2");
- header.setValue("Accept", "*/*");
- header.setValue("Host", url.host());
- header.setValue("Content-Type", "application/x-www-form-urlencoded");
- header.setValue("Content-Length", QString::number(postData.length()));
- currentRequestId = http->request(header, postData, filebuffer);
- loop.exec();
- filebuffer->close();
- QJson::Parser parser;
- bool ok;
- QStringList result;
- QVariantList list = parser.parse(filebuffer->buffer(),&ok).toList();
- foreach (QVariant station, list)
- {
- QVariantMap map = station.toMap();
- result.append(map["Description"].toString());
- }
- return result;
- }
- QStringList parserTranslink::getTrainRestrictions()
- {
- QStringList result;
- result.append(tr("Bus"));
- result.append(tr("Train"));
- result.append(tr("Ferry"));
- result.append(tr("Tram"));
- return result;
- }
- QStringList parserTranslink::getStationsByGPS(qreal latitude, qreal longitude)
- {
- Q_UNUSED(latitude);
- Q_UNUSED(longitude);
- QStringList result;
- return result;
- }
- ResultInfo parserTranslink::getJourneyData(QString destinationStation, QString arrivalStation, QString viaStation, QDate date, QTime time, int mode, int trainrestrictions)
- {
- Q_UNUSED(destinationStation);
- Q_UNUSED(arrivalStation);
- Q_UNUSED(viaStation);
- Q_UNUSED(date);
- Q_UNUSED(time);
- Q_UNUSED(mode);
- Q_UNUSED(trainrestrictions);
- ResultInfo result;
- return result;
- }
- ResultInfo parserTranslink::getJourneyData(QString queryUrl)
- {
- Q_UNUSED(queryUrl);
- ResultInfo result;
- return result;
- }
- DetailResultInfo parserTranslink::getJourneyDetailsData(QString queryUrl)
- {
- Q_UNUSED(queryUrl);
- DetailResultInfo result;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement