From abe926dc1519e7a29769a1a050e80cc5512146a3 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Thu, 28 Apr 2022 19:36:39 +0200 Subject: Allow Qt plugins in subfolder. --- src/plugincontainer.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/plugincontainer.cpp') diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 61169196..f71d89e4 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -823,6 +823,33 @@ QObject* PluginContainer::loadQtPlugin(const QString& filepath) return nullptr; } +std::optional PluginContainer::isQtPluginFolder(const QString& filepath) const { + + if (!QFileInfo(filepath).isDir()) { + return {}; + } + + QDirIterator iter(filepath, QDir::Files | QDir::NoDotAndDotDot); + while (iter.hasNext()) { + iter.next(); + const auto filePath = iter.filePath(); + + // not a library, skip + if (!QLibrary::isLibrary(filePath)) { + continue; + } + + // check if we have proper metadata - this does not load the plugin (metaData() should + // be very lightweight) + const QPluginLoader loader(filePath); + if (!loader.metaData().isEmpty()) { + return filePath; + } + } + + return {}; +} + void PluginContainer::loadPlugin(QString const& filepath) { std::vector plugins; @@ -832,6 +859,12 @@ void PluginContainer::loadPlugin(QString const& filepath) plugins.push_back(plugin); } } + else if (auto p = isQtPluginFolder(filepath)) { + QObject* plugin = loadQtPlugin(*p); + if (plugin) { + plugins.push_back(plugin); + } + } else { // We need to check if this can be handled by a proxy. for (auto* proxy : this->plugins()) { @@ -1049,7 +1082,7 @@ void PluginContainer::loadPlugins() QString pluginPath = qApp->applicationDirPath() + "/" + ToQString(AppConfig::pluginPath()); log::debug("looking for plugins in {}", QDir::toNativeSeparators(pluginPath)); - QDirIterator iter(pluginPath, QDir::Files | QDir::NoDotAndDotDot); + QDirIterator iter(pluginPath, QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); while (iter.hasNext()) { iter.next(); @@ -1076,6 +1109,9 @@ void PluginContainer::loadPlugins() if (QLibrary::isLibrary(filepath)) { loadQtPlugin(filepath); } + else if (auto p = isQtPluginFolder(filepath)) { + loadQtPlugin(*p); + } } if (skipPlugin.isEmpty()) { -- cgit v1.3.1