Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 5776a48b authored by Volker Krause's avatar Volker Krause

Allow more control over render plugin loading

Also, use this to disable plugins for unit testing, so kdepim-addons
doesn't interfere.
parent 1bfd5b8c
......@@ -19,6 +19,7 @@
*/
#include "setupenv.h"
#include "messagepartthemes/default/messagepartrendererfactory.h"
#include <QStandardPaths>
......@@ -35,4 +36,7 @@ void MessageViewer::Test::setupEnv()
QStandardPaths::setTestModeEnabled(true);
QIcon::setThemeName(QStringLiteral("breeze"));
QLocale::setDefault(QLocale(QStringLiteral("en_US")));
// disable plugin loading, so kdepim-addons doesn't interfere with our tests
MessagePartRendererFactory::instance()->setPluginPath(QString());
}
......@@ -62,7 +62,10 @@ void MessagePartRendererFactoryPrivate::setup()
void MessagePartRendererFactoryPrivate::loadPlugins()
{
KPluginLoader::forEachPlugin(QStringLiteral("messageviewer/bodypartformatter"), [this](const QString &path) {
if (m_pluginSubdir.isEmpty())
return;
KPluginLoader::forEachPlugin(m_pluginSubdir, [this](const QString &path) {
QPluginLoader loader(path);
const auto pluginData = loader.metaData().value(QLatin1String("MetaData")).toObject().value(QLatin1String("renderer")).toArray();
if (pluginData.isEmpty()) {
......@@ -128,8 +131,11 @@ MessagePartRendererFactory::MessagePartRendererFactory()
{
}
MessagePartRendererFactory::~MessagePartRendererFactory()
MessagePartRendererFactory::~MessagePartRendererFactory() = default;
void MessagePartRendererFactory::setPluginPath(const QString& subdir)
{
d->m_pluginSubdir = subdir;
}
MessagePartRendererFactory *MessagePartRendererFactory::instance()
......
......@@ -49,6 +49,13 @@ public:
MessagePartRendererFactory();
~MessagePartRendererFactory();
/** Customize where to look for render plugins.
* This is the sub directory appended to the Qt plugin search paths.
* An empty string disables plugin loading.
* This only has any effect before the first call to renderersForPart().
*/
void setPluginPath(const QString &subdir);
static MessagePartRendererFactory *instance();
QVector<MessagePartRendererBase*> renderersForPart(const QMetaObject *mo, const MimeTreeParser::MessagePart::Ptr &mp) const;
......
......@@ -54,6 +54,7 @@ public:
void insert(const QByteArray &type, MessagePartRendererBase *formatter, const QString &mimeType = QString(), int priority = 0);
QHash<QByteArray, std::vector<RendererInfo>> m_renderers;
QString m_pluginSubdir = QStringLiteral("messageviewer/bodypartformatter");
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment