summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativeengine.cpp
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2010-03-31 11:00:31 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2010-03-31 11:00:31 (GMT)
commitd401f416478628ce84afd2cd755f8df91edee22d (patch)
tree47c199a2ed053276c9159db9b3c577456e8a9f6a /src/declarative/qml/qdeclarativeengine.cpp
parent5323b5df1587d05de29857305ec0726e2f87610d (diff)
parent93ee746f5b63670af280dfe2e8acaebeb48723b8 (diff)
downloadQt-d401f416478628ce84afd2cd755f8df91edee22d.zip
Qt-d401f416478628ce84afd2cd755f8df91edee22d.tar.gz
Qt-d401f416478628ce84afd2cd755f8df91edee22d.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'src/declarative/qml/qdeclarativeengine.cpp')
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 2cae632..3e570e5 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -81,6 +81,7 @@
#include <QDebug>
#include <QMetaObject>
#include <QStack>
+#include <QMap>
#include <QPluginLoader>
#include <QtCore/qlibraryinfo.h>
#include <QtCore/qthreadstorage.h>
@@ -342,7 +343,8 @@ void QDeclarativeEnginePrivate::clear(SimpleList<QDeclarativeParserStatus> &pss)
}
Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer);
-Q_GLOBAL_STATIC(QSet<QString>, qmlEnginePluginsWithRegisteredTypes);
+typedef QMap<QString, QString> StringStringMap;
+Q_GLOBAL_STATIC(StringStringMap, qmlEnginePluginsWithRegisteredTypes); // stores the uri
void QDeclarativeEnginePrivate::init()
{
@@ -1844,34 +1846,43 @@ bool QDeclarativeEngine::importExtension(const QString &fileName, const QString
qDebug() << "QDeclarativeEngine::importExtension" << uri << "from" << fileName;
QFileInfo fileInfo(fileName);
const QString absoluteFilePath = fileInfo.absoluteFilePath();
- QPluginLoader loader(absoluteFilePath);
- if (QDeclarativeExtensionInterface *iface = qobject_cast<QDeclarativeExtensionInterface *>(loader.instance())) {
- const QByteArray bytes = uri.toUtf8();
- const char *moduleId = bytes.constData();
+ QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this);
+ bool engineInitialized = d->initializedPlugins.contains(absoluteFilePath);
+ bool typesRegistered = qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath);
- // ### this code should probably be protected with a mutex.
- if (! qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath)) {
- // types should only be registered once (they're global).
+ if (typesRegistered) {
+ Q_ASSERT_X(qmlEnginePluginsWithRegisteredTypes()->value(absoluteFilePath) == uri,
+ "QDeclarativeEngine::importExtension",
+ "Internal error: Plugin imported previously with different uri");
+ }
- qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath);
- iface->registerTypes(moduleId);
- }
+ if (!engineInitialized || !typesRegistered) {
+ QPluginLoader loader(absoluteFilePath);
- QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this);
+ if (QDeclarativeExtensionInterface *iface = qobject_cast<QDeclarativeExtensionInterface *>(loader.instance())) {
- if (! d->initializedPlugins.contains(absoluteFilePath)) {
- // things on the engine (eg. adding new global objects) have to be done for every engine.
+ const QByteArray bytes = uri.toUtf8();
+ const char *moduleId = bytes.constData();
+ if (!typesRegistered) {
- // protect against double initialization
- d->initializedPlugins.insert(absoluteFilePath);
- iface->initializeEngine(this, moduleId);
- }
+ // ### this code should probably be protected with a mutex.
+ qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath, uri);
+ iface->registerTypes(moduleId);
+ }
+ if (!engineInitialized) {
+ // things on the engine (eg. adding new global objects) have to be done for every engine.
- return true;
+ // protect against double initialization
+ d->initializedPlugins.insert(absoluteFilePath);
+ iface->initializeEngine(this, moduleId);
+ }
+ } else {
+ return false;
+ }
}
- return false;
+ return true;
}
/*!