File indexing completed on 2024-12-15 03:45:00
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include "schemaentrytemplates.h" 0008 0009 #include <core/product.h> 0010 0011 #include <QDebug> 0012 #include <QDirIterator> 0013 #include <QJsonArray> 0014 #include <QJsonDocument> 0015 #include <QStandardPaths> 0016 0017 #include <algorithm> 0018 0019 using namespace KUserFeedback::Console; 0020 0021 QVector<Product> SchemaEntryTemplates::availableTemplates() 0022 { 0023 QVector<Product> templates; 0024 0025 auto dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("org.kde.user-feedback/schematemplates"), QStandardPaths::LocateDirectory); 0026 dirs += QStringLiteral(":/org.kde.user-feedback/schematemplates"); 0027 foreach (const auto &dir, dirs) { 0028 QDirIterator it(dir, {QStringLiteral("*.schema")}, QDir::Files | QDir::Readable); 0029 while (it.hasNext()) { 0030 const auto fileName = it.next(); 0031 QFile f(fileName); 0032 if (!f.open(QFile::ReadOnly)) 0033 continue; 0034 const auto ps = Product::fromJson(f.readAll()); 0035 if (ps.isEmpty()) 0036 qWarning() << "Failed to read template" << fileName; 0037 templates += ps; 0038 } 0039 } 0040 0041 std::sort(templates.begin(), templates.end(), [](const auto &lhs, const auto &rhs) { 0042 return lhs.name() < rhs.name(); 0043 }); 0044 0045 return templates; 0046 }