KPackage

utils.h
1#pragma once
2
3#include "kpackage_debug.h"
4#include <KPluginMetaData>
5#include <QString>
6#include <QVersionNumber>
7
8inline QString readKPackageType(const KPluginMetaData &metaData)
9{
10 return metaData.value(QStringLiteral("KPackageStructure"));
11}
12
13inline KPluginMetaData structureForKPackageType(const QString &packageFormat)
14{
15 const QString guessedPath = QStringLiteral("kf6/packagestructure/") + QString(packageFormat).toLower().replace(QLatin1Char('/'), QLatin1Char('_'));
16 KPluginMetaData guessedData(guessedPath);
17 if (guessedData.isValid() && readKPackageType(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"), [packageFormat](const KPluginMetaData &metaData) {
24 return readKPackageType(metaData) == packageFormat;
25 });
26 return plugins.isEmpty() ? KPluginMetaData() : plugins.first();
27}
28
29inline bool isVersionNewer(const QString &version1, const QString &version2)
30{
31 const auto v1 = QVersionNumber::fromString(version1);
32 const auto v2 = QVersionNumber::fromString(version2);
33 return v2 > v1;
34}
bool value(QStringView key, bool defaultValue) const
static QList< KPluginMetaData > findPlugins(const QString &directory, std::function< bool(const KPluginMetaData &)> filter={}, KPluginMetaDataOptions options={})
bool isEmpty() const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString toLower() const const
QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.