KPublicTransport

manager.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_MANAGER_H
8#define KPUBLICTRANSPORT_MANAGER_H
9
10#include "kpublictransport_export.h"
11
12#include <QObject>
13
14#include <memory>
15
17
18/** Query operations and data types for accessing realtime public transport information
19 * from online services.
20 */
21namespace KPublicTransport {
22
23class Attribution;
24class Backend;
25class JourneyReply;
26class JourneyRequest;
27class LocationReply;
28class LocationRequest;
29class ManagerPrivate;
30class StopoverReply;
31class StopoverRequest;
32class TripReply;
33class TripRequest;
36
37/** Entry point for starting public transport queries.
38 *
39 * Queries return reply objects, you are responsible for deleting those,
40 * typically by calling deleteLater() on them after having retrieved their
41 * result (similar to how QNetworkAccessManager works).
42 */
43class KPUBLICTRANSPORT_EXPORT Manager : public QObject
44{
46 /** QML-compatible access to attributions(). */
47 Q_PROPERTY(QVariantList attributions READ attributionsVariant NOTIFY attributionsChanged)
48 /** Allow usage of insecure backends (default: off). */
50
51 /** @see enabledBackends() */
53 /** @see disabledBackends() */
55 /** @see backendsEnabledByDefault() */
57
58 /** QML-compatible access to backends(). */
59 Q_PROPERTY(QVariantList backends READ backendsVariant NOTIFY backendsChanged)
60
61public:
62 explicit Manager(QObject *parent = nullptr);
63 ~Manager() override;
64
65 /** Set the network access manager to use for network operations.
66 * If not set, an instance is created internally.
67 * Ownership is not transferred.
68 */
70
71 /** Returns whether access to insecure backends is allowed. */
72 [[nodiscard]] bool allowInsecureBackends() const;
73 /** Allow usage of insecure backends, that is services not using
74 * transport encryption.
75 */
76 void setAllowInsecureBackends(bool insecure);
77
78 /** Query a journey. */
79 [[nodiscard]] JourneyReply* queryJourney(const JourneyRequest &req) const;
80
81 /** Query arrivals or departures from a specific station. */
82 [[nodiscard]] StopoverReply* queryStopover(const StopoverRequest &req) const;
83
84 /** Query location information based on coordinates or (parts of) the name. */
85 [[nodiscard]] LocationReply* queryLocation(const LocationRequest &req) const;
86
87 /** Query trip information.
88 * That is a specific run of a vehicle on a route.
89 * When there's a backend supporting trip queries this returns the full trip.
90 * For backends not supporting this, this internally falls back to a journey
91 * query and thus might return only a subset of the trip, based on the JourneySection
92 * used in the request.
93 *
94 * @since 25.04
95 */
96 Q_INVOKABLE [[nodiscard]] KPublicTransport::TripReply* queryTrip(const TripRequest &req) const;
97
98 /** Query vehicle and platform layout information.
99 * This is only available for some trains and some operators, so be prepared
100 * for empty results.
101 */
102 [[nodiscard]] VehicleLayoutReply* queryVehicleLayout(const VehicleLayoutRequest &req) const;
103
104 /** Returns all static attribution information, as well as all dynamic ones
105 * found in the cache or accumulated during the lifetime of this instance.
106 */
107 [[nodiscard]] const std::vector<Attribution>& attributions() const;
108
109 /** Returns information about all available backends. */
110 [[nodiscard]] const std::vector<Backend>& backends() const;
111
112 /** Returns whether the use of the backend with a given identifier is enabled. */
113 Q_INVOKABLE [[nodiscard]] bool isBackendEnabled(const QString &backendId) const;
114 /** Sets whether the backend with the given identifier should be used.
115 * @note If allowInsecureBackends() is @c false, this has precedence.
116 */
117 void setBackendEnabled(const QString &backendId, bool enabled);
118
119 /** Returns the identifiers of explicitly enabled backends.
120 * Use this for persisting the settings, not for checking for enabled backends.
121 */
122 [[nodiscard]] QStringList enabledBackends() const;
123 /** Sets the explicitly enabled backends.
124 * Use for restoring persisted settings.
125 */
126 void setEnabledBackends(const QStringList &backendIds);
127 /** Returns the identifiers of explicitly disabled backends.
128 * Use this for persisting settings, not for checking for disabled backends.
129 */
130 [[nodiscard]] QStringList disabledBackends() const;
131 /** Sets the explicitly disabled backends.
132 * Use for restoring persisted settings.
133 */
134 void setDisabledBackends(const QStringList &backendIds);
135 /**
136 * Returns wheter backends are enabled by default.
137 * Defaults to true.
138 */
139 [[nodiscard]] bool backendsEnabledByDefault() const;
140 /**
141 * Set wheter backends are enabled by default.
142 */
143 void setBackendsEnabledByDefault(bool byDefault);
144
145public Q_SLOTS:
146 /** Reload backend configuration.
147 * Can be used when on-disk configuration has been changed.
148 * Automatically called on language changes.
149 */
150 void reload();
151
153 void attributionsChanged();
154 void configurationChanged();
155 void backendsChanged();
156
157private:
158 bool eventFilter(QObject *object, QEvent *event) override;
159 Q_DECL_HIDDEN QVariantList attributionsVariant() const;
160 Q_DECL_HIDDEN QVariantList backendsVariant() const;
161
162 std::unique_ptr<ManagerPrivate> d;
163};
164
165}
166
167#endif // KPUBLICTRANSPORT_MANAGER_H
Copyright and license information about the provided data.
Definition attribution.h:29
Information about a backend service queried for location/departure/journey data.
Definition backend.h:22
Journey query response.
Describes a journey search.
Describes a location search.
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:1111
void setEnabledBackends(const QStringList &backendIds)
Sets the explicitly enabled backends.
Definition manager.cpp:1085
void setBackendEnabled(const QString &backendId, bool enabled)
Sets whether the backend with the given identifier should be used.
Definition manager.cpp:1068
void reload()
Reload backend configuration.
Definition manager.cpp:1007
StopoverReply * queryStopover(const StopoverRequest &req) const
Query arrivals or departures from a specific station.
Definition manager.cpp:651
QStringList disabledBackends
Definition manager.h:54
Q_INVOKABLE bool isBackendEnabled(const QString &backendId) const
Returns whether the use of the backend with a given identifier is enabled.
Definition manager.cpp:1040
Q_INVOKABLE KPublicTransport::TripReply * queryTrip(const TripRequest &req) const
Query trip information.
Definition manager.cpp:839
void setDisabledBackends(const QStringList &backendIds)
Sets the explicitly disabled backends.
Definition manager.cpp:1098
VehicleLayoutReply * queryVehicleLayout(const VehicleLayoutRequest &req) const
Query vehicle and platform layout information.
Definition manager.cpp:947
QVariantList backends
QML-compatible access to backends().
Definition manager.h:59
bool allowInsecureBackends
Allow usage of insecure backends (default: off).
Definition manager.h:49
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
QStringList enabledBackends
Definition manager.h:52
QVariantList attributions
QML-compatible access to attributions().
Definition manager.h:47
Departure or arrival query reply.
Describes an arrival or departure search.
Reply to a trip query.
Definition tripreply.h:23
Request for a single trip.
Definition triprequest.h:29
Reply to a vehicle layout query.
Describes a query for vehicle layout information.
Query operations and data types for accessing realtime public transport information from online servi...
QObject(QObject *parent)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
virtual bool event(QEvent *e)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:53:27 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.