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>
38#if defined(Q_OS_ANDROID)
39static char assets_string[] =
"assets";
40static char content_string[] =
"content";
41static char authority_externalstorage[] =
"com.android.externalstorage.documents";
42static char authority_downloads_documents[] =
"com.android.providers.downloads.documents";
43static char authority_media_documents[] =
"com.android.providers.media.documents";
48#if QT_CONFIG(qml_network)
49class QQmlFileNetworkReply :
public QObject
54 ~QQmlFileNetworkReply();
61 void networkFinished();
65 static int finishedIndex;
66 static int downloadProgressIndex;
67 static int networkFinishedIndex;
68 static int networkDownloadProgressIndex;
69 static int replyFinishedIndex;
70 static int replyDownloadProgressIndex;
96#if QT_CONFIG(qml_network)
97 QQmlFileNetworkReply *
reply;
101#if QT_CONFIG(qml_network)
102int QQmlFileNetworkReply::finishedIndex = -1;
103int QQmlFileNetworkReply::downloadProgressIndex = -1;
104int QQmlFileNetworkReply::networkFinishedIndex = -1;
105int QQmlFileNetworkReply::networkDownloadProgressIndex = -1;
106int QQmlFileNetworkReply::replyFinishedIndex = -1;
107int QQmlFileNetworkReply::replyDownloadProgressIndex = -1;
110: m_engine(e), m_p(
p), m_reply(
nullptr)
112 if (finishedIndex == -1) {
116 networkFinishedIndex = smo->
indexOfMethod(
"networkFinished()");
117 networkDownloadProgressIndex = smo->indexOfMethod(
"networkDownloadProgress(qint64,qint64)");
122 Q_ASSERT(finishedIndex != -1 && downloadProgressIndex != -1 &&
123 networkFinishedIndex != -1 && networkDownloadProgressIndex != -1 &&
124 replyFinishedIndex != -1 && replyDownloadProgressIndex != -1);
129 m_reply = m_engine->networkAccessManager()->get(req);
134QQmlFileNetworkReply::~QQmlFileNetworkReply()
137 m_reply->disconnect();
138 m_reply->deleteLater();
142void QQmlFileNetworkReply::networkFinished()
144 if (m_reply->error()) {
145 m_p->errorString = m_reply->errorString();
148 m_p->data = m_reply->readAll();
151 m_reply->deleteLater();
154 m_p->reply =
nullptr;
159void QQmlFileNetworkReply::networkDownloadProgress(
qint64 a,
qint64 b)
161 emit downloadProgress(
a,
b);
205#if QT_CONFIG(qml_network)
263#if QT_CONFIG(qml_network)
339#if QT_CONFIG(qml_network)
340 d->reply =
new QQmlFileNetworkReply(
engine, d,
url);
374#if QT_CONFIG(qml_network)
378 d->reply =
new QQmlFileNetworkReply(
engine, d, qurl);
406#if QT_CONFIG(qml_network)
412bool QQmlFile::connectFinished(
QObject *
object,
const char *
method)
414 if (!d || !d->reply) {
415 qWarning(
"QQmlFile: connectFinished() called when not loading.");
428 if (!d || !d->reply) {
429 qWarning(
"QQmlFile: connectFinished() called when not loading.");
441bool QQmlFile::connectDownloadProgress(
QObject *
object,
const char *
method)
443 if (!d || !d->reply) {
444 qWarning(
"QQmlFile: connectDownloadProgress() called when not loading.");
456bool QQmlFile::connectDownloadProgress(
QObject *
object,
int method)
458 if (!d || !d->reply) {
459 qWarning(
"QQmlFile: connectDownloadProgress() called when not loading.");
486#if defined(Q_OS_ANDROID)
517 return url.size() >= 7 &&
523 return url.size() >= 5 &&
529#if defined(Q_OS_ANDROID)
531 return url.length() >= 8 &&
535 return url.length() >= 9 &&
544#if defined(Q_OS_ANDROID)
545static bool hasLocalContentAuthority(
const QUrl &
url)
576#if defined(Q_OS_ANDROID)
582 return hasLocalContentAuthority(
url);
592 if (urlLength < schemeLength + 1)
608 if (urlLength < schemeLength + 3)
612 if (
url[schemeLength + 1] == slash &&
url[schemeLength + 2] == slash) {
614 if (urlLength < schemeLength + 4 ||
url[schemeLength + 3] != slash)
615 return schemeLength + 3;
621#if defined(Q_OS_ANDROID)
629 return authorityAndPath.startsWith(
QLatin1String(authority_externalstorage))
630 || authorityAndPath.startsWith(
QLatin1String(authority_downloads_documents))
631 || authorityAndPath.startsWith(
QLatin1String(authority_media_documents));
649 switch (
url[0].toLatin1()) {
658 &&
url.size() > fileLength
665#if defined(Q_OS_ANDROID)
668 return hasScheme(
url, assets_string, strlen(assets_string))
672 return hasScheme(
url, content_string, strlen(content_string))
673 && hasLocalContentAuthority(
url, strlen(content_string));
696#if defined(Q_OS_ANDROID)
700 if (hasLocalContentAuthority(
url))
711 if (!
file.isLocalFile())
717 return file.toLocalFile();
723 if (urlLength <
offset + 2)
730 if (urlLength <
offset + 3)
762#if defined(Q_OS_ANDROID)
765 if (
hasScheme(
url, content_string, strlen(content_string)))
766 return hasLocalContentAuthority(
url, strlen(content_string)) ?
url :
QString();
774#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.
QFILE_MAYBE_NODISCARD 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.
static bool isLocalFile(const QString &url)
Returns true if url is a local file that can be opened with \l{QFile}.
static bool isSynchronous(const QString &url)
static QString urlToLocalFileOrQrc(const QString &)
If url is a local file returns a path suitable for passing to \l{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.
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
Returns the number of characters in this string.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qsizetype length() const noexcept
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
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
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 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