From ac3f707d31c4194b3152d0a48eeaf563dc08e78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Thu, 26 May 2022 19:39:50 +0200 Subject: [PATCH] Track the master plugin in a plugin group. --- src/pluginmanager.cpp | 43 ++++++++++++++++++++++++++++++----- src/pluginmanager.h | 5 ++++ src/settingsdialogplugins.cpp | 9 +++----- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/pluginmanager.cpp b/src/pluginmanager.cpp index d5db90410..f81a590b3 100644 --- a/src/pluginmanager.cpp +++ b/src/pluginmanager.cpp @@ -248,6 +248,12 @@ bool PluginManager::isEnabled(MOBase::IPlugin* plugin) const return plugin == m_core->managedGame(); } + // check the master of the group + const auto& d = details(plugin); + if (d.master() && d.master() != plugin) { + return isEnabled(d.master()); + } + return m_extensions.isEnabled(details(plugin).extension()); } @@ -485,8 +491,26 @@ bool PluginManager::loadPlugins(const MOBase::PluginExtension& extension) } for (auto& objectGroup : objects) { + + // safety for min_element + if (objectGroup.isEmpty()) { + continue; + } + + // find the best interface + auto it = std::min_element(std::begin(objectGroup), std::end(objectGroup), + [&](auto const& lhs, auto const& rhs) { + return isBetterInterface(lhs, rhs); + }); + IPlugin* master = qobject_cast(*it); + + // register plugins in the group for (auto* object : objectGroup) { - registerPlugin(extension, object, objectGroup); + IPlugin* plugin = registerPlugin(extension, object, objectGroup); + + if (plugin) { + m_details.at(plugin).m_master = master; + } } } @@ -693,14 +717,21 @@ std::vector PluginManager::makeLoaders() // load the python proxy { - auto pluginLoader = std::make_unique( - QCoreApplication::applicationDirPath() + "/proxies/python/python_proxy.dll", - this); + const QString proxyPath = + QCoreApplication::applicationDirPath() + "/proxies/python"; + auto pluginLoader = + std::make_unique(proxyPath + "/python_proxy.dll", this); if (auto* object = pluginLoader->instance(); object) { auto loader = qobject_cast(object); - loaders.push_back( - PluginLoaderPtr(loader, PluginLoaderDeleter{pluginLoader.release()})); + QString errorMessage; + + if (loader->initialize(errorMessage)) { + loaders.push_back( + PluginLoaderPtr(loader, PluginLoaderDeleter{pluginLoader.release()})); + } else { + log::error("failed to initialize proxy from '{}': {}", proxyPath, errorMessage); + } } } diff --git a/src/pluginmanager.h b/src/pluginmanager.h index 604750ab2..2b0e9836e 100644 --- a/src/pluginmanager.h +++ b/src/pluginmanager.h @@ -47,6 +47,10 @@ class PluginDetails // const auto* proxy() const { return m_organizer; } + // the "master" of the group this plugin belongs to + // + MOBase::IPlugin* master() const { return m_master; } + // the extension containing this plugin // const MOBase::PluginExtension& extension() const { return *m_extension; } @@ -74,6 +78,7 @@ class PluginDetails PluginManager* m_manager; MOBase::IPlugin* m_plugin; const MOBase::PluginExtension* m_extension; + MOBase::IPlugin* m_master; std::vector> m_requirements; OrganizerProxy* m_organizer; diff --git a/src/settingsdialogplugins.cpp b/src/settingsdialogplugins.cpp index 359964dc0..1a6d0c90d 100644 --- a/src/settingsdialogplugins.cpp +++ b/src/settingsdialogplugins.cpp @@ -37,18 +37,15 @@ PluginsSettingsTab::PluginsSettingsTab(Settings& s, PluginManager& pluginManager extensionItem->setData(0, Qt::DisplayRole, extension->metadata().name()); ui->pluginsList->addTopLevelItem(extensionItem); - QSet handledNames; - - // Handle child item: for (auto* plugin : plugins) { - if (handledNames.contains(plugin->name())) { + + // only show master + if (pluginManager.details(plugin).master() != plugin) { continue; } QTreeWidgetItem* pluginItem = new QTreeWidgetItem(extensionItem); pluginItem->setData(0, Qt::DisplayRole, plugin->localizedName()); - - handledNames.insert(plugin->name()); } }