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 VehicleLayoutReply;
33class VehicleLayoutRequest;
34
35/** Entry point for starting public transport queries.
36 *
37 * Queries return reply objects, you are responsible for deleting those,
38 * typically by calling deleteLater() on them after having retrieved their
39 * result (similar to how QNetworkAccessManager works).
40 */
41class KPUBLICTRANSPORT_EXPORT Manager : public QObject
42{
43 Q_OBJECT
44 /** QML-compatible access to attributions(). */
45 Q_PROPERTY(QVariantList attributions READ attributionsVariant NOTIFY attributionsChanged)
46 /** Allow usage of insecure backends (default: off). */
47 Q_PROPERTY(bool allowInsecureBackends READ allowInsecureBackends WRITE setAllowInsecureBackends NOTIFY configurationChanged)
48
49 /** @see enabledBackends() */
50 Q_PROPERTY(QStringList enabledBackends READ enabledBackends WRITE setEnabledBackends NOTIFY configurationChanged)
51 /** @see disabledBackends() */
52 Q_PROPERTY(QStringList disabledBackends READ disabledBackends WRITE setDisabledBackends NOTIFY configurationChanged)
53 /** @see backendsEnabledByDefault() */
54 Q_PROPERTY(bool backendsEnabledByDefault READ backendsEnabledByDefault WRITE setBackendsEnabledByDefault NOTIFY configurationChanged)
55
56 /** QML-compatible access to backends(). */
57 Q_PROPERTY(QVariantList backends READ backendsVariant NOTIFY backendsChanged)
58
59public:
60 explicit Manager(QObject *parent = nullptr);
61 ~Manager() override;
62
63 /** Set the network access manager to use for network operations.
64 * If not set, an instance is created internally.
65 * Ownership is not transferred.
66 */
67 void setNetworkAccessManager(QNetworkAccessManager *nam);
68
69 /** Returns whether access to insecure backends is allowed. */
70 [[nodiscard]] bool allowInsecureBackends() const;
71 /** Allow usage of insecure backends, that is services not using
72 * transport encryption.
73 */
74 void setAllowInsecureBackends(bool insecure);
75
76 /** Query a journey. */
77 [[nodiscard]] JourneyReply* queryJourney(const JourneyRequest &req) const;
78
79 /** Query arrivals or departures from a specific station. */
80 [[nodiscard]] StopoverReply* queryStopover(const StopoverRequest &req) const;
81
82 /** Query location information based on coordinates or (parts of) the name. */
83 [[nodiscard]] LocationReply* queryLocation(const LocationRequest &req) const;
84
85 /** Query vehicle and platform layout information.
86 * This is only available for some trains and some operators, so be prepared
87 * for empty results.
88 */
89 [[nodiscard]] VehicleLayoutReply* queryVehicleLayout(const VehicleLayoutRequest &req) const;
90
91 /** Returns all static attribution information, as well as all dynamic ones
92 * found in the cache or accumulated during the lifetime of this instance.
93 */
94 [[nodiscard]] const std::vector<Attribution>& attributions() const;
95
96 /** Returns information about all available backends. */
97 [[nodiscard]] const std::vector<Backend>& backends() const;
98
99 /** Returns whether the use of the backend with a given identifier is enabled. */
100 Q_INVOKABLE [[nodiscard]] bool isBackendEnabled(const QString &backendId) const;
101 /** Sets whether the backend with the given identifier should be used.
102 * @note If allowInsecureBackends() is @c false, this has precedence.
103 */
104 void setBackendEnabled(const QString &backendId, bool enabled);
105
106 /** Returns the identifiers of explicitly enabled backends.
107 * Use this for persisting the settings, not for checking for enabled backends.
108 */
109 [[nodiscard]] QStringList enabledBackends() const;
110 /** Sets the explicitly enabled backends.
111 * Use for restoring persisted settings.
112 */
113 void setEnabledBackends(const QStringList &backendIds);
114 /** Returns the identifiers of explicitly disabled backends.
115 * Use this for persisting settings, not for checking for disabled backends.
116 */
117 [[nodiscard]] QStringList disabledBackends() const;
118 /** Sets the explicitly disabled backends.
119 * Use for restoring persisted settings.
120 */
121 void setDisabledBackends(const QStringList &backendIds);
122 /**
123 * Returns wheter backends are enabled by default.
124 * Defaults to true.
125 */
126 [[nodiscard]] bool backendsEnabledByDefault() const;
127 /**
128 * Set wheter backends are enabled by default.
129 */
130 void setBackendsEnabledByDefault(bool byDefault);
131
132public Q_SLOTS:
133 /** Reload backend configuration.
134 * Can be used when on-disk configuration has been changed.
135 * Automatically called on language changes.
136 */
137 void reload();
138
139Q_SIGNALS:
140 void attributionsChanged();
141 void configurationChanged();
142 void backendsChanged();
143
144private:
145 bool eventFilter(QObject *object, QEvent *event) override;
146 Q_DECL_HIDDEN QVariantList attributionsVariant() const;
147 Q_DECL_HIDDEN QVariantList backendsVariant() const;
148
149 std::unique_ptr<ManagerPrivate> d;
150};
151
152}
153
154#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.
Entry point for starting public transport queries.
Definition manager.h:42
Departure or arrival query reply.
Describes an arrival or departure search.
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...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.