diff options
author | Morten Johan Sørvig <morten.sorvig@nokia.com> | 2011-01-06 09:30:18 (GMT) |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@nokia.com> | 2011-01-07 07:58:37 (GMT) |
commit | e24d7c9cab4a50fe682478d43ac74e867666d48b (patch) | |
tree | c6f8d0213631db68178d6115a9c7cd7df833e958 /src | |
parent | cc8877068dc6ae8f3142ffec0b85f6fbac4a0d81 (diff) | |
download | Qt-e24d7c9cab4a50fe682478d43ac74e867666d48b.zip Qt-e24d7c9cab4a50fe682478d43ac74e867666d48b.tar.gz Qt-e24d7c9cab4a50fe682478d43ac74e867666d48b.tar.bz2 |
Lighthouse: Support external plugins.
Add -platformpluginpath command line option that
spesifies an additional directory to scan for
plugins. Also read QT_QPA_PLATFORM_PLUGIN_PATH.
QlatformIntegrationFacgtory::create() now tries
to load the plugin from the external path first.
Similarly, keys() returns the keys from the
extra path in addition to the "internal" keys
API changes:
QPlatformIntegration::create() and keys() now take
an optional const QString &platformPluginPath.
New file:
externalplugin.pri, contains instructions and a
base setup for building external plugins.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qapplication_qpa.cpp | 12 | ||||
-rw-r--r-- | src/gui/kernel/qplatformintegrationfactory_qpa.cpp | 27 | ||||
-rw-r--r-- | src/gui/kernel/qplatformintegrationfactory_qpa_p.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/externalplugin.pri | 29 |
4 files changed, 63 insertions, 9 deletions
diff --git a/src/gui/kernel/qapplication_qpa.cpp b/src/gui/kernel/qapplication_qpa.cpp index a164c2d..fdbb931 100644 --- a/src/gui/kernel/qapplication_qpa.cpp +++ b/src/gui/kernel/qapplication_qpa.cpp @@ -444,11 +444,11 @@ void QApplication::alert(QWidget *, int) { } -static void init_platform(const QString &name) +static void init_platform(const QString &name, const QString &platformPluginPath) { - QApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name); + QApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, platformPluginPath); if (!QApplicationPrivate::platform_integration) { - QStringList keys = QPlatformIntegrationFactory::keys(); + QStringList keys = QPlatformIntegrationFactory::keys(platformPluginPath); QString fatalMessage = QString::fromLatin1("Failed to load platform plugin \"%1\". Available platforms are: \n").arg(name); foreach(QString key, keys) { @@ -513,6 +513,7 @@ void qt_init(QApplicationPrivate *priv, int type) } QList<QByteArray> pluginList; + QString platformPluginPath = QLatin1String(qgetenv("QT_QPA_PLATFORM_PLUGIN_PATH")); QString platformName = QLatin1String(qgetenv("QT_QPA_PLATFORM")); // Get command line params @@ -527,6 +528,9 @@ void qt_init(QApplicationPrivate *priv, int type) if (arg == "-fn" || arg == "-font") { if (++i < argc) appFont = QString::fromLocal8Bit(argv[i]); + } else if (arg == "-platformpluginpath") { + if (++i < argc) + platformPluginPath = QLatin1String(argv[i]); } else if (arg == "-platform") { if (++i < argc) platformName = QLatin1String(argv[i]); @@ -550,7 +554,7 @@ void qt_init(QApplicationPrivate *priv, int type) } #endif - init_platform(platformName); + init_platform(platformName, platformPluginPath); init_plugins(pluginList); QColormap::initialize(); diff --git a/src/gui/kernel/qplatformintegrationfactory_qpa.cpp b/src/gui/kernel/qplatformintegrationfactory_qpa.cpp index 9122e1a..17a130d 100644 --- a/src/gui/kernel/qplatformintegrationfactory_qpa.cpp +++ b/src/gui/kernel/qplatformintegrationfactory_qpa.cpp @@ -52,15 +52,27 @@ QT_BEGIN_NAMESPACE #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, (QPlatformIntegrationFactoryInterface_iid, QLatin1String("/platforms"), Qt::CaseInsensitive)) +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader, + (QPlatformIntegrationFactoryInterface_iid, QLatin1String(""), Qt::CaseInsensitive)) #endif -QPlatformIntegration *QPlatformIntegrationFactory::create(const QString& key) +QPlatformIntegration *QPlatformIntegrationFactory::create(const QString& key, const QString &platformPluginPath) { QPlatformIntegration *ret = 0; QStringList paramList = key.split(QLatin1Char(':')); 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<QPlatformIntegrationFactoryInterface*>(directLoader()->instance(platform))) + ret = factory->create(key, paramList); + + if (ret) + return ret; + } if (QPlatformIntegrationFactoryInterface *factory = qobject_cast<QPlatformIntegrationFactoryInterface*>(loader()->instance(platform))) ret = factory->create(platform, paramList); #endif @@ -74,10 +86,19 @@ QPlatformIntegration *QPlatformIntegrationFactory::create(const QString& key) \sa create() */ -QStringList QPlatformIntegrationFactory::keys() +QStringList QPlatformIntegrationFactory::keys(const QString &platformPluginPath) { #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) - QStringList list = loader()->keys(); + QStringList list; + + if (!platformPluginPath.isEmpty()) { + QCoreApplication::addLibraryPath(platformPluginPath); + foreach (const QString &key, directLoader()->keys()) { + list += key + QString(QLatin1String(" (from %1)")).arg(platformPluginPath); + } + } + + list += loader()->keys(); #else QStringList list; #endif diff --git a/src/gui/kernel/qplatformintegrationfactory_qpa_p.h b/src/gui/kernel/qplatformintegrationfactory_qpa_p.h index ba02d2c..77e1da1 100644 --- a/src/gui/kernel/qplatformintegrationfactory_qpa_p.h +++ b/src/gui/kernel/qplatformintegrationfactory_qpa_p.h @@ -66,8 +66,8 @@ class QPlatformIntegration; class QPlatformIntegrationFactory { public: - static QStringList keys(); - static QPlatformIntegration *create(const QString&); + static QStringList keys(const QString &platformPluginPath = QString()); + static QPlatformIntegration *create(const QString &key, const QString &platformPluginPath = QString()); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/externalplugin.pri b/src/plugins/platforms/externalplugin.pri new file mode 100644 index 0000000..54da4d9 --- /dev/null +++ b/src/plugins/platforms/externalplugin.pri @@ -0,0 +1,29 @@ +# +# Lighthouse now has preliminarily support for building and +# loading platform plugins from outside the Qt source/build +# tree. +# +# 1) Building external plugins: +# Set QTDIR to the Qt build directory, copy this file to +# the plugin source repository and include it at the top +# of the plugin's pro file. Use QT_SOURCE_TREE if you +# want to pull in source code from Qt: +# +# include($$QT_SOURCE_TREE/src/plugins/platforms/fontdatabases/genericunix/genericunix.pri) +# +# 2) Loading external plugins: +# Specify the path to the directory containing the +# plugin on the command line, in addition to the +# platform name. +# +# ./wiggly -platformPluginPath /path/to/myPlugin -platform gullfaksA +# + +!exists($$(QTDIR)/.qmake.cache) { + error("Please set QTDIR to the Qt build directory") +} + +QT_SOURCE_TREE = $$fromfile($$(QTDIR)/.qmake.cache,QT_SOURCE_TREE) +QT_BUILD_TREE = $$fromfile($$(QTDIR)/.qmake.cache,QT_BUILD_TREE) + +include($$QT_SOURCE_TREE/src/plugins/qpluginbase.pri) |