Skip to content

Commit 0ec7b79

Browse files
committed
Track the master plugin in a plugin group.
1 parent a488364 commit 0ec7b79

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

src/pluginmanager.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ bool PluginManager::isEnabled(MOBase::IPlugin* plugin) const
248248
return plugin == m_core->managedGame();
249249
}
250250

251+
// check the master of the group
252+
const auto& d = details(plugin);
253+
if (d.master() && d.master() != plugin) {
254+
return isEnabled(d.master());
255+
}
256+
251257
return m_extensions.isEnabled(details(plugin).extension());
252258
}
253259

@@ -485,8 +491,26 @@ bool PluginManager::loadPlugins(const MOBase::PluginExtension& extension)
485491
}
486492

487493
for (auto& objectGroup : objects) {
494+
495+
// safety for min_element
496+
if (objectGroup.isEmpty()) {
497+
continue;
498+
}
499+
500+
// find the best interface
501+
auto it = std::min_element(std::begin(objectGroup), std::end(objectGroup),
502+
[&](auto const& lhs, auto const& rhs) {
503+
return isBetterInterface(lhs, rhs);
504+
});
505+
IPlugin* master = qobject_cast<IPlugin*>(*it);
506+
507+
// register plugins in the group
488508
for (auto* object : objectGroup) {
489-
registerPlugin(extension, object, objectGroup);
509+
IPlugin* plugin = registerPlugin(extension, object, objectGroup);
510+
511+
if (plugin) {
512+
m_details.at(plugin).m_master = master;
513+
}
490514
}
491515
}
492516

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

694718
// load the python proxy
695719
{
696-
auto pluginLoader = std::make_unique<QPluginLoader>(
697-
QCoreApplication::applicationDirPath() + "/proxies/python/python_proxy.dll",
698-
this);
720+
const QString proxyPath =
721+
QCoreApplication::applicationDirPath() + "/proxies/python";
722+
auto pluginLoader =
723+
std::make_unique<QPluginLoader>(proxyPath + "/python_proxy.dll", this);
699724

700725
if (auto* object = pluginLoader->instance(); object) {
701726
auto loader = qobject_cast<MOBase::IPluginLoader*>(object);
702-
loaders.push_back(
703-
PluginLoaderPtr(loader, PluginLoaderDeleter{pluginLoader.release()}));
727+
QString errorMessage;
728+
729+
if (loader->initialize(errorMessage)) {
730+
loaders.push_back(
731+
PluginLoaderPtr(loader, PluginLoaderDeleter{pluginLoader.release()}));
732+
} else {
733+
log::error("failed to initialize proxy from '{}': {}", proxyPath, errorMessage);
734+
}
704735
}
705736
}
706737

src/pluginmanager.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class PluginDetails
4747
//
4848
const auto* proxy() const { return m_organizer; }
4949

50+
// the "master" of the group this plugin belongs to
51+
//
52+
MOBase::IPlugin* master() const { return m_master; }
53+
5054
// the extension containing this plugin
5155
//
5256
const MOBase::PluginExtension& extension() const { return *m_extension; }
@@ -74,6 +78,7 @@ class PluginDetails
7478
PluginManager* m_manager;
7579
MOBase::IPlugin* m_plugin;
7680
const MOBase::PluginExtension* m_extension;
81+
MOBase::IPlugin* m_master;
7782
std::vector<std::shared_ptr<const MOBase::IPluginRequirement>> m_requirements;
7883
OrganizerProxy* m_organizer;
7984

src/settingsdialogplugins.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,15 @@ PluginsSettingsTab::PluginsSettingsTab(Settings& s, PluginManager& pluginManager
3737
extensionItem->setData(0, Qt::DisplayRole, extension->metadata().name());
3838
ui->pluginsList->addTopLevelItem(extensionItem);
3939

40-
QSet<QString> handledNames;
41-
42-
// Handle child item:
4340
for (auto* plugin : plugins) {
44-
if (handledNames.contains(plugin->name())) {
41+
42+
// only show master
43+
if (pluginManager.details(plugin).master() != plugin) {
4544
continue;
4645
}
4746

4847
QTreeWidgetItem* pluginItem = new QTreeWidgetItem(extensionItem);
4948
pluginItem->setData(0, Qt::DisplayRole, plugin->localizedName());
50-
51-
handledNames.insert(plugin->name());
5249
}
5350
}
5451

0 commit comments

Comments
 (0)