MCPcopy Create free account
hub / github.com/KDE/labplot / enablePlugin

Method enablePlugin

src/backend/core/plugin/PluginManager.cpp:59–109  ·  view source on GitHub ↗

* \brief Load a plugin and append it to the plugin list in the settings. * * \param absolutePath Absolute path to the plugin file. * \return True, if the plugin was successfully loaded. Even if false is returned, * the path is still appended to the settings. */

Source from the content-addressed store, hash-verified

57 * the path is still appended to the settings.
58 */
59bool PluginManager::enablePlugin(const QString& absolutePath) {
60 loadAll();
61
62 // save the plugin in the settings
63 // TODO
64 // QSettings settings(SETTINGS_FORMAT, QSettings::UserScope, SciDAVis::appName, SciDAVis::appName);
65 // settings.beginGroup("PluginManager");
66 // QStringList pluginPaths = settings.value("enabledPlugins", QStringList()).toStringList();
67 // pluginPaths.removeDuplicates();
68 // if (!pluginPaths.contains(absolutePath)) {
69 // pluginPaths << absolutePath;
70 // settings.setValue("enabledPlugins", pluginPaths);
71 // }
72 // settings.endGroup();
73
74 // check whether it's already loaded
75 bool result = true;
76 bool alreadyLoaded = false;
77 for (auto* loader : m_loadedPlugins) {
78 if (loader->fileName() == absolutePath) {
79 alreadyLoaded = true;
80 break;
81 }
82 }
83
84 if (!alreadyLoaded) {
85 PluginLoader* pluginLoader = nullptr;
86 // check whether a loader for this plugin already exists
87 for (auto* loader : m_pluginsWithErrors) {
88 if (loader->fileName() == absolutePath) {
89 pluginLoader = loader;
90 m_pluginsWithErrors.removeAll(loader);
91 break;
92 }
93 }
94
95 if (!pluginLoader)
96 pluginLoader = new PluginLoader(absolutePath);
97
98 // try to load the plugin
99 if (!pluginLoader->load()) {
100 m_pluginsWithErrors << pluginLoader;
101 result = false;
102 } else {
103 m_loadedPlugins << pluginLoader;
104 m_allPlugins << pluginLoader->instance();
105 }
106 }
107
108 return result;
109}
110
111/**
112 * \brief Remove the plugin from the plugin list in the settings (and unload it if rightNow == true).

Callers

nothing calls this directly

Calls 4

removeAllMethod · 0.80
fileNameMethod · 0.45
loadMethod · 0.45
instanceMethod · 0.45

Tested by

no test coverage detected