File indexing completed on 2024-05-12 04:38:19
0001 /* 0002 SPDX-FileCopyrightText: 2008 Andreas Pakulat <apaku@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "pluginpreferences.h" 0008 0009 #include <QVBoxLayout> 0010 0011 #include <KPluginWidget> 0012 #include <KConfigGroup> 0013 0014 #include <interfaces/isession.h> 0015 0016 #include "../core.h" 0017 #include "../plugincontroller.h" 0018 #include "debug.h" 0019 0020 0021 namespace KDevelop 0022 { 0023 0024 PluginPreferences::PluginPreferences(QWidget* parent) 0025 : ConfigPage(nullptr, nullptr, parent) 0026 { 0027 auto* lay = new QVBoxLayout(this ); 0028 lay->setContentsMargins(0, 0, 0, 0); 0029 selector = new KPluginWidget( this ); 0030 KConfigGroup cfgGroup(Core::self()->activeSession()->config(), "Plugins"); 0031 selector->setConfig(cfgGroup); 0032 lay->addWidget( selector ); 0033 QMap<QString, QVector<KPluginMetaData>> plugins; 0034 const QMap<QString, QString> categories = { 0035 { QStringLiteral("Core"), i18nc("@title:group", "Core") }, 0036 { QStringLiteral("Project Management"), i18nc("@title:group", "Project Management") }, 0037 { QStringLiteral("Version Control"), i18nc("@title:group", "Version Control") }, 0038 { QStringLiteral("Utilities"), i18nc("@title:group", "Utilities") }, 0039 { QStringLiteral("Documentation"), i18nc("@title:group", "Documentation") }, 0040 { QStringLiteral("Language Support"), i18nc("@title:group", "Language Support") }, 0041 { QStringLiteral("Debugging"), i18nc("@title:group", "Debugging") }, 0042 { QStringLiteral("Testing"), i18nc("@title:group", "Testing") }, 0043 { QStringLiteral("Analyzers"), i18nc("@title:group", "Analyzers") }, 0044 { QStringLiteral("Runtimes"), i18nc("@title:group", "Runtimes") }, 0045 { QStringLiteral("Other"), i18nc("@title:group", "Other") } 0046 }; 0047 const auto pluginInfos = Core::self()->pluginControllerInternal()->allPluginInfos(); 0048 for (const KPluginMetaData& info : pluginInfos) { 0049 const QString loadMode = info.value(QStringLiteral("X-KDevelop-LoadMode")); 0050 if( loadMode.isEmpty() || loadMode == QLatin1String("UserSelectable") ) 0051 { 0052 QString category = info.category(); 0053 if (!categories.contains(category)) { 0054 if (!category.isEmpty()) { 0055 qCWarning(SHELL) << "unknown category for plugin" << info.name() << ":" << info.category(); 0056 } 0057 category = QStringLiteral("Other"); 0058 } 0059 plugins[category] << info; 0060 } else 0061 qCDebug(SHELL) << "skipping..." << info.pluginId() << info.value(QStringLiteral("X-KDevelop-Category")) << loadMode; 0062 } 0063 0064 for (auto it = plugins.constBegin(), end = plugins.constEnd(); it != end; ++it) { 0065 selector->addPlugins(it.value(), categories.value(it.key())); 0066 } 0067 connect(selector, &KPluginWidget::changed, this, &PluginPreferences::changed); 0068 } 0069 0070 void PluginPreferences::defaults() 0071 { 0072 Core::self()->pluginControllerInternal()->resetToDefaults(); 0073 selector->load(); 0074 } 0075 0076 void PluginPreferences::apply() 0077 { 0078 selector->save(); 0079 qCDebug(SHELL) << "Plugins before apply: " << Core::self()->pluginControllerInternal()->allPluginNames(); 0080 Core::self()->pluginControllerInternal()->updateLoadedPlugins(); 0081 qCDebug(SHELL) << "Plugins after apply: " << Core::self()->pluginControllerInternal()->allPluginNames(); 0082 selector->load(); // Some plugins may have failed to load, they must be unchecked. 0083 } 0084 0085 void PluginPreferences::reset() 0086 { 0087 selector->load(); 0088 } 0089 0090 } 0091 0092 #include "moc_pluginpreferences.cpp"