aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlfile.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>2013-04-04 16:17:35 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-05 12:28:25 +0200
commit6eed3409c4ecf69d3c43cdcbeeca829624b9fe25 (patch)
treee342ac85f4bd6267a1618f2f6fff44fe381ee03c /src/qml/qml/qqmlfile.cpp
parente5d9cb4f3534e2d2fe6d28867b71c87ccb1438db (diff)
Android: Support implicit import paths for assets:/ urls
The assets: scheme is not handled by QNetworkAccessManager, so it needs to be special cased along side the qrc: scheme. We make QML recognize it as a synchronously loaded, local file, and we make the type loader get the correct path and check existence of the directory correctly. This makes it possible to implicitly import the containing directory of QML files that are bundled in the assets directory. Task-number: QTBUG-30510 Change-Id: I048292757e509066a4af342081ec8428e2bd8af3 Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlfile.cpp')
-rw-r--r--src/qml/qml/qqmlfile.cpp66
1 files changed, 62 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlfile.cpp b/src/qml/qml/qqmlfile.cpp
index 836f68da28..4e76fbd2e5 100644
--- a/src/qml/qml/qqmlfile.cpp
+++ b/src/qml/qml/qqmlfile.cpp
@@ -64,6 +64,10 @@ static QString qrc_string(QLatin1String("qrc"));
static QString file_string(QLatin1String("file"));
static QString bundle_string(QLatin1String("bundle"));
+#if defined(Q_OS_ANDROID)
+static QString assets_string(QLatin1String("assets"));
+#endif
+
class QQmlFilePrivate;
class QQmlFileNetworkReply : public QObject
{
@@ -484,6 +488,8 @@ 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.
+
+\note On Android, urls with assets:/ scheme are also considered synchronous.
*/
bool QQmlFile::isSynchronous(const QUrl &url)
{
@@ -491,16 +497,25 @@ bool QQmlFile::isSynchronous(const QUrl &url)
if ((scheme.length() == 4 && 0 == scheme.compare(file_string, Qt::CaseInsensitive)) ||
(scheme.length() == 6 && 0 == scheme.compare(bundle_string, Qt::CaseInsensitive)) ||
- (scheme.length() == 3 && 0 == scheme.compare(qrc_string, Qt::CaseInsensitive)))
+ (scheme.length() == 3 && 0 == scheme.compare(qrc_string, Qt::CaseInsensitive))) {
return true;
- else
+
+#if defined(Q_OS_ANDROID)
+ } else if (scheme.length() == 6 && 0 == scheme.compare(assets_string, Qt::CaseInsensitive)) {
+ return true;
+#endif
+
+ } else {
return false;
+ }
}
/*!
Returns true if QQmlFile will open \a url synchronously.
Synchronous urls have a qrc:/, file://, or bundle:// scheme.
+
+\note On Android, urls with assets:/ scheme are also considered synchronous.
*/
bool QQmlFile::isSynchronous(const QString &url)
{
@@ -529,6 +544,15 @@ bool QQmlFile::isSynchronous(const QString &url)
}
+#if defined(Q_OS_ANDROID)
+ else if (f == QLatin1Char('a') || f == QLatin1Char('A')) {
+ return url.length() >= 8 /* assets:/ */ &&
+ url.startsWith(assets_string, Qt::CaseInsensitive) &&
+ url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/');
+
+ }
+#endif
+
return false;
}
@@ -559,22 +583,33 @@ bool QQmlFile::isBundle(const QUrl &url)
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.
+
+\note On Android, urls with assets:/ scheme are also considered local files.
*/
bool QQmlFile::isLocalFile(const QUrl &url)
{
QString scheme = url.scheme();
if ((scheme.length() == 4 && 0 == scheme.compare(file_string, Qt::CaseInsensitive)) ||
- (scheme.length() == 3 && 0 == scheme.compare(qrc_string, Qt::CaseInsensitive)))
+ (scheme.length() == 3 && 0 == scheme.compare(qrc_string, Qt::CaseInsensitive))) {
return true;
- else
+
+#if defined(Q_OS_ANDROID)
+ } else if (scheme.length() == 6 && 0 == scheme.compare(assets_string, Qt::CaseInsensitive)) {
+ return true;
+#endif
+
+ } else {
return false;
+ }
}
/*!
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.
+
+\note On Android, urls with assets:/ scheme are also considered local files.
*/
bool QQmlFile::isLocalFile(const QString &url)
{
@@ -596,6 +631,14 @@ bool QQmlFile::isLocalFile(const QString &url)
url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/');
}
+#if defined(Q_OS_ANDROID)
+ else if (f == QLatin1Char('a') || f == QLatin1Char('A')) {
+ return url.length() >= 8 /* assets:/ */ &&
+ url.startsWith(assets_string, Qt::CaseInsensitive) &&
+ url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/');
+
+ }
+#endif
return false;
}
@@ -611,6 +654,15 @@ QString QQmlFile::urlToLocalFileOrQrc(const QUrl& url)
return QLatin1Char(':') + url.path();
return QString();
}
+
+#if defined(Q_OS_ANDROID)
+ else if (url.scheme().compare(QLatin1String("assets"), Qt::CaseInsensitive) == 0) {
+ if (url.authority().isEmpty())
+ return url.toString();
+ return QString();
+ }
+#endif
+
return url.toLocalFile();
}
@@ -642,6 +694,12 @@ QString QQmlFile::urlToLocalFileOrQrc(const QString& url)
return QString();
}
+#if defined(Q_OS_ANDROID)
+ else if (url.startsWith(QLatin1String("assets:"), Qt::CaseInsensitive)) {
+ return url;
+ }
+#endif
+
return toLocalFile(url);
}