Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlfile.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qqmlfile.h" | - | ||||||||||||
41 | - | |||||||||||||
42 | #include <QtCore/qurl.h> | - | ||||||||||||
43 | #include <QtCore/qobject.h> | - | ||||||||||||
44 | #include <QtCore/qmetaobject.h> | - | ||||||||||||
45 | #include <QtCore/qfile.h> | - | ||||||||||||
46 | #include <private/qqmlengine_p.h> | - | ||||||||||||
47 | #include <private/qqmlglobal_p.h> | - | ||||||||||||
48 | - | |||||||||||||
49 | /*! | - | ||||||||||||
50 | \class QQmlFile | - | ||||||||||||
51 | \brief The QQmlFile class gives access to local and remote files. | - | ||||||||||||
52 | - | |||||||||||||
53 | \internal | - | ||||||||||||
54 | - | |||||||||||||
55 | Supports file:// and qrc:/ uris and whatever QNetworkAccessManager supports. | - | ||||||||||||
56 | */ | - | ||||||||||||
57 | - | |||||||||||||
58 | #define QQMLFILE_MAX_REDIRECT_RECURSION 16 | - | ||||||||||||
59 | - | |||||||||||||
60 | QT_BEGIN_NAMESPACE | - | ||||||||||||
61 | - | |||||||||||||
62 | static char qrc_string[] = "qrc"; | - | ||||||||||||
63 | static char file_string[] = "file"; | - | ||||||||||||
64 | - | |||||||||||||
65 | #if defined(Q_OS_ANDROID) | - | ||||||||||||
66 | static char assets_string[] = "assets"; | - | ||||||||||||
67 | #endif | - | ||||||||||||
68 | - | |||||||||||||
69 | class QQmlFilePrivate; | - | ||||||||||||
70 | - | |||||||||||||
71 | #if QT_CONFIG(qml_network) | - | ||||||||||||
72 | class QQmlFileNetworkReply : public QObject | - | ||||||||||||
73 | { | - | ||||||||||||
74 | Q_OBJECT | - | ||||||||||||
75 | public: | - | ||||||||||||
76 | QQmlFileNetworkReply(QQmlEngine *, QQmlFilePrivate *, const QUrl &); | - | ||||||||||||
77 | ~QQmlFileNetworkReply(); | - | ||||||||||||
78 | - | |||||||||||||
79 | signals: | - | ||||||||||||
80 | void finished(); | - | ||||||||||||
81 | void downloadProgress(qint64, qint64); | - | ||||||||||||
82 | - | |||||||||||||
83 | public slots: | - | ||||||||||||
84 | void networkFinished(); | - | ||||||||||||
85 | void networkDownloadProgress(qint64, qint64); | - | ||||||||||||
86 | - | |||||||||||||
87 | public: | - | ||||||||||||
88 | static int finishedIndex; | - | ||||||||||||
89 | static int downloadProgressIndex; | - | ||||||||||||
90 | static int networkFinishedIndex; | - | ||||||||||||
91 | static int networkDownloadProgressIndex; | - | ||||||||||||
92 | static int replyFinishedIndex; | - | ||||||||||||
93 | static int replyDownloadProgressIndex; | - | ||||||||||||
94 | - | |||||||||||||
95 | private: | - | ||||||||||||
96 | QQmlEngine *m_engine; | - | ||||||||||||
97 | QQmlFilePrivate *m_p; | - | ||||||||||||
98 | - | |||||||||||||
99 | int m_redirectCount; | - | ||||||||||||
100 | QNetworkReply *m_reply; | - | ||||||||||||
101 | }; | - | ||||||||||||
102 | #endif | - | ||||||||||||
103 | - | |||||||||||||
104 | class QQmlFilePrivate | - | ||||||||||||
105 | { | - | ||||||||||||
106 | public: | - | ||||||||||||
107 | QQmlFilePrivate(); | - | ||||||||||||
108 | - | |||||||||||||
109 | mutable QUrl url; | - | ||||||||||||
110 | mutable QString urlString; | - | ||||||||||||
111 | - | |||||||||||||
112 | QByteArray data; | - | ||||||||||||
113 | - | |||||||||||||
114 | enum Error { | - | ||||||||||||
115 | None, NotFound, CaseMismatch, Network | - | ||||||||||||
116 | }; | - | ||||||||||||
117 | - | |||||||||||||
118 | Error error; | - | ||||||||||||
119 | QString errorString; | - | ||||||||||||
120 | #if QT_CONFIG(qml_network) | - | ||||||||||||
121 | QQmlFileNetworkReply *reply; | - | ||||||||||||
122 | #endif | - | ||||||||||||
123 | }; | - | ||||||||||||
124 | - | |||||||||||||
125 | #if QT_CONFIG(qml_network) | - | ||||||||||||
126 | int QQmlFileNetworkReply::finishedIndex = -1; | - | ||||||||||||
127 | int QQmlFileNetworkReply::downloadProgressIndex = -1; | - | ||||||||||||
128 | int QQmlFileNetworkReply::networkFinishedIndex = -1; | - | ||||||||||||
129 | int QQmlFileNetworkReply::networkDownloadProgressIndex = -1; | - | ||||||||||||
130 | int QQmlFileNetworkReply::replyFinishedIndex = -1; | - | ||||||||||||
131 | int QQmlFileNetworkReply::replyDownloadProgressIndex = -1; | - | ||||||||||||
132 | - | |||||||||||||
133 | QQmlFileNetworkReply::QQmlFileNetworkReply(QQmlEngine *e, QQmlFilePrivate *p, const QUrl &url) | - | ||||||||||||
134 | : m_engine(e), m_p(p), m_redirectCount(0), m_reply(nullptr) | - | ||||||||||||
135 | { | - | ||||||||||||
136 | if (finishedIndex == -1) {
| 0 | ||||||||||||
137 | finishedIndex = QMetaMethod::fromSignal(&QQmlFileNetworkReply::finished).methodIndex(); | - | ||||||||||||
138 | downloadProgressIndex = QMetaMethod::fromSignal(&QQmlFileNetworkReply::downloadProgress).methodIndex(); | - | ||||||||||||
139 | const QMetaObject *smo = &staticMetaObject; | - | ||||||||||||
140 | networkFinishedIndex = smo->indexOfMethod("networkFinished()"); | - | ||||||||||||
141 | networkDownloadProgressIndex = smo->indexOfMethod("networkDownloadProgress(qint64,qint64)"); | - | ||||||||||||
142 | - | |||||||||||||
143 | replyFinishedIndex = QMetaMethod::fromSignal(&QNetworkReply::finished).methodIndex(); | - | ||||||||||||
144 | replyDownloadProgressIndex = QMetaMethod::fromSignal(&QNetworkReply::downloadProgress).methodIndex(); | - | ||||||||||||
145 | } never executed: end of block | 0 | ||||||||||||
146 | Q_ASSERT(finishedIndex != -1 && downloadProgressIndex != -1 && | - | ||||||||||||
147 | networkFinishedIndex != -1 && networkDownloadProgressIndex != -1 && | - | ||||||||||||
148 | replyFinishedIndex != -1 && replyDownloadProgressIndex != -1); | - | ||||||||||||
149 | - | |||||||||||||
150 | QNetworkRequest req(url); | - | ||||||||||||
151 | req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); | - | ||||||||||||
152 | - | |||||||||||||
153 | m_reply = m_engine->networkAccessManager()->get(req); | - | ||||||||||||
154 | QMetaObject::connect(m_reply, replyFinishedIndex, this, networkFinishedIndex); | - | ||||||||||||
155 | QMetaObject::connect(m_reply, replyDownloadProgressIndex, this, networkDownloadProgressIndex); | - | ||||||||||||
156 | } never executed: end of block | 0 | ||||||||||||
157 | - | |||||||||||||
158 | QQmlFileNetworkReply::~QQmlFileNetworkReply() | - | ||||||||||||
159 | { | - | ||||||||||||
160 | if (m_reply) {
| 0 | ||||||||||||
161 | m_reply->disconnect(); | - | ||||||||||||
162 | m_reply->deleteLater(); | - | ||||||||||||
163 | } never executed: end of block | 0 | ||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||
165 | - | |||||||||||||
166 | void QQmlFileNetworkReply::networkFinished() | - | ||||||||||||
167 | { | - | ||||||||||||
168 | ++m_redirectCount; | - | ||||||||||||
169 | if (m_redirectCount < QQMLFILE_MAX_REDIRECT_RECURSION) {
| 0 | ||||||||||||
170 | QVariant redirect = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||||||||
171 | if (redirect.isValid()) {
| 0 | ||||||||||||
172 | QUrl url = m_reply->url().resolved(redirect.toUrl()); | - | ||||||||||||
173 | - | |||||||||||||
174 | QNetworkRequest req(url); | - | ||||||||||||
175 | req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); | - | ||||||||||||
176 | - | |||||||||||||
177 | m_reply->deleteLater(); | - | ||||||||||||
178 | m_reply = m_engine->networkAccessManager()->get(req); | - | ||||||||||||
179 | - | |||||||||||||
180 | QMetaObject::connect(m_reply, replyFinishedIndex, | - | ||||||||||||
181 | this, networkFinishedIndex); | - | ||||||||||||
182 | QMetaObject::connect(m_reply, replyDownloadProgressIndex, | - | ||||||||||||
183 | this, networkDownloadProgressIndex); | - | ||||||||||||
184 | - | |||||||||||||
185 | return; never executed: return; | 0 | ||||||||||||
186 | } | - | ||||||||||||
187 | } never executed: end of block | 0 | ||||||||||||
188 | - | |||||||||||||
189 | if (m_reply->error()) {
| 0 | ||||||||||||
190 | m_p->errorString = m_reply->errorString(); | - | ||||||||||||
191 | m_p->error = QQmlFilePrivate::Network; | - | ||||||||||||
192 | } else { never executed: end of block | 0 | ||||||||||||
193 | m_p->data = m_reply->readAll(); | - | ||||||||||||
194 | } never executed: end of block | 0 | ||||||||||||
195 | - | |||||||||||||
196 | m_reply->deleteLater(); | - | ||||||||||||
197 | m_reply = nullptr; | - | ||||||||||||
198 | - | |||||||||||||
199 | m_p->reply = nullptr; | - | ||||||||||||
200 | emit finished(); | - | ||||||||||||
201 | delete this; | - | ||||||||||||
202 | } never executed: end of block | 0 | ||||||||||||
203 | - | |||||||||||||
204 | void QQmlFileNetworkReply::networkDownloadProgress(qint64 a, qint64 b) | - | ||||||||||||
205 | { | - | ||||||||||||
206 | emit downloadProgress(a, b); | - | ||||||||||||
207 | } never executed: end of block | 0 | ||||||||||||
208 | #endif // qml_network | - | ||||||||||||
209 | - | |||||||||||||
210 | QQmlFilePrivate::QQmlFilePrivate() | - | ||||||||||||
211 | : error(None) | - | ||||||||||||
212 | #if QT_CONFIG(qml_network) | - | ||||||||||||
213 | , reply(nullptr) | - | ||||||||||||
214 | #endif | - | ||||||||||||
215 | { | - | ||||||||||||
216 | } never executed: end of block | 0 | ||||||||||||
217 | - | |||||||||||||
218 | QQmlFile::QQmlFile() | - | ||||||||||||
219 | : d(new QQmlFilePrivate) | - | ||||||||||||
220 | { | - | ||||||||||||
221 | } never executed: end of block | 0 | ||||||||||||
222 | - | |||||||||||||
223 | QQmlFile::QQmlFile(QQmlEngine *e, const QUrl &url) | - | ||||||||||||
224 | : d(new QQmlFilePrivate) | - | ||||||||||||
225 | { | - | ||||||||||||
226 | load(e, url); | - | ||||||||||||
227 | } never executed: end of block | 0 | ||||||||||||
228 | - | |||||||||||||
229 | QQmlFile::QQmlFile(QQmlEngine *e, const QString &url) | - | ||||||||||||
230 | : QQmlFile(e, QUrl(url)) | - | ||||||||||||
231 | { | - | ||||||||||||
232 | } never executed: end of block | 0 | ||||||||||||
233 | - | |||||||||||||
234 | QQmlFile::~QQmlFile() | - | ||||||||||||
235 | { | - | ||||||||||||
236 | #if QT_CONFIG(qml_network) | - | ||||||||||||
237 | delete d->reply; | - | ||||||||||||
238 | #endif | - | ||||||||||||
239 | delete d; | - | ||||||||||||
240 | d = nullptr; | - | ||||||||||||
241 | } never executed: end of block | 0 | ||||||||||||
242 | - | |||||||||||||
243 | bool QQmlFile::isNull() const | - | ||||||||||||
244 | { | - | ||||||||||||
245 | return status() == Null; never executed: return status() == Null; | 0 | ||||||||||||
246 | } | - | ||||||||||||
247 | - | |||||||||||||
248 | bool QQmlFile::isReady() const | - | ||||||||||||
249 | { | - | ||||||||||||
250 | return status() == Ready; never executed: return status() == Ready; | 0 | ||||||||||||
251 | } | - | ||||||||||||
252 | - | |||||||||||||
253 | bool QQmlFile::isError() const | - | ||||||||||||
254 | { | - | ||||||||||||
255 | return status() == Error; never executed: return status() == Error; | 0 | ||||||||||||
256 | } | - | ||||||||||||
257 | - | |||||||||||||
258 | bool QQmlFile::isLoading() const | - | ||||||||||||
259 | { | - | ||||||||||||
260 | return status() == Loading; never executed: return status() == Loading; | 0 | ||||||||||||
261 | } | - | ||||||||||||
262 | - | |||||||||||||
263 | QUrl QQmlFile::url() const | - | ||||||||||||
264 | { | - | ||||||||||||
265 | if (!d->urlString.isEmpty()) {
| 0 | ||||||||||||
266 | d->url = QUrl(d->urlString); | - | ||||||||||||
267 | d->urlString = QString(); | - | ||||||||||||
268 | } never executed: end of block | 0 | ||||||||||||
269 | return d->url; never executed: return d->url; | 0 | ||||||||||||
270 | } | - | ||||||||||||
271 | - | |||||||||||||
272 | QQmlFile::Status QQmlFile::status() const | - | ||||||||||||
273 | { | - | ||||||||||||
274 | if (d->url.isEmpty() && d->urlString.isEmpty())
| 0 | ||||||||||||
275 | return Null; never executed: return Null; | 0 | ||||||||||||
276 | #if QT_CONFIG(qml_network) | - | ||||||||||||
277 | else if (d->reply)
| 0 | ||||||||||||
278 | return Loading; never executed: return Loading; | 0 | ||||||||||||
279 | #endif | - | ||||||||||||
280 | else if (d->error != QQmlFilePrivate::None)
| 0 | ||||||||||||
281 | return Error; never executed: return Error; | 0 | ||||||||||||
282 | else | - | ||||||||||||
283 | return Ready; never executed: return Ready; | 0 | ||||||||||||
284 | } | - | ||||||||||||
285 | - | |||||||||||||
286 | QString QQmlFile::error() const | - | ||||||||||||
287 | { | - | ||||||||||||
288 | switch (d->error) { | - | ||||||||||||
289 | default: never executed: default: | 0 | ||||||||||||
290 | case QQmlFilePrivate::None: never executed: case QQmlFilePrivate::None: | 0 | ||||||||||||
291 | return QString(); never executed: return QString(); | 0 | ||||||||||||
292 | case QQmlFilePrivate::NotFound: never executed: case QQmlFilePrivate::NotFound: | 0 | ||||||||||||
293 | return QLatin1String("File not found"); never executed: return QLatin1String("File not found"); | 0 | ||||||||||||
294 | case QQmlFilePrivate::CaseMismatch: never executed: case QQmlFilePrivate::CaseMismatch: | 0 | ||||||||||||
295 | return QLatin1String("File name case mismatch"); never executed: return QLatin1String("File name case mismatch"); | 0 | ||||||||||||
296 | } | - | ||||||||||||
297 | } | - | ||||||||||||
298 | - | |||||||||||||
299 | qint64 QQmlFile::size() const | - | ||||||||||||
300 | { | - | ||||||||||||
301 | return d->data.size(); never executed: return d->data.size(); | 0 | ||||||||||||
302 | } | - | ||||||||||||
303 | - | |||||||||||||
304 | const char *QQmlFile::data() const | - | ||||||||||||
305 | { | - | ||||||||||||
306 | return d->data.constData(); never executed: return d->data.constData(); | 0 | ||||||||||||
307 | } | - | ||||||||||||
308 | - | |||||||||||||
309 | QByteArray QQmlFile::dataByteArray() const | - | ||||||||||||
310 | { | - | ||||||||||||
311 | return d->data; never executed: return d->data; | 0 | ||||||||||||
312 | } | - | ||||||||||||
313 | - | |||||||||||||
314 | void QQmlFile::load(QQmlEngine *engine, const QUrl &url) | - | ||||||||||||
315 | { | - | ||||||||||||
316 | Q_ASSERT(engine); | - | ||||||||||||
317 | - | |||||||||||||
318 | clear(); | - | ||||||||||||
319 | d->url = url; | - | ||||||||||||
320 | - | |||||||||||||
321 | if (isLocalFile(url)) {
| 0 | ||||||||||||
322 | QString lf = urlToLocalFileOrQrc(url); | - | ||||||||||||
323 | - | |||||||||||||
324 | if (!QQml_isFileCaseCorrect(lf)) {
| 0 | ||||||||||||
325 | d->error = QQmlFilePrivate::CaseMismatch; | - | ||||||||||||
326 | return; never executed: return; | 0 | ||||||||||||
327 | } | - | ||||||||||||
328 | - | |||||||||||||
329 | QFile file(lf); | - | ||||||||||||
330 | if (file.open(QFile::ReadOnly)) {
| 0 | ||||||||||||
331 | d->data = file.readAll(); | - | ||||||||||||
332 | } else { never executed: end of block | 0 | ||||||||||||
333 | d->error = QQmlFilePrivate::NotFound; | - | ||||||||||||
334 | } never executed: end of block | 0 | ||||||||||||
335 | } else { | - | ||||||||||||
336 | #if QT_CONFIG(qml_network) | - | ||||||||||||
337 | d->reply = new QQmlFileNetworkReply(engine, d, url); | - | ||||||||||||
338 | #else | - | ||||||||||||
339 | d->error = QQmlFilePrivate::NotFound; | - | ||||||||||||
340 | #endif | - | ||||||||||||
341 | } never executed: end of block | 0 | ||||||||||||
342 | } | - | ||||||||||||
343 | - | |||||||||||||
344 | void QQmlFile::load(QQmlEngine *engine, const QString &url) | - | ||||||||||||
345 | { | - | ||||||||||||
346 | Q_ASSERT(engine); | - | ||||||||||||
347 | - | |||||||||||||
348 | clear(); | - | ||||||||||||
349 | - | |||||||||||||
350 | d->urlString = url; | - | ||||||||||||
351 | - | |||||||||||||
352 | if (isLocalFile(url)) {
| 0 | ||||||||||||
353 | QString lf = urlToLocalFileOrQrc(url); | - | ||||||||||||
354 | - | |||||||||||||
355 | if (!QQml_isFileCaseCorrect(lf)) {
| 0 | ||||||||||||
356 | d->error = QQmlFilePrivate::CaseMismatch; | - | ||||||||||||
357 | return; never executed: return; | 0 | ||||||||||||
358 | } | - | ||||||||||||
359 | - | |||||||||||||
360 | QFile file(lf); | - | ||||||||||||
361 | if (file.open(QFile::ReadOnly)) {
| 0 | ||||||||||||
362 | d->data = file.readAll(); | - | ||||||||||||
363 | } else { never executed: end of block | 0 | ||||||||||||
364 | d->error = QQmlFilePrivate::NotFound; | - | ||||||||||||
365 | } never executed: end of block | 0 | ||||||||||||
366 | } else { | - | ||||||||||||
367 | #if QT_CONFIG(qml_network) | - | ||||||||||||
368 | QUrl qurl(url); | - | ||||||||||||
369 | d->url = qurl; | - | ||||||||||||
370 | d->urlString = QString(); | - | ||||||||||||
371 | d->reply = new QQmlFileNetworkReply(engine, d, qurl); | - | ||||||||||||
372 | #else | - | ||||||||||||
373 | d->error = QQmlFilePrivate::NotFound; | - | ||||||||||||
374 | #endif | - | ||||||||||||
375 | } never executed: end of block | 0 | ||||||||||||
376 | } | - | ||||||||||||
377 | - | |||||||||||||
378 | void QQmlFile::clear() | - | ||||||||||||
379 | { | - | ||||||||||||
380 | d->url = QUrl(); | - | ||||||||||||
381 | d->urlString = QString(); | - | ||||||||||||
382 | d->data = QByteArray(); | - | ||||||||||||
383 | d->error = QQmlFilePrivate::None; | - | ||||||||||||
384 | } never executed: end of block | 0 | ||||||||||||
385 | - | |||||||||||||
386 | void QQmlFile::clear(QObject *) | - | ||||||||||||
387 | { | - | ||||||||||||
388 | clear(); | - | ||||||||||||
389 | } never executed: end of block | 0 | ||||||||||||
390 | - | |||||||||||||
391 | #if QT_CONFIG(qml_network) | - | ||||||||||||
392 | bool QQmlFile::connectFinished(QObject *object, const char *method) | - | ||||||||||||
393 | { | - | ||||||||||||
394 | if (!d || !d->reply) {
| 0 | ||||||||||||
395 | qWarning("QQmlFile: connectFinished() called when not loading."); | - | ||||||||||||
396 | return false; never executed: return false; | 0 | ||||||||||||
397 | } | - | ||||||||||||
398 | - | |||||||||||||
399 | return QObject::connect(d->reply, SIGNAL(finished()), never executed: return QObject::connect(d->reply, qFlagLocation("2""finished()" "\0" __FILE__ ":" "399"), object, method); | 0 | ||||||||||||
400 | object, method); never executed: return QObject::connect(d->reply, qFlagLocation("2""finished()" "\0" __FILE__ ":" "399"), object, method); | 0 | ||||||||||||
401 | } | - | ||||||||||||
402 | - | |||||||||||||
403 | bool QQmlFile::connectFinished(QObject *object, int method) | - | ||||||||||||
404 | { | - | ||||||||||||
405 | if (!d || !d->reply) {
| 0 | ||||||||||||
406 | qWarning("QQmlFile: connectFinished() called when not loading."); | - | ||||||||||||
407 | return false; never executed: return false; | 0 | ||||||||||||
408 | } | - | ||||||||||||
409 | - | |||||||||||||
410 | return QMetaObject::connect(d->reply, QQmlFileNetworkReply::finishedIndex, never executed: return QMetaObject::connect(d->reply, QQmlFileNetworkReply::finishedIndex, object, method); | 0 | ||||||||||||
411 | object, method); never executed: return QMetaObject::connect(d->reply, QQmlFileNetworkReply::finishedIndex, object, method); | 0 | ||||||||||||
412 | } | - | ||||||||||||
413 | - | |||||||||||||
414 | bool QQmlFile::connectDownloadProgress(QObject *object, const char *method) | - | ||||||||||||
415 | { | - | ||||||||||||
416 | if (!d || !d->reply) {
| 0 | ||||||||||||
417 | qWarning("QQmlFile: connectDownloadProgress() called when not loading."); | - | ||||||||||||
418 | return false; never executed: return false; | 0 | ||||||||||||
419 | } | - | ||||||||||||
420 | - | |||||||||||||
421 | return QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), never executed: return QObject::connect(d->reply, qFlagLocation("2""downloadProgress(qint64,qint64)" "\0" __FILE__ ":" "421"), object, method); | 0 | ||||||||||||
422 | object, method); never executed: return QObject::connect(d->reply, qFlagLocation("2""downloadProgress(qint64,qint64)" "\0" __FILE__ ":" "421"), object, method); | 0 | ||||||||||||
423 | } | - | ||||||||||||
424 | - | |||||||||||||
425 | bool QQmlFile::connectDownloadProgress(QObject *object, int method) | - | ||||||||||||
426 | { | - | ||||||||||||
427 | if (!d || !d->reply) {
| 0 | ||||||||||||
428 | qWarning("QQmlFile: connectDownloadProgress() called when not loading."); | - | ||||||||||||
429 | return false; never executed: return false; | 0 | ||||||||||||
430 | } | - | ||||||||||||
431 | - | |||||||||||||
432 | return QMetaObject::connect(d->reply, QQmlFileNetworkReply::downloadProgressIndex, never executed: return QMetaObject::connect(d->reply, QQmlFileNetworkReply::downloadProgressIndex, object, method); | 0 | ||||||||||||
433 | object, method); never executed: return QMetaObject::connect(d->reply, QQmlFileNetworkReply::downloadProgressIndex, object, method); | 0 | ||||||||||||
434 | } | - | ||||||||||||
435 | #endif | - | ||||||||||||
436 | - | |||||||||||||
437 | /*! | - | ||||||||||||
438 | Returns true if QQmlFile will open \a url synchronously. | - | ||||||||||||
439 | - | |||||||||||||
440 | Synchronous urls have a qrc:/ or file:// scheme. | - | ||||||||||||
441 | - | |||||||||||||
442 | \note On Android, urls with assets:/ scheme are also considered synchronous. | - | ||||||||||||
443 | */ | - | ||||||||||||
444 | bool QQmlFile::isSynchronous(const QUrl &url) | - | ||||||||||||
445 | { | - | ||||||||||||
446 | QString scheme = url.scheme(); | - | ||||||||||||
447 | - | |||||||||||||
448 | if ((scheme.length() == 4 && 0 == scheme.compare(QLatin1String(file_string), Qt::CaseInsensitive)) ||
| 108-14548 | ||||||||||||
449 | (scheme.length() == 3 && 0 == scheme.compare(QLatin1String(qrc_string), Qt::CaseInsensitive))) {
| 0-192 | ||||||||||||
450 | return true; executed 14484 times by 127 tests: return true; Executed by:
| 14484 | ||||||||||||
451 | - | |||||||||||||
452 | #if defined(Q_OS_ANDROID) | - | ||||||||||||
453 | } else if (scheme.length() == 6 && 0 == scheme.compare(QLatin1String(assets_string), Qt::CaseInsensitive)) { | - | ||||||||||||
454 | return true; | - | ||||||||||||
455 | #endif | - | ||||||||||||
456 | - | |||||||||||||
457 | } else { | - | ||||||||||||
458 | return false; executed 192 times by 9 tests: return false; Executed by:
| 192 | ||||||||||||
459 | } | - | ||||||||||||
460 | } | - | ||||||||||||
461 | - | |||||||||||||
462 | /*! | - | ||||||||||||
463 | Returns true if QQmlFile will open \a url synchronously. | - | ||||||||||||
464 | - | |||||||||||||
465 | Synchronous urls have a qrc:/ or file:// scheme. | - | ||||||||||||
466 | - | |||||||||||||
467 | \note On Android, urls with assets:/ scheme are also considered synchronous. | - | ||||||||||||
468 | */ | - | ||||||||||||
469 | bool QQmlFile::isSynchronous(const QString &url) | - | ||||||||||||
470 | { | - | ||||||||||||
471 | if (url.length() < 5 /* qrc:/ */)
| 0 | ||||||||||||
472 | return false; never executed: return false; | 0 | ||||||||||||
473 | - | |||||||||||||
474 | QChar f = url[0]; | - | ||||||||||||
475 | - | |||||||||||||
476 | if (f == QLatin1Char('f') || f == QLatin1Char('F')) {
| 0 | ||||||||||||
477 | - | |||||||||||||
478 | return url.length() >= 7 /* file:// */ && never executed: return url.length() >= 7 && url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); | 0 | ||||||||||||
479 | url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && never executed: return url.length() >= 7 && url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); | 0 | ||||||||||||
480 | url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); never executed: return url.length() >= 7 && url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); | 0 | ||||||||||||
481 | - | |||||||||||||
482 | } else if (f == QLatin1Char('q') || f == QLatin1Char('Q')) {
| 0 | ||||||||||||
483 | - | |||||||||||||
484 | return url.length() >= 5 /* qrc:/ */ && never executed: return url.length() >= 5 && url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); | 0 | ||||||||||||
485 | url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && never executed: return url.length() >= 5 && url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); | 0 | ||||||||||||
486 | url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); never executed: return url.length() >= 5 && url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); | 0 | ||||||||||||
487 | - | |||||||||||||
488 | } | - | ||||||||||||
489 | - | |||||||||||||
490 | #if defined(Q_OS_ANDROID) | - | ||||||||||||
491 | else if (f == QLatin1Char('a') || f == QLatin1Char('A')) { | - | ||||||||||||
492 | return url.length() >= 8 /* assets:/ */ && | - | ||||||||||||
493 | url.startsWith(QLatin1String(assets_string), Qt::CaseInsensitive) && | - | ||||||||||||
494 | url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/'); | - | ||||||||||||
495 | - | |||||||||||||
496 | } | - | ||||||||||||
497 | #endif | - | ||||||||||||
498 | - | |||||||||||||
499 | return false; never executed: return false; | 0 | ||||||||||||
500 | } | - | ||||||||||||
501 | - | |||||||||||||
502 | /*! | - | ||||||||||||
503 | Returns true if \a url is a local file that can be opened with QFile. | - | ||||||||||||
504 | - | |||||||||||||
505 | Local file urls have either a qrc:/ or file:// scheme. | - | ||||||||||||
506 | - | |||||||||||||
507 | \note On Android, urls with assets:/ scheme are also considered local files. | - | ||||||||||||
508 | */ | - | ||||||||||||
509 | bool QQmlFile::isLocalFile(const QUrl &url) | - | ||||||||||||
510 | { | - | ||||||||||||
511 | QString scheme = url.scheme(); | - | ||||||||||||
512 | - | |||||||||||||
513 | if ((scheme.length() == 4 && 0 == scheme.compare(QLatin1String(file_string), Qt::CaseInsensitive)) ||
| 52-45745 | ||||||||||||
514 | (scheme.length() == 3 && 0 == scheme.compare(QLatin1String(qrc_string), Qt::CaseInsensitive))) {
| 0-45682 | ||||||||||||
515 | return true; executed 15373 times by 126 tests: return true; Executed by:
| 15373 | ||||||||||||
516 | - | |||||||||||||
517 | #if defined(Q_OS_ANDROID) | - | ||||||||||||
518 | } else if (scheme.length() == 6 && 0 == scheme.compare(QLatin1String(assets_string), Qt::CaseInsensitive)) { | - | ||||||||||||
519 | return true; | - | ||||||||||||
520 | #endif | - | ||||||||||||
521 | - | |||||||||||||
522 | } else { | - | ||||||||||||
523 | return false; executed 45682 times by 47 tests: return false; Executed by:
| 45682 | ||||||||||||
524 | } | - | ||||||||||||
525 | } | - | ||||||||||||
526 | - | |||||||||||||
527 | /*! | - | ||||||||||||
528 | Returns true if \a url is a local file that can be opened with QFile. | - | ||||||||||||
529 | - | |||||||||||||
530 | Local file urls have either a qrc:/ or file:// scheme. | - | ||||||||||||
531 | - | |||||||||||||
532 | \note On Android, urls with assets:/ scheme are also considered local files. | - | ||||||||||||
533 | */ | - | ||||||||||||
534 | bool QQmlFile::isLocalFile(const QString &url) | - | ||||||||||||
535 | { | - | ||||||||||||
536 | if (url.length() < 5 /* qrc:/ */)
| 0-64061 | ||||||||||||
537 | return false; never executed: return false; | 0 | ||||||||||||
538 | - | |||||||||||||
539 | QChar f = url[0]; | - | ||||||||||||
540 | - | |||||||||||||
541 | if (f == QLatin1Char('f') || f == QLatin1Char('F')) {
| 0-54480 | ||||||||||||
542 | - | |||||||||||||
543 | return url.length() >= 7 /* file:// */ && executed 9581 times by 126 tests: return url.length() >= 7 && url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); Executed by:
| 9581 | ||||||||||||
544 | url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && executed 9581 times by 126 tests: return url.length() >= 7 && url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); Executed by:
| 9581 | ||||||||||||
545 | url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); executed 9581 times by 126 tests: return url.length() >= 7 && url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); Executed by:
| 9581 | ||||||||||||
546 | - | |||||||||||||
547 | } else if (f == QLatin1Char('q') || f == QLatin1Char('Q')) {
| 0-45680 | ||||||||||||
548 | - | |||||||||||||
549 | return url.length() >= 5 /* qrc:/ */ && executed 8800 times by 138 tests: return url.length() >= 5 && url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); Executed by:
| 8800 | ||||||||||||
550 | url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && executed 8800 times by 138 tests: return url.length() >= 5 && url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); Executed by:
| 8800 | ||||||||||||
551 | url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); executed 8800 times by 138 tests: return url.length() >= 5 && url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); Executed by:
| 8800 | ||||||||||||
552 | - | |||||||||||||
553 | } | - | ||||||||||||
554 | #if defined(Q_OS_ANDROID) | - | ||||||||||||
555 | else if (f == QLatin1Char('a') || f == QLatin1Char('A')) { | - | ||||||||||||
556 | return url.length() >= 8 /* assets:/ */ && | - | ||||||||||||
557 | url.startsWith(QLatin1String(assets_string), Qt::CaseInsensitive) && | - | ||||||||||||
558 | url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/'); | - | ||||||||||||
559 | - | |||||||||||||
560 | } | - | ||||||||||||
561 | #endif | - | ||||||||||||
562 | - | |||||||||||||
563 | return false; executed 45680 times by 48 tests: return false; Executed by:
| 45680 | ||||||||||||
564 | } | - | ||||||||||||
565 | - | |||||||||||||
566 | /*! | - | ||||||||||||
567 | If \a url is a local file returns a path suitable for passing to QFile. Otherwise returns an | - | ||||||||||||
568 | empty string. | - | ||||||||||||
569 | */ | - | ||||||||||||
570 | QString QQmlFile::urlToLocalFileOrQrc(const QUrl& url) | - | ||||||||||||
571 | { | - | ||||||||||||
572 | if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) {
| 3507-141998 | ||||||||||||
573 | if (url.authority().isEmpty())
| 0-3507 | ||||||||||||
574 | return QLatin1Char(':') + url.path(); executed 3507 times by 17 tests: return QLatin1Char(':') + url.path(); Executed by:
| 3507 | ||||||||||||
575 | return QString(); never executed: return QString(); | 0 | ||||||||||||
576 | } | - | ||||||||||||
577 | - | |||||||||||||
578 | #if defined(Q_OS_ANDROID) | - | ||||||||||||
579 | else if (url.scheme().compare(QLatin1String("assets"), Qt::CaseInsensitive) == 0) { | - | ||||||||||||
580 | if (url.authority().isEmpty()) | - | ||||||||||||
581 | return url.toString(); | - | ||||||||||||
582 | return QString(); | - | ||||||||||||
583 | } | - | ||||||||||||
584 | #endif | - | ||||||||||||
585 | - | |||||||||||||
586 | return url.toLocalFile(); executed 141998 times by 141 tests: return url.toLocalFile(); Executed by:
| 141998 | ||||||||||||
587 | } | - | ||||||||||||
588 | - | |||||||||||||
589 | static QString toLocalFile(const QString &url) | - | ||||||||||||
590 | { | - | ||||||||||||
591 | const QUrl file(url); | - | ||||||||||||
592 | if (!file.isLocalFile())
| 132784-466847 | ||||||||||||
593 | return QString(); executed 132784 times by 16 tests: return QString(); Executed by:
| 132784 | ||||||||||||
594 | - | |||||||||||||
595 | //XXX TODO: handle windows hostnames: "//servername/path/to/file.txt" | - | ||||||||||||
596 | - | |||||||||||||
597 | return file.toLocalFile(); executed 466847 times by 127 tests: return file.toLocalFile(); Executed by:
| 466847 | ||||||||||||
598 | } | - | ||||||||||||
599 | - | |||||||||||||
600 | /*! | - | ||||||||||||
601 | If \a url is a local file returns a path suitable for passing to QFile. Otherwise returns an | - | ||||||||||||
602 | empty string. | - | ||||||||||||
603 | */ | - | ||||||||||||
604 | QString QQmlFile::urlToLocalFileOrQrc(const QString& url) | - | ||||||||||||
605 | { | - | ||||||||||||
606 | if (url.startsWith(QLatin1String("qrc://"), Qt::CaseInsensitive)) {
| 2-622073 | ||||||||||||
607 | if (url.length() > 6)
| 0-2 | ||||||||||||
608 | return QLatin1Char(':') + url.midRef(6); executed 2 times by 1 test: return QLatin1Char(':') + url.midRef(6); Executed by:
| 2 | ||||||||||||
609 | return QString(); never executed: return QString(); | 0 | ||||||||||||
610 | } | - | ||||||||||||
611 | - | |||||||||||||
612 | if (url.startsWith(QLatin1String("qrc:"), Qt::CaseInsensitive)) {
| 22442-599631 | ||||||||||||
613 | if (url.length() > 4)
| 0-22442 | ||||||||||||
614 | return QLatin1Char(':') + url.midRef(4); executed 22442 times by 138 tests: return QLatin1Char(':') + url.midRef(4); Executed by:
| 22442 | ||||||||||||
615 | return QString(); never executed: return QString(); | 0 | ||||||||||||
616 | } | - | ||||||||||||
617 | - | |||||||||||||
618 | #if defined(Q_OS_ANDROID) | - | ||||||||||||
619 | else if (url.startsWith(QLatin1String("assets:"), Qt::CaseInsensitive)) { | - | ||||||||||||
620 | return url; | - | ||||||||||||
621 | } | - | ||||||||||||
622 | #endif | - | ||||||||||||
623 | - | |||||||||||||
624 | return toLocalFile(url); executed 599631 times by 133 tests: return toLocalFile(url); Executed by:
| 599631 | ||||||||||||
625 | } | - | ||||||||||||
626 | - | |||||||||||||
627 | QT_END_NAMESPACE | - | ||||||||||||
628 | - | |||||||||||||
629 | #include "qqmlfile.moc" | - | ||||||||||||
Source code | Switch to Preprocessed file |