From 6f3bda0dce945a5fc75d8ebad302820fe9979d9b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 10 Apr 2012 18:11:30 +0100 Subject: [PATCH] Initial bundle support Change-Id: I095249f64ecf4ef1e3fbfb164e3d50edffab61e8 Reviewed-by: Roberto Raggi --- .../folderlistmodel/qquickfolderlistmodel.cpp | 6 +- src/qml/qml/parser/parser.pri | 4 +- src/qml/qml/qml.pri | 4 + src/qml/qml/qqmlbundle.cpp | 319 +++++++ src/qml/qml/qqmlbundle_p.h | 122 +++ src/qml/qml/qqmlcompiler.cpp | 10 +- src/qml/qml/qqmlcompiler_p.h | 2 +- src/qml/qml/qqmldirparser.cpp | 48 +- src/qml/qml/qqmldirparser_p.h | 10 +- src/qml/qml/qqmlengine.cpp | 38 - src/qml/qml/qqmlengine.h | 3 +- src/qml/qml/qqmlengine_p.h | 3 - src/qml/qml/qqmlfile.cpp | 804 +++++++++++++++++ src/qml/qml/qqmlfile.h | 124 +++ src/qml/qml/qqmlimport.cpp | 969 ++++++++++++--------- src/qml/qml/qqmlimport_p.h | 24 +- src/qml/qml/qqmlscript.cpp | 63 +- src/qml/qml/qqmlscript_p.h | 14 +- src/qml/qml/qqmltypeloader.cpp | 312 +++++-- src/qml/qml/qqmltypeloader_p.h | 100 ++- src/qml/qml/qquickworkerscript.cpp | 3 +- src/qml/qml/v8/qv8include.cpp | 3 +- src/quick/items/qquickanimatedimage.cpp | 6 +- src/quick/items/qquickborderimage.cpp | 6 +- src/quick/util/qquickfontloader.cpp | 4 +- src/quick/util/qquickpixmapcache.cpp | 5 +- tests/auto/qml/qml.pro | 1 + .../data/bundleImport/bundleImport.1.qml | 4 + .../data/bundleImport/bundleImport.2.qml | 4 + .../data/bundleImport/bundledata/MyType.qml | 6 + .../bundleImport/bundledata/subdir/MySubType.qml | 7 + .../data/componentFromBundle/bundledata/test.qml | 6 + tests/auto/qml/qqmlbundle/data/import.qml | 4 + .../data/imports/bundletest/bundledata/qmldir | 1 + .../imports/bundletest/bundledata/subdir/qmldir | 1 + .../qqmlbundle/data/imports/bundletest/empty.json | 1 + .../qqmlbundle/data/imports/bundletest/plugin.cpp | 81 ++ .../qqmlbundle/data/imports/bundletest/plugin1.pro | 5 + .../data/relativeQmldir/bundledata/subdir/qmldir | 1 + .../data/relativeQmldir/bundledata/subdir/st.qml | 6 + .../data/relativeQmldir/bundledata/test.qml | 4 + .../relativeResolution.1/bundledata/MyType.qml | 6 + .../data/relativeResolution.1/bundledata/test.qml | 4 + .../bundledata/subdir/MyType.qml | 6 + .../bundledata/subdir/test.qml | 4 + tests/auto/qml/qqmlbundle/qqmlbundle.pro | 2 + tests/auto/qml/qqmlbundle/tst_qqmlbundle.cpp | 260 ++++++ tests/auto/qml/qqmlbundle/tst_qqmlbundle.pro | 15 + tools/qmlbundle/main.cpp | 220 +++++ tools/qmlbundle/qmlbundle.pro | 12 + tools/qmlscene/main.cpp | 11 +- tools/tools.pro | 2 +- 52 files changed, 3034 insertions(+), 646 deletions(-) create mode 100644 src/qml/qml/qqmlbundle.cpp create mode 100644 src/qml/qml/qqmlbundle_p.h create mode 100644 src/qml/qml/qqmlfile.cpp create mode 100644 src/qml/qml/qqmlfile.h create mode 100644 tests/auto/qml/qqmlbundle/data/bundleImport/bundleImport.1.qml create mode 100644 tests/auto/qml/qqmlbundle/data/bundleImport/bundleImport.2.qml create mode 100644 tests/auto/qml/qqmlbundle/data/bundleImport/bundledata/MyType.qml create mode 100644 tests/auto/qml/qqmlbundle/data/bundleImport/bundledata/subdir/MySubType.qml create mode 100644 tests/auto/qml/qqmlbundle/data/componentFromBundle/bundledata/test.qml create mode 100644 tests/auto/qml/qqmlbundle/data/import.qml create mode 100644 tests/auto/qml/qqmlbundle/data/imports/bundletest/bundledata/qmldir create mode 100644 tests/auto/qml/qqmlbundle/data/imports/bundletest/bundledata/subdir/qmldir create mode 100644 tests/auto/qml/qqmlbundle/data/imports/bundletest/empty.json create mode 100644 tests/auto/qml/qqmlbundle/data/imports/bundletest/plugin.cpp create mode 100644 tests/auto/qml/qqmlbundle/data/imports/bundletest/plugin1.pro create mode 100644 tests/auto/qml/qqmlbundle/data/relativeQmldir/bundledata/subdir/qmldir create mode 100644 tests/auto/qml/qqmlbundle/data/relativeQmldir/bundledata/subdir/st.qml create mode 100644 tests/auto/qml/qqmlbundle/data/relativeQmldir/bundledata/test.qml create mode 100644 tests/auto/qml/qqmlbundle/data/relativeResolution.1/bundledata/MyType.qml create mode 100644 tests/auto/qml/qqmlbundle/data/relativeResolution.1/bundledata/test.qml create mode 100644 tests/auto/qml/qqmlbundle/data/relativeResolution.2/bundledata/subdir/MyType.qml create mode 100644 tests/auto/qml/qqmlbundle/data/relativeResolution.2/bundledata/subdir/test.qml create mode 100644 tests/auto/qml/qqmlbundle/qqmlbundle.pro create mode 100644 tests/auto/qml/qqmlbundle/tst_qqmlbundle.cpp create mode 100644 tests/auto/qml/qqmlbundle/tst_qqmlbundle.pro create mode 100644 tools/qmlbundle/main.cpp create mode 100644 tools/qmlbundle/qmlbundle.pro diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp index b937fbd..218d795 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp @@ -44,7 +44,7 @@ #include "fileinfothread_p.h" #include "fileproperty_p.h" #include -#include +#include QT_BEGIN_NAMESPACE @@ -369,7 +369,7 @@ void QQuickFolderListModel::setFolder(const QUrl &folder) if (folder == d->currentDir) return; - QString localPath = QQmlEnginePrivate::urlToLocalFileOrQrc(folder); + QString localPath = QQmlFile::urlToLocalFileOrQrc(folder); QString resolvedPath = QDir::cleanPath(QUrl(localPath).path()); beginResetModel(); @@ -412,7 +412,7 @@ void QQuickFolderListModel::setRootFolder(const QUrl &path) if (path.isEmpty()) return; - QString localPath = QQmlEnginePrivate::urlToLocalFileOrQrc(path); + QString localPath = QQmlFile::urlToLocalFileOrQrc(path); QString resolvedPath = QDir::cleanPath(QUrl(localPath).path()); QFileInfo info(resolvedPath); diff --git a/src/qml/qml/parser/parser.pri b/src/qml/qml/parser/parser.pri index 6be85ba..7dba8bc 100644 --- a/src/qml/qml/parser/parser.pri +++ b/src/qml/qml/parser/parser.pri @@ -8,7 +8,7 @@ HEADERS += \ $$PWD/qqmljsmemorypool_p.h \ $$PWD/qqmljsparser_p.h \ $$PWD/qqmljsglobal_p.h \ - $$PWD/qqmljskeywords_p.h + $$PWD/qqmljskeywords_p.h \ SOURCES += \ $$PWD/qqmljsast.cpp \ @@ -16,4 +16,4 @@ SOURCES += \ $$PWD/qqmljsengine_p.cpp \ $$PWD/qqmljsgrammar.cpp \ $$PWD/qqmljslexer.cpp \ - $$PWD/qqmljsparser.cpp + $$PWD/qqmljsparser.cpp \ diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri index 1237740..30acea1 100644 --- a/src/qml/qml/qml.pri +++ b/src/qml/qml/qml.pri @@ -51,6 +51,8 @@ SOURCES += \ $$PWD/qqmlabstractbinding.cpp \ $$PWD/qqmlvaluetypeproxybinding.cpp \ $$PWD/qqmlglobal.cpp \ + $$PWD/qqmlfile.cpp \ + $$PWD/qqmlbundle.cpp \ HEADERS += \ $$PWD/qqmlglobal_p.h \ @@ -122,6 +124,8 @@ HEADERS += \ $$PWD/qqmljavascriptexpression_p.h \ $$PWD/qqmlabstractbinding_p.h \ $$PWD/qqmlvaluetypeproxybinding_p.h \ + $$PWD/qqmlfile.h \ + $$PWD/qqmlbundle_p.h \ include(parser/parser.pri) include(rewriter/rewriter.pri) diff --git a/src/qml/qml/qqmlbundle.cpp b/src/qml/qml/qqmlbundle.cpp new file mode 100644 index 0000000..fa47cb5 --- /dev/null +++ b/src/qml/qml/qqmlbundle.cpp @@ -0,0 +1,319 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qqmlbundle_p.h" +#include +#include +#include + +static const unsigned char qmlBundleHeaderData[] = { 255, 'q', 'm', 'l', 'd', 'i', 'r', 255 }; +static const unsigned int qmlBundleHeaderLength = 8; + +// +// Entries +// +QString QQmlBundle::FileEntry::fileName() const +{ + return QString((QChar *)&data[0], fileNameLength / sizeof(QChar)); +} + +bool QQmlBundle::FileEntry::isFileName(const QString &fileName) const +{ + return fileName.length() * sizeof(QChar) == (unsigned)fileNameLength && + 0 == ::memcmp(fileName.constData(), &data[0], fileNameLength); +} + +const char *QQmlBundle::FileEntry::contents() const { + return &data[fileNameLength]; +} + +quint64 QQmlBundle::FileEntry::fileSize() const +{ + return size - (sizeof(FileEntry) + fileNameLength); +} + + +// +// QQmlBundle +// +QQmlBundle::QQmlBundle(const QString &fileName) +: file(fileName), + buffer(0), + bufferSize(0), + opened(false), + headerWritten(false) +{ +} + +QQmlBundle::~QQmlBundle() +{ + close(); +} + +bool QQmlBundle::open(QIODevice::OpenMode mode) +{ + if (!opened) { + if (!file.open(mode)) + return false; + + bufferSize = file.size(); + buffer = file.map(0, bufferSize); + + if (bufferSize == 0 || + (bufferSize >= 8 && 0 == ::memcmp(buffer, qmlBundleHeaderData, qmlBundleHeaderLength))) { + opened = true; + headerWritten = false; + return true; + } else { + close(); + return false; + } + } + return true; +} + +void QQmlBundle::close() +{ + if (opened) { + opened = false; + headerWritten = false; + file.unmap(buffer); + file.close(); + } +} + +QList QQmlBundle::files() const +{ + QList files; + const char *ptr = (const char *) buffer + qmlBundleHeaderLength; + const char *end = (const char *) buffer + bufferSize; + + while (ptr < end) { + const Entry *cmd = (const Entry *) ptr; + + switch (static_cast(cmd->kind)) { + case Entry::File: { + const FileEntry *f = reinterpret_cast(cmd); + files.append(f); + } break; + + case Entry::Link: + case Entry::Skip: { + // Skip + } break; + + default: + // throw an error + return QList(); + } // switch + + ptr += cmd->size; + Q_ASSERT(ptr <= end); // throw an error + } + return files; +} + +void QQmlBundle::remove(const FileEntry *entry) +{ + Q_ASSERT(entry->kind == Entry::File); // ### throw an error + Q_ASSERT(file.isWritable()); + const_cast(entry)->kind = Entry::Skip; +} + +int QQmlBundle::bundleHeaderLength() +{ + return qmlBundleHeaderLength; +} + +bool QQmlBundle::isBundleHeader(const char *data, int size) +{ + if ((unsigned int)size < qmlBundleHeaderLength) + return false; + + return 0 == ::memcmp(data, qmlBundleHeaderData, qmlBundleHeaderLength); +} + +// +// find a some empty space we can use to insert new entries. +// +const QQmlBundle::Entry *QQmlBundle::findInsertPoint(quint64 size, qint64 *offset) +{ + const char *ptr = (const char *) buffer + qmlBundleHeaderLength; + const char *end = (const char *) buffer + bufferSize; + + while (ptr < end) { + const Entry *cmd = (const Entry *) ptr; + + if (cmd->kind == Entry::Skip && size + sizeof(RawEntry) < cmd->size) { + *offset = ptr - ((const char *) buffer + qmlBundleHeaderLength); + return cmd; + } + + ptr += cmd->size; + Q_ASSERT(ptr <= end); // throw an error + } + + return 0; +} + +const QQmlBundle::FileEntry *QQmlBundle::find(const QString &fileName) const +{ + const char *ptr = (const char *) buffer + qmlBundleHeaderLength; + const char *end = (const char *) buffer + bufferSize; + + while (ptr < end) { + const Entry *cmd = (const Entry *) ptr; + + if (cmd->kind == Entry::File) { + const FileEntry *fileEntry = static_cast(cmd); + + if (fileEntry->isFileName(fileName)) + return fileEntry; + } + + ptr += cmd->size; + Q_ASSERT(ptr <= end); // throw an error + } + + return 0; +} + +const QQmlBundle::FileEntry *QQmlBundle::link(const FileEntry *entry, const QString &linkName) const +{ + const char *ptr = (const char *) buffer + entry->link; + + while (ptr != (const char *)buffer) { + const Entry *cmd = (const Entry *) ptr; + Q_ASSERT(cmd->kind == Entry::Link); + + const FileEntry *fileEntry = static_cast(cmd); + if (fileEntry->fileName() == linkName) + return fileEntry; + + ptr = (const char *) buffer + fileEntry->link; + } + + return 0; +} + +const QQmlBundle::FileEntry *QQmlBundle::find(const QChar *fileName, int length) const +{ + return find(QString::fromRawData(fileName, length)); +} + +bool QQmlBundle::add(const QString &name, const QString &fileName) +{ + if (!file.isWritable()) + return false; + else if (find(fileName)) + return false; + + QFile inputFile(fileName); + if (!inputFile.open(QFile::ReadOnly)) + return false; + + // ### use best-fit algorithm + if (!file.atEnd()) + file.seek(file.size()); + + FileEntry cmd; + const quint64 inputFileSize = inputFile.size(); + + cmd.kind = Entry::File; + cmd.link = 0; + cmd.size = sizeof(FileEntry) + name.length() * sizeof(QChar) + inputFileSize; + cmd.fileNameLength = name.length() * sizeof(QChar); + + if (bufferSize == 0 && headerWritten == false) { + file.write((const char *)qmlBundleHeaderData, qmlBundleHeaderLength); + headerWritten = true; + } + + file.write((const char *) &cmd, sizeof(FileEntry)); + file.write((const char *) name.constData(), name.length() * sizeof(QChar)); + + uchar *source = inputFile.map(0, inputFileSize); + file.write((const char *) source, inputFileSize); + inputFile.unmap(source); + return true; +} + +bool QQmlBundle::add(const QString &fileName) +{ + return add(fileName, fileName); +} + +bool QQmlBundle::addMetaLink(const QString &fileName, + const QString &linkName, + const QByteArray &data) +{ + if (!file.isWritable()) + return false; + + const FileEntry *fileEntry = find(fileName); + if (!fileEntry) + return false; + + // ### use best-fit algorithm + if (!file.atEnd()) + file.seek(file.size()); + + FileEntry cmd; + + const quint64 inputFileSize = data.size(); + + cmd.kind = Entry::Link; + cmd.link = fileEntry->link; + cmd.size = sizeof(FileEntry) + linkName.length() * sizeof(QChar) + inputFileSize; + cmd.fileNameLength = linkName.length() * sizeof(QChar); + + if (bufferSize == 0 && headerWritten == false) { + file.write((const char *)qmlBundleHeaderData, qmlBundleHeaderLength); + headerWritten = true; + } + + const_cast(fileEntry)->link = file.size(); + + file.write((const char *) &cmd, sizeof(FileEntry)); + file.write((const char *) linkName.constData(), linkName.length() * sizeof(QChar)); + file.write((const char *) data.constData(), inputFileSize); + return true; +} diff --git a/src/qml/qml/qqmlbundle_p.h b/src/qml/qml/qqmlbundle_p.h new file mode 100644 index 0000000..029acf1 --- /dev/null +++ b/src/qml/qml/qqmlbundle_p.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQMLBUNDLE_P_H +#define QQMLBUNDLE_P_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Q_QML_EXPORT QQmlBundle +{ + Q_DISABLE_COPY(QQmlBundle) +public: + struct Q_PACKED Q_QML_EXPORT Entry + { + enum Kind { + File = 123, // Normal file + Skip, // Empty space + Link // A meta data linked file + + // ### add entries for qmldir, index, ... + }; + + int kind; + quint64 size; + }; + + struct Q_PACKED Q_QML_EXPORT RawEntry : public Entry + { + char data[]; // trailing data + }; + + struct Q_PACKED Q_QML_EXPORT FileEntry : public Entry + { + quint64 link; + int fileNameLength; + char data[]; // trailing data + + QString fileName() const; + bool isFileName(const QString &) const; + + quint64 fileSize() const; + const char *contents() const; + }; + + QQmlBundle(const QString &fileName); + ~QQmlBundle(); + + bool open(QIODevice::OpenMode mode = QIODevice::ReadWrite); + void close(); + + QList files() const; + void remove(const FileEntry *entry); + bool add(const QString &fileName); + bool add(const QString &name, const QString &fileName); + + bool addMetaLink(const QString &fileName, + const QString &linkName, + const QByteArray &data); + + const FileEntry *find(const QString &fileName) const; + const FileEntry *find(const QChar *fileName, int length) const; + + const FileEntry *link(const FileEntry *, const QString &linkName) const; + + static int bundleHeaderLength(); + static bool isBundleHeader(const char *, int size); +private: + const Entry *findInsertPoint(quint64 size, qint64 *offset); + +private: + QFile file; + uchar *buffer; + quint64 bufferSize; + bool opened:1; + bool headerWritten:1; +}; + +QT_END_NAMESPACE + +#endif // QQMLBUNDLE_P_H diff --git a/src/qml/qml/qqmlcompiler.cpp b/src/qml/qml/qqmlcompiler.cpp index 8c47c7c..5708a84 100644 --- a/src/qml/qml/qqmlcompiler.cpp +++ b/src/qml/qml/qqmlcompiler.cpp @@ -1742,7 +1742,7 @@ bool QQmlCompiler::buildProperty(QQmlScript::Property *prop, } QQmlType *type = 0; - QQmlImportedNamespace *typeNamespace = 0; + QQmlImportNamespace *typeNamespace = 0; unit->imports().resolveType(prop->name().toString(), &type, 0, 0, 0, &typeNamespace); if (typeNamespace) { @@ -1849,10 +1849,10 @@ bool QQmlCompiler::buildProperty(QQmlScript::Property *prop, return true; } -bool QQmlCompiler::buildPropertyInNamespace(QQmlImportedNamespace *ns, - QQmlScript::Property *nsProp, - QQmlScript::Object *obj, - const BindingContext &ctxt) +bool QQmlCompiler::buildPropertyInNamespace(QQmlImportNamespace *ns, + QQmlScript::Property *nsProp, + QQmlScript::Object *obj, + const BindingContext &ctxt) { if (!nsProp->value) COMPILE_EXCEPTION(nsProp, tr("Invalid use of namespace")); diff --git a/src/qml/qml/qqmlcompiler_p.h b/src/qml/qml/qqmlcompiler_p.h index 3b6fdf1..5a52dcf 100644 --- a/src/qml/qml/qqmlcompiler_p.h +++ b/src/qml/qml/qqmlcompiler_p.h @@ -318,7 +318,7 @@ private: const QQmlCompilerTypes::BindingContext &); bool buildProperty(QQmlScript::Property *prop, QQmlScript::Object *obj, const QQmlCompilerTypes::BindingContext &); - bool buildPropertyInNamespace(QQmlImportedNamespace *ns, + bool buildPropertyInNamespace(QQmlImportNamespace *ns, QQmlScript::Property *prop, QQmlScript::Object *obj, const QQmlCompilerTypes::BindingContext &); diff --git a/src/qml/qml/qqmldirparser.cpp b/src/qml/qml/qqmldirparser.cpp index 8228931..2da4a33 100644 --- a/src/qml/qml/qqmldirparser.cpp +++ b/src/qml/qml/qqmldirparser.cpp @@ -43,6 +43,7 @@ #include "qqmlerror.h" #include "qqmlglobal_p.h" +#include #include #include #include @@ -58,26 +59,6 @@ QQmlDirParser::~QQmlDirParser() { } -QUrl QQmlDirParser::url() const -{ - return _url; -} - -void QQmlDirParser::setUrl(const QUrl &url) -{ - _url = url; -} - -QString QQmlDirParser::fileSource() const -{ - return _filePathSouce; -} - -void QQmlDirParser::setFileSource(const QString &filePath) -{ - _filePathSouce = filePath; -} - QString QQmlDirParser::source() const { return _source; @@ -94,6 +75,9 @@ bool QQmlDirParser::isParsed() const return _isParsed; } +/*! +\a url is used for generating errors. +*/ bool QQmlDirParser::parse() { if (_isParsed) @@ -105,23 +89,6 @@ bool QQmlDirParser::parse() _components.clear(); _scripts.clear(); - if (_source.isEmpty() && !_filePathSouce.isEmpty()) { - QFile file(_filePathSouce); - if (!QQml_isFileCaseCorrect(_filePathSouce)) { - QQmlError error; - error.setDescription(QString::fromUtf8("cannot load module \"$$URI$$\": File name case mismatch for \"%1\"").arg(_filePathSouce)); - _errors.prepend(error); - return false; - } else if (file.open(QFile::ReadOnly)) { - _source = QString::fromUtf8(file.readAll()); - } else { - QQmlError error; - error.setDescription(QString::fromUtf8("module \"$$URI$$\" definition \"%1\" not readable").arg(_filePathSouce)); - _errors.prepend(error); - return false; - } - } - QTextStream stream(&_source); int lineNumber = 0; @@ -246,7 +213,6 @@ bool QQmlDirParser::parse() void QQmlDirParser::reportError(int line, int column, const QString &description) { QQmlError error; - error.setUrl(_url); error.setLine(line); error.setColumn(column); error.setDescription(description); @@ -261,6 +227,12 @@ bool QQmlDirParser::hasError() const return false; } +void QQmlDirParser::setError(const QQmlError &e) +{ + _errors.clear(); + _errors.append(e); +} + QList QQmlDirParser::errors(const QString &uri) const { QList errors = _errors; diff --git a/src/qml/qml/qqmldirparser_p.h b/src/qml/qml/qqmldirparser_p.h index f46e178..77fe277 100644 --- a/src/qml/qml/qqmldirparser_p.h +++ b/src/qml/qml/qqmldirparser_p.h @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE class QQmlError; +class QQmlEngine; class QQmlDirParser { Q_DISABLE_COPY(QQmlDirParser) @@ -68,12 +69,6 @@ public: QQmlDirParser(); ~QQmlDirParser(); - QUrl url() const; - void setUrl(const QUrl &url); - - QString fileSource() const; - void setFileSource(const QString &filePath); - QString source() const; void setSource(const QString &source); @@ -81,6 +76,7 @@ public: bool parse(); bool hasError() const; + void setError(const QQmlError &); QList errors(const QString &uri) const; struct Plugin @@ -146,9 +142,7 @@ private: private: QList _errors; - QUrl _url; QString _source; - QString _filePathSouce; QList _components; QList