reservationmanager.h 2.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
    Copyright (C) 2018 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef RESERVATIONMANAGER_H
#define RESERVATIONMANAGER_H

21 22
#include <KItinerary/ExtractorRepository>

23 24
#include <QHash>
#include <QObject>
25
#include <QVariant>
26

27 28
class PkPassManager;

Volker Krause's avatar
Volker Krause committed
29 30
class QUrl;

31 32 33 34 35 36 37 38
/** Manages JSON-LD reservation data. */
class ReservationManager : public QObject
{
    Q_OBJECT
public:
    ReservationManager(QObject *parent = nullptr);
    ~ReservationManager();

39 40
    void setPkPassManager(PkPassManager *mgr);

41
    QVector<QString> reservations() const;
42
    Q_INVOKABLE QVariant reservation(const QString &id) const;
43

Volker Krause's avatar
Volker Krause committed
44
    Q_INVOKABLE void importReservation(const QUrl &filename);
45
    Q_INVOKABLE void addReservation(const QVariant &res);
46
    Q_INVOKABLE void updateReservation(const QString &resId, const QVariant &res);
Volker Krause's avatar
Volker Krause committed
47
    Q_INVOKABLE void removeReservation(const QString &id);
48

49 50
    void importReservation(const QByteArray &data);

51 52 53 54 55 56
signals:
    void reservationAdded(const QString &id);
    void reservationUpdated(const QString &id);
    void reservationRemoved(const QString &id);

private:
57 58 59 60 61 62
    void importReservations(const QVector<QVariant> &resData);

    void passAdded(const QString &passId);
    void passUpdated(const QString &passId);
    void passRemoved(const QString &passId);

63
    mutable QHash<QString, QVariant> m_reservations;
64 65
    PkPassManager *m_passMgr = nullptr;
    KItinerary::ExtractorRepository m_extractorRepo;
66 67 68
};

#endif // RESERVATIONMANAGER_H