diff options
Diffstat (limited to 'src/core/services')
-rw-r--r-- | src/core/services/qdownloadhelperservice.cpp | 216 | ||||
-rw-r--r-- | src/core/services/qdownloadhelperservice_p.h | 130 | ||||
-rw-r--r-- | src/core/services/qdownloadhelperservice_p_p.h | 76 | ||||
-rw-r--r-- | src/core/services/qdownloadnetworkworker.cpp | 148 | ||||
-rw-r--r-- | src/core/services/qdownloadnetworkworker_p.h | 101 | ||||
-rw-r--r-- | src/core/services/qservicelocator.cpp | 11 | ||||
-rw-r--r-- | src/core/services/qservicelocator_p.h | 3 | ||||
-rw-r--r-- | src/core/services/services.pri | 8 |
8 files changed, 691 insertions, 2 deletions
diff --git a/src/core/services/qdownloadhelperservice.cpp b/src/core/services/qdownloadhelperservice.cpp new file mode 100644 index 000000000..70a2cbfe4 --- /dev/null +++ b/src/core/services/qdownloadhelperservice.cpp @@ -0,0 +1,216 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdownloadhelperservice_p.h" +#include "qdownloadnetworkworker_p.h" +#include <Qt3DCore/QAspectEngine> +#include <Qt3DCore/private/qabstractserviceprovider_p.h> +#include <Qt3DCore/private/qaspectengine_p.h> +#include <Qt3DCore/private/qaspectthread_p.h> +#include <Qt3DCore/private/qaspectmanager_p.h> +#include <Qt3DCore/private/qservicelocator_p.h> + +#include <QFile> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +QDownloadRequest::QDownloadRequest(const QUrl &url) + : m_url(url) + , m_succeeded(false) + , m_cancelled(false) +{ + +} + +QDownloadRequest::~QDownloadRequest() +{ + +} + +void QDownloadRequest::onDownloaded() +{ + // this is called in dl thread. It's an opportunity to do long running tasks + // like loading the data into a QImage +} + + +class Q_AUTOTEST_EXPORT QDownloadHelperServicePrivate : public QAbstractServiceProviderPrivate +{ +public: + explicit QDownloadHelperServicePrivate(const QString &description); + ~QDownloadHelperServicePrivate(); + + void init(); + void shutdown(); + void _q_onRequestCompleted(const QDownloadRequestPtr &request); + + Q_DECLARE_PUBLIC(QDownloadHelperService) + + QThread *m_downloadThread; + QDownloadNetworkWorker *m_downloadWorker; +}; + + +QDownloadHelperServicePrivate::QDownloadHelperServicePrivate(const QString &description) + : QAbstractServiceProviderPrivate(QServiceLocator::DownloadHelperService, description) + , m_downloadThread(nullptr) + , m_downloadWorker(nullptr) +{ +} + +QDownloadHelperServicePrivate::~QDownloadHelperServicePrivate() +{ +} + +void QDownloadHelperServicePrivate::init() +{ + Q_Q(QDownloadHelperService); + m_downloadThread = new QThread(q); + m_downloadWorker = new QDownloadNetworkWorker; + m_downloadWorker->moveToThread(m_downloadThread); + QObject::connect(m_downloadWorker, SIGNAL(requestDownloaded(const Qt3DCore::QDownloadRequestPtr &)), + q, SLOT(_q_onRequestCompleted(const Qt3DCore::QDownloadRequestPtr &))); + m_downloadThread->start(); +} + +void QDownloadHelperServicePrivate::shutdown() +{ + emit m_downloadWorker->cancelAllRequests(); + m_downloadThread->exit(); + m_downloadThread->wait(); + m_downloadWorker->deleteLater(); +} + +void QDownloadHelperServicePrivate::_q_onRequestCompleted(const Qt3DCore::QDownloadRequestPtr &request) +{ + request->onCompleted(); +} + + +QDownloadHelperService::QDownloadHelperService(const QString &description) + : QAbstractServiceProvider(*new QDownloadHelperServicePrivate(description)) +{ + Q_D(QDownloadHelperService); + d->init(); + qRegisterMetaType<Qt3DCore::QDownloadRequestPtr>(); +} + +QDownloadHelperService::~QDownloadHelperService() +{ + Q_D(QDownloadHelperService); + d->shutdown(); +} + +void QDownloadHelperService::submitRequest(const Qt3DCore::QDownloadRequestPtr &request) +{ + Q_D(QDownloadHelperService); + + if (isLocal(request->url())) { + QFile file(urlToLocalFileOrQrc(request->url())); + if (file.open(QIODevice::ReadOnly)) { + request->m_data = file.readAll(); + file.close(); + request->m_succeeded = true; + } else { + request->m_succeeded = false; + } + request->onCompleted(); + } else { + emit d->m_downloadWorker->submitRequest(request); + } +} + +void QDownloadHelperService::cancelRequest(const Qt3DCore::QDownloadRequestPtr &request) +{ + Q_D(QDownloadHelperService); + request->m_cancelled = true; + emit d->m_downloadWorker->cancelRequest(request); +} + +void QDownloadHelperService::cancelAllRequests() +{ + Q_D(QDownloadHelperService); + emit d->m_downloadWorker->cancelAllRequests(); +} + +QString QDownloadHelperService::urlToLocalFileOrQrc(const QUrl &url) +{ + const QString scheme(url.scheme().toLower()); + if (scheme == QLatin1String("qrc")) { + if (url.authority().isEmpty()) + return QLatin1Char(':') + url.path(); + return QString(); + } + +#if defined(Q_OS_ANDROID) + if (scheme == QLatin1String("assets")) { + if (url.authority().isEmpty()) + return url.toString(); + return QString(); + } +#endif + + return url.toLocalFile(); +} + +QDownloadHelperService *QDownloadHelperService::getService(QAspectEngine *engine) +{ + auto enginePrivate = Qt3DCore::QAspectEnginePrivate::get(engine); + return enginePrivate->m_aspectThread->aspectManager()->serviceLocator()->downloadHelperService(); +} + +bool QDownloadHelperService::isLocal(const QUrl &url) +{ + const QString scheme(url.scheme().toLower()); + if (scheme == QLatin1String("file") || scheme == QLatin1String("qrc")) + return true; +#if defined(Q_OS_ANDROID) + if (scheme == QLatin1String("assets")) + return true; +#endif + return false; +} + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#include "moc_qdownloadhelperservice_p.cpp" diff --git a/src/core/services/qdownloadhelperservice_p.h b/src/core/services/qdownloadhelperservice_p.h new file mode 100644 index 000000000..780ed4806 --- /dev/null +++ b/src/core/services/qdownloadhelperservice_p.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DCORE_QDOWNLOADHELPERSERVICE_P_H +#define QT3DCORE_QDOWNLOADHELPERSERVICE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QSharedPointer> +#include <QObject> +#include <QUrl> + +#include <Qt3DCore/qaspectjob.h> +#include <Qt3DCore/qt3dcore_global.h> +#include <Qt3DCore/private/qservicelocator_p.h> + +QT_BEGIN_NAMESPACE + +class QThread; +class QNetworkAccessManager; +class QNetworkReply; + +namespace Qt3DCore { + +class QAspectEngine; +class QDownloadNetworkWorker; +class QDownloadHelperService; +class QDownloadHelperServicePrivate; + +class QT3DCORESHARED_EXPORT QDownloadRequest +{ +public: + QDownloadRequest(const QUrl &url); + virtual ~QDownloadRequest(); + + QUrl url() const { return m_url; } + bool succeeded() const { return m_succeeded; } + bool cancelled() const { return m_cancelled; } + + virtual void onDownloaded(); // this is called in dl thread + virtual void onCompleted() = 0; // this is called in job thread + +protected: + QUrl m_url; + QByteArray m_data; + +private: + friend class QDownloadNetworkWorker; + friend class QDownloadHelperService; + bool m_succeeded; + bool m_cancelled; +}; + +typedef QSharedPointer<QDownloadRequest> QDownloadRequestPtr; + + +class QT3DCORESHARED_EXPORT QDownloadHelperService : public QAbstractServiceProvider +{ + Q_OBJECT +public: + explicit QDownloadHelperService(const QString &description = QString()); + ~QDownloadHelperService(); + + void submitRequest(const QDownloadRequestPtr &request); + void cancelRequest(const QDownloadRequestPtr &request); + void cancelAllRequests(); + + static QString urlToLocalFileOrQrc(const QUrl &url); + static bool isLocal(const QUrl &url); + static QDownloadHelperService *getService(QAspectEngine *engine); + +private: + Q_DECLARE_PRIVATE(QDownloadHelperService) + Q_PRIVATE_SLOT(d_func(), void _q_onRequestCompleted(const Qt3DCore::QDownloadRequestPtr &)) +}; + +typedef QSharedPointer<QDownloadHelperService> QDownloadHelperServicePtr; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(Qt3DCore::QDownloadRequestPtr) // LCOV_EXCL_LINE + +#endif // QT3DCORE_QDOWNLOADHELPERSERVICE_P_H diff --git a/src/core/services/qdownloadhelperservice_p_p.h b/src/core/services/qdownloadhelperservice_p_p.h new file mode 100644 index 000000000..202ae5236 --- /dev/null +++ b/src/core/services/qdownloadhelperservice_p_p.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DCORE_QDOWNLOADHELPERSERVICE_P_P_H +#define QT3DCORE_QDOWNLOADHELPERSERVICE_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QSharedPointer> +#include <QObject> +#include <QUrl> + +#include <Qt3DCore/qaspectjob.h> +#include <Qt3DCore/private/qservicelocator_p.h> +#include <Qt3DCore/private/qdownloadhelperservice_p.h> +#include <Qt3DCore/private/qabstractserviceprovider_p.h> + +QT_BEGIN_NAMESPACE + +class QThread; +class QNetworkAccessManager; +class QNetworkReply; + +namespace Qt3DCore { + + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QDOWNLOADHELPERSERVICE_P_P_H diff --git a/src/core/services/qdownloadnetworkworker.cpp b/src/core/services/qdownloadnetworkworker.cpp new file mode 100644 index 000000000..c728a1779 --- /dev/null +++ b/src/core/services/qdownloadnetworkworker.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdownloadhelperservice_p.h" +#include "qdownloadnetworkworker_p.h" + +#include <QNetworkAccessManager> +#include <QNetworkRequest> +#include <QNetworkReply> +#include <QDataStream> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { + +QDownloadNetworkWorker::QDownloadNetworkWorker(QObject *parent) + : QObject(parent) + , m_networkManager(nullptr) +{ + connect(this, &QDownloadNetworkWorker::submitRequest, + this, &QDownloadNetworkWorker::onRequestSubmited); + connect(this, &QDownloadNetworkWorker::cancelRequest, + this, &QDownloadNetworkWorker::onRequestCancelled); + connect(this, &QDownloadNetworkWorker::cancelAllRequests, + this, &QDownloadNetworkWorker::onAllRequestsCancelled); +} + +void QDownloadNetworkWorker::onRequestSubmited(const QDownloadRequestPtr &request) +{ + QMutexLocker l(&m_mutex); + if (!m_networkManager) { + m_networkManager = new QNetworkAccessManager(this); + connect(m_networkManager, &QNetworkAccessManager::finished, + this, &QDownloadNetworkWorker::onRequestFinished); + } + auto reply = m_networkManager->get(QNetworkRequest(request->url())); + m_requests << QPair<QDownloadRequestPtr, QNetworkReply *>(request, reply); + connect(reply, &QNetworkReply::downloadProgress, this, &QDownloadNetworkWorker::onDownloadProgressed); +} + +void QDownloadNetworkWorker::onRequestCancelled(const QDownloadRequestPtr &request) +{ + QMutexLocker l(&m_mutex); + auto it = std::find_if(m_requests.begin(), m_requests.end(), + [request](QPair<QDownloadRequestPtr, QNetworkReply *> e) { + return e.first == request; + }); + if (it == m_requests.end()) + return; + + (*it).first->m_cancelled = true; + (*it).second->abort(); +} + +void QDownloadNetworkWorker::onAllRequestsCancelled() +{ + QMutexLocker l(&m_mutex); + for (auto e: qAsConst(m_requests)) { + e.first->m_cancelled = true; + e.second->abort(); + } + m_requests.clear(); +} + +void QDownloadNetworkWorker::onRequestFinished(QNetworkReply *reply) +{ + QMutexLocker l(&m_mutex); + auto it = std::find_if(m_requests.begin(), m_requests.end(), + [reply](QPair<QDownloadRequestPtr, QNetworkReply *> e) { + return e.second == reply; + }); + if (it == m_requests.end()) + return; + + auto request = (*it).first; + if (reply->error() == QNetworkReply::NoError) { + request->m_succeeded = true; + } + request->onDownloaded(); + emit requestDownloaded(request); + + m_requests.erase(it); +} + +void QDownloadNetworkWorker::onDownloadProgressed(qint64 bytesReceived, qint64 bytesTotal) +{ + Q_UNUSED(bytesReceived); + Q_UNUSED(bytesTotal); + // TODO forward progress details somewhere + + QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); + if (!reply) + return; + + QMutexLocker l(&m_mutex); + auto it = std::find_if(m_requests.begin(), m_requests.end(), + [reply](QPair<QDownloadRequestPtr, QNetworkReply *> e) { + return e.second == reply; + }); + if (it == m_requests.end()) + return; + + auto request = (*it).first; + QDataStream stream(&request->m_data, QIODevice::Append); + QByteArray data = reply->readAll(); + stream.writeRawData(data.data(), data.size()); +} + +} // namespace Qt3DCore + +QT_END_NAMESPACE + diff --git a/src/core/services/qdownloadnetworkworker_p.h b/src/core/services/qdownloadnetworkworker_p.h new file mode 100644 index 000000000..faecbca2f --- /dev/null +++ b/src/core/services/qdownloadnetworkworker_p.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DCORE_QDOWNLOADNETWORKWORKER_P_H +#define QT3DCORE_QDOWNLOADNETWORKWORKER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QSharedPointer> +#include <QObject> +#include <QUrl> +#include <Qt3DCore/private/qdownloadhelperservice_p.h> +#include <QMutex> + +QT_BEGIN_NAMESPACE + +class QThread; +class QNetworkAccessManager; +class QNetworkReply; + +namespace Qt3DCore { + +class QDownloadRequest; +typedef QSharedPointer<QDownloadRequest> QDownloadRequestPtr; + +class QDownloadNetworkWorker : public QObject +{ + Q_OBJECT +public: + QDownloadNetworkWorker(QObject *parent = nullptr); + +signals: + void submitRequest(const Qt3DCore::QDownloadRequestPtr &request); + void cancelRequest(const Qt3DCore::QDownloadRequestPtr &request); + void cancelAllRequests(); + + void requestDownloaded(const Qt3DCore::QDownloadRequestPtr &request); + +private Q_SLOTS: + void onRequestSubmited(const Qt3DCore::QDownloadRequestPtr &request); + void onRequestCancelled(const Qt3DCore::QDownloadRequestPtr &request); + void onAllRequestsCancelled(); + void onRequestFinished(QNetworkReply *reply); + void onDownloadProgressed(qint64 bytesReceived, qint64 bytesTotal); + +private: + QNetworkAccessManager *m_networkManager; + QVector< QPair<QDownloadRequestPtr, QNetworkReply *> > m_requests; + QMutex m_mutex; +}; + +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QDOWNLOADNETWORKWORKER_P_H diff --git a/src/core/services/qservicelocator.cpp b/src/core/services/qservicelocator.cpp index 9d12cfe2c..bdcb4a521 100644 --- a/src/core/services/qservicelocator.cpp +++ b/src/core/services/qservicelocator.cpp @@ -43,9 +43,11 @@ #include <Qt3DCore/private/nullservices_p.h> #include <Qt3DCore/private/qabstractserviceprovider_p.h> +#include <Qt3DCore/private/qdownloadhelperservice_p.h> #include <Qt3DCore/private/qeventfilterservice_p.h> #include <Qt3DCore/private/qtickclockservice_p.h> + QT_BEGIN_NAMESPACE namespace Qt3DCore { @@ -96,6 +98,7 @@ public: NullOpenGLInformationService m_nullOpenGLInfo; QTickClockService m_defaultFrameAdvanceService; QEventFilterService m_eventFilterService; + QDownloadHelperService m_downloadHelperService; int m_nonNullDefaultServices; }; @@ -229,6 +232,12 @@ QEventFilterService *QServiceLocator::eventFilterService() return static_cast<QEventFilterService *>(d->m_services.value(EventFilterService, &d->m_eventFilterService)); } +QDownloadHelperService *QServiceLocator::downloadHelperService() +{ + Q_D(QServiceLocator); + return static_cast<QDownloadHelperService *>(d->m_services.value(DownloadHelperService, &d->m_downloadHelperService)); +} + /* \internal */ @@ -244,6 +253,8 @@ QAbstractServiceProvider *QServiceLocator::_q_getServiceHelper(int type) return frameAdvanceService(); case EventFilterService: return eventFilterService(); + case DownloadHelperService: + return downloadHelperService(); default: return d->m_services.value(type, nullptr); } diff --git a/src/core/services/qservicelocator_p.h b/src/core/services/qservicelocator_p.h index 1c5db4a5b..9534b33ce 100644 --- a/src/core/services/qservicelocator_p.h +++ b/src/core/services/qservicelocator_p.h @@ -84,6 +84,7 @@ class QOpenGLInformationService; class QSystemInformationService; class QServiceLocatorPrivate; class QEventFilterService; +class QDownloadHelperService; class QT3DCORESHARED_EXPORT QServiceLocator { @@ -97,6 +98,7 @@ public: CollisionService, FrameAdvanceService, EventFilterService, + DownloadHelperService, #if !defined(Q_QDOC) DefaultServiceCount, // Add additional default services before here #endif @@ -120,6 +122,7 @@ public: QOpenGLInformationService *openGLInformation(); QAbstractFrameAdvanceService *frameAdvanceService(); QEventFilterService *eventFilterService(); + QDownloadHelperService *downloadHelperService(); private: Q_DISABLE_COPY(QServiceLocator) diff --git a/src/core/services/services.pri b/src/core/services/services.pri index ae0cfd9f8..f311b8329 100644 --- a/src/core/services/services.pri +++ b/src/core/services/services.pri @@ -5,7 +5,9 @@ SOURCES += \ $$PWD/qopenglinformationservice.cpp \ $$PWD/qtickclockservice.cpp \ $$PWD/qabstractframeadvanceservice.cpp \ - $$PWD/qeventfilterservice.cpp + $$PWD/qeventfilterservice.cpp \ + $$PWD/qdownloadhelperservice.cpp \ + $$PWD/qdownloadnetworkworker.cpp HEADERS += \ $$PWD/qservicelocator_p.h \ @@ -18,6 +20,8 @@ HEADERS += \ $$PWD/qtickclockservice_p.h \ $$PWD/qabstractframeadvanceservice_p.h \ $$PWD/qabstractframeadvanceservice_p_p.h \ - $$PWD/qeventfilterservice_p.h + $$PWD/qeventfilterservice_p.h \ + $$PWD/qdownloadhelperservice_p.h \ + $$PWD/qdownloadnetworkworker_p.h INCLUDEPATH += $$PWD |