Commit c9a2c84b authored by Volker Krause's avatar Volker Krause
Browse files

Factor out location query, for re-use in journey and departure queries

parent ce215d90
......@@ -117,55 +117,11 @@ bool HafasMgateBackend::queryLocation(LocationReply *reply, QNetworkAccessManage
m_parser.setLocationIdentifierType(locationIdentifierType());
const auto req = reply->request();
QJsonObject methodObj;
if (req.hasCoordinate()) {
QJsonObject cfg;
cfg.insert(QLatin1String("polyEnc"), QLatin1String("GPA"));
QJsonObject coord;
coord.insert(QLatin1String("x"), (int)(req.latitude() * 1000000));
coord.insert(QLatin1String("y"), (int)(req.longitude() * 1000000));
QJsonObject ring;
ring.insert(QLatin1String("cCrd"), coord);
ring.insert(QLatin1String("maxDist"), 20000); // not sure which unit...
QJsonObject reqObj;
reqObj.insert(QLatin1String("ring"), ring);
// ### make this configurable in LocationRequest
reqObj.insert(QLatin1String("getStops"), true);
reqObj.insert(QLatin1String("getPOIs"), false);
reqObj.insert(QLatin1String("maxLoc"), 12);
methodObj.insert(QLatin1String("cfg"), cfg);
methodObj.insert(QLatin1String("meth"), QLatin1String("LocGeoPos"));
methodObj.insert(QLatin1String("req"), reqObj);
} else if (!req.name().isEmpty()) {
QJsonObject cfg;
cfg.insert(QLatin1String("polyEnc"), QLatin1String("GPA"));
QJsonObject loc;
loc.insert(QLatin1String("name"), req.name()); // + '?' for auto completion search?
loc.insert(QLatin1String("type"), QLatin1String("S")); // station: S, address: A, POI: P
QJsonObject input;
input.insert(QLatin1String("field"), QLatin1String("S"));
input.insert(QLatin1String("loc"), loc);
// ### make this configurable in LocationRequest
input.insert(QLatin1String("maxLoc"), 12);
QJsonObject reqObj;
reqObj.insert(QLatin1String("input"), input);
methodObj.insert(QLatin1String("cfg"), cfg);
methodObj.insert(QLatin1String("meth"), QLatin1String("LocMatch"));
methodObj.insert(QLatin1String("req"), reqObj);
} else {
const auto netReply = postLocationQuery(req, nam);
if (!netReply) {
return false;
}
auto netReply = postRequest(methodObj, nam);
QObject::connect(netReply, &QNetworkReply::finished, [netReply, reply, this]() {
qDebug() << netReply->request().url();
switch (netReply->error()) {
......@@ -261,6 +217,59 @@ QNetworkReply* HafasMgateBackend::postRequest(const QJsonObject &svcReq, QNetwor
return nam->post(netReq, content);
}
QNetworkReply* HafasMgateBackend::postLocationQuery(const LocationRequest &req, QNetworkAccessManager *nam) const
{
QJsonObject methodObj;
if (req.hasCoordinate()) {
QJsonObject cfg;
cfg.insert(QLatin1String("polyEnc"), QLatin1String("GPA"));
QJsonObject coord;
coord.insert(QLatin1String("x"), (int)(req.latitude() * 1000000));
coord.insert(QLatin1String("y"), (int)(req.longitude() * 1000000));
QJsonObject ring;
ring.insert(QLatin1String("cCrd"), coord);
ring.insert(QLatin1String("maxDist"), 20000); // not sure which unit...
QJsonObject reqObj;
reqObj.insert(QLatin1String("ring"), ring);
// ### make this configurable in LocationRequest
reqObj.insert(QLatin1String("getStops"), true);
reqObj.insert(QLatin1String("getPOIs"), false);
reqObj.insert(QLatin1String("maxLoc"), 12);
methodObj.insert(QLatin1String("cfg"), cfg);
methodObj.insert(QLatin1String("meth"), QLatin1String("LocGeoPos"));
methodObj.insert(QLatin1String("req"), reqObj);
} else if (!req.name().isEmpty()) {
QJsonObject cfg;
cfg.insert(QLatin1String("polyEnc"), QLatin1String("GPA"));
QJsonObject loc;
loc.insert(QLatin1String("name"), req.name()); // + '?' for auto completion search?
loc.insert(QLatin1String("type"), QLatin1String("S")); // station: S, address: A, POI: P
QJsonObject input;
input.insert(QLatin1String("field"), QLatin1String("S"));
input.insert(QLatin1String("loc"), loc);
// ### make this configurable in LocationRequest
input.insert(QLatin1String("maxLoc"), 12);
QJsonObject reqObj;
reqObj.insert(QLatin1String("input"), input);
methodObj.insert(QLatin1String("cfg"), cfg);
methodObj.insert(QLatin1String("meth"), QLatin1String("LocMatch"));
methodObj.insert(QLatin1String("req"), reqObj);
} else {
return nullptr;
}
return postRequest(methodObj, nam);
}
void HafasMgateBackend::setMicMacSalt(const QString &salt)
{
m_micMacSalt = QByteArray::fromHex(salt.toUtf8());
......
......@@ -28,6 +28,8 @@ class QNetworkReply;
namespace KPublicTransport {
class LocationRequest;
/** Backend for the Hafas mgate.exe interface. */
class HafasMgateBackend : public AbstractBackend
{
......@@ -55,6 +57,7 @@ public:
private:
QNetworkReply* postRequest(const QJsonObject &svcReq, QNetworkAccessManager *nam) const;
QNetworkReply* postLocationQuery(const LocationRequest &req, QNetworkAccessManager *nam) const;
void setMicMacSalt(const QString &salt);
void setChecksumSalt(const QString &salt);
void setLineModeMap(const QJsonObject &obj);
......
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