1// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QT3DCORE_QDOWNLOADHELPERSERVICE_P_H
5#define QT3DCORE_QDOWNLOADHELPERSERVICE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QSharedPointer>
19#include <QObject>
20#include <QUrl>
21
22#include <Qt3DCore/qaspectjob.h>
23#include <Qt3DCore/qt3dcore_global.h>
24#include <Qt3DCore/private/qservicelocator_p.h>
25
26QT_BEGIN_NAMESPACE
27
28class QThread;
29class QNetworkAccessManager;
30class QNetworkReply;
31
32namespace Qt3DCore {
33
34class QAspectEngine;
35class QDownloadNetworkWorker;
36class QDownloadHelperService;
37class QDownloadHelperServicePrivate;
38
39class Q_3DCORESHARED_EXPORT QDownloadRequest
40{
41public:
42 QDownloadRequest(const QUrl &url);
43 virtual ~QDownloadRequest();
44
45 QUrl url() const { return m_url; }
46 bool succeeded() const { return m_succeeded; }
47 bool cancelled() const { return m_cancelled; }
48
49 virtual void onDownloaded(); // this is called in dl thread
50 virtual void onCompleted() = 0; // this is called in the aspect thread
51
52protected:
53 QUrl m_url;
54 QByteArray m_data;
55
56private:
57 friend class QDownloadNetworkWorker;
58 friend class QDownloadHelperService;
59 bool m_succeeded;
60 bool m_cancelled;
61};
62
63typedef QSharedPointer<QDownloadRequest> QDownloadRequestPtr;
64
65
66class Q_3DCORESHARED_EXPORT QDownloadHelperService : public QAbstractServiceProvider
67{
68 Q_OBJECT
69public:
70 explicit QDownloadHelperService(const QString &description = QString());
71 ~QDownloadHelperService();
72
73 void submitRequest(const QDownloadRequestPtr &request);
74 void cancelRequest(const QDownloadRequestPtr &request);
75 void cancelAllRequests();
76
77 static QString urlToLocalFileOrQrc(const QUrl &url);
78 static bool isLocal(const QUrl &url);
79 static QDownloadHelperService *getService(QAspectEngine *engine);
80
81private:
82 Q_DECLARE_PRIVATE(QDownloadHelperService)
83 Q_PRIVATE_SLOT(d_func(), void _q_onRequestCompleted(const Qt3DCore::QDownloadRequestPtr &))
84};
85
86typedef QSharedPointer<QDownloadHelperService> QDownloadHelperServicePtr;
87
88} // namespace Qt3DCore
89
90QT_END_NAMESPACE
91
92Q_DECLARE_METATYPE(Qt3DCore::QDownloadRequestPtr) // LCOV_EXCL_LINE
93
94#endif // QT3DCORE_QDOWNLOADHELPERSERVICE_P_H
95

source code of qt3d/src/core/services/qdownloadhelperservice_p.h