diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-11-12 21:23:35 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-11-12 21:23:35 +0100 |
| commit | 56dcdd33a2110a8c5ad13cc9401ce87fb3d7bf80 (patch) | |
| tree | 897b7c56ed02540d0a606681b4b967d33a553f5f | |
| parent | 15059907c9bd0061f502c64457fce20c7e60a07f (diff) | |
It's 2020.
| -rw-r--r-- | src/plugincontainer.cpp | 51 | ||||
| -rw-r--r-- | src/plugincontainer.h | 14 | ||||
| -rw-r--r-- | src/settingsdialogplugins.cpp | 2 |
3 files changed, 30 insertions, 37 deletions
diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 94e4760c..d2f42fb4 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -253,6 +253,11 @@ QStringList PluginContainer::implementedInterfaces(IPlugin* plugin) const return {};
}
+ return implementedInterfaces(oPlugin);
+}
+
+QStringList PluginContainer::implementedInterfaces(QObject * oPlugin) const
+{
// Find all the names:
QStringList names;
boost::mp11::mp_for_each<PluginTypeOrder>([oPlugin, &names](const auto* p) {
@@ -275,26 +280,8 @@ QStringList PluginContainer::implementedInterfaces(IPlugin* plugin) const QString PluginContainer::topImplementedInterface(IPlugin* plugin) const
{
- // We need a QObject to be able to qobject_cast<> to the plugin types:
- QObject* oPlugin = as_qobject(plugin);
-
- if (!oPlugin) {
- return {};
- }
-
- // Find all the names:
- QString name;
- boost::mp11::mp_for_each<PluginTypeOrder>([oPlugin, &name](auto* p) {
- using plugin_type = std::decay_t<decltype(*p)>;
- if (name.isEmpty() && qobject_cast<plugin_type*>(oPlugin)) {
- auto tname = PluginTypeName<plugin_type>::value();
- if (!tname.isEmpty()) {
- name = tname;
- }
- }
- });
-
- return name;
+ auto interfaces = implementedInterfaces(plugin);
+ return interfaces.isEmpty() ? "" : interfaces[0];
}
bool PluginContainer::isBetterInterface(QObject* lhs, QObject* rhs) const
@@ -408,7 +395,7 @@ IPlugin* PluginContainer::registerPlugin(QObject *plugin, const QString &fileNam && as_qobject(other)->property("filename") == fileName) {
if (isBetterInterface(plugin, as_qobject(other))) {
log::debug("replacing plugin '{}' with interfaces [{}] by one with interfaces [{}]",
- pluginObj->name(), implementedInterfaces(other).join(", "), implementedInterfaces(pluginObj).join(", "));
+ pluginObj->name(), implementedInterfaces(other).join(", "), implementedInterfaces(plugin).join(", "));
bf::at_key<QString>(m_AccessPlugins)[pluginObj->name()] = pluginObj;
}
}
@@ -562,15 +549,6 @@ IPlugin* PluginContainer::registerPlugin(QObject *plugin, const QString &fileNam return nullptr;
}
-struct clearPlugins
-{
- template<typename T>
- void operator()(T& t) const
- {
- t.second.clear();
- }
-};
-
void PluginContainer::unloadPlugins()
{
if (m_UserInterface != nullptr) {
@@ -582,7 +560,7 @@ void PluginContainer::unloadPlugins() m_Organizer->disconnectPlugins();
}
- bf::for_each(m_Plugins, clearPlugins());
+ bf::for_each(m_Plugins, [](auto& t) { t.second.clear(); });
for (const boost::signals2::connection &connection : m_DiagnosisConnections) {
connection.disconnect();
@@ -614,17 +592,18 @@ bool PluginContainer::isEnabled(IPlugin* plugin) const return plugin == m_Organizer->managedGame();
}
- // Check if the plugin is enabled:
- if (!m_Organizer->persistent(plugin->name(), "enabled", true).toBool()) {
- return false;
- }
-
+ // Check the master, if any:
auto& requirements = m_Requirements.at(plugin);
if (requirements.master()) {
return isEnabled(requirements.master());
}
+ // Check if the plugin is enabled:
+ if (!m_Organizer->persistent(plugin->name(), "enabled", true).toBool()) {
+ return false;
+ }
+
// Check the requirements:
return m_Requirements.at(plugin).canEnable();
}
diff --git a/src/plugincontainer.h b/src/plugincontainer.h index 89ab5528..ac40e413 100644 --- a/src/plugincontainer.h +++ b/src/plugincontainer.h @@ -331,6 +331,20 @@ private: friend class PluginRequirements;
+
+ /**
+ * @brief Retrieved the (localized) names of interfaces implemented by the given
+ * plugin.
+ *
+ * @param plugin The plugin to retrieve interface for.
+ *
+ * @return the (localized) names of interfaces implemented by this plugin.
+ *
+ * @note This function can be used to get implemented interfaces before registering
+ * a plugin.
+ */
+ QStringList implementedInterfaces(QObject* plugin) const;
+
/**
* @brief Check if a plugin implements a "better" interface than another
* one, as specified by PluginTypeOrder.
diff --git a/src/settingsdialogplugins.cpp b/src/settingsdialogplugins.cpp index ba690d41..f019cd2f 100644 --- a/src/settingsdialogplugins.cpp +++ b/src/settingsdialogplugins.cpp @@ -31,7 +31,7 @@ PluginsSettingsTab::PluginsSettingsTab(Settings& s, PluginContainer* pluginConta // display plugin settings QSet<QString> handledNames; for (IPlugin* plugin : settings().plugins().plugins()) { - if (handledNames.contains(plugin->name()) || !plugin->master().isEmpty()) { + if (handledNames.contains(plugin->name()) || m_pluginContainer->requirements(plugin).master()) { continue; } |
