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

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KPUBLICTRANSPORT_GBFSSERVICE_H
0008 #define KPUBLICTRANSPORT_GBFSSERVICE_H
0009 
0010 #include "kpublictransport_export.h"
0011 
0012 #include <QRectF>
0013 #include <QString>
0014 #include <QUrl>
0015 
0016 #include <vector>
0017 
0018 class QJsonObject;
0019 
0020 namespace KPublicTransport {
0021 
0022 /** A single service offering a GBFS feed.
0023  *  @internal only exported for testing and the feed discovery tool
0024  */
0025 class KPUBLICTRANSPORT_EXPORT GBFSService
0026 {
0027     Q_GADGET
0028     Q_PROPERTY(QUrl discoveryUrl MEMBER discoveryUrl)
0029     Q_PROPERTY(QString systemId MEMBER systemId)
0030     Q_PROPERTY(QRectF boudingBox MEMBER boundingBox)
0031 
0032 public:
0033     QUrl discoveryUrl;
0034     QString systemId;
0035     QRectF boundingBox;
0036 
0037     /** Generate a systemId based on the URL.
0038      *  This is used for cases of colliding systemIds.
0039      */
0040     void generateSystemId();
0041 
0042     static QJsonObject toJson(const GBFSService &service);
0043     static GBFSService fromJson(const QJsonObject &obj);
0044 };
0045 
0046 /** All GBFS services.
0047  *  @internal only exported for testing
0048  */
0049 class KPUBLICTRANSPORT_EXPORT GBFSServiceRepository
0050 {
0051 public:
0052     static const std::vector<GBFSService>& services();
0053     static void store(const GBFSService &service);
0054 
0055 private:
0056     static void load();
0057     static std::vector<GBFSService> m_services;
0058 };
0059 
0060 }
0061 
0062 #endif // KPUBLICTRANSPORT_GBFSSERVICE_H