From 107c28d3613b27c7a97aee3572693df8bf6ea8ea Mon Sep 17 00:00:00 2001 From: David Faure Date: Sun, 12 Jun 2016 15:35:17 +0200 Subject: [PATCH] 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 --- src/plasma/pluginloader.cpp | 32 +++++++++++++++++++++++++++++--- src/plasma/pluginloader.h | 2 ++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/plasma/pluginloader.cpp b/src/plasma/pluginloader.cpp index 511f196a4..fa551307a 100644 --- a/src/plasma/pluginloader.cpp +++ b/src/plasma/pluginloader.cpp @@ -45,6 +45,7 @@ #include "private/storage_p.h" #include "private/package_p.h" #include "private/packagestructure_p.h" +#include #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 diff --git a/src/plasma/pluginloader.h b/src/plasma/pluginloader.h index 76549c6bd..80cd1e9a6 100644 --- a/src/plasma/pluginloader.h +++ b/src/plasma/pluginloader.h @@ -471,6 +471,8 @@ protected: virtual ~PluginLoader(); private: + bool isPluginVersionCompatible(KPluginLoader &loader); + PluginLoaderPrivate *const d; };