From 054e50babc340f1d8b6c037fca143f90dbd0c1f2 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 18 Jul 2013 06:02:37 -0700 Subject: Intercept qmldir files with the url interceptor There's another code path which loads qmldir files directly, and it did not use the interceptor when available. Note that this, like other interceptors, does not affect baseUrl and so any other qmldir file still must have paths relative from the initial URL. Change-Id: I620943c36d488d22fbaf1793514075d31ab76e3e Reviewed-by: Lars Knoll --- src/qml/qml/qqmltypeloader.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/qml/qml') diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 4b398fb6b8..85d2fe41d9 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -1801,9 +1801,25 @@ bool QQmlTypeLoader::directoryExists(const QString &path) Return a QmldirContent for absoluteFilePath. The QmldirContent may be cached. \a filePath is either a bundle URL, or a local file path. + +It can also be a remote path for a remote directory import, but it will have been cached by now in this case. */ -const QQmlTypeLoader::QmldirContent *QQmlTypeLoader::qmldirContent(const QString &filePath, const QString &uriHint) -{ +const QQmlTypeLoader::QmldirContent *QQmlTypeLoader::qmldirContent(const QString &filePathIn, const QString &uriHint) +{ + QUrl url(filePathIn); //May already contain bundle or http scheme + if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("https")) + return *(m_importQmlDirCache.value(filePathIn)); //Can't load the remote here, but should be cached + else if (!QQmlFile::isBundle(filePathIn)) + url = QUrl::fromLocalFile(filePathIn); + if (engine() && engine()->urlInterceptor()) + url = engine()->urlInterceptor()->intercept(url, QQmlAbstractUrlInterceptor::QmldirFile); + Q_ASSERT(url.scheme() == QLatin1String("file") || url.scheme() == QLatin1String("bundle")); + QString filePath; + if (url.scheme() == QLatin1String("file")) + filePath = url.toLocalFile(); + else + filePath = url.path(); + QmldirContent *qmldir; QmldirContent **val = m_importQmlDirCache.value(filePath); if (!val) { @@ -1813,13 +1829,10 @@ const QQmlTypeLoader::QmldirContent *QQmlTypeLoader::qmldirContent(const QString #define NOT_READABLE_ERROR QString(QLatin1String("module \"$$URI$$\" definition \"%1\" not readable")) #define CASE_MISMATCH_ERROR QString(QLatin1String("cannot load module \"$$URI$$\": File name case mismatch for \"%1\"")) - if (QQmlFile::isBundle(filePath)) { - - QUrl url(filePath); - + if (QQmlFile::isBundle(url.toString())) { QQmlFile file(engine(), url); if (file.isError()) { - ERROR(NOT_READABLE_ERROR.arg(filePath)); + ERROR(NOT_READABLE_ERROR.arg(url.toString())); } else { QString content(QString::fromUtf8(file.data(), file.size())); qmldir->setContent(filePath, content); -- cgit v1.2.3