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_QDOWNLOADNETWORKWORKER_P_H |
5 | #define QT3DCORE_QDOWNLOADNETWORKWORKER_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 | #include <Qt3DCore/private/qdownloadhelperservice_p.h> |
22 | #include <QMutex> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QThread; |
27 | class QNetworkAccessManager; |
28 | class QNetworkReply; |
29 | |
30 | namespace Qt3DCore { |
31 | |
32 | class QDownloadRequest; |
33 | typedef QSharedPointer<QDownloadRequest> QDownloadRequestPtr; |
34 | |
35 | class QDownloadNetworkWorker : public QObject |
36 | { |
37 | Q_OBJECT |
38 | public: |
39 | QDownloadNetworkWorker(QObject *parent = nullptr); |
40 | |
41 | signals: |
42 | void submitRequest(const Qt3DCore::QDownloadRequestPtr &request); |
43 | void cancelRequest(const Qt3DCore::QDownloadRequestPtr &request); |
44 | void cancelAllRequests(); |
45 | |
46 | void requestDownloaded(const Qt3DCore::QDownloadRequestPtr &request); |
47 | |
48 | private Q_SLOTS: |
49 | void onRequestSubmited(const Qt3DCore::QDownloadRequestPtr &request); |
50 | void onRequestCancelled(const Qt3DCore::QDownloadRequestPtr &request); |
51 | void onAllRequestsCancelled(); |
52 | void onRequestFinished(QNetworkReply *reply); |
53 | void onDownloadProgressed(qint64 bytesReceived, qint64 bytesTotal); |
54 | |
55 | private: |
56 | QNetworkAccessManager *m_networkManager; |
57 | QList< QPair<QDownloadRequestPtr, QNetworkReply *> > m_requests; |
58 | QMutex m_mutex; |
59 | }; |
60 | |
61 | } // namespace Qt3DCore |
62 | |
63 | QT_END_NAMESPACE |
64 | |
65 | #endif // QT3DCORE_QDOWNLOADNETWORKWORKER_P_H |
66 | |