QtGui: Add command line arguments to the platform plugin.

Set -platformargument foo[=bar] as a dynamic property
on the native interface.

Change-Id: Ica8b25478da0ce9508b90370f15812fd11ff5d13
Reviewed-on: http://codereview.qt-project.org/6031
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Oliver Wolff <oliver.wolff@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
bb10
Friedemann Kleint 2011-10-05 11:08:32 +02:00 committed by Qt by Nokia
parent a4a94544f2
commit 88ffab79cb
1 changed files with 27 additions and 1 deletions

View File

@ -47,6 +47,7 @@
#include "qfont.h"
#include "qplatformfontdatabase_qpa.h"
#include "qplatformwindow_qpa.h"
#include "qplatformnativeinterface_qpa.h"
#include <QtCore/QAbstractEventDispatcher>
#include <QtCore/private/qcoreapplication_p.h>
@ -218,8 +219,19 @@ QWindow *QGuiApplication::topLevelAt(const QPoint &pos)
}
static void init_platform(QString name, const QString &platformPluginPath)
static void init_platform(const QString &pluginArgument, const QString &platformPluginPath)
{
// Split into platform name and arguments
QString name;
QStringList arguments;
foreach (const QString &token, pluginArgument.split(QLatin1Char(':'))) {
if (name.isEmpty()) {
name = token;
} else {
arguments.push_back(token);
}
}
if (name.isEmpty()) {
const QStringList keys = QPlatformIntegrationFactory::keys(platformPluginPath);
#if defined(Q_OS_MAC)
@ -248,6 +260,20 @@ static void init_platform(QString name, const QString &platformPluginPath)
fatalMessage.append(key + QLatin1Char('\n'));
}
qFatal("%s", fatalMessage.toLocal8Bit().constData());
return;
}
// Set arguments as dynamic properties on the native interface as
// boolean 'foo' or strings: 'foo=bar'
if (!arguments.isEmpty()) {
QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface();
foreach (const QString &argument, arguments) {
const int equalsPos = argument.indexOf(QLatin1Char('='));
const QByteArray name =
equalsPos != -1 ? argument.left(equalsPos).toAscii() : argument.toAscii();
const QVariant value =
equalsPos != -1 ? QVariant(argument.mid(equalsPos + 1)) : QVariant(true);
nativeInterface->setProperty(name.constData(), value);
}
}
}