Commit 18b7700d authored by Volker Krause's avatar Volker Krause
Browse files

Allow to query for arrivals too

This still misses working result parsing, and better naming of the classes.
parent 3c5f0fb5
......@@ -123,7 +123,7 @@ void HafasMgateBackend::queryDeparture(DepartureReply *reply, const QString &loc
req.insert(QLatin1String("stbLoc"), stbLoc);
req.insert(QLatin1String("time"), request.dateTime().toString(QLatin1String("hhmmss")));
req.insert(QLatin1String("type"), QLatin1String("DEP"));
req.insert(QLatin1String("type"), request.mode() == DepartureRequest::QueryDeparture ? QLatin1String("DEP") : QLatin1String("ARR"));
stationBoard.insert(QLatin1String("cfg"), cfg);
stationBoard.insert(QLatin1String("meth"), QLatin1String("StationBoard"));
......
......@@ -107,7 +107,7 @@ bool NavitiaBackend::queryDeparture(DepartureReply *reply, QNetworkAccessManager
QStringLiteral("/v1/coverage/") +
(m_coverage.isEmpty() ? QString::number(req.stop().latitude()) + QLatin1Char(';') + QString::number(req.stop().longitude()) : m_coverage) +
QStringLiteral("/coord/") + QString::number(req.stop().latitude()) + QLatin1Char(';') + QString::number(req.stop().longitude()) +
QStringLiteral("/departures")
(req.mode() == DepartureRequest::QueryDeparture ? QStringLiteral("/departures") : QStringLiteral("/arrivals"))
);
QUrlQuery query;
......
......@@ -29,6 +29,7 @@ class DepartureRequestPrivate : public QSharedData {
public:
Location stop;
QDateTime dateTime;
DepartureRequest::Mode mode = DepartureRequest::QueryDeparture;
};
}
......@@ -66,3 +67,14 @@ void DepartureRequest::setDateTime(const QDateTime &dt)
d.detach();
d->dateTime = dt;
}
DepartureRequest::Mode DepartureRequest::mode() const
{
return d->mode;
}
void DepartureRequest::setMode(DepartureRequest::Mode mode)
{
d.detach();
d->mode = mode;
}
......@@ -45,6 +45,14 @@ public:
QDateTime dateTime() const;
void setDateTime(const QDateTime &dt);
/** Query departures or arrivals? */
enum Mode {
QueryArrival,
QueryDeparture
};
Mode mode() const;
void setMode(Mode mode);
private:
QExplicitlySharedDataPointer<DepartureRequestPrivate> d;
};
......
......@@ -43,7 +43,7 @@ public:
ptMgr.setNetworkAccessManager(&nam);
}
Q_INVOKABLE void queryDeparture(double fromLat, double fromLon, const QString &id, const QString &idType)
Q_INVOKABLE void queryDeparture(double fromLat, double fromLon, const QString &id, const QString &idType, bool queryArrival)
{
engine->rootContext()->setContextProperty(QStringLiteral("_departures"), QVariantList());
m_loading = true;
......@@ -55,7 +55,10 @@ public:
from.setCoordinate(fromLat, fromLon);
from.setIdentifier(idType, id);
auto reply = ptMgr.queryDeparture(DepartureRequest(from));
DepartureRequest depReq(from);
depReq.setMode(queryArrival ? DepartureRequest::QueryArrival : DepartureRequest::QueryDeparture);
auto reply = ptMgr.queryDeparture(depReq);
QObject::connect(reply, &DepartureReply::finished, [reply, this]{
m_loading = false;
emit loadingChanged();
......
......@@ -136,6 +136,11 @@ Kirigami.ApplicationWindow {
ColumnLayout {
anchors.fill: parent
QQC2.CheckBox {
id: arrivalBox
text: checked ? "Arrival" : "Departure"
}
QQC2.CheckBox {
text: "Allow insecure backends"
onToggled: _queryMgr.setAllowInsecure(checked)
......@@ -148,7 +153,7 @@ Kirigami.ApplicationWindow {
textRole: "name"
onCurrentIndexChanged: {
var obj = exampleModel.get(currentIndex);
_queryMgr.queryDeparture(obj.lat, obj.lon, obj.locId, obj.idType);
_queryMgr.queryDeparture(obj.lat, obj.lon, obj.locId, obj.idType, arrivalBox.checked);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment