File indexing completed on 2025-02-02 05:02:30

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef LIVEDATA_H
0008 #define LIVEDATA_H
0009 
0010 #include <KPublicTransport/Journey>
0011 #include <KPublicTransport/Stopover>
0012 
0013 #include <QDateTime>
0014 #include <QHash>
0015 
0016 /** Realttime information about a public transport reservation */
0017 class LiveData
0018 {
0019 public:
0020     enum Type {
0021         NoType = 0,
0022         Departure = 1,
0023         Arrival = 2,
0024         Journey = 4,
0025         AllTypes = Departure | Arrival | Journey
0026     };
0027 
0028     KPublicTransport::Stopover stopover(Type type) const;
0029     void setStopover(Type type, const KPublicTransport::Stopover &stop);
0030     void setTimestamp(Type type, const QDateTime &dt);
0031 
0032     bool isEmpty() const;
0033 
0034     KPublicTransport::Stopover departure;
0035     QDateTime departureTimestamp;
0036     KPublicTransport::Stopover arrival;
0037     QDateTime arrivalTimestamp;
0038     KPublicTransport::JourneySection journey;
0039     QDateTime journeyTimestamp;
0040 
0041     /** Load live data for reservation batch with id @resId. */
0042     static LiveData load(const QString &resId);
0043     /** Store this data for reservation batch @p resId. */
0044     void store(const QString &resId, int types = AllTypes) const;
0045     /** Removes all stored data for a given id. */
0046     static void remove(const QString &resId);
0047 
0048     /** List all reservations for which there are stored live data information.
0049      *  Used for exporting.
0050      */
0051     static std::vector<QString> listAll();
0052 
0053     /** Clears all stored live data.
0054      *  @internal For unit tests only.
0055      */
0056     static void clearStorage();
0057 };
0058 
0059 #endif // LIVEDATA_H