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

0001 /*
0002     SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KPUBLICTRANSPORT_EFABACKEND_H
0008 #define KPUBLICTRANSPORT_EFABACKEND_H
0009 
0010 #include "abstractbackend.h"
0011 
0012 #include <memory>
0013 
0014 class QUrlQuery;
0015 
0016 namespace KPublicTransport {
0017 
0018 class EfaParser;
0019 
0020 /** Backend for EFA public transport systems. */
0021 class EfaBackend : public AbstractBackend
0022 {
0023     Q_GADGET
0024     /** Base URL for EFA API calls. */
0025     Q_PROPERTY(QString endpoint MEMBER m_endpoint)
0026     /** Identifier type used for stations. Default is backendId(). */
0027     Q_PROPERTY(QString locationIdentifierType MEMBER m_locationIdentifierType)
0028     /** Backend is using compact XML responses. */
0029     Q_PROPERTY(QString xmlOutputFormat WRITE setXmlOutputFormat)
0030 
0031     /** Additional "mId" argument value, needed by some instances. */
0032     Q_PROPERTY(QString mId MEMBER m_mId)
0033 
0034     /** Override for commands send to the server.
0035      *  Defaults are usually fine, only change this for bizarre backends.
0036      */
0037     Q_PROPERTY(QString stopfinderRequestCommand MEMBER m_stopfinderRequestCommand)
0038     Q_PROPERTY(QString dmRequestCommand MEMBER m_dmRequestCommand)
0039     Q_PROPERTY(QString tripRequestCommand MEMBER m_tripRequestCommand)
0040 
0041 public:
0042     EfaBackend();
0043     ~EfaBackend() override;
0044 
0045     static inline constexpr const char* type() { return "efa"; }
0046     Capabilities capabilities() const override;
0047     bool needsLocationQuery(const Location  &loc, AbstractBackend::QueryType type) const override;
0048     bool queryLocation(const LocationRequest &request, LocationReply *reply, QNetworkAccessManager *nam) const override;
0049     bool queryStopover(const StopoverRequest &request, StopoverReply *reply, QNetworkAccessManager *nam) const override;
0050     bool queryJourney(const JourneyRequest &request, JourneyReply *reply, QNetworkAccessManager *nam) const override;
0051 
0052 private:
0053     QString locationIdentifierType() const;
0054     std::unique_ptr<EfaParser> make_parser() const;
0055     QUrlQuery commonQuery() const;
0056 
0057     void setXmlOutputFormat(const QString &format);
0058 
0059     QString m_endpoint;
0060     QString m_locationIdentifierType;
0061     bool m_compactXmlResponse = false;
0062 
0063     QString m_mId;
0064     QString m_stopfinderRequestCommand;
0065     QString m_dmRequestCommand;
0066     QString m_tripRequestCommand;
0067 };
0068 
0069 }
0070 
0071 #endif // KPUBLICTRANSPORT_EFABACKEND_H