File indexing completed on 2024-06-16 04:56:07

0001 /* -*- mode: c++; c-basic-offset:4 -*-
0002     selftest/libkleopatrarccheck.cpp
0003 
0004     This file is part of Kleopatra, the KDE keymanager
0005     SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include <config-kleopatra.h>
0011 
0012 #include "libkleopatrarccheck.h"
0013 
0014 #include "implementation_p.h"
0015 
0016 #include <utils/archivedefinition.h>
0017 
0018 #include <Libkleo/ChecksumDefinition>
0019 
0020 #include <KLocalizedString>
0021 
0022 using namespace Kleo;
0023 using namespace Kleo::_detail;
0024 
0025 namespace
0026 {
0027 
0028 class LibKleopatraRcCheck : public SelfTestImplementation
0029 {
0030 public:
0031     explicit LibKleopatraRcCheck()
0032         : SelfTestImplementation(i18nc("@title", "Config File 'libkleopatrarc'"))
0033     {
0034         runTest();
0035     }
0036 
0037     void runTest()
0038     {
0039         QStringList errors;
0040         ArchiveDefinition::getArchiveDefinitions(errors);
0041         ChecksumDefinition::getChecksumDefinitions(errors);
0042 
0043         m_passed = errors.empty();
0044         if (m_passed) {
0045             return;
0046         }
0047         m_error = i18n("Errors found");
0048 
0049         // The building of the following string is a bit of a hack to avoid
0050         // that xi18nc does not escape the html tags while not breaking
0051         // the historic string.
0052         m_explanation = xi18nc("@info",
0053                                "<para>Kleopatra detected the following errors in the libkleopatrarc configuration:</para>"
0054                                "%1",
0055                                QStringLiteral("%1"))
0056                             .arg(QStringLiteral("<ol><li>") + errors.join(QLatin1StringView("</li><li>")) + QStringLiteral("</li></ol>"));
0057     }
0058 
0059     ///* reimp */ bool canFixAutomatically() const { return false; }
0060 };
0061 }
0062 
0063 std::shared_ptr<SelfTest> Kleo::makeLibKleopatraRcSelfTest()
0064 {
0065     return std::shared_ptr<SelfTest>(new LibKleopatraRcCheck);
0066 }