1 | #pragma once |
2 | |
3 | #include "kpackage_debug.h" |
4 | #include <KPluginMetaData> |
5 | #include <QString> |
6 | #include <QVersionNumber> |
7 | |
8 | inline QString readKPackageType(const KPluginMetaData &metaData) |
9 | { |
10 | return metaData.value(QStringLiteral("KPackageStructure" )); |
11 | } |
12 | |
13 | inline KPluginMetaData structureForKPackageType(const QString &packageFormat) |
14 | { |
15 | const QString guessedPath = QStringLiteral("kf6/packagestructure/" ) + QString(packageFormat).toLower().replace(before: QLatin1Char('/'), after: QLatin1Char('_')); |
16 | KPluginMetaData guessedData(guessedPath); |
17 | if (guessedData.isValid() && readKPackageType(metaData: guessedData) == packageFormat) { |
18 | return guessedData; |
19 | } |
20 | qCDebug(KPACKAGE_LOG) << "Could not find package structure for" << packageFormat << "by plugin path. The guessed path was" << guessedPath; |
21 | |
22 | const QList<KPluginMetaData> plugins = |
23 | KPluginMetaData::findPlugins(QStringLiteral("kf6/packagestructure" ), filter: [packageFormat](const KPluginMetaData &metaData) { |
24 | return readKPackageType(metaData) == packageFormat; |
25 | }); |
26 | return plugins.isEmpty() ? KPluginMetaData() : plugins.first(); |
27 | } |
28 | |
29 | inline bool isVersionNewer(const QString &version1, const QString &version2) |
30 | { |
31 | const auto v1 = QVersionNumber::fromString(string: version1); |
32 | const auto v2 = QVersionNumber::fromString(string: version2); |
33 | return v2 > v1; |
34 | } |
35 | |