1 /*
2     SPDX-FileCopyrightText: 2008 Andreas Pakulat <apaku@gmx.de>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "pluginpreferences.h"
8 
9 #include <QVBoxLayout>
10 
11 #include <KPluginSelector>
12 #include <KPluginInfo>
13 
14 #include <interfaces/isession.h>
15 
16 #include "../core.h"
17 #include "../plugincontroller.h"
18 #include "debug.h"
19 
20 
21 namespace KDevelop
22 {
23 
PluginPreferences(QWidget * parent)24 PluginPreferences::PluginPreferences(QWidget* parent)
25     : ConfigPage(nullptr, nullptr, parent)
26 {
27     auto* lay = new QVBoxLayout(this );
28     lay->setContentsMargins(0, 0, 0, 0);
29     selector = new KPluginSelector( this );
30     lay->addWidget( selector );
31     QMap<QString, QList<KPluginInfo>> plugins;
32     const QMap<QString, QString> categories = {
33         { QStringLiteral("Core"),               i18nc("@title:group", "Core") },
34         { QStringLiteral("Project Management"), i18nc("@title:group", "Project Management") },
35         { QStringLiteral("Version Control"),    i18nc("@title:group", "Version Control") },
36         { QStringLiteral("Utilities"),          i18nc("@title:group", "Utilities") },
37         { QStringLiteral("Documentation"),      i18nc("@title:group", "Documentation") },
38         { QStringLiteral("Language Support"),   i18nc("@title:group", "Language Support") },
39         { QStringLiteral("Debugging"),          i18nc("@title:group", "Debugging") },
40         { QStringLiteral("Testing"),            i18nc("@title:group", "Testing") },
41         { QStringLiteral("Analyzers"),          i18nc("@title:group", "Analyzers") },
42         { QStringLiteral("Runtimes"),           i18nc("@title:group", "Runtimes") },
43         { QStringLiteral("Other"),              i18nc("@title:group", "Other") }
44     };
45     const auto pluginInfos = Core::self()->pluginControllerInternal()->allPluginInfos();
46     for (const KPluginMetaData& info : pluginInfos) {
47         const QString loadMode = info.value(QStringLiteral("X-KDevelop-LoadMode"));
48         if( loadMode.isEmpty() || loadMode == QLatin1String("UserSelectable") )
49         {
50             QString category = info.category();
51             if (!categories.contains(category)) {
52                 if (!category.isEmpty()) {
53                     qCWarning(SHELL) << "unknown category for plugin" << info.name() << ":" << info.category();
54                 }
55                 category = QStringLiteral("Other");
56             }
57             KPluginInfo kpi(info);
58             plugins[category] << kpi;
59         } else
60             qCDebug(SHELL) << "skipping..." << info.pluginId() << info.value(QStringLiteral("X-KDevelop-Category")) << loadMode;
61     }
62 
63     for (auto it = plugins.constBegin(), end = plugins.constEnd(); it != end; ++it) {
64         selector->addPlugins(it.value(), KPluginSelector::ReadConfigFile,
65                              categories.value(it.key()),
66                              // no filter by category key, we did it ourselves above & will not work with "Other"
67                              QString(),
68                              Core::self()->activeSession()->config());
69     }
70     connect(selector, &KPluginSelector::changed, this, &PluginPreferences::changed);
71 }
72 
defaults()73 void PluginPreferences::defaults()
74 {
75     Core::self()->pluginControllerInternal()->resetToDefaults();
76     selector->load();
77 }
78 
apply()79 void PluginPreferences::apply()
80 {
81     selector->save();
82     qCDebug(SHELL) << "Plugins before apply: " << Core::self()->pluginControllerInternal()->allPluginNames();
83     Core::self()->pluginControllerInternal()->updateLoadedPlugins();
84     qCDebug(SHELL) << "Plugins after apply: " << Core::self()->pluginControllerInternal()->allPluginNames();
85     selector->load(); // Some plugins may have failed to load, they must be unchecked.
86 }
87 
reset()88 void PluginPreferences::reset()
89 {
90     selector->load();
91 }
92 
93 }
94 
95 
96