PluginLoader: improve error message about plugin version compatibility

Summary:
The name of the actual plugin was missing, making the warning rather useless.
Since this is only used within PluginLoader, I added a private function
isPluginVersionCompatible(KPluginLoader), taking code from
Plasma::isPluginVersionCompatible(uint). That one could probably be deprecated,
although no public replacement would be available, just "use PluginLoader".

Test Plan: plasmoidviewer -a org.kde.plasma.digitalclock

Reviewers: mart

Reviewed By: mart

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D1825
This commit is contained in:
David Faure 2016-06-12 15:35:17 +02:00
parent 181869e636
commit 107c28d361
2 changed files with 31 additions and 3 deletions

View File

@ -45,6 +45,7 @@
#include "private/storage_p.h"
#include "private/package_p.h"
#include "private/packagestructure_p.h"
#include <plasma/version.h>
#include "debug_p.h"
namespace Plasma
@ -201,7 +202,7 @@ Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVari
if (!plugins.isEmpty()) {
KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins);
KPluginLoader loader(lst.first().libraryPath());
if (!Plasma::isPluginVersionCompatible(loader.pluginVersion())) {
if (!isPluginVersionCompatible(loader)) {
return 0;
}
KPluginFactory *factory = loader.factory();
@ -384,7 +385,7 @@ Service *PluginLoader::loadService(const QString &name, const QVariantList &args
if (!plugins.isEmpty()) {
KPluginInfo::List lst = KPluginInfo::fromMetaData(plugins);
KPluginLoader loader(lst.first().libraryPath());
if (!Plasma::isPluginVersionCompatible(loader.pluginVersion())) {
if (!isPluginVersionCompatible(loader)) {
return 0;
}
KPluginFactory *factory = loader.factory();
@ -450,7 +451,7 @@ ContainmentActions *PluginLoader::loadContainmentActions(Containment *parent, co
KService::Ptr offer = offers.first();
KPluginLoader plugin(*offer);
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
if (!isPluginVersionCompatible(plugin)) {
return 0;
}
@ -911,5 +912,30 @@ KPluginInfo::List PluginLoader::standardInternalServiceInfo() const
return standardInternalInfo(QStringLiteral("services"));
}
bool PluginLoader::isPluginVersionCompatible(KPluginLoader &loader)
{
const quint32 version = loader.pluginVersion();
if (version == quint32(-1)) {
// unversioned, just let it through
qCWarning(LOG_PLASMA) << loader.fileName() << "unversioned plugin detected, may result in instability";
return true;
}
// we require PLASMA_VERSION_MAJOR and PLASMA_VERSION_MINOR
const quint32 minVersion = PLASMA_MAKE_VERSION(PLASMA_VERSION_MAJOR, 0, 0);
const quint32 maxVersion = PLASMA_MAKE_VERSION(PLASMA_VERSION_MAJOR, PLASMA_VERSION_MINOR, 60);
if (version < minVersion || version > maxVersion) {
#ifndef NDEBUG
qCDebug(LOG_PLASMA) << loader.fileName() << ": this plugin is compiled against incompatible Plasma version" << version
<< "This build is compatible with" << PLASMA_VERSION_MAJOR << ".0.0 (" << minVersion
<< ") to" << PLASMA_VERSION_STRING << "(" << maxVersion << ")";
#endif
return false;
}
return true;
}
} // Plasma Namespace

View File

@ -471,6 +471,8 @@ protected:
virtual ~PluginLoader();
private:
bool isPluginVersionCompatible(KPluginLoader &loader);
PluginLoaderPrivate *const d;
};