Skip to content

Commit

Permalink
Track the master plugin in a plugin group.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed May 26, 2022
1 parent bf833a7 commit ac3f707
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
43 changes: 37 additions & 6 deletions src/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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<IPlugin*>(*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;
}
}
}

Expand Down Expand Up @@ -693,14 +717,21 @@ std::vector<PluginManager::PluginLoaderPtr> PluginManager::makeLoaders()

// load the python proxy
{
auto pluginLoader = std::make_unique<QPluginLoader>(
QCoreApplication::applicationDirPath() + "/proxies/python/python_proxy.dll",
this);
const QString proxyPath =
QCoreApplication::applicationDirPath() + "/proxies/python";
auto pluginLoader =
std::make_unique<QPluginLoader>(proxyPath + "/python_proxy.dll", this);

if (auto* object = pluginLoader->instance(); object) {
auto loader = qobject_cast<MOBase::IPluginLoader*>(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);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/pluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -74,6 +78,7 @@ class PluginDetails
PluginManager* m_manager;
MOBase::IPlugin* m_plugin;
const MOBase::PluginExtension* m_extension;
MOBase::IPlugin* m_master;
std::vector<std::shared_ptr<const MOBase::IPluginRequirement>> m_requirements;
OrganizerProxy* m_organizer;

Expand Down
9 changes: 3 additions & 6 deletions src/settingsdialogplugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ PluginsSettingsTab::PluginsSettingsTab(Settings& s, PluginManager& pluginManager
extensionItem->setData(0, Qt::DisplayRole, extension->metadata().name());
ui->pluginsList->addTopLevelItem(extensionItem);

QSet<QString> 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());
}
}

Expand Down

0 comments on commit ac3f707

Please sign in to comment.