KPublicTransport
manager.cpp
83 [[nodiscard]] static std::unique_ptr<AbstractBackend> loadNetwork(const QJsonObject &backendType, const QJsonObject &obj);
85 [[nodiscard]] static std::unique_ptr<AbstractBackend> loadNetwork(const QJsonObject &backendType, const QJsonObject &obj);
92 void resolveLocation(LocationRequest &&locReq, const AbstractBackend *backend, const std::function<void(const Location &loc)> &callback);
93 [[nodiscard]] bool queryJourney(const AbstractBackend *backend, const JourneyRequest &req, JourneyReply *reply);
94 [[nodiscard]] bool queryStopover(const AbstractBackend *backend, const StopoverRequest &req, StopoverReply *reply);
101 [[nodiscard]] int queryLocationOnBackend(const LocationRequest &req, LocationReply *reply, const Backend &backend);
108 // we store both explicitly to have a third state, backends with the enabled state being the "default" (whatever that might eventually be)
127 m_nam->enableStrictTransportSecurityStore(true, QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/org.kde.kpublictransport/hsts/"_L1);
147 QDirIterator it(searchDir + "/org.kde.kpublictransport/networks"_L1, {u"*.json"_s}, QDir::Files);
151 if (std::any_of(m_backends.begin(), m_backends.end(), [&id](const auto &backend) { return backend.identifier() == id; })) {
165 qCWarning(Log) << "Failed to parse public transport network configuration:" << error.errorString() << it.fileName();
181 qCWarning(Log) << "Failed to load public transport network configuration config:" << it.fileName();
226std::unique_ptr<AbstractBackend> ManagerPrivate::loadNetwork(const QJsonObject &backendType, const QJsonObject &obj)
235std::unique_ptr<AbstractBackend> ManagerPrivate::loadNetwork(const QJsonObject &backendType, const QJsonObject &obj)
244static void applyBackendOptions(AbstractBackend *backend, const QMetaObject *mo, const QJsonObject &obj)
261 std::transform(a.begin(), a.end(), std::back_inserter(l), [](const auto &v) { return v.toString(); });
288 std::transform(langArray.begin(), langArray.end(), std::back_inserter(langs), [](const auto &v) { return v.toString(); });
292template<typename T> std::unique_ptr<AbstractBackend> ManagerPrivate::loadNetwork(const QJsonObject &obj)
320void ManagerPrivate::resolveLocation(LocationRequest &&locReq, const AbstractBackend *backend, const std::function<void(const Location&)> &callback)
371bool ManagerPrivate::queryJourney(const AbstractBackend* backend, const JourneyRequest &req, JourneyReply *reply)
400 resolveLocation(std::move(toReq), backend, [jnyRequest, reply, backend, this](const Location &loc) {
423 resolveLocation(std::move(toReq), backend, [req, toReq, reply, backend, this](const Location &loc) {
437bool ManagerPrivate::queryStopover(const AbstractBackend *backend, const StopoverRequest &req, StopoverReply *reply)
562 for (const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
611 if ((context.type == RequestContext::Next && context.backend->hasCapability(AbstractBackend::CanQueryNextJourney))
612 ||(context.type == RequestContext::Previous && context.backend->hasCapability(AbstractBackend::CanQueryPreviousJourney)))
628 } else if (context.type == RequestContext::Previous && req.dateTimeMode() == JourneyRequest::Departure) {
669 for (const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
674 if (req.mode() == StopoverRequest::QueryArrival && (BackendPrivate::impl(backend)->capabilities() & AbstractBackend::CanQueryArrivals) == 0) {
675 qCDebug(Log) << "Skipping backend due to not supporting arrival queries:" << backend.identifier();
699 if ((context.type == RequestContext::Next && context.backend->hasCapability(AbstractBackend::CanQueryNextDeparture))
732int ManagerPrivate::queryLocationOnBackend(const LocationRequest &req, LocationReply *reply, const Backend &backend)
773 const auto isCountryOnly = !loc.hasCoordinate() && !loc.country().isEmpty() && loc.region().isEmpty();
825// * accepting all specialized modes for an requested generic mode. Line::isSame takes care of most of this
827// * being more tolerant towards moved departure times if the route is assumed to be unique during a day
828[[nodiscard]] static bool isSameTrip(KPublicTransport::JourneySection req, const KPublicTransport::JourneySection &res)
830 if (req.route().line().mode() == Line::Train && Line::modeIsRailBound(res.route().line().mode())) {
837 if (Route::isSame(req.route(), res.route()) && res.route().line().mode() == Line::Mode::LongDistanceTrain) {
838 const auto depDelta = std::abs(req.scheduledDepartureTime().secsTo(res.scheduledDepartureTime()));
862 for (const auto coverageType : { CoverageArea::Realtime, CoverageArea::Regular, CoverageArea::Any }) {
873 if (!coverage.coversLocation(req.journeySection().from()) || !coverage.coversLocation(req.journeySection().to())) {
877 if (!coverage.coversLocation(req.journeySection().from()) && !coverage.coversLocation(req.journeySection().to())) {
927 if (std::ranges::count_if(journey.sections(), [](const auto &sec) { return sec.mode() == JourneySection::PublicTransport; }) != 1) {
934 qCDebug(Log) << "Got journey information:" << (*it).route().line().name() << (*it).scheduledDepartureTime();
936 qCDebug(Log) << "Found journey information:" << (*it).route().line().name() << (*it).expectedDeparturePlatform() << (*it).expectedDepartureTime();
1037 std::transform(d->m_attributions.begin(), d->m_attributions.end(), std::back_inserter(l), [](const auto &attr) { return QVariant::fromValue(attr); });
1049 if (std::binary_search(d->m_disabledBackends.cbegin(), d->m_disabledBackends.cend(), backendId)) {
1130 std::transform(d->m_backends.begin(), d->m_backends.end(), std::back_inserter(l), [](const auto &b) { return QVariant::fromValue(b); });
1136 if (event->type() == QEvent::LanguageChange && object == QCoreApplication::instance() && !QCoreApplication::closingDown()) {
static Attribution fromJson(const QJsonObject &obj)
Deserialize an Attribution object from JSON.
Definition attribution.cpp:48
Information about a backend service queried for location/departure/journey data.
Definition backend.h:22
void setArrivalTime(const QDateTime &dt)
Sets the desired arrival time.
Definition journeyrequest.cpp:91
void setDepartureTime(const QDateTime &dt)
Set the desired departure time.
Definition journeyrequest.cpp:84
bool downloadAssets
Download graphic assets such as line logos for the data requested here.
Definition journeyrequest.h:94
bool isValid() const
Returns true if this is a valid request, that is, it has enough parameters set to perform a query.
Definition journeyrequest.cpp:65
QString cacheKey() const
Unique string representation used for caching results.
Definition journeyrequest.cpp:269
KPublicTransport::Location from
The starting point of the journey search.
Definition journeyrequest.h:41
void setBackendIds(const QStringList &backendIds)
Set identifiers of backends that should be queried.
Definition journeyrequest.cpp:147
KPublicTransport::JourneySection::Modes modes
Modes of transportation that should be considered for this query.
Definition journeyrequest.h:51
DateTimeMode dateTimeMode
Controls whether to search for journeys starting or ending at the given time.
Definition journeyrequest.h:87
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...
Definition journey.cpp:750
@ RentedVehicle
free floating or dock-based rental bike service, electric scooters, car sharing services,...
Definition journey.h:52
static bool modeIsRailBound(KPublicTransport::Line::Mode mode)
true if mode is bound to rail tracks.
Definition line.cpp:139
bool isValid() const
Returns true if this is a valid request, that is it has enough parameters set to perform a query.
Definition locationrequest.cpp:44
QString cacheKey() const
Unique string representation used for caching results.
Definition locationrequest.cpp:107
KPublicTransport::Location location
Location object containing the search parameters.
Definition locationrequest.h:31
@ RentedVehicleStation
a pick-up/drop-off point for dock-based rental bike/scooter systems
Definition location.h:38
static Location merge(const Location &lhs, const Location &rhs)
Merge two departure instances.
Definition location.cpp:407
QString country
Country of the location as ISO 3166-1 alpha 2 code, if known.
Definition location.h:67
LocationReply * queryLocation(const LocationRequest &req) const
Query location information based on coordinates or (parts of) the name.
Definition manager.cpp:756
JourneyReply * queryJourney(const JourneyRequest &req) const
Query a journey.
Definition manager.cpp:543
void setBackendsEnabledByDefault(bool byDefault)
Set wheter backends are enabled by default.
Definition manager.cpp:1118
void setEnabledBackends(const QStringList &backendIds)
Sets the explicitly enabled backends.
Definition manager.cpp:1092
bool backendsEnabledByDefault
Definition manager.h:56
void setBackendEnabled(const QString &backendId, bool enabled)
Sets whether the backend with the given identifier should be used.
Definition manager.cpp:1075
StopoverReply * queryStopover(const StopoverRequest &req) const
Query arrivals or departures from a specific station.
Definition manager.cpp:651
Q_INVOKABLE bool isBackendEnabled(const QString &backendId) const
Returns whether the use of the backend with a given identifier is enabled.
Definition manager.cpp:1047
Q_INVOKABLE KPublicTransport::TripReply * queryTrip(const TripRequest &req) const
Query trip information.
Definition manager.cpp:846
void setDisabledBackends(const QStringList &backendIds)
Sets the explicitly disabled backends.
Definition manager.cpp:1105
VehicleLayoutReply * queryVehicleLayout(const VehicleLayoutRequest &req) const
Query vehicle and platform layout information.
Definition manager.cpp:954
void setNetworkAccessManager(QNetworkAccessManager *nam)
Set the network access manager to use for network operations.
Definition manager.cpp:516
void setAllowInsecureBackends(bool insecure)
Allow usage of insecure backends, that is services not using transport encryption.
Definition manager.cpp:534
void finished()
Emitted whenever the corresponding search has been completed.
const std::vector< Attribution > & attributions() const
Returns the attributions for the provided data.
Definition reply.cpp:84
@ NoBackend
No backend was found to satisfy this request, e.g. due to no backend covering the requested area.
Definition reply.h:38
static bool isSame(const Route &lhs, const Route &rhs)
Checks if to instances refer to the same route (which does not necessarily mean they are exactly equa...
Definition line.cpp:271
Describes an arrival or departure search.
Definition stopoverrequest.h:33
bool downloadAssets
Enable downloading of graphic assets such as line logos for the data requested here.
Definition stopoverrequest.h:64
QString cacheKey() const
Unique string representation used for caching results.
Definition stopoverrequest.cpp:152
KPublicTransport::Location stop
The location at which to search for departures/arrivals.
Definition stopoverrequest.h:37
bool isValid() const
Returns true if this is a valid request, that is it has enough parameters set to perform a query.
Definition triprequest.cpp:39
KPublicTransport::JourneySection journeySection
A JourneySection for which the full trip is requested.
Definition triprequest.h:32
Reply to a vehicle layout query.
Definition vehiclelayoutreply.h:22
Describes a query for vehicle layout information.
Definition vehiclelayoutrequest.h:25
QString cacheKey() const
Unique string representation used for caching results.
Definition vehiclelayoutrequest.cpp:45
bool isValid() const
Returns true if this is a valid request, that is it has enough parameters set to perform a query.
Definition vehiclelayoutrequest.cpp:40
KPublicTransport::Stopover stopover
The stopover vehicle and platform layout information are requested for.
Definition vehiclelayoutrequest.h:29
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...
Definition attribution.cpp:16
bool closingDown()
QCoreApplication * instance()
QDateTime addSecs(qint64 s) const const
qint64 secsTo(const QDateTime &other) const const
Files
LanguageChange
ReadOnly
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonValue value(QLatin1StringView key) const const
NoError
QJsonArray toArray() const const
QJsonObject toObject() const const
QString toString() const const
iterator begin()
iterator end()
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)
int indexOfProperty(const char *name) const const
QMetaProperty property(int index) const const
QStringList
NoLessSafeRedirectPolicy
Q_EMITQ_EMIT
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)
GenericCacheLocation
QStringList standardLocations(StandardLocation type)
QString writableLocation(StandardLocation type)
bool isEmpty() const const
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 11:47:05 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 11:47:05 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.