[WIP] Initial support for adding reservations without files

Summary:
This is just an initial review to gather feedback. It should be
the first building block to allow itinerary to work also when creating
events without reservation files attached.

Test Plan: Compiles

Reviewers: vkrause

Reviewed By: vkrause

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D12834
parent e8d0c9ee
......@@ -24,7 +24,6 @@
#include <KItinerary/Flight>
#include <KItinerary/JsonLdDocument>
#include <KItinerary/MergeUtil>
#include <KItinerary/Reservation>
#include <QDate>
#include <QDir>
......@@ -37,6 +36,7 @@
#include <QUuid>
#include <QVector>
using namespace KItinerary;
ReservationManager::ReservationManager(QObject* parent)
......@@ -164,6 +164,23 @@ void ReservationManager::importReservations(const QVector<QVariant> &resData)
}
}
void ReservationManager::addReservation(const QVariant &res)
{
QString resId = QUuid::createUuid().toString();
const auto basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/reservations/");
QDir::root().mkpath(basePath);
const QString path = basePath + resId + QLatin1String(".jsonld");
QFile f(path);
if (!f.open(QFile::WriteOnly)) {
qCWarning(Log) << "Unable to create file:" << f.errorString();
return;
}
f.write(QJsonDocument(JsonLdDocument::toJson({res})).toJson());
m_reservations.insert(resId, res);
emit reservationAdded(resId);
}
void ReservationManager::removeReservation(const QString& id)
{
const auto basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/reservations/");
......
......@@ -22,6 +22,7 @@
#include <QHash>
#include <QObject>
#include <QVariant>
class PkPassManager;
......@@ -41,6 +42,7 @@ public:
QVariant reservation(const QString &id) const;
Q_INVOKABLE void importReservation(const QUrl &filename);
Q_INVOKABLE void addReservation(const QVariant &res);
void removeReservation(const QString &id);
signals:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment