Commit 49b1dcae authored by Volker Krause's avatar Volker Krause
Browse files

Implement importing health certificates from full data exports

parent c7491770
......@@ -481,6 +481,7 @@ void ApplicationController::importBundle(KItinerary::File *file)
importer.importDocuments(m_docMgr);
importer.importFavoriteLocations(m_favLocModel);
importer.importTransfers(m_resMgr, m_transferMgr);
importer.importHealthCertificates(m_healthCertMgr);
importer.importLiveData(m_liveDataMgr);
importer.importSettings();
......
......@@ -50,6 +50,12 @@ static QString basePath()
void HealthCertificateManager::importCertificate(const QByteArray &rawData)
{
// check whether we know this certificate already
for (const auto &c : m_certificates) {
if (certificateRawData(c) == rawData) {
return;
}
}
#if HAVE_KHEALTHCERTIFICATE
CertData certData;
certData.cert = KHealthCertificateParser::parse(rawData);
......@@ -73,8 +79,6 @@ void HealthCertificateManager::importCertificate(const QByteArray &rawData)
beginInsertRows({}, m_certificates.size(), m_certificates.size());
m_certificates.push_back(std::move(certData));
endInsertRows();
#else
Q_UNUSED(rawData);
#endif
}
......@@ -128,18 +132,7 @@ QVariant HealthCertificateManager::data(const QModelIndex &index, int role) cons
case CertificateRole:
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 {};
return certificateRawData(v);
case StorageIdRole:
return v.name;
}
......@@ -179,3 +172,19 @@ void HealthCertificateManager::loadCertificates()
}
endResetModel();
}
QByteArray HealthCertificateManager::certificateRawData(const CertData &certData) const
{
#if HAVE_KHEALTHCERTIFICATE
if (certData.cert.userType() == qMetaTypeId<KVaccinationCertificate>()) {
return certData.cert.value<KVaccinationCertificate>().rawData();
}
if (certData.cert.userType() == qMetaTypeId<KTestCertificate>()) {
return certData.cert.value<KTestCertificate>().rawData();
}
if (certData.cert.userType() == qMetaTypeId<KRecoveryCertificate>()) {
return certData.cert.value<KRecoveryCertificate>().rawData();
}
#endif
return {};
}
......@@ -40,12 +40,14 @@ public:
QHash<int, QByteArray> roleNames() const override;
private:
void loadCertificates();
struct CertData {
QString name;
QVariant cert;
};
void loadCertificates();
QByteArray certificateRawData(const CertData &certData) const;
std::vector<CertData> m_certificates;
};
......
......@@ -191,6 +191,15 @@ void Importer::importFavoriteLocations(FavoriteLocationModel *favLocModel)
}
}
void Importer::importHealthCertificates(HealthCertificateManager *healthCertMgr)
{
const auto domain = QStringLiteral("org.kde.itinerary/health-certificates");
const auto certIds = m_file->listCustomData(domain);
for (const auto &certId : certIds) {
healthCertMgr->importCertificate(m_file->customData(domain, certId));
}
}
void Importer::importLiveData(LiveDataManager *liveDataMgr)
{
const auto ids = m_file->listCustomData(QStringLiteral("org.kde.itinerary/live-data"));
......
......@@ -49,6 +49,7 @@ public:
void importDocuments(DocumentManager *docMgr);
void importTransfers(const ReservationManager *resMgr, TransferManager *transferMgr);
void importFavoriteLocations(FavoriteLocationModel *favLocModel);
void importHealthCertificates(HealthCertificateManager *healthCertMgr);
void importLiveData(LiveDataManager *liveDataMgr);
void importSettings();
......
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