Commit 636fa0eb authored by Volker Krause's avatar Volker Krause
Browse files

Sort health certificates by longest relevant first

That is a good approximation of a sensible order, as eg. outdated test
certificates will end up further down now.
parent 1dd32d24
......@@ -76,8 +76,10 @@ void HealthCertificateManager::importCertificate(const QByteArray &rawData)
f.write(rawData);
f.close();
beginInsertRows({}, m_certificates.size(), m_certificates.size());
m_certificates.push_back(std::move(certData));
const auto it = std::lower_bound(m_certificates.begin(), m_certificates.end(), certData, certLessThan);
const auto row = std::distance(m_certificates.begin(), it);
beginInsertRows({}, row, row);
m_certificates.insert(it, std::move(certData));
endInsertRows();
#endif
}
......@@ -170,6 +172,7 @@ void HealthCertificateManager::loadCertificates()
m_certificates.push_back(std::move(certData));
}
std::sort(m_certificates.begin(), m_certificates.end(), certLessThan);
endResetModel();
}
......@@ -188,3 +191,13 @@ QByteArray HealthCertificateManager::certificateRawData(const CertData &certData
#endif
return {};
}
bool HealthCertificateManager::certLessThan(const CertData &lhs, const CertData &rhs)
{
const auto lhsDt = KHealthCertificate::relevantUntil(lhs.cert);
const auto rhsDt = KHealthCertificate::relevantUntil(rhs.cert);
if (lhsDt == rhsDt) {
return lhs.name < rhs.name;
}
return lhsDt > rhsDt;
}
......@@ -44,6 +44,7 @@ private:
QString name;
QVariant cert;
};
static bool certLessThan(const CertData &lhs, const CertData &rhs);
void loadCertificates();
QByteArray certificateRawData(const CertData &certData) const;
......
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