KPackage

utils.h
1// SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
2// SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#pragma once
6
7#include "kpackage_debug.h"
8#include <KPluginMetaData>
9#include <QString>
10#include <QVersionNumber>
11
12inline QString readKPackageType(const KPluginMetaData &metaData)
13{
14 return metaData.value(QStringLiteral("KPackageStructure"));
15}
16
17inline KPluginMetaData structureForKPackageType(const QString &packageFormat)
18{
19 const QString guessedPath = QStringLiteral("kf6/packagestructure/") + QString(packageFormat).toLower().replace(QLatin1Char('/'), QLatin1Char('_'));
20 KPluginMetaData guessedData(guessedPath);
21 if (guessedData.isValid() && readKPackageType(guessedData) == packageFormat) {
22 return guessedData;
23 }
24 qCDebug(KPACKAGE_LOG) << "Could not find package structure for" << packageFormat << "by plugin path. The guessed path was" << guessedPath;
25
26 const QList<KPluginMetaData> plugins =
27 KPluginMetaData::findPlugins(QStringLiteral("kf6/packagestructure"), [packageFormat](const KPluginMetaData &metaData) {
28 return readKPackageType(metaData) == packageFormat;
29 });
30 return plugins.isEmpty() ? KPluginMetaData() : plugins.first();
31}
32
33inline bool isVersionNewer(const QString &version1, const QString &version2)
34{
35 const auto v1 = QVersionNumber::fromString(version1);
36 const auto v2 = QVersionNumber::fromString(version2);
37 return v2 > v1;
38}
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 Fri Nov 29 2024 11:54:28 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.