Commit ebd1c31c authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Fix most systemsettings and kinfocenter KCM not being shown

For systemsettings we've been gradually moving around things in order to not rely on KServiceTypeTrader for loading KCMs in systemsettings

This caused those KCMs to be not found here using KServiceTypeTrader

To fix this take the loading logic from systemsettings and apply it here too

(cherry picked from commit 4b1a36ee)
parent d59a668e
Pipeline #209987 passed with stage
in 1 minute and 24 seconds
......@@ -15,6 +15,7 @@
#include <QTreeWidgetItemIterator>
#include <QVBoxLayout>
#include <KAuthorized>
#include <KDesktopFile>
#include <KLineEdit>
#include <KMessageBox>
......@@ -43,6 +44,8 @@
#include <prefs.h>
#include <set>
using namespace KHC;
Navigator::Navigator( View *view, QWidget *parent )
......@@ -158,6 +161,93 @@ void Navigator::insertParentAppDocs( const QString &name, NavigatorItem *topItem
}
}
// copied from systemsettings
QList<KPluginMetaData> Navigator::findKCMsMetaData(KCMType source)
{
QList<KPluginMetaData> modules;
std::set<QString> uniquePluginIds;
auto filter = [](const KPluginMetaData &data) {
const auto supportedPlatforms = data.value(QStringLiteral("X-KDE-OnlyShowOnQtPlatforms"), QStringList());
return supportedPlatforms.isEmpty() || supportedPlatforms.contains(qGuiApp->platformName());
};
// We need the exist calls because otherwise the trader language aborts if the property doesn't exist and the second part of the or is not evaluated
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
KService::List services;
#endif
QVector<KPluginMetaData> metaDataList = KPluginMetaData::findPlugins(QStringLiteral("plasma/kcms"), filter);
if (source & SystemSettings) {
metaDataList << KPluginMetaData::findPlugins(QStringLiteral("plasma/kcms/systemsettings"), filter);
metaDataList << KPluginMetaData::findPlugins(QStringLiteral("plasma/kcms/systemsettings_qwidgets"), filter);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
services +=
KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-System-Settings-Parent-Category] != ''"));
#endif
}
if (source & KInfoCenter) {
metaDataList << KPluginMetaData::findPlugins(QStringLiteral("plasma/kcms/kinfocenter"), filter);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
services += KServiceTypeTrader::self()->query(QStringLiteral("KCModule"), QStringLiteral("[X-KDE-ParentApp] == 'kinfocenter'"));
#endif
}
for (const auto &m : qAsConst(metaDataList)) {
// We check both since porting a module to loading view KPluginMetaData drops ".desktop" from the pluginId()
if (!KAuthorized::authorizeControlModule(m.pluginId()) || !KAuthorized::authorizeControlModule(m.pluginId().append(QStringLiteral(".desktop")))) {
continue;
}
modules << m;
const bool inserted = uniquePluginIds.insert(m.pluginId()).second;
if (!inserted) {
qWarning() << "the plugin" << m.pluginId() << " was found in multiple namespaces";
}
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
for (const auto &s : qAsConst(services)) {
if (!s->noDisplay() && !s->exec().isEmpty() && KAuthorized::authorizeControlModule(s->menuId())) {
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("kservices5/") + s->entryPath());
const KPluginMetaData data = KPluginMetaData::fromDesktopFile(path);
const bool inserted = uniquePluginIds.insert(data.pluginId()).second;
if (inserted) {
modules << data;
}
}
}
#endif
std::stable_sort(modules.begin(), modules.end(), [](const KPluginMetaData &m1, const KPluginMetaData &m2) {
return QString::compare(m1.pluginId(), m2.pluginId(), Qt::CaseInsensitive) < 0;
});
return modules;
}
void Navigator::insertSystemSettingsDocs( const QString &name, NavigatorItem *topItem, KCMType type )
{
qCDebug(KHC_LOG) << "Requested KCM documents for ID" << name;
const QList<KPluginMetaData> list = findKCMsMetaData(type);
bool no_children_present = true;
for ( const KPluginMetaData &md : std::as_const(list))
{
QString docPath = md.value(QStringLiteral("X-DocPath"));
if ( !docPath.isNull() ) {
// First parameter is ignored if second is an absolute path
const QUrl url(QStringLiteral("help:/") + docPath);
QString icon = md.iconName();
if ( icon.isEmpty() ) icon = QStringLiteral("text-plain");
DocEntry *entry = new DocEntry( md.name(), url.url(), icon );
NavigatorItem *item = new NavigatorAppItem( entry, topItem );
item->setAutoDeleteDocEntry( true );
}
no_children_present = false;
}
topItem->sortChildren( 0, Qt::AscendingOrder /* ascending */ );
topItem->setHidden(no_children_present);
}
void Navigator::insertKCMDocs( const QString &name, NavigatorItem *topItem, const QString &type )
{
qCDebug(KHC_LOG) << "Requested KCM documents for ID" << name;
......
......@@ -14,6 +14,8 @@
#include <QTimer>
#include <QUrl>
#include <KPluginMetaData>
class QProgressBar;
class QTabWidget;
class QTreeWidget;
......@@ -36,6 +38,11 @@ class Navigator : public QWidget
explicit Navigator(View *, QWidget *parent= nullptr);
virtual ~Navigator();
enum KCMType {
SystemSettings = 1,
KInfoCenter = 2,
};
QUrl homeURL();
SearchEngine *searchEngine() const;
......@@ -46,6 +53,7 @@ class Navigator : public QWidget
void insertScrollKeeperDocs( NavigatorItem *parent );
void insertInfoDocs( NavigatorItem *parentItem );
void insertKCMDocs(const QString &, NavigatorItem*parent, const QString &);
void insertSystemSettingsDocs( const QString &name, NavigatorItem *topItem, KCMType type );
void insertIOWorkerDocs(const QString &, NavigatorItem*parent);
void createItemFromDesktopFile( NavigatorItem *item, const QString &name );
......@@ -94,6 +102,8 @@ class Navigator : public QWidget
void insertPlugins();
void hideSearch();
QList<KPluginMetaData> findKCMsMetaData(KCMType source);
QTreeWidget *mContentsTree = nullptr;
Glossary *mGlossaryTree = nullptr;
......
......@@ -70,7 +70,7 @@ void PluginTraverser::process( DocEntry *entry )
if ( entry->khelpcenterSpecial() == QLatin1String("konqueror") ) {
mNavigator->insertParentAppDocs( entry->khelpcenterSpecial(), mCurrentItem );
} else if ( entry->khelpcenterSpecial() == QLatin1String("kcontrol") ) {
mNavigator->insertKCMDocs( entry->khelpcenterSpecial(), mCurrentItem, QStringLiteral("kcontrol") );
mNavigator->insertSystemSettingsDocs( entry->khelpcenterSpecial(), mCurrentItem, Navigator::SystemSettings );
} else if ( entry->khelpcenterSpecial() == QLatin1String("konquerorcontrol") ) {
mNavigator->insertKCMDocs( entry->khelpcenterSpecial(), mCurrentItem, QStringLiteral("konquerorcontrol") );
} else if ( entry->khelpcenterSpecial() == QLatin1String("filemanagercontrol") ) {
......@@ -80,7 +80,7 @@ void PluginTraverser::process( DocEntry *entry )
} else if ( entry->khelpcenterSpecial() == QLatin1String("othercontrol") ) {
mNavigator->insertKCMDocs( entry->khelpcenterSpecial(), mCurrentItem, QStringLiteral("othercontrol") );
} else if ( entry->khelpcenterSpecial() == QLatin1String("kinfocenter") ) {
mNavigator->insertKCMDocs( entry->khelpcenterSpecial(), mCurrentItem, QStringLiteral("kinfocenter") );
mNavigator->insertSystemSettingsDocs( entry->khelpcenterSpecial(), mCurrentItem, Navigator::KInfoCenter);
} else if ( entry->khelpcenterSpecial() == QLatin1String("kioworker") ) {
mNavigator->insertIOWorkerDocs( entry->khelpcenterSpecial(), mCurrentItem );
} else if ( entry->khelpcenterSpecial() == QLatin1String("info") ) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment