8#include "assetrepository_p.h"
9#include "backends/srbijavozbackend.h"
10#include "journeyreply.h"
11#include "journeyrequest.h"
12#include "requestcontext_p.h"
13#include "locationreply.h"
14#include "locationrequest.h"
16#include "stopoverreply.h"
17#include "stopoverrequest.h"
19#include "triprequest.h"
20#include "vehiclelayoutrequest.h"
21#include "vehiclelayoutreply.h"
22#include "datatypes/attributionutil_p.h"
23#include "datatypes/backend.h"
24#include "datatypes/backend_p.h"
25#include "datatypes/disruption.h"
26#include "datatypes/json_p.h"
27#include "geo/geojson_p.h"
29#include <KPublicTransport/Journey>
30#include <KPublicTransport/Location>
31#include <KPublicTransport/Stopover>
33#include "backends/accessibilitycloudbackend.h"
34#include "backends/cache.h"
35#include "backends/deutschebahnbackend.h"
36#include "backends/efabackend.h"
37#include "backends/hafasmgatebackend.h"
38#include "backends/hafasquerybackend.h"
39#include "backends/ivvassbackend.h"
40#include "backends/motisbackend.h"
41#include "backends/motis2backend.h"
42#include "backends/navitiabackend.h"
43#include "backends/oebbbackend.h"
44#include "backends/openjourneyplannerbackend.h"
45#include "backends/opentripplannergraphqlbackend.h"
46#include "backends/opentripplannerrestbackend.h"
47#include "backends/ltglinkbackend.h"
48#include "gbfs/gbfsbackend.h"
50#include <QCoreApplication>
51#include <QDirIterator>
53#include <QJsonDocument>
55#include <QMetaProperty>
56#include <QNetworkAccessManager>
57#include <QStandardPaths>
66static inline void initResources() {
67 Q_INIT_RESOURCE(asset_attributions);
68 Q_INIT_RESOURCE(gbfs);
69 Q_INIT_RESOURCE(geometry);
70 Q_INIT_RESOURCE(images);
71 Q_INIT_RESOURCE(networks);
72 Q_INIT_RESOURCE(network_certs);
74 Q_INIT_RESOURCE(stations);
80 [[nodiscard]] QNetworkAccessManager* nam();
82 [[nodiscard]] std::unique_ptr<AbstractBackend> loadNetwork(
const QJsonObject &obj);
83 template <
typename Backend,
typename Backend2,
typename ...Backends>
84 [[nodiscard]]
static std::unique_ptr<AbstractBackend> loadNetwork(
const QJsonObject &backendType,
const QJsonObject &obj);
85 template <
typename Backend>
86 [[nodiscard]]
static std::unique_ptr<AbstractBackend> loadNetwork(
const QJsonObject &backendType,
const QJsonObject &obj);
88 [[nodiscard]]
static std::unique_ptr<AbstractBackend> loadNetwork(
const QJsonObject &obj);
90 template <
typename RequestT>
91 [[nodiscard]]
bool shouldSkipBackend(
const Backend &backend,
const RequestT &req)
const;
93 void resolveLocation(LocationRequest &&locReq,
const AbstractBackend *backend,
const std::function<
void(
const Location &loc)> &callback);
94 [[nodiscard]]
bool queryJourney(
const AbstractBackend *backend,
const JourneyRequest &req, JourneyReply *reply);
95 [[nodiscard]]
bool queryStopover(
const AbstractBackend *backend,
const StopoverRequest &req, StopoverReply *reply);
97 template <
typename RepT,
typename ReqT>
98 [[nodiscard]] RepT* makeReply(
const ReqT &request);
100 void readCachedAttributions();
102 [[nodiscard]]
int queryLocationOnBackend(
const LocationRequest &req, LocationReply *reply,
const Backend &backend);
104 Manager *q =
nullptr;
105 QNetworkAccessManager *m_nam =
nullptr;
106 std::vector<Backend> m_backends;
107 std::vector<Attribution> m_attributions;
110 QStringList m_enabledBackends;
111 QStringList m_disabledBackends;
113 bool m_allowInsecure =
false;
114 bool m_hasReadCachedAttributions =
false;
115 bool m_backendsEnabledByDefault =
true;
118 [[nodiscard]]
bool shouldSkipBackend(
const Backend &backend)
const;
125 m_nam =
new QNetworkAccessManager(q);
127 m_nam->setStrictTransportSecurityEnabled(
true);
134void ManagerPrivate::loadNetworks()
136 if (!m_backends.empty()) {
140 QStringList searchDirs;
146 std::vector<Attribution> attributions;
147 for (
const auto &searchDir : searchDirs) {
148 QDirIterator it(searchDir +
"/org.kde.kpublictransport/networks"_L1, {u
"*.json"_s},
QDir::Files);
149 while (it.hasNext()) {
151 const auto id = it.fileInfo().baseName();
152 if (std::any_of(m_backends.begin(), m_backends.end(), [&
id](
const auto &backend) { return backend.identifier() == id; })) {
157 QFile f(it.filePath());
159 qCWarning(Log) <<
"Failed to open public transport network configuration:" << f.errorString();
163 QJsonParseError
error;
166 qCWarning(Log) <<
"Failed to parse public transport network configuration:" <<
error.errorString() << it.fileName();
170 auto net = loadNetwork(doc.object());
172 net->setBackendId(
id);
174 if (!net->attribution().isEmpty()) {
175 attributions.push_back(net->attribution());
178 auto b = BackendPrivate::fromJson(doc.object());
179 BackendPrivate::setImpl(b, std::move(net));
180 m_backends.push_back(std::move(b));
182 qCWarning(Log) <<
"Failed to load public transport network configuration config:" << it.fileName();
187 std::stable_sort(m_backends.begin(), m_backends.end(), [](
const auto &lhs,
const auto &rhs) {
188 return lhs.identifier() < rhs.identifier();
191 AttributionUtil::sort(attributions);
192 if (m_attributions.empty()) {
194 m_attributions = std::move(attributions);
197 AttributionUtil::merge(m_attributions, attributions);
200 qCDebug(Log) << m_backends.size() <<
"public transport network configurations loaded";
203std::unique_ptr<AbstractBackend> ManagerPrivate::loadNetwork(
const QJsonObject &obj)
209 OpenTripPlannerGraphQLBackend,
210 OpenTripPlannerRestBackend,
217 OpenJourneyPlannerBackend,
221 AccessibilityCloudBackend,
227template <
typename Backend,
typename Backend2,
typename ...Backends>
228std::unique_ptr<AbstractBackend> ManagerPrivate::loadNetwork(
const QJsonObject &backendType,
const QJsonObject &obj)
230 if (backendType.
value(QLatin1String(Backend::type())).toBool()) {
231 return loadNetwork<Backend>(obj);
233 return loadNetwork<Backend2, Backends...>(backendType, obj);
236template <
typename Backend>
237std::unique_ptr<AbstractBackend> ManagerPrivate::loadNetwork(
const QJsonObject &backendType,
const QJsonObject &obj)
239 if (backendType.
value(QLatin1String(Backend::type())).toBool()) {
240 return ManagerPrivate::loadNetwork<Backend>(obj);
242 qCWarning(Log) <<
"Unknown backend type:" << backendType;
246static void applyBackendOptions(AbstractBackend *backend,
const QMetaObject *mo,
const QJsonObject &obj)
249 for (
auto it = opts.begin(); it != opts.end(); ++it) {
252 qCWarning(Log) <<
"Unknown backend setting:" << it.key();
256 if (it.value().isObject()) {
257 mp.writeOnGadget(backend, it.value().toObject());
258 }
else if (it.value().isArray()) {
259 const auto a = it.value().toArray();
263 std::transform(a.begin(), a.end(), std::back_inserter(l), [](
const auto &v) { return v.toString(); });
264 mp.writeOnGadget(backend, l);
266 mp.writeOnGadget(backend, it.value().toArray());
269 mp.writeOnGadget(backend, it.value().toVariant());
275 backend->setAttribution(attr);
278 if (!tzId.isEmpty()) {
279 QTimeZone tz(tzId.toUtf8());
281 backend->setTimeZone(tz);
283 qCWarning(Log) <<
"Invalid timezone:" << tzId;
287 const auto langArray = obj.
value(
"supportedLanguages"_L1).
toArray();
289 langs.
reserve(langArray.size());
290 std::transform(langArray.begin(), langArray.end(), std::back_inserter(langs), [](
const auto &v) { return v.toString(); });
291 backend->setSupportedLanguages(langs);
294template<
typename T> std::unique_ptr<AbstractBackend> ManagerPrivate::loadNetwork(
const QJsonObject &obj)
296 std::unique_ptr<AbstractBackend> backend(
new T);
297 applyBackendOptions(backend.get(), &T::staticMetaObject, obj);
301bool ManagerPrivate::shouldSkipBackend(
const Backend &backend)
const
303 if (!backend.
isSecure() && !m_allowInsecure) {
304 qCDebug(Log) <<
"Skipping insecure backend:" << backend.
identifier();
307 return !q->isBackendEnabled(backend.
identifier());
310template <
typename RequestT>
311bool ManagerPrivate::shouldSkipBackend(
const Backend &backend,
const RequestT &req)
const
313 if (!req.backendIds().isEmpty() && !req.backendIds().contains(backend.
identifier())) {
317 return shouldSkipBackend(backend);
322void ManagerPrivate::resolveLocation(
LocationRequest &&locReq,
const AbstractBackend *backend,
const std::function<
void(
const Location&)> &callback)
325 locReq.setMaximumResults(1);
328 const auto cacheEntry = Cache::lookupLocation(backend->backendId(), locReq.cacheKey());
329 switch (cacheEntry.type) {
330 case CacheHitType::Negative:
333 case CacheHitType::Positive:
334 if (!cacheEntry.data.empty()) {
335 const auto loc = cacheEntry.data[0];
340 case CacheHitType::Miss:
345 auto locReply =
new LocationReply(locReq, q);
346 if (backend->queryLocation(locReq, locReply, nam())) {
347 locReply->setPendingOps(1);
349 locReply->setPendingOps(0);
352 locReply->deleteLater();
353 if (locReply->result().empty()) {
356 callback(locReply->result()[0]);
361static Location::Types locationTypesForJourneyRequest(
const JourneyRequest &req)
364 if (req.
modes() & JourneySection::PublicTransport) {
375 auto cache = Cache::lookupJourney(backend->backendId(), req.
cacheKey());
376 switch (cache.type) {
377 case CacheHitType::Negative:
378 qCDebug(Log) <<
"Negative cache hit for backend" << backend->backendId();
380 case CacheHitType::Positive:
381 qCDebug(Log) <<
"Positive cache hit for backend" << backend->backendId();
382 reply->addAttributions(std::move(cache.attributions));
383 reply->addResult(backend, std::move(cache.data));
385 case CacheHitType::Miss:
386 qCDebug(Log) <<
"Cache miss for backend" << backend->backendId();
391 if (backend->needsLocationQuery(req.
from(), AbstractBackend::QueryType::Journey)) {
392 LocationRequest fromReq(req.
from());
393 fromReq.setTypes(locationTypesForJourneyRequest(req));
394 resolveLocation(std::move(fromReq), backend, [reply, backend, req,
this](
const Location &loc) {
395 auto jnyRequest = req;
397 jnyRequest.setFrom(fromLoc);
399 if (backend->needsLocationQuery(jnyRequest.to(), AbstractBackend::QueryType::Journey)) {
400 LocationRequest toReq(jnyRequest.to());
401 toReq.setTypes(locationTypesForJourneyRequest(req));
402 resolveLocation(std::move(toReq), backend, [jnyRequest, reply, backend,
this](
const Location &loc) {
403 auto jnyReq = jnyRequest;
406 if (!backend->queryJourney(jnyReq, reply, nam())) {
414 if (!backend->queryJourney(jnyRequest, reply, nam())) {
422 if (backend->needsLocationQuery(req.
to(), AbstractBackend::QueryType::Journey)) {
423 LocationRequest toReq(req.
to());
424 toReq.setTypes(locationTypesForJourneyRequest(req));
425 resolveLocation(std::move(toReq), backend, [req, toReq, reply, backend,
this](
const Location &loc) {
427 auto jnyRequest = req;
428 jnyRequest.setTo(toLoc);
429 if (!backend->queryJourney(jnyRequest, reply, nam())) {
436 return backend->queryJourney(req, reply, nam());
441 auto cache = Cache::lookupStopover(backend->backendId(), req.
cacheKey());
442 switch (cache.type) {
443 case CacheHitType::Negative:
444 qCDebug(Log) <<
"Negative cache hit for backend" << backend->backendId();
446 case CacheHitType::Positive:
447 qCDebug(Log) <<
"Positive cache hit for backend" << backend->backendId();
448 reply->addAttributions(std::move(cache.attributions));
449 reply->addResult(backend, std::move(cache.data));
451 case CacheHitType::Miss:
452 qCDebug(Log) <<
"Cache miss for backend" << backend->backendId();
457 if (backend->needsLocationQuery(req.
stop(), AbstractBackend::QueryType::Departure)) {
458 qCDebug(Log) <<
"Backend needs location query first:" << backend->backendId();
459 LocationRequest locReq(req.
stop());
461 locReq.setMaximumDistance(250);
462 resolveLocation(std::move(locReq), backend, [reply, req, backend,
this](
const Location &loc) {
464 auto depRequest = req;
465 depRequest.setStop(depLoc);
466 if (!backend->queryStopover(depRequest, reply, nam())) {
473 return backend->queryStopover(req, reply, nam());
476void ManagerPrivate::readCachedAttributions()
478 if (m_hasReadCachedAttributions) {
482 Cache::allCachedAttributions(m_attributions);
483 m_hasReadCachedAttributions =
true;
486template<
typename RepT,
typename ReqT>
487RepT* ManagerPrivate::makeReply(
const ReqT &request)
489 auto reply =
new RepT(request, q);
491 AttributionUtil::merge(m_attributions, reply->
attributions());
498Manager::Manager(QObject *parent)
500 , d(new ManagerPrivate)
503 qRegisterMetaType<Disruption::Effect>();
506 if (!AssetRepository::instance()) {
507 auto assetRepo =
new AssetRepository(
this);
508 assetRepo->setNetworkAccessManagerProvider(std::bind(&ManagerPrivate::nam, d.get()));
516Manager::~Manager() =
default;
520 if (d->m_nam == nam) {
524 if (d->m_nam && d->m_nam->parent() ==
this) {
533 return d->m_allowInsecure;
538 if (d->m_allowInsecure == insecure) {
541 d->m_allowInsecure = insecure;
542 Q_EMIT configurationChanged();
554 reply->setPendingOps(pendingOps);
561 if (req.contexts().empty()) {
563 bool foundNonGlobalCoverage =
false;
564 for (
const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
565 const auto checkBackend = [&](
const Backend &backend,
bool bothLocationMatch) {
566 if (triedBackends.
contains(backend.
identifier()) || d->shouldSkipBackend(backend, req)) {
569 const auto coverage = backend.coverageArea(coverageType);
570 if (coverage.isEmpty()) {
574 if (bothLocationMatch) {
575 if (!coverage.coversLocation(req.
from()) || !coverage.coversLocation(req.
to())) {
579 if (!coverage.coversLocation(req.
from()) && !coverage.coversLocation(req.
to())) {
585 foundNonGlobalCoverage |= !coverage.isGlobal();
587 if (d->queryJourney(BackendPrivate::impl(backend), req, reply)) {
593 for (
const auto &backend: d->m_backends) {
594 checkBackend(backend,
true);
596 if (pendingOps && foundNonGlobalCoverage) {
601 for (
const auto &backend: d->m_backends) {
602 checkBackend(backend,
false);
604 if (pendingOps && foundNonGlobalCoverage) {
611 for (
const auto &context : req.contexts()) {
613 if ((context.type == RequestContext::Next && context.backend->hasCapability(AbstractBackend::CanQueryNextJourney))
614 ||(context.type == RequestContext::Previous && context.backend->hasCapability(AbstractBackend::CanQueryPreviousJourney)))
616 if (d->queryJourney(context.backend, req, reply)) {
626 if (d->queryJourney(context.backend, r, reply)) {
633 if (d->queryJourney(context.backend, r, reply)) {
642 reply->addAttributions(AssetRepository::instance()->
attributions());
649 reply->setPendingOps(pendingOps);
661 reply->setPendingOps(pendingOps);
668 if (req.contexts().empty()) {
670 bool foundNonGlobalCoverage =
false;
671 for (
const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
672 for (
const auto &backend: d->m_backends) {
673 if (triedBackends.
contains(backend.identifier()) || d->shouldSkipBackend(backend, req)) {
677 qCDebug(
Log) <<
"Skipping backend due to not supporting arrival queries:" << backend.identifier();
680 const auto coverage = backend.coverageArea(coverageType);
681 if (coverage.isEmpty() || !coverage.coversLocation(req.
stop())) {
684 triedBackends.
insert(backend.identifier());
685 foundNonGlobalCoverage |= !coverage.isGlobal();
687 if (d->queryStopover(BackendPrivate::impl(backend), req, reply)) {
692 if (pendingOps && foundNonGlobalCoverage) {
699 for (
const auto &context : req.contexts()) {
701 if ((context.type == RequestContext::Next && context.backend->hasCapability(AbstractBackend::CanQueryNextDeparture))
702 ||(context.type == RequestContext::Previous && context.backend->hasCapability(AbstractBackend::CanQueryPreviousDeparture)))
704 if (d->queryStopover(context.backend, req, reply)) {
711 if (context.type == RequestContext::Next) {
713 r.setDateTime(context.dateTime);
714 if (d->queryStopover(context.backend, r, reply)) {
723 reply->addAttributions(AssetRepository::instance()->
attributions());
730 reply->setPendingOps(pendingOps);
737 switch (cache.type) {
738 case CacheHitType::Negative:
739 qCDebug(
Log) <<
"Negative cache hit for backend" << backend.
identifier();
741 case CacheHitType::Positive:
742 qCDebug(
Log) <<
"Positive cache hit for backend" << backend.
identifier();
743 reply->addAttributions(std::move(cache.attributions));
744 reply->addResult(std::move(cache.data));
746 case CacheHitType::Miss:
747 qCDebug(
Log) <<
"Cache miss for backend" << backend.
identifier();
748 reply->addAttribution(BackendPrivate::impl(backend)->attribution());
749 if (BackendPrivate::impl(backend)->queryLocation(req, reply, nam())) {
766 reply->setPendingOps(pendingOps);
773 bool foundNonGlobalCoverage =
false;
776 for (
const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
778 for (
const auto &backend : d->m_backends) {
779 if (triedBackends.
contains(backend.
identifier()) || d->shouldSkipBackend(backend, req)) {
782 const auto coverage = backend.coverageArea(coverageType);
783 if (coverage.isEmpty() || !coverage.coversLocation(loc)) {
786 if (isCountryOnly && !coverage.hasNationWideCoverage(loc.
country())) {
791 foundNonGlobalCoverage |= !coverage.isGlobal();
792 pendingOps += d->queryLocationOnBackend(req, reply, backend);
794 if (pendingOps && foundNonGlobalCoverage) {
799 for (
const auto &backend : d->m_backends) {
800 if (triedBackends.
contains(backend.
identifier()) || d->shouldSkipBackend(backend, req)) {
803 const auto coverage = backend.coverageArea(coverageType);
804 if (coverage.isEmpty() || !coverage.coversLocation(loc)) {
809 foundNonGlobalCoverage |= !coverage.isGlobal();
810 pendingOps += d->queryLocationOnBackend(req, reply, backend);
812 if (pendingOps && foundNonGlobalCoverage) {
821 reply->setPendingOps(pendingOps);
827 auto reply = d->makeReply<
TripReply>(req);
833 reply->setPendingOps(pendingOps);
841 for (
const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
842 const auto checkBackend = [&](
const Backend &backend,
bool bothLocationMatch) {
843 if (triedBackends.
contains(backend.
identifier()) || d->shouldSkipBackend(backend, req)) {
846 const auto coverage = backend.coverageArea(coverageType);
847 if (coverage.isEmpty()) {
851 if (bothLocationMatch) {
863 if (BackendPrivate::impl(backend)->
queryTrip(req, reply, d->nam())) {
869 for (
const auto &backend: d->m_backends) {
870 checkBackend(backend,
true);
877 for (
const auto &backend: d->m_backends) {
878 checkBackend(backend,
false);
886 if (pendingOps == 0) {
893 jnyReq.setIncludeIntermediateStops(
true);
894 jnyReq.setIncludePaths(
true);
895 jnyReq.setModes(JourneySection::PublicTransport);
898 jnyReply->setParent(reply);
900 jnyReply->deleteLater();
902 reply->addError(jnyReply->error(), jnyReply->errorString());
905 for (
const auto &journey : jnyReply->result()) {
906 if (std::ranges::count_if(journey.sections(), [](
const auto &sec) { return sec.mode() == JourneySection::PublicTransport; }) != 1) {
909 const auto it = std::ranges::find_if(journey.sections(), [](
const auto &sec) {
910 return sec.mode() == JourneySection::PublicTransport;
912 assert(it != journey.sections().end());
913 qCDebug(
Log) <<
"Got journey information:" << (*it).route().line().name() << (*it).scheduledDepartureTime();
915 qCDebug(
Log) <<
"Found journey information:" << (*it).route().line().name() << (*it).expectedDeparturePlatform() << (*it).expectedDepartureTime();
916 reply->addAttributions(jnyReply->attributions());
925 reply->setPendingOps(1);
927 reply->setPendingOps(pendingOps);
937 int negativeCacheHit = 0;
942 reply->setPendingOps(pendingOps);
948 for (
const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular }) {
949 for (
const auto &backend : d->m_backends) {
950 if (d->shouldSkipBackend(backend, req)) {
953 const auto coverage = backend.coverageArea(coverageType);
954 if (coverage.isEmpty() || !coverage.coversLocation(req.
stopover().
stopPoint())) {
957 reply->addAttribution(BackendPrivate::impl(backend)->attribution());
960 switch (cache.type) {
961 case CacheHitType::Negative:
963 qCDebug(
Log) <<
"Negative cache hit for backend" << backend.
identifier();
965 case CacheHitType::Positive:
966 qCDebug(
Log) <<
"Positive cache hit for backend" << backend.
identifier();
967 if (cache.data.size() == 1) {
968 reply->addAttributions(std::move(cache.attributions));
969 reply->addResult(cache.data[0]);
973 case CacheHitType::Miss:
974 qCDebug(
Log) <<
"Cache miss for backend" << backend.
identifier();
986 if (pendingOps == 0 && negativeCacheHit == 0) {
989 reply->setPendingOps(pendingOps);
995 if (d->m_backends.empty()) {
998 d->m_backends.clear();
1000 Q_EMIT backendsChanged();
1006 d->readCachedAttributions();
1007 return d->m_attributions;
1010QVariantList Manager::attributionsVariant()
const
1013 d->readCachedAttributions();
1015 l.
reserve(d->m_attributions.size());
1016 std::transform(d->m_attributions.begin(), d->m_attributions.end(), std::back_inserter(l), [](
const auto &attr) { return QVariant::fromValue(attr); });
1023 return d->m_backends;
1028 if (std::binary_search(d->m_disabledBackends.cbegin(), d->m_disabledBackends.cend(), backendId)) {
1031 if (std::binary_search(d->m_enabledBackends.cbegin(), d->m_enabledBackends.cend(), backendId)) {
1035 return d->m_backendsEnabledByDefault;
1040 const auto it = std::lower_bound(l.
begin(), l.
end(), value);
1041 if (it == l.
end() || (*it) != value) {
1046static void sortedRemove(QStringList &l,
const QString &value)
1048 const auto it = std::lower_bound(l.
begin(), l.
end(), value);
1049 if (it != l.
end() && (*it) == value) {
1057 sortedInsert(d->m_enabledBackends, backendId);
1058 sortedRemove(d->m_disabledBackends, backendId);
1060 sortedRemove(d->m_enabledBackends, backendId);
1061 sortedInsert(d->m_disabledBackends, backendId);
1063 Q_EMIT configurationChanged();
1068 return d->m_enabledBackends;
1074 for (
const auto &backendId : backendIds) {
1081 return d->m_disabledBackends;
1087 for (
const auto &backendId : backendIds) {
1094 return d->m_backendsEnabledByDefault;
1099 d->m_backendsEnabledByDefault = byDefault;
1101 Q_EMIT configurationChanged();
1104QVariantList Manager::backendsVariant()
const
1108 l.
reserve(d->m_backends.size());
1109 std::transform(d->m_backends.begin(), d->m_backends.end(), std::back_inserter(l), [](
const auto &b) { return QVariant::fromValue(b); });
1122#include "moc_manager.cpp"
static Attribution fromJson(const QJsonObject &obj)
Deserialize an Attribution object from JSON.
Information about a backend service queried for location/departure/journey data.
bool isSecure
Supports secrure network access.
QString identifier
Internal identifier of this backend.
Describes a journey search.
KPublicTransport::Location to
The journey destination.
void setArrivalTime(const QDateTime &dt)
Sets the desired arrival time.
void setDepartureTime(const QDateTime &dt)
Set the desired departure time.
bool downloadAssets
Download graphic assets such as line logos for the data requested here.
@ Departure
dateTime() represents the desired departure time.
bool isValid() const
Returns true if this is a valid request, that is, it has enough parameters set to perform a query.
QString cacheKey() const
Unique string representation used for caching results.
KPublicTransport::Location from
The starting point of the journey search.
void setBackendIds(const QStringList &backendIds)
Set identifiers of backends that should be queried.
KPublicTransport::JourneySection::Modes modes
Modes of transportation that should be considered for this query.
DateTimeMode dateTimeMode
Controls whether to search for journeys starting or ending at the given time.
A segment of a journey plan.
static bool isSame(const JourneySection &lhs, const JourneySection &rhs)
Checks if two instances refer to the same journey section (which does not necessarily mean they are e...
KPublicTransport::Location from
Departure location of this segment.
QDateTime scheduledDepartureTime
Planned departure time.
@ RentedVehicle
free floating or dock-based rental bike service, electric scooters, car sharing services,...
KPublicTransport::Location to
Arrival location of this segment.
LocationRequest request() const
The request this is the reply for.
Describes a location search.
bool isValid() const
Returns true if this is a valid request, that is it has enough parameters set to perform a query.
QString cacheKey() const
Unique string representation used for caching results.
KPublicTransport::Location location
Location object containing the search parameters.
QString region
Region (as in ISO 3166-2) of the location, if known.
@ RentedVehicleStation
a pick-up/drop-off point for dock-based rental bike/scooter systems
@ Place
a location that isn't of any specific type
@ Stop
a public transport stop (train station, bus stop, etc)
static Location merge(const Location &lhs, const Location &rhs)
Merge two departure instances.
QString country
Country of the location as ISO 3166-1 alpha 2 code, if known.
LocationReply * queryLocation(const LocationRequest &req) const
Query location information based on coordinates or (parts of) the name.
JourneyReply * queryJourney(const JourneyRequest &req) const
Query a journey.
void setBackendsEnabledByDefault(bool byDefault)
Set wheter backends are enabled by default.
void setEnabledBackends(const QStringList &backendIds)
Sets the explicitly enabled backends.
bool backendsEnabledByDefault
void setBackendEnabled(const QString &backendId, bool enabled)
Sets whether the backend with the given identifier should be used.
void reload()
Reload backend configuration.
StopoverReply * queryStopover(const StopoverRequest &req) const
Query arrivals or departures from a specific station.
QStringList disabledBackends
Q_INVOKABLE bool isBackendEnabled(const QString &backendId) const
Returns whether the use of the backend with a given identifier is enabled.
Q_INVOKABLE KPublicTransport::TripReply * queryTrip(const TripRequest &req) const
Query trip information.
void setDisabledBackends(const QStringList &backendIds)
Sets the explicitly disabled backends.
VehicleLayoutReply * queryVehicleLayout(const VehicleLayoutRequest &req) const
Query vehicle and platform layout information.
QVariantList backends
QML-compatible access to backends().
bool allowInsecureBackends
Allow usage of insecure backends (default: off).
void setNetworkAccessManager(QNetworkAccessManager *nam)
Set the network access manager to use for network operations.
void setAllowInsecureBackends(bool insecure)
Allow usage of insecure backends, that is services not using transport encryption.
QStringList enabledBackends
QVariantList attributions
QML-compatible access to attributions().
void finished()
Emitted whenever the corresponding search has been completed.
const std::vector< Attribution > & attributions() const
Returns the attributions for the provided data.
@ InvalidRequest
Incomplete or otherwise invalid request.
@ NoBackend
No backend was found to satisfy this request, e.g. due to no backend covering the requested area.
@ NoError
Nothing went wrong.
@ NotFoundError
The requested journey/departure/place could not be found.
Departure or arrival query reply.
Describes an arrival or departure search.
@ QueryArrival
Search for arrivals.
bool downloadAssets
Enable downloading of graphic assets such as line logos for the data requested here.
bool isValid() const
Returns true if this is a valid request, ie.
QString cacheKey() const
Unique string representation used for caching results.
KPublicTransport::Location stop
The location at which to search for departures/arrivals.
Mode mode
Controls whether to search for arrivals or departures.
KPublicTransport::Location stopPoint
The stop point of this departure.
Request for a single trip.
bool isValid() const
Returns true if this is a valid request, that is it has enough parameters set to perform a query.
QStringList backendIds
Identifiers of backends that should be queried.
KPublicTransport::JourneySection journeySection
A JourneySection for which the full trip is requested.
Reply to a vehicle layout query.
Describes a query for vehicle layout information.
QString cacheKey() const
Unique string representation used for caching results.
bool isValid() const
Returns true if this is a valid request, that is it has enough parameters set to perform a query.
KPublicTransport::Stopover stopover
The stopover vehicle and platform layout information are requested for.
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Query operations and data types for accessing realtime public transport information from online servi...
QCoreApplication * instance()
QDateTime addSecs(qint64 s) const const
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonValue value(QLatin1StringView key) const const
QJsonArray toArray() const const
QJsonObject toObject() const const
QString toString() const const
iterator erase(const_iterator begin, const_iterator end)
iterator insert(const_iterator before, parameter_type value)
void push_back(parameter_type value)
void reserve(qsizetype size)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
virtual bool eventFilter(QObject *watched, QEvent *event)
void installEventFilter(QObject *filterObj)
bool contains(const QSet< T > &other) const const
iterator insert(const T &value)
QStringList standardLocations(StandardLocation type)
QString writableLocation(StandardLocation type)
bool isEmpty() const const