File indexing completed on 2024-05-12 04:42:37

0001 /*
0002     SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef KPUBLICTRANSPORT_MOTISBACKEND_H
0007 #define KPUBLICTRANSPORT_MOTISBACKEND_H
0008 
0009 #include "abstractbackend.h"
0010 
0011 #include <QUrl>
0012 
0013 class QNetworkRequest;
0014 
0015 namespace KPublicTransport {
0016 
0017 /** Backend for Motis-based providers. */
0018 class MotisBackend : public AbstractBackend
0019 {
0020     Q_GADGET
0021     Q_PROPERTY(QUrl endpoint MEMBER m_endpoint)
0022     Q_PROPERTY(QString locationIdentifierType MEMBER m_locationIdentifierType)
0023     /** Intermodal journey search is functional on this instance.
0024      *  Defaults to @c true.
0025      */
0026     Q_PROPERTY(bool intermodal MEMBER m_intermodal)
0027 
0028 public:
0029     explicit MotisBackend();
0030     ~MotisBackend() override;
0031 
0032     static inline constexpr const char* type() { return "motis"; }
0033     [[nodiscard]] Capabilities capabilities() const override;
0034     [[nodiscard]] bool needsLocationQuery(const Location &loc, AbstractBackend::QueryType type) const override;
0035     [[nodiscard]] bool queryLocation(const LocationRequest &req, LocationReply *reply, QNetworkAccessManager *nam) const override;
0036     [[nodiscard]] bool queryStopover(const StopoverRequest &req, StopoverReply *reply, QNetworkAccessManager *nam) const override;
0037     [[nodiscard]] bool queryJourney(const JourneyRequest &req, JourneyReply *reply, QNetworkAccessManager *nam) const override;
0038 
0039 private:
0040     template <typename Request>
0041     QNetworkReply* makeRequest(const Request &req, Reply *reply, const QJsonObject &query, QNetworkAccessManager *nam) const;
0042 
0043     QUrl m_endpoint;
0044     QString m_locationIdentifierType;
0045     bool m_intermodal = true;
0046 };
0047 
0048 }
0049 
0050 #endif