6#include <QtCore/qurl.h>
7#include <QtCore/qobject.h>
8#include <QtCore/qmetaobject.h>
9#include <QtCore/qfile.h>
10#include <private/qqmlengine_p.h>
11#include <private/qqmlglobal_p.h>
27#if defined(Q_OS_ANDROID)
28static char assets_string[] =
"assets";
29static char content_string[] =
"content";
30static char authority_externalstorage[] =
"com.android.externalstorage.documents";
31static char authority_downloads_documents[] =
"com.android.providers.downloads.documents";
32static char authority_media_documents[] =
"com.android.providers.media.documents";
37#if QT_CONFIG(qml_network)
38class QQmlFileNetworkReply :
public QObject
43 ~QQmlFileNetworkReply();
50 void networkFinished();
54 static int finishedIndex;
55 static int downloadProgressIndex;
56 static int networkFinishedIndex;
57 static int networkDownloadProgressIndex;
58 static int replyFinishedIndex;
59 static int replyDownloadProgressIndex;
85#if QT_CONFIG(qml_network)
86 QQmlFileNetworkReply *
reply;
90#if QT_CONFIG(qml_network)
91int QQmlFileNetworkReply::finishedIndex = -1;
92int QQmlFileNetworkReply::downloadProgressIndex = -1;
93int QQmlFileNetworkReply::networkFinishedIndex = -1;
94int QQmlFileNetworkReply::networkDownloadProgressIndex = -1;
95int QQmlFileNetworkReply::replyFinishedIndex = -1;
96int QQmlFileNetworkReply::replyDownloadProgressIndex = -1;
101 if (finishedIndex == -1) {
105 networkFinishedIndex = smo->
indexOfMethod(
"networkFinished()");
106 networkDownloadProgressIndex = smo->
indexOfMethod(
"networkDownloadProgress(qint64,qint64)");
111 Q_ASSERT(finishedIndex != -1 && downloadProgressIndex != -1 &&
112 networkFinishedIndex != -1 && networkDownloadProgressIndex != -1 &&
113 replyFinishedIndex != -1 && replyDownloadProgressIndex != -1);
118 m_reply = m_engine->networkAccessManager()->get(req);
123QQmlFileNetworkReply::~QQmlFileNetworkReply()
126 m_reply->disconnect();
127 m_reply->deleteLater();
131void QQmlFileNetworkReply::networkFinished()
133 if (m_reply->error()) {
134 m_p->errorString = m_reply->errorString();
137 m_p->data = m_reply->readAll();
140 m_reply->deleteLater();
143 m_p->reply =
nullptr;
148void QQmlFileNetworkReply::networkDownloadProgress(
qint64 a,
qint64 b)
150 emit downloadProgress(
a,
b);
180#if QT_CONFIG(qml_network)
220#if QT_CONFIG(qml_network)
280#if QT_CONFIG(qml_network)
281 d->reply =
new QQmlFileNetworkReply(
engine, d,
url);
311#if QT_CONFIG(qml_network)
315 d->reply =
new QQmlFileNetworkReply(
engine, d, qurl);
335#if QT_CONFIG(qml_network)
336bool QQmlFile::connectFinished(
QObject *
object,
const char *
method)
338 if (!d || !d->reply) {
339 qWarning(
"QQmlFile: connectFinished() called when not loading.");
349 if (!d || !d->reply) {
350 qWarning(
"QQmlFile: connectFinished() called when not loading.");
358bool QQmlFile::connectDownloadProgress(
QObject *
object,
const char *
method)
360 if (!d || !d->reply) {
361 qWarning(
"QQmlFile: connectDownloadProgress() called when not loading.");
369bool QQmlFile::connectDownloadProgress(
QObject *
object,
int method)
371 if (!d || !d->reply) {
372 qWarning(
"QQmlFile: connectDownloadProgress() called when not loading.");
396#if defined(Q_OS_ANDROID)
424 return url.size() >= 7 &&
430 return url.size() >= 5 &&
436#if defined(Q_OS_ANDROID)
438 return url.length() >= 8 &&
442 return url.length() >= 9 &&
451#if defined(Q_OS_ANDROID)
452static bool hasLocalContentAuthority(
const QUrl &
url)
482#if defined(Q_OS_ANDROID)
488 return hasLocalContentAuthority(
url);
498 if (urlLength < schemeLength + 1)
514 if (urlLength < schemeLength + 3)
518 if (
url[schemeLength + 1] == slash &&
url[schemeLength + 2] == slash) {
520 if (urlLength < schemeLength + 4 ||
url[schemeLength + 3] != slash)
521 return schemeLength + 3;
527#if defined(Q_OS_ANDROID)
554 switch (
url[0].toLatin1()) {
563 &&
url.size() > fileLength
570#if defined(Q_OS_ANDROID)
573 return hasScheme(
url, assets_string, strlen(assets_string))
577 return hasScheme(
url, content_string, strlen(content_string))
578 && hasLocalContentAuthority(
url, strlen(content_string));
599#if defined(Q_OS_ANDROID)
603 if (hasLocalContentAuthority(
url))
614 if (!
file.isLocalFile())
620 return file.toLocalFile();
626 if (urlLength <
offset + 2)
633 if (urlLength <
offset + 3)
663#if defined(Q_OS_ANDROID)
666 if (
hasScheme(
url, content_string, strlen(content_string)))
667 return hasLocalContentAuthority(
url, strlen(content_string)) ?
url :
QString();
675#include "qqmlfile.moc"
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
This signal is emitted to indicate the progress of the download part of this network request,...
void finished()
This signal is emitted when the reply has finished processing.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
@ HttpPipeliningAllowedAttribute
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
The QQmlEngine class provides an environment for instantiating QML components.
The QQmlFile class gives access to local and remote files.
static bool isLocalFile(const QString &url)
Returns true if url is a local file that can be opened with QFile.
static bool isSynchronous(const QString &url)
Returns true if QQmlFile will open url synchronously.
static QString urlToLocalFileOrQrc(const QString &)
If url is a local file returns a path suitable for passing to QFile.
const char * data() const
QByteArray dataByteArray() const
void load(QQmlEngine *, const QUrl &)
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
qsizetype size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qsizetype length() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
QString authority(ComponentFormattingOptions options=PrettyDecoded) const
Returns the authority of the URL if it is defined; otherwise an empty string is returned.
QString scheme() const
Returns the scheme of the URL.
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr offset
bool QQml_isFileCaseCorrect(const QString &fileName, int lengthIn)
Returns true if the case of fileName is equivalent to the file case of fileName on disk,...
static QT_BEGIN_NAMESPACE char qrc_string[]
static QString toLocalFile(const QString &url)
static bool isDoubleSlashed(const QString &url, qsizetype offset)
static char file_string[]
static qsizetype authorityOffset(const QString &url, qsizetype schemeLength)
static bool hasScheme(const QString &url, const char *scheme, qsizetype schemeLength)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
#define QT_CONFIG(feature)
if(qFloatDistance(a, b)<(1<< 7))
[0]
QUrl url("example.com")
[constructor-url-reference]
\inmodule QtCore \reentrant