diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2014-12-09 12:26:59 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-12-12 06:13:47 +0100 |
commit | 88508e9f4081a9b0008793dbe90c65f6b96c0f0f (patch) | |
tree | 9813ac08b1474051451f0926cc90d88594d20657 /src/qml | |
parent | fdd367efd705f958af1f70413e726d337e8ec1ca (diff) |
Remove QML bundle code
This feature is effectively not maintained, experimental and undocumented.
Consensus on the mailing list is to remove it:
http://lists.qt-project.org/pipermail/development/2014-December/019384.html
Change-Id: Iaa73b3e90806c338ef81bbd4307ddd2addd37964
Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/qml/qml.pri | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlbundle.cpp | 310 | ||||
-rw-r--r-- | src/qml/qml/qqmlbundle_p.h | 119 | ||||
-rw-r--r-- | src/qml/qml/qqmlfile.cpp | 276 | ||||
-rw-r--r-- | src/qml/qml/qqmlfile.h | 15 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 51 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 142 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 22 |
8 files changed, 41 insertions, 896 deletions
diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri index 013f757c90..cad839ba9d 100644 --- a/src/qml/qml/qml.pri +++ b/src/qml/qml/qml.pri @@ -49,7 +49,6 @@ SOURCES += \ $$PWD/qqmlvaluetypeproxybinding.cpp \ $$PWD/qqmlglobal.cpp \ $$PWD/qqmlfile.cpp \ - $$PWD/qqmlbundle.cpp \ $$PWD/qqmlmemoryprofiler.cpp \ $$PWD/qqmlplatform.cpp \ $$PWD/qqmlbinding.cpp \ @@ -121,7 +120,6 @@ HEADERS += \ $$PWD/qqmlabstractbinding_p.h \ $$PWD/qqmlvaluetypeproxybinding_p.h \ $$PWD/qqmlfile.h \ - $$PWD/qqmlbundle_p.h \ $$PWD/qqmlmemoryprofiler_p.h \ $$PWD/qqmlplatform_p.h \ $$PWD/qqmlbinding_p.h \ diff --git a/src/qml/qml/qqmlbundle.cpp b/src/qml/qml/qqmlbundle.cpp deleted file mode 100644 index 1034dd1b4c..0000000000 --- a/src/qml/qml/qqmlbundle.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qqmlbundle_p.h" -#include <iostream> -#include <cstdlib> - -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]; -} - -quint32 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<const QQmlBundle::FileEntry *> QQmlBundle::files() const -{ - QList<const FileEntry *> 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<Entry::Kind>(cmd->kind)) { - case Entry::File: { - const FileEntry *f = reinterpret_cast<const FileEntry *>(cmd); - files.append(f); - } break; - - case Entry::Link: - case Entry::Skip: { - // Skip - } break; - - default: - // throw an error - return QList<const FileEntry *>(); - } // 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<FileEntry *>(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(quint32 size, qint32 *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<const FileEntry *>(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<const FileEntry *>(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 quint32 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 quint32 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 *>(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 deleted file mode 100644 index e1066ed378..0000000000 --- a/src/qml/qml/qqmlbundle_p.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQMLBUNDLE_P_H -#define QQMLBUNDLE_P_H - -#include <QtCore/qfile.h> -#include <QtCore/qstring.h> -#include <private/qtqmlglobal_p.h> - -#ifdef Q_CC_MSVC -// nonstandard extension used : zero-sized array in struct/union. -# pragma warning( disable : 4200 ) -#endif - -QT_BEGIN_NAMESPACE - -class Q_QML_PRIVATE_EXPORT QQmlBundle -{ - Q_DISABLE_COPY(QQmlBundle) -public: - struct Q_QML_PRIVATE_EXPORT Entry - { - enum Kind { - File = 123, // Normal file - Skip, // Empty space - Link // A meta data linked file - - // ### add entries for qmldir, index, ... - }; - - int kind; - quint32 size; - }; - - struct Q_QML_PRIVATE_EXPORT RawEntry : public Entry - { - char data[]; // trailing data - }; - - struct Q_QML_PRIVATE_EXPORT FileEntry : public Entry - { - quint32 link; - int fileNameLength; - char data[]; // trailing data - - QString fileName() const; - bool isFileName(const QString &) const; - - quint32 fileSize() const; - const char *contents() const; - }; - - QQmlBundle(const QString &fileName); - ~QQmlBundle(); - - bool open(QIODevice::OpenMode mode = QIODevice::ReadWrite); - void close(); - - QList<const FileEntry *> 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(quint32 size, qint32 *offset); - -private: - QFile file; - uchar *buffer; - quint32 bufferSize; - bool opened:1; - bool headerWritten:1; -}; - -QT_END_NAMESPACE - -#endif // QQMLBUNDLE_P_H diff --git a/src/qml/qml/qqmlfile.cpp b/src/qml/qml/qqmlfile.cpp index 1aa350acc8..fe3c83cd3a 100644 --- a/src/qml/qml/qqmlfile.cpp +++ b/src/qml/qml/qqmlfile.cpp @@ -36,6 +36,7 @@ #include <QtCore/qurl.h> #include <QtCore/qobject.h> #include <QtCore/qmetaobject.h> +#include <QtCore/qfile.h> #include <private/qqmlengine_p.h> #include <private/qqmlglobal_p.h> @@ -45,7 +46,7 @@ \internal -Supports file://, qrc:/, bundle:// uris and whatever QNetworkAccessManager supports. +Supports file:// and qrc:/ uris and whatever QNetworkAccessManager supports. */ #define QQMLFILE_MAX_REDIRECT_RECURSION 16 @@ -54,7 +55,6 @@ QT_BEGIN_NAMESPACE static char qrc_string[] = "qrc"; static char file_string[] = "file"; -static char bundle_string[] = "bundle"; #if defined(Q_OS_ANDROID) static char assets_string[] = "assets"; @@ -100,9 +100,6 @@ public: mutable QUrl url; mutable QString urlString; - QQmlBundleData *bundle; - const QQmlBundle::FileEntry *file; - QByteArray data; enum Error { @@ -199,7 +196,7 @@ void QQmlFileNetworkReply::networkDownloadProgress(qint64 a, qint64 b) } QQmlFilePrivate::QQmlFilePrivate() -: bundle(0), file(0), error(None), reply(0) +: error(None), reply(0) { } @@ -222,11 +219,7 @@ QQmlFile::QQmlFile(QQmlEngine *e, const QString &url) QQmlFile::~QQmlFile() { - if (d->reply) - delete d->reply; - if (d->bundle) - d->bundle->release(); - + delete d->reply; delete d; d = 0; } @@ -287,31 +280,17 @@ QString QQmlFile::error() const qint64 QQmlFile::size() const { - if (d->file) return d->file->fileSize(); - else return d->data.size(); + return d->data.size(); } const char *QQmlFile::data() const { - if (d->file) return d->file->contents(); - else return d->data.constData(); + return d->data.constData(); } QByteArray QQmlFile::dataByteArray() const { - if (d->file) return QByteArray(d->file->contents(), d->file->fileSize()); - else return d->data; -} - -QByteArray QQmlFile::metaData(const QString &name) const -{ - if (d->file) { - Q_ASSERT(d->bundle); - const QQmlBundle::FileEntry *meta = d->bundle->link(d->file, name); - if (meta) - return QByteArray::fromRawData(meta->contents(), meta->fileSize()); - } - return QByteArray(); + return d->data; } void QQmlFile::load(QQmlEngine *engine, const QUrl &url) @@ -321,25 +300,7 @@ void QQmlFile::load(QQmlEngine *engine, const QUrl &url) clear(); d->url = url; - if (isBundle(url)) { - // Bundle - QQmlEnginePrivate *p = QQmlEnginePrivate::get(engine); - QQmlBundleData *bundle = p->typeLoader.getBundle(url.host()); - - d->error = QQmlFilePrivate::NotFound; - - if (bundle) { - QString filename = url.path().mid(1); - const QQmlBundle::FileEntry *entry = bundle->find(filename); - if (entry) { - d->file = entry; - d->bundle = bundle; - d->bundle->addref(); - d->error = QQmlFilePrivate::None; - } - bundle->release(); - } - } else if (isLocalFile(url)) { + if (isLocalFile(url)) { QString lf = urlToLocalFileOrQrc(url); if (!QQml_isFileCaseCorrect(lf)) { @@ -366,33 +327,7 @@ void QQmlFile::load(QQmlEngine *engine, const QString &url) d->urlString = url; - if (isBundle(url)) { - // Bundle - QQmlEnginePrivate *p = QQmlEnginePrivate::get(engine); - - d->error = QQmlFilePrivate::NotFound; - - int index = url.indexOf(QLatin1Char('/'), 9); - if (index == -1) - return; - - QStringRef identifier(&url, 9, index - 9); - - QQmlBundleData *bundle = p->typeLoader.getBundle(identifier); - - d->error = QQmlFilePrivate::NotFound; - - if (bundle) { - QString filename = url.mid(index); - const QQmlBundle::FileEntry *entry = bundle->find(filename); - if (entry) { - d->data = QByteArray(entry->contents(), entry->fileSize()); - d->error = QQmlFilePrivate::None; - } - bundle->release(); - } - - } else if (isLocalFile(url)) { + if (isLocalFile(url)) { QString lf = urlToLocalFileOrQrc(url); if (!QQml_isFileCaseCorrect(lf)) { @@ -419,9 +354,6 @@ void QQmlFile::clear() d->url = QUrl(); d->urlString = QString(); d->data = QByteArray(); - if (d->bundle) d->bundle->release(); - d->bundle = 0; - d->file = 0; d->error = QQmlFilePrivate::None; } @@ -477,7 +409,7 @@ bool QQmlFile::connectDownloadProgress(QObject *object, int method) /*! Returns true if QQmlFile will open \a url synchronously. -Synchronous urls have a qrc:/, file://, or bundle:// scheme. +Synchronous urls have a qrc:/ or file:// scheme. \note On Android, urls with assets:/ scheme are also considered synchronous. */ @@ -486,7 +418,6 @@ bool QQmlFile::isSynchronous(const QUrl &url) QString scheme = url.scheme(); if ((scheme.length() == 4 && 0 == scheme.compare(QLatin1String(file_string), Qt::CaseInsensitive)) || - (scheme.length() == 6 && 0 == scheme.compare(QLatin1String(bundle_string), Qt::CaseInsensitive)) || (scheme.length() == 3 && 0 == scheme.compare(QLatin1String(qrc_string), Qt::CaseInsensitive))) { return true; @@ -503,7 +434,7 @@ bool QQmlFile::isSynchronous(const QUrl &url) /*! Returns true if QQmlFile will open \a url synchronously. -Synchronous urls have a qrc:/, file://, or bundle:// scheme. +Synchronous urls have a qrc:/ or file:// scheme. \note On Android, urls with assets:/ scheme are also considered synchronous. */ @@ -520,12 +451,6 @@ bool QQmlFile::isSynchronous(const QString &url) url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); - } else if (f == QLatin1Char('b') || f == QLatin1Char('B')) { - - return url.length() >= 9 /* bundle:// */ && - url.startsWith(QLatin1String(bundle_string), Qt::CaseInsensitive) && - url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/') && url[8] == QLatin1Char('/'); - } else if (f == QLatin1Char('q') || f == QLatin1Char('Q')) { return url.length() >= 5 /* qrc:/ */ && @@ -547,29 +472,6 @@ bool QQmlFile::isSynchronous(const QString &url) } /*! -Returns true if \a url is a bundle. - -Bundle urls have a bundle:// scheme. -*/ -bool QQmlFile::isBundle(const QString &url) -{ - return url.length() >= 9 && url.startsWith(QLatin1String(bundle_string), Qt::CaseInsensitive) && - url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/') && url[8] == QLatin1Char('/'); -} - -/*! -Returns true if \a url is a bundle. - -Bundle urls have a bundle:// scheme. -*/ -bool QQmlFile::isBundle(const QUrl &url) -{ - QString scheme = url.scheme(); - - return scheme.length() == 6 && 0 == scheme.compare(QLatin1String(bundle_string), Qt::CaseInsensitive); -} - -/*! Returns true if \a url is a local file that can be opened with QFile. Local file urls have either a qrc:/ or file:// scheme. @@ -688,162 +590,6 @@ QString QQmlFile::urlToLocalFileOrQrc(const QString& url) return toLocalFile(url); } -bool QQmlFile::bundleDirectoryExists(const QString &dir, QQmlEngine *e) -{ - if (!isBundle(dir)) - return false; - - int index = dir.indexOf(QLatin1Char('/'), 9); - - if (index == -1 && dir.length() > 9) // We accept "bundle://<blah>" with no extra path - index = dir.length(); - - if (index == -1) - return false; - - QStringRef identifier(&dir, 9, index - 9); - - QQmlBundleData *bundle = QQmlEnginePrivate::get(e)->typeLoader.getBundle(identifier); - - if (bundle) { - int lastIndex = dir.lastIndexOf(QLatin1Char('/')); - - if (lastIndex <= index) { - bundle->release(); - return true; - } - - QStringRef d(&dir, index + 1, lastIndex - index); - - QList<const QQmlBundle::FileEntry *> entries = bundle->files(); - - for (int ii = 0; ii < entries.count(); ++ii) { - QString name = entries.at(ii)->fileName(); - if (name.startsWith(d)) { - bundle->release(); - return true; - } - } - - bundle->release(); - } - - return false; -} - -bool QQmlFile::bundleDirectoryExists(const QUrl &url, QQmlEngine *e) -{ - if (!isBundle(url)) - return false; - - QQmlBundleData *bundle = QQmlEnginePrivate::get(e)->typeLoader.getBundle(url.host()); - - if (bundle) { - QString path = url.path(); - - int lastIndex = path.lastIndexOf(QLatin1Char('/')); - - if (lastIndex == -1) { - bundle->release(); - return true; - } - - QStringRef d(&path, 0, lastIndex); - - QList<const QQmlBundle::FileEntry *> entries = bundle->files(); - - for (int ii = 0; ii < entries.count(); ++ii) { - QString name = entries.at(ii)->fileName(); - if (name.startsWith(d)) { - bundle->release(); - return true; - } - } - - bundle->release(); - } - - return false; -} - -bool QQmlFile::bundleFileExists(const QString &file, QQmlEngine *e) -{ - if (!isBundle(file)) - return false; - - int index = file.indexOf(QLatin1Char('/'), 9); - - if (index == -1) - return false; - - QStringRef identifier(&file, 9, index - 9); - QStringRef path(&file, index + 1, file.length() - index - 1); - - QQmlBundleData *bundle = QQmlEnginePrivate::get(e)->typeLoader.getBundle(identifier); - - if (bundle) { - const QQmlBundle::FileEntry *entry = bundle->find(path.constData(), path.length()); - bundle->release(); - - return entry != 0; - } - - return false; -} - -bool QQmlFile::bundleFileExists(const QUrl &, QQmlEngine *) -{ - qFatal("Not implemented"); - return true; -} - -/*! -Returns the file name for the bundle file referenced by \a url or an -empty string if \a url isn't a bundle url. -*/ -QString QQmlFile::bundleFileName(const QString &url, QQmlEngine *e) -{ - if (!isBundle(url)) - return QString(); - - int index = url.indexOf(QLatin1Char('/'), 9); - - if (index == -1) - index = url.length(); - - QStringRef identifier(&url, 9, index - 9); - - QQmlBundleData *bundle = QQmlEnginePrivate::get(e)->typeLoader.getBundle(identifier); - - if (bundle) { - QString rv = bundle->fileName; - bundle->release(); - return rv; - } - - return QString(); -} - -/*! -Returns the file name for the bundle file referenced by \a url or an -empty string if \a url isn't a bundle url. -*/ -QString QQmlFile::bundleFileName(const QUrl &url, QQmlEngine *e) -{ - if (!isBundle(url)) - return QString(); - - QQmlBundleData *bundle = QQmlEnginePrivate::get(e)->typeLoader.getBundle(url.host()); - - if (bundle) { - QString rv = bundle->fileName; - bundle->release(); - return rv; - } - - return QString(); -} - QT_END_NAMESPACE #include "qqmlfile.moc" diff --git a/src/qml/qml/qqmlfile.h b/src/qml/qml/qqmlfile.h index 3d27224500..482d3242c9 100644 --- a/src/qml/qml/qqmlfile.h +++ b/src/qml/qml/qqmlfile.h @@ -68,8 +68,6 @@ public: const char *data() const; QByteArray dataByteArray() const; - QByteArray metaData(const QString &) const; - void load(QQmlEngine *, const QUrl &); void load(QQmlEngine *, const QString &); @@ -84,24 +82,11 @@ public: static bool isSynchronous(const QString &url); static bool isSynchronous(const QUrl &url); - static bool isBundle(const QString &url); - static bool isBundle(const QUrl &url); - static bool isLocalFile(const QString &url); static bool isLocalFile(const QUrl &url); static QString urlToLocalFileOrQrc(const QString &); static QString urlToLocalFileOrQrc(const QUrl &); - - static bool bundleDirectoryExists(const QString &, QQmlEngine *); - static bool bundleDirectoryExists(const QUrl &, QQmlEngine *); - - static bool bundleFileExists(const QString &, QQmlEngine *); - static bool bundleFileExists(const QUrl &, QQmlEngine *); - - static QString bundleFileName(const QString &, QQmlEngine *); - static QString bundleFileName(const QUrl &, QQmlEngine *); - private: Q_DISABLE_COPY(QQmlFile) QQmlFilePrivate *d; diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 807eb05362..cb8764e773 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -668,13 +668,9 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader, for (uint i = 0; i < sizeof(urlsToTry) / sizeof(urlsToTry[0]); ++i) { const QString url = urlsToTry[i]; - if (QQmlFile::isBundle(url)) { - exists = QQmlFile::bundleFileExists(url, typeLoader->engine()); - } else { - exists = !typeLoader->absoluteFilePath(QQmlFile::urlToLocalFileOrQrc(url)).isEmpty(); - if (!exists) - exists = QQmlMetaType::findCachedCompilationUnit(QUrl(url)); - } + exists = !typeLoader->absoluteFilePath(QQmlFile::urlToLocalFileOrQrc(url)).isEmpty(); + if (!exists) + exists = QQmlMetaType::findCachedCompilationUnit(QUrl(url)); if (exists) { qmlUrl = url; @@ -879,7 +875,7 @@ bool QQmlImportsPrivate::populatePluginPairVector(QVector<StaticPluginPair> &res /*! Import an extension defined by a qmldir file. -\a qmldirFilePath is either a raw file path, or a bundle url. +\a qmldirFilePath is a raw file path. */ bool QQmlImportsPrivate::importExtension(const QString &qmldirFilePath, const QString &uri, @@ -1012,17 +1008,11 @@ bool QQmlImportsPrivate::getQmldirContent(const QString &qmldirIdentifier, const Q_ASSERT(errors); Q_ASSERT(qmldir); - *qmldir = typeLoader->qmldirContent(qmldirIdentifier, uri); + *qmldir = typeLoader->qmldirContent(qmldirIdentifier); if (*qmldir) { // Ensure that parsing was successful if ((*qmldir)->hasError()) { - QUrl url; - - if (QQmlFile::isBundle(qmldirIdentifier)) - url = QUrl(qmldirIdentifier); - else - url = QUrl::fromLocalFile(qmldirIdentifier); - + QUrl url = QUrl::fromLocalFile(qmldirIdentifier); const QList<QQmlError> qmldirErrors = (*qmldir)->errors(uri); for (int i = 0; i < qmldirErrors.size(); ++i) { QQmlError error = qmldirErrors.at(i); @@ -1328,30 +1318,7 @@ bool QQmlImportsPrivate::addFileImport(const QString& uri, const QString &prefix QString qmldirIdentifier; - if (QQmlFile::isBundle(qmldirUrl)) { - - QString dir = resolveLocalUrl(base, importUri); - Q_ASSERT(QQmlFile::isBundle(dir)); - if (!QQmlFile::bundleDirectoryExists(dir, typeLoader->engine())) { - if (!isImplicitImport) { - QQmlError error; - error.setDescription(QQmlImportDatabase::tr("\"%1\": no such directory").arg(uri)); - error.setUrl(QUrl(qmldirUrl)); - errors->prepend(error); - } - return false; - } - - // Transforms the (possible relative) uri into our best guess relative to the - // import paths. - importUri = resolvedUri(dir, database); - if (importUri.endsWith(Slash)) - importUri.chop(1); - - if (QQmlFile::bundleFileExists(qmldirUrl, typeLoader->engine())) - qmldirIdentifier = qmldirUrl; - - } else if (QQmlFile::isLocalFile(qmldirUrl)) { + if (QQmlFile::isLocalFile(qmldirUrl)) { QString localFileOrQrc = QQmlFile::urlToLocalFileOrQrc(qmldirUrl); Q_ASSERT(!localFileOrQrc.isEmpty()); @@ -1555,12 +1522,12 @@ bool QQmlImports::locateQmldir(QQmlImportDatabase *importDb, bool QQmlImports::isLocal(const QString &url) { - return QQmlFile::isBundle(url) || !QQmlFile::urlToLocalFileOrQrc(url).isEmpty(); + return !QQmlFile::urlToLocalFileOrQrc(url).isEmpty(); } bool QQmlImports::isLocal(const QUrl &url) { - return QQmlFile::isBundle(url) || !QQmlFile::urlToLocalFileOrQrc(url).isEmpty(); + return !QQmlFile::urlToLocalFileOrQrc(url).isEmpty(); } void QQmlImports::setDesignerSupportRequired(bool b) diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index f64bec935e..fb435a50af 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -1288,7 +1288,7 @@ bool QQmlTypeLoader::Blob::updateQmldir(QQmlQmldirData *data, const QV4::Compile if (!importQualifier.isEmpty()) { // Does this library contain any qualified scripts? QUrl libraryUrl(qmldirUrl); - const QmldirContent *qmldir = typeLoader()->qmldirContent(qmldirIdentifier, qmldirUrl); + const QmldirContent *qmldir = typeLoader()->qmldirContent(qmldirIdentifier); foreach (const QQmlDirParser::Script &script, qmldir->scripts()) { QUrl scriptUrl = libraryUrl.resolved(QUrl(script.fileName)); QQmlScriptBlob *blob = typeLoader()->getScript(scriptUrl); @@ -1335,7 +1335,7 @@ bool QQmlTypeLoader::Blob::addImport(const QV4::CompiledData::Import *import, QL if (!importQualifier.isEmpty()) { // Does this library contain any qualified scripts? QUrl libraryUrl(qmldirUrl); - const QmldirContent *qmldir = typeLoader()->qmldirContent(qmldirFilePath, qmldirUrl); + const QmldirContent *qmldir = typeLoader()->qmldirContent(qmldirFilePath); foreach (const QQmlDirParser::Script &script, qmldir->scripts()) { QUrl scriptUrl = libraryUrl.resolved(QUrl(script.fileName)); QQmlScriptBlob *blob = typeLoader()->getScript(scriptUrl); @@ -1687,82 +1687,15 @@ QQmlQmldirData *QQmlTypeLoader::getQmldir(const QUrl &url) return qmldirData; } +// #### Qt 6: Remove this function, it exists only for binary compatibility. /*! -Returns a QQmlBundleData for \a identifier. -*/ -QQmlBundleData *QQmlTypeLoader::getBundle(const QString &identifier) -{ - return getBundle(QHashedStringRef(identifier)); -} - -QQmlBundleData *QQmlTypeLoader::getBundle(const QHashedStringRef &identifier) -{ - lock(); - - QQmlBundleData *rv = 0; - QQmlBundleData **bundle = m_bundleCache.value(identifier); - if (bundle) { - rv = *bundle; - rv->addref(); - } - - unlock(); - - return rv; -} - -QQmlBundleData::QQmlBundleData(const QString &file) -: QQmlBundle(file), fileName(file) -{ -} - -// XXX check for errors etc. -void QQmlTypeLoader::addBundle(const QString &identifier, const QString &fileName) -{ - lock(); - addBundleNoLock(identifier, fileName); - unlock(); -} - -void QQmlTypeLoader::addBundleNoLock(const QString &identifier, const QString &fileName) -{ - QQmlBundleData *data = new QQmlBundleData(fileName); - if (data->open()) { - - m_bundleCache.insert(identifier, data); - - } else { - data->release(); - } -} - -QString QQmlTypeLoader::bundleIdForQmldir(const QString &name, const QString &uriHint) -{ - lock(); - QString *bundleId = m_qmldirBundleIdCache.value(name); - if (!bundleId) { - QString newBundleId = QLatin1String("qml.") + uriHint.toLower() /* XXX toLower()? */; - if (m_qmldirBundleIdCache.contains(newBundleId)) - newBundleId += QString::number(m_qmldirBundleIdCache.count()); - m_qmldirBundleIdCache.insert(name, newBundleId); - addBundleNoLock(newBundleId, name); - unlock(); - return newBundleId; - } else { - unlock(); - return *bundleId; - } -} - + * \internal + */ bool QQmlEngine::addNamedBundle(const QString &name, const QString &fileName) { - Q_D(QQmlEngine); - - if (name.startsWith(QLatin1String("qml."))) // reserved - return false; - - d->typeLoader.addBundle(name, fileName); - return true; + Q_UNUSED(name) + Q_UNUSED(fileName) + return false; } /*! @@ -1881,20 +1814,20 @@ 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. +\a filePath is 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 &filePathIn, const QString &uriHint) +const QQmlTypeLoader::QmldirContent *QQmlTypeLoader::qmldirContent(const QString &filePathIn) { - QUrl url(filePathIn); //May already contain bundle or http scheme + QUrl url(filePathIn); //May already contain 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)) + else 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")); + Q_ASSERT(url.scheme() == QLatin1String("file")); QString filePath; if (url.scheme() == QLatin1String("file")) filePath = url.toLocalFile(); @@ -1910,45 +1843,14 @@ 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(url.toString())) { - QQmlFile file(engine(), url); - if (file.isError()) { - ERROR(NOT_READABLE_ERROR.arg(url.toString())); - } else { - QString content(QString::fromUtf8(file.data(), file.size())); - qmldir->setContent(filePath, content); - } - + QFile file(filePath); + if (!QQml_isFileCaseCorrect(filePath)) { + ERROR(CASE_MISMATCH_ERROR.arg(filePath)); + } else if (file.open(QFile::ReadOnly)) { + QByteArray data = file.readAll(); + qmldir->setContent(filePath, QString::fromUtf8(data)); } else { - - QFile file(filePath); - if (!QQml_isFileCaseCorrect(filePath)) { - ERROR(CASE_MISMATCH_ERROR.arg(filePath)); - } else if (file.open(QFile::ReadOnly)) { - QByteArray data = file.read(QQmlBundle::bundleHeaderLength()); - - if (QQmlBundle::isBundleHeader(data.constData(), data.length())) { - QString id = bundleIdForQmldir(filePath, uriHint); - - QString bundleUrl = QLatin1String("bundle://") + id + QLatin1Char('/'); - - QUrl url(bundleUrl + QLatin1String("qmldir")); - - QQmlFile file(engine(), url); - if (file.isError()) { - ERROR(NOT_READABLE_ERROR.arg(filePath)); - } else { - QString content(QString::fromUtf8(file.data(), file.size())); - qmldir->setContent(QQmlFile::bundleFileName(bundleUrl, engine()), content); - } - } else { - data += file.readAll(); - qmldir->setContent(filePath, QString::fromUtf8(data)); - } - } else { - ERROR(NOT_READABLE_ERROR.arg(filePath)); - } - + ERROR(NOT_READABLE_ERROR.arg(filePath)); } #undef ERROR @@ -2208,10 +2110,6 @@ bool QQmlTypeData::loadImplicitImport() void QQmlTypeData::dataReceived(const Data &data) { QString code = QString::fromUtf8(data.data(), data.size()); - QByteArray preparseData; - - if (data.isFile()) preparseData = data.asFile()->metaData(QLatin1String("qml:preparse")); - QQmlEngine *qmlEngine = typeLoader()->engine(); m_document.reset(new QmlIR::Document(QV8Engine::getV4(qmlEngine)->debugger != 0)); QmlIR::IRBuilder compiler(QV8Engine::get(qmlEngine)->illegalNames()); diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 02adf09eed..64e3937a74 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -57,7 +57,6 @@ #include <private/qqmlimport_p.h> #include <private/qqmlcleanup_p.h> #include <private/qqmldirparser_p.h> -#include <private/qqmlbundle_p.h> #include <private/qflagpointer_p.h> #include <private/qqmlirbuilder_p.h> @@ -207,14 +206,6 @@ private: class QQmlTypeLoaderThread; -class QQmlBundleData : public QQmlBundle, - public QQmlRefCount -{ -public: - QQmlBundleData(const QString &); - QString fileName; -}; - class Q_AUTOTEST_EXPORT QQmlTypeLoader { Q_DECLARE_TR_FUNCTIONS(QQmlTypeLoader) @@ -294,14 +285,10 @@ public: QQmlScriptBlob *getScript(const QUrl &); QQmlQmldirData *getQmldir(const QUrl &); - QQmlBundleData *getBundle(const QString &); - QQmlBundleData *getBundle(const QHashedStringRef &); - void addBundle(const QString &, const QString &); - QString absoluteFilePath(const QString &path); bool directoryExists(const QString &path); - const QmldirContent *qmldirContent(const QString &filePath, const QString &uriHint); + const QmldirContent *qmldirContent(const QString &filePath); void setQmldirContent(const QString &filePath, const QString &content); void clearCache(); @@ -328,9 +315,6 @@ private: void shutdownThread(); - void addBundleNoLock(const QString &, const QString &); - QString bundleIdForQmldir(const QString &qmldir, const QString &uriHint); - void loadThread(QQmlDataBlob *); void loadWithStaticDataThread(QQmlDataBlob *, const QByteArray &); void loadWithCachedUnitThread(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit); @@ -366,8 +350,6 @@ private: typedef QStringHash<bool> StringSet; typedef QStringHash<StringSet*> ImportDirCache; typedef QStringHash<QmldirContent *> ImportQmlDirCache; - typedef QStringHash<QQmlBundleData *> BundleCache; - typedef QStringHash<QString> QmldirBundleIdCache; QQmlEngine *m_engine; QQmlTypeLoaderThread *m_thread; @@ -377,8 +359,6 @@ private: QmldirCache m_qmldirCache; ImportDirCache m_importDirCache; ImportQmlDirCache m_importQmlDirCache; - BundleCache m_bundleCache; - QmldirBundleIdCache m_qmldirBundleIdCache; }; class Q_AUTOTEST_EXPORT QQmlTypeData : public QQmlTypeLoader::Blob |