From 4e4403d69c60ea6429b3ad5e7898a84b1dc92be5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 8 May 2012 13:14:09 +0200 Subject: No longer use deprecated methods for plugin loading. Change-Id: I19c66b1c41ea4dd236726c86d7d071b210ec9244 Reviewed-by: Lars Knoll --- src/gui/kernel/qgenericpluginfactory_qpa.cpp | 19 +++++++----- src/gui/kernel/qplatformintegrationfactory_qpa.cpp | 36 +++++++++++----------- src/gui/kernel/qplatformthemefactory_qpa.cpp | 34 ++++++++++---------- 3 files changed, 46 insertions(+), 43 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qgenericpluginfactory_qpa.cpp b/src/gui/kernel/qgenericpluginfactory_qpa.cpp index d4a7a9c20e..90da16f868 100644 --- a/src/gui/kernel/qgenericpluginfactory_qpa.cpp +++ b/src/gui/kernel/qgenericpluginfactory_qpa.cpp @@ -79,12 +79,12 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, */ QObject *QGenericPluginFactory::create(const QString& key, const QString &specification) { - QString driver = key.toLower(); + const QString driver = key.toLower(); #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) #ifndef QT_NO_LIBRARY - if (QGenericPluginFactoryInterface *factory = qobject_cast(loader()->instance(driver))) - return factory->create(driver, specification); + if (QObject *object = qLoadPlugin1(loader(), driver, specification)) + return object; #endif #endif return 0; @@ -101,11 +101,14 @@ QStringList QGenericPluginFactory::keys() #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL) #ifndef QT_NO_LIBRARY - QStringList plugins = loader()->keys(); - for (int i = 0; i < plugins.size(); ++i) { - if (!list.contains(plugins.at(i))) - list += plugins.at(i); - } + typedef QMultiMap PluginKeyMap; + typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; + + const PluginKeyMap keyMap = loader()->keyMap(); + const PluginKeyMapConstIterator cend = keyMap.constEnd(); + for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) + if (!list.contains(it.value())) + list += it.value(); #endif //QT_NO_LIBRARY #endif //QT_MAKEDLL return list; diff --git a/src/gui/kernel/qplatformintegrationfactory_qpa.cpp b/src/gui/kernel/qplatformintegrationfactory_qpa.cpp index 2092f2d0ba..3b05742f09 100644 --- a/src/gui/kernel/qplatformintegrationfactory_qpa.cpp +++ b/src/gui/kernel/qplatformintegrationfactory_qpa.cpp @@ -43,6 +43,7 @@ #include #include "private/qfactoryloader_p.h" #include "qmutex.h" +#include "qdir.h" #include "qguiapplication.h" #include "qdebug.h" @@ -58,26 +59,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader, QPlatformIntegration *QPlatformIntegrationFactory::create(const QString& key, const QString &platformPluginPath) { - QPlatformIntegration *ret = 0; QStringList paramList = key.split(QLatin1Char(':')); - QString platform = paramList.takeFirst().toLower(); + const QString platform = paramList.takeFirst().toLower(); #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) // Try loading the plugin from platformPluginPath first: if (!platformPluginPath.isEmpty()) { QCoreApplication::addLibraryPath(platformPluginPath); - if (QPlatformIntegrationFactoryInterface *factory = - qobject_cast(directLoader()->instance(platform))) - ret = factory->create(key, paramList); - - if (ret) + if (QPlatformIntegration *ret = qLoadPlugin1(directLoader(), platform, paramList)) return ret; } - if (QPlatformIntegrationFactoryInterface *factory = qobject_cast(loader()->instance(platform))) - ret = factory->create(platform, paramList); + if (QPlatformIntegration *ret = qLoadPlugin1(loader(), platform, paramList)) + return ret; #endif - - return ret; + return 0; } /*! @@ -86,23 +81,28 @@ QPlatformIntegration *QPlatformIntegrationFactory::create(const QString& key, co \sa create() */ + QStringList QPlatformIntegrationFactory::keys(const QString &platformPluginPath) { #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) QStringList list; - if (!platformPluginPath.isEmpty()) { QCoreApplication::addLibraryPath(platformPluginPath); - foreach (const QString &key, directLoader()->keys()) { - list += key + QString(QLatin1String(" (from %1)")).arg(platformPluginPath); + list = directLoader()->keyMap().values(); + if (!list.isEmpty()) { + const QString postFix = QStringLiteral(" (from ") + + QDir::toNativeSeparators(platformPluginPath) + + QLatin1Char(')'); + const QStringList::iterator end = list.end(); + for (QStringList::iterator it = list.begin(); it != end; ++it) + (*it).append(postFix); } } - - list += loader()->keys(); + list.append(loader()->keyMap().values()); + return list; #else - QStringList list; + return QStringList(); #endif - return list; } QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformthemefactory_qpa.cpp b/src/gui/kernel/qplatformthemefactory_qpa.cpp index 8294591c4b..c809a7fba3 100644 --- a/src/gui/kernel/qplatformthemefactory_qpa.cpp +++ b/src/gui/kernel/qplatformthemefactory_qpa.cpp @@ -41,6 +41,7 @@ #include #include +#include #include "private/qfactoryloader_p.h" #include "qmutex.h" @@ -58,26 +59,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader, QPlatformTheme *QPlatformThemeFactory::create(const QString& key, const QString &platformPluginPath) { - QPlatformTheme *ret = 0; QStringList paramList = key.split(QLatin1Char(':')); - QString platform = paramList.takeFirst().toLower(); + const QString platform = paramList.takeFirst().toLower(); #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) // Try loading the plugin from platformPluginPath first: if (!platformPluginPath.isEmpty()) { QCoreApplication::addLibraryPath(platformPluginPath); - if (QPlatformThemeFactoryInterface *factory = - qobject_cast(directLoader()->instance(platform))) - ret = factory->create(key, paramList); - - if (ret) + if (QPlatformTheme *ret = qLoadPlugin1(directLoader(), platform, paramList)) return ret; } - if (QPlatformThemeFactoryInterface *factory = qobject_cast(loader()->instance(platform))) - ret = factory->create(platform, paramList); + if (QPlatformTheme *ret = qLoadPlugin1(loader(), platform, paramList)) + return ret; #endif - - return ret; + return 0; } /*! @@ -93,16 +88,21 @@ QStringList QPlatformThemeFactory::keys(const QString &platformPluginPath) if (!platformPluginPath.isEmpty()) { QCoreApplication::addLibraryPath(platformPluginPath); - foreach (const QString &key, directLoader()->keys()) { - list += key + QString(QLatin1String(" (from %1)")).arg(platformPluginPath); + list += directLoader()->keyMap().values(); + if (!list.isEmpty()) { + const QString postFix = QStringLiteral(" (from ") + + QDir::toNativeSeparators(platformPluginPath) + + QLatin1Char(')'); + const QStringList::iterator end = list.end(); + for (QStringList::iterator it = list.begin(); it != end; ++it) + (*it).append(postFix); } } - - list += loader()->keys(); + list += loader()->keyMap().values(); + return list; #else - QStringList list; + return QStringList(); #endif - return list; } QT_END_NAMESPACE -- cgit v1.2.3