From 5eb3c2fc8f90509cb368ab56f14364d6e17844f1 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 23 Feb 2010 12:48:16 +0100 Subject: Look for QML plugins in the paths specified in QML_PLUGIN_PATH env var. --- src/declarative/qml/qmlengine.cpp | 30 +++++++++++++++++++++++++---- src/declarative/qml/qmlengine_p.h | 3 +++ src/declarative/qml/qmlextensioninterface.h | 2 +- src/declarative/qml/qmlextensionplugin.h | 2 +- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 98e16aa..a7c3d08 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -158,6 +158,21 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) } globalClass = new QmlGlobalScriptClass(&scriptEngine); fileImportPath.append(QLibraryInfo::location(QLibraryInfo::DataPath)+QDir::separator()+QLatin1String("qml")); + + // env import paths + QByteArray envImportPath = qgetenv("QML_IMPORT_PATH"); + if (!envImportPath.isEmpty()) { +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) + QLatin1Char pathSep(';'); +#else + QLatin1Char pathSep(':'); +#endif + foreach (const QString &path, QString::fromLatin1(envImportPath).split(pathSep, QString::SkipEmptyParts)) { + QString canonicalPath = QDir(path).canonicalPath(); + if (!canonicalPath.isEmpty() && !environmentImportPath.contains(canonicalPath)) + environmentImportPath.append(canonicalPath); + } + } } QUrl QmlScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url) @@ -1334,9 +1349,16 @@ public: url.replace(QLatin1Char('.'), QLatin1Char('/')); bool found = false; QString content; - QString dir; - QStringList paths = importPath; - paths.prepend(QFileInfo(base.toLocalFile()).path()); + QString dir; + + // user import paths + QStringList paths; + + // base.. + paths += QFileInfo(base.toLocalFile()).path(); + paths += importPath; + paths += QmlEnginePrivate::get(engine)->environmentImportPath; + foreach (const QString &p, paths) { dir = p+QLatin1Char('/')+url; QFileInfo fi(dir+QLatin1String("/qmldir")); @@ -1575,7 +1597,7 @@ bool QmlEngine::importExtension(const QString &fileName, const QString &uri) QPluginLoader loader(fileName); if (QmlExtensionInterface *iface = qobject_cast(loader.instance())) { - iface->initialize(this, uri); + iface->initialize(this, uri.toUtf8().constData()); return true; } diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 53a88b1..85c5fbe 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -264,6 +264,9 @@ public: QmlImportsPrivate *d; }; + + QStringList environmentImportPath; + QString resolvePlugin(const QDir &dir, const QString &baseName, const QStringList &suffixes, const QString &prefix = QString()); diff --git a/src/declarative/qml/qmlextensioninterface.h b/src/declarative/qml/qmlextensioninterface.h index cbdd34c..b993e82 100644 --- a/src/declarative/qml/qmlextensioninterface.h +++ b/src/declarative/qml/qmlextensioninterface.h @@ -54,7 +54,7 @@ class QmlEngine; struct Q_DECLARATIVE_EXPORT QmlExtensionInterface { - virtual void initialize(QmlEngine *engine, const QString &uri) = 0; + virtual void initialize(QmlEngine *engine, const char *uri) = 0; }; Q_DECLARE_INTERFACE(QmlExtensionInterface, "com.trolltech.Qt.QmlExtensionInterface/1.0") diff --git a/src/declarative/qml/qmlextensionplugin.h b/src/declarative/qml/qmlextensionplugin.h index 82553e7..8cc64ad 100644 --- a/src/declarative/qml/qmlextensionplugin.h +++ b/src/declarative/qml/qmlextensionplugin.h @@ -62,7 +62,7 @@ public: explicit QmlExtensionPlugin(QObject *parent = 0); ~QmlExtensionPlugin(); - virtual void initialize(QmlEngine *engine, const QString &uri) = 0; + virtual void initialize(QmlEngine *engine, const char *uri) = 0; }; QT_END_NAMESPACE -- cgit v0.12