KPublicTransport

manager.h
1 /*
2  SPDX-FileCopyrightText: 2018 Volker Krause <[email protected]>
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  */
21 namespace KPublicTransport {
22 
23 class Attribution;
24 class Backend;
25 class JourneyReply;
26 class JourneyRequest;
27 class LocationReply;
28 class LocationRequest;
29 class ManagerPrivate;
30 class StopoverReply;
31 class StopoverRequest;
32 class VehicleLayoutReply;
33 class 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  */
41 class 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 public:
57  explicit Manager(QObject *parent = nullptr);
58  ~Manager();
59 
60  /** Set the network access manager to use for network operations.
61  * If not set, an instance is created internally.
62  * Ownership is not transferred.
63  */
64  void setNetworkAccessManager(QNetworkAccessManager *nam);
65 
66  /** Returns whether access to insecure backends is allowed. */
67  bool allowInsecureBackends() const;
68  /** Allow usage of insecure backends, that is services not using
69  * transport encryption.
70  */
71  void setAllowInsecureBackends(bool insecure);
72 
73  /** Query a journey. */
74  JourneyReply* queryJourney(const JourneyRequest &req) const;
75 
76  /** Query arrivals or departures from a specific station. */
77  StopoverReply* queryStopover(const StopoverRequest &req) const;
78  [[deprecated("Use queryStopovers instead")]] StopoverReply* queryDeparture(const StopoverRequest &req) const;
79 
80  /** Query location information based on coordinates or (parts of) the name. */
81  LocationReply* queryLocation(const LocationRequest &req) const;
82 
83  /** Query vehicle and platform layout information.
84  * This is only available for some trains and some operators, so be prepared
85  * for empty results.
86  */
87  VehicleLayoutReply* queryVehicleLayout(const VehicleLayoutRequest &req) const;
88 
89  /** Returns all static attribution information, as well as all dynamic ones
90  * found in the cache or accumulated during the lifetime of this instance.
91  */
92  const std::vector<Attribution>& attributions() const;
93 
94  /** Returns information about all available backends. */
95  const std::vector<Backend>& backends() const;
96 
97  /** Returns whether the use of the backend with a given identifier is enabled. */
98  bool isBackendEnabled(const QString &backendId) const;
99  /** Sets whether the backend with the given identifier should be used.
100  * @note If allowInsecureBackends() is @c false, this has precedence.
101  */
102  void setBackendEnabled(const QString &backendId, bool enabled);
103 
104  /** Returns the identifiers of explicitly enabled backends.
105  * Use this for persisting the settings, not for checking for enabled backends.
106  */
107  QStringList enabledBackends() const;
108  /** Sets the explicitly enabled backends.
109  * Use for restoring persisted settings.
110  */
111  void setEnabledBackends(const QStringList &backendIds);
112  /** Returns the identifiers of explicitly disabled backends.
113  * Use this for persisting settings, not for checking for disabled backends.
114  */
115  QStringList disabledBackends() const;
116  /** Sets the explicitly disabled backends.
117  * Use for restoring persisted settings.
118  */
119  void setDisabledBackends(const QStringList &backendIds);
120  /**
121  * Returns wheter backends are enabled by default.
122  * Defaults to true.
123  */
124  bool backendsEnabledByDefault() const;
125  /**
126  * Set wheter backends are enabled by default.
127  */
128  void setBackendsEnabledByDefault(bool byDefault);
129 
130 
131 Q_SIGNALS:
132  void attributionsChanged();
133  void configurationChanged();
134 
135 private:
136  Q_DECL_HIDDEN QVariantList attributionsVariant() const;
137 
138  std::unique_ptr<ManagerPrivate> d;
139 };
140 
141 }
142 
143 #endif // KPUBLICTRANSPORT_MANAGER_H
Information about a backend service queried for location/departure/journey data.
Definition: backend.h:21
Departure or arrival query reply.
Definition: stopoverreply.h:22
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
Journey query response.
Definition: journeyreply.h:21
Describes an arrival or departure search.
Location query reply.
Definition: locationreply.h:22
Describes a query for vehicle layout information.
Copyright and license information about the provided data.
Definition: attribution.h:28
Reply to a vehicle layout query.
Describes a location search.
Describes a journey search.
Entry point for starting public transport queries.
Definition: manager.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 23:07:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.