Commit 63dd1bbe authored by Volker Krause's avatar Volker Krause
Browse files

Implement exporting of health certificates

parent 66fc95d7
......@@ -9,6 +9,7 @@
#include <reservationmanager.h>
#include <documentmanager.h>
#include <favoritelocationmodel.h>
#include <healthcertificatemanager.h>
#include <transfermanager.h>
#include <tripgroupmanager.h>
......@@ -133,12 +134,15 @@ private Q_SLOTS:
FavoriteLocationModel favLoc;
HealthCertificateManager healthCertMgr;
ApplicationController appController;
appController.setPkPassManager(&passMgr);
appController.setReservationManager(&resMgr);
appController.setDocumentManager(&docMgr);
appController.setTransferManager(&transferMgr);
appController.setFavoriteLocationModel(&favLoc);
appController.setHealthCertificateManager(&healthCertMgr);
appController.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/4U8465-v1.json")));
appController.importFromUrl(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/boardingpass-v1.pkpass")));
......
......@@ -44,11 +44,15 @@ private Q_SLOTS:
QAbstractItemModelTester modelTester(&mgr);
QSignalSpy insertSpy(&mgr, &QAbstractItemModel::rowsInserted);
QCOMPARE(mgr.rowCount(), 0);
mgr.importCertificate(readFile(QLatin1String(SOURCE_DIR "/data/health-certificates/full-vaccination.txt")));
const auto rawData = readFile(QLatin1String(SOURCE_DIR "/data/health-certificates/full-vaccination.txt"));
mgr.importCertificate(rawData);
#if HAVE_KHEALTHCERTIFICATE
QCOMPARE(mgr.rowCount(), 1);
QCOMPARE(insertSpy.size(), 1);
QVERIFY(!mgr.data(mgr.index(0, 0), Qt::DisplayRole).toString().isEmpty());
QVERIFY(!mgr.data(mgr.index(0, 0), HealthCertificateManager::CertificateRole).isNull());
QCOMPARE(mgr.data(mgr.index(0, 0), HealthCertificateManager::RawDataRole).toByteArray(), rawData);
QVERIFY(!mgr.data(mgr.index(0, 0), HealthCertificateManager::StorageIdRole).toString().isEmpty());
#endif
}
......
......@@ -8,6 +8,7 @@
#include "documentmanager.h"
#include "favoritelocationmodel.h"
#include "gpxexport.h"
#include "healthcertificatemanager.h"
#include "importexport.h"
#include "livedatamanager.h"
#include "logging.h"
......@@ -176,6 +177,11 @@ void ApplicationController::setTripGroupManager(TripGroupManager *tripGroupMgr)
m_tripGroupMgr = tripGroupMgr;
}
void ApplicationController::setHealthCertificateManager(HealthCertificateManager *healthCertMgr)
{
m_healthCertMgr = healthCertMgr;
}
#ifdef Q_OS_ANDROID
void ApplicationController::importFromIntent(const KAndroidExtras::Intent &intent)
{
......@@ -412,6 +418,7 @@ void ApplicationController::exportToFile(const QString &filePath)
exporter.exportDocuments(m_docMgr);
exporter.exportFavoriteLocations(m_favLocModel);
exporter.exportTransfers(m_resMgr, m_transferMgr);
exporter.exportHealthCertificates(m_healthCertMgr);
exporter.exportLiveData();
exporter.exportSettings();
}
......
......@@ -11,6 +11,7 @@
class DocumentManager;
class FavoriteLocationModel;
class HealthCertificateManager;
class LiveDataManager;
class PkPassManager;
class ReservationManager;
......@@ -44,6 +45,7 @@ public:
void setFavoriteLocationModel(FavoriteLocationModel *favLocModel);
void setLiveDataManager(LiveDataManager *liveDataMgr);
void setTripGroupManager(TripGroupManager *tripGroupMgr);
void setHealthCertificateManager(HealthCertificateManager *healthCertMgr);
// data import
void importFromIntent(const KAndroidExtras::Intent &intent);
......@@ -89,6 +91,7 @@ private:
FavoriteLocationModel *m_favLocModel = nullptr;
LiveDataManager *m_liveDataMgr = nullptr;
TripGroupManager *m_tripGroupMgr = nullptr;
HealthCertificateManager *m_healthCertMgr = nullptr;
QNetworkAccessManager *m_nam = nullptr;
};
......
......@@ -107,25 +107,41 @@ int HealthCertificateManager::rowCount(const QModelIndex& parent) const
QVariant HealthCertificateManager::data(const QModelIndex &index, int role) const
{
const auto &v = m_certificates[index.row()];
switch (role) {
case Qt::DisplayRole:
#if HAVE_KHEALTHCERTIFICATE
if (m_certificates[index.row()].cert.userType() == qMetaTypeId<KVaccinationCertificate>()) {
const auto cert = m_certificates[index.row()].cert.value<KVaccinationCertificate>();
if (v.cert.userType() == qMetaTypeId<KVaccinationCertificate>()) {
const auto cert = v.cert.value<KVaccinationCertificate>();
return i18n("Vaccination %1/%2 (%3)", cert.dose(), cert.totalDoses(), cert.name());
}
if (m_certificates[index.row()].cert.userType() == qMetaTypeId<KTestCertificate>()) {
const auto cert = m_certificates[index.row()].cert.value<KTestCertificate>();
if (v.cert.userType() == qMetaTypeId<KTestCertificate>()) {
const auto cert = v.cert.value<KTestCertificate>();
return i18n("Test %1 (%2)", QLocale().toString(cert.date(), QLocale::NarrowFormat), cert.name());
}
if (m_certificates[index.row()].cert.userType() == qMetaTypeId<KRecoveryCertificate>()) {
const auto cert = m_certificates[index.row()].cert.value<KRecoveryCertificate>();
if (v.cert.userType() == qMetaTypeId<KRecoveryCertificate>()) {
const auto cert = v.cert.value<KRecoveryCertificate>();
return i18n("Recovery (%1)", cert.name());
}
#endif
return {};
case CertificateRole:
return m_certificates[index.row()].cert;
return v.cert;
case RawDataRole:
#if HAVE_KHEALTHCERTIFICATE
if (v.cert.userType() == qMetaTypeId<KVaccinationCertificate>()) {
return v.cert.value<KVaccinationCertificate>().rawData();
}
if (v.cert.userType() == qMetaTypeId<KTestCertificate>()) {
return v.cert.value<KTestCertificate>().rawData();
}
if (v.cert.userType() == qMetaTypeId<KRecoveryCertificate>()) {
return v.cert.value<KRecoveryCertificate>().rawData();
}
#endif
return {};
case StorageIdRole:
return v.name;
}
return {};
}
......@@ -134,6 +150,8 @@ QHash<int, QByteArray> HealthCertificateManager::roleNames() const
{
auto rns = QAbstractListModel::roleNames();
rns.insert(CertificateRole, "certificate");
rns.insert(RawDataRole, "rawData");
rns.insert(StorageIdRole, "storageId");
return rns;
}
......
......@@ -31,6 +31,8 @@ public:
enum {
CertificateRole = Qt::UserRole,
RawDataRole,
StorageIdRole,
};
int rowCount(const QModelIndex &parent = {}) const override;
......
......@@ -8,6 +8,7 @@
#include "documentmanager.h"
#include "favoritelocationmodel.h"
#include "healthcertificatemanager.h"
#include "livedata.h"
#include "livedatamanager.h"
#include "logging.h"
......@@ -94,6 +95,17 @@ void Exporter::exportFavoriteLocations(const FavoriteLocationModel* favLocModel)
}
}
void Exporter::exportHealthCertificates(const HealthCertificateManager *healthCertMgr)
{
for (int i = 0; i < healthCertMgr->rowCount(); ++i) {
const auto idx = healthCertMgr->index(i, 0);
m_file->addCustomData(
QStringLiteral("org.kde.itinerary/health-certificates"),
healthCertMgr->data(idx, HealthCertificateManager::StorageIdRole).toString(),
healthCertMgr->data(idx, HealthCertificateManager::RawDataRole).toByteArray());
}
}
void Exporter::exportLiveData()
{
for (const auto &id : LiveData::listAll()) {
......
......@@ -9,6 +9,7 @@
class DocumentManager;
class FavoriteLocationModel;
class HealthCertificateManager;
class LiveDataManager;
class PkPassManager;
class ReservationManager;
......@@ -29,6 +30,7 @@ public:
void exportDocuments(const DocumentManager *docMgr);
void exportTransfers(const ReservationManager *resMgr, const TransferManager *transferMgr);
void exportFavoriteLocations(const FavoriteLocationModel *favLocModel);
void exportHealthCertificates(const HealthCertificateManager *healthCertMgr);
void exportLiveData();
void exportSettings();
......
......@@ -318,6 +318,7 @@ int main(int argc, char **argv)
appController.setTransferManager(&transferManager);
appController.setLiveDataManager(&liveDataMgr);
appController.setTripGroupManager(&tripGroupMgr);
appController.setHealthCertificateManager(&healthCertificateMgr);
#ifndef Q_OS_ANDROID
QObject::connect(&service, &KDBusService::activateRequested, [&](const QStringList &args, const QString &workingDir) {
qCDebug(Log) << "remote activation" << args << workingDir;
......
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