File indexing completed on 2024-12-01 03:41:54

0001 #pragma once
0002 
0003 #include "kpackage_debug.h"
0004 #include <KPluginMetaData>
0005 #include <QString>
0006 #include <QVersionNumber>
0007 
0008 inline QString readKPackageType(const KPluginMetaData &metaData)
0009 {
0010     return metaData.value(QStringLiteral("KPackageStructure"));
0011 }
0012 
0013 inline KPluginMetaData structureForKPackageType(const QString &packageFormat)
0014 {
0015     const QString guessedPath = QStringLiteral("kf6/packagestructure/") + QString(packageFormat).toLower().replace(QLatin1Char('/'), QLatin1Char('_'));
0016     KPluginMetaData guessedData(guessedPath);
0017     if (guessedData.isValid() && readKPackageType(guessedData) == packageFormat) {
0018         return guessedData;
0019     }
0020     qCDebug(KPACKAGE_LOG) << "Could not find package structure for" << packageFormat << "by plugin path. The guessed path was" << guessedPath;
0021 
0022     const QList<KPluginMetaData> plugins =
0023         KPluginMetaData::findPlugins(QStringLiteral("kf6/packagestructure"), [packageFormat](const KPluginMetaData &metaData) {
0024             return readKPackageType(metaData) == packageFormat;
0025         });
0026     return plugins.isEmpty() ? KPluginMetaData() : plugins.first();
0027 }
0028 
0029 inline bool isVersionNewer(const QString &version1, const QString &version2)
0030 {
0031     const auto v1 = QVersionNumber::fromString(version1);
0032     const auto v2 = QVersionNumber::fromString(version2);
0033     return v2 > v1;
0034 }