diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2022-04-28 19:36:39 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2022-05-02 17:04:04 +0200 |
| commit | abe926dc1519e7a29769a1a050e80cc5512146a3 (patch) | |
| tree | 3794c9de48bbc29fa9b2bcaf2ac5f0953c238f4f /src/plugincontainer.cpp | |
| parent | 14c6ee4d27b443d271b59d894ac6c06028aa45ff (diff) | |
Allow Qt plugins in subfolder.
Diffstat (limited to 'src/plugincontainer.cpp')
| -rw-r--r-- | src/plugincontainer.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
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<QString> 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<QObject*> 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<IPluginProxy>()) {
@@ -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()) {
|
