6#include "restonboardbackend_p.h"
8#include "positiondata_p.h"
10#include "../../lib/json/jsonp_p.h"
12#include <KPublicTransport/Journey>
17#include <QJsonDocument>
19#include <QNetworkAccessManager>
20#include <QNetworkReply>
24RestOnboardBackend::RestOnboardBackend(
QObject *parent)
25 : AbstractOnboardBackend(parent)
29RestOnboardBackend::~RestOnboardBackend() =
default;
33 QFile configFile(qEnvironmentVariable(
"KPUBLICTRANSPORT_ONBOARD_FAKE_CONFIG"));
35 qCWarning(
Log) << configFile.errorString() << configFile.fileName();
49 QFile f(fakeResponseFile(key));
51 qCWarning(
Log) << f.errorString() << f.fileName();
61 if (Q_UNLIKELY(qEnvironmentVariableIsSet(
"KPUBLICTRANSPORT_ONBOARD_FAKE_CONFIG"))) {
62 Q_EMIT positionReceived(parsePositionData(fakeResponse(
QLatin1String(
"positionResponse"))));
66 if (!supportsPosition()) {
70 auto reply = nam->
get(createPositionRequest());
74 qCWarning(
Log) << reply->url() << reply->errorString();
75 Q_EMIT positionReceived({});
81 Q_EMIT positionReceived(parsePositionData(doc.array()));
83 Q_EMIT positionReceived(parsePositionData(doc.object()));
90 if (Q_UNLIKELY(qEnvironmentVariableIsSet(
"KPUBLICTRANSPORT_ONBOARD_FAKE_CONFIG"))) {
91 Q_EMIT journeyReceived(parseJourneyData(fakeResponse(
QLatin1String(
"journeyResponse"))));
95 if (!supportsJourney()) {
99 auto reply = nam->
get(createJourneyRequest());
101 reply->deleteLater();
103 qCWarning(
Log) << reply->url() << reply->errorString();
104 Q_EMIT journeyReceived({});
110 Q_EMIT journeyReceived(parseJourneyData(doc.array()));
112 Q_EMIT journeyReceived(parseJourneyData(doc.object()));
QString path(const QString &relativePath)
Query operations and data types for accessing realtime public transport information from online servi...
QString absolutePath() const const
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonObject object() const const
QJsonValue value(QLatin1StringView key) const const
QString toString() const const
QNetworkReply * get(const QNetworkRequest &request)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)