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_GBFSSTORE_H
0008 #define KPUBLICTRANSPORT_GBFSSTORE_H
0009 
0010 #include "gbfs.h"
0011 
0012 #include <QString>
0013 
0014 class QJsonDocument;
0015 
0016 namespace KPublicTransport {
0017 
0018 /** Local storage of GBFS data.
0019  *  @see https://github.com/NABSA/gbfs/blob/master/gbfs.md
0020  */
0021 class GBFSStore
0022 {
0023 public:
0024     explicit GBFSStore();
0025     explicit GBFSStore(const QString &systemId);
0026     ~GBFSStore();
0027 
0028     /** Store is set up with a system id and is thus usable. */
0029     bool isValid() const;
0030 
0031     /** We have a file for @p type, but it could be outdated. */
0032     bool hasData(GBFS::FileType type) const;
0033     /** We have a file for @p type, and it's up-to-date. */
0034     bool hasCurrentData(GBFS::FileType type) const;
0035     /** Store data for @p type. */
0036     void storeData(GBFS::FileType type, const QJsonDocument &doc);
0037     /** Load data for @p type. */
0038     QJsonDocument loadData(GBFS::FileType type) const;
0039 
0040     /** Delete expired transient information. */
0041     static void expire();
0042 
0043 private:
0044     QString fileName(GBFS::FileType type) const;
0045 
0046     QString m_systemId;
0047 };
0048 
0049 }
0050 
0051 #endif // KPUBLICTRANSPORT_GBFSSTORE_H