summaryrefslogtreecommitdiff
path: root/src/plugincontainer.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-11-12 21:23:35 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2020-11-12 21:23:35 +0100
commit56dcdd33a2110a8c5ad13cc9401ce87fb3d7bf80 (patch)
tree897b7c56ed02540d0a606681b4b967d33a553f5f /src/plugincontainer.cpp
parent15059907c9bd0061f502c64457fce20c7e60a07f (diff)
It's 2020.
Diffstat (limited to 'src/plugincontainer.cpp')
-rw-r--r--src/plugincontainer.cpp51
1 files changed, 15 insertions, 36 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();
}