summaryrefslogtreecommitdiffstats
path: root/src/core/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/services')
-rw-r--r--src/core/services/nullservices_p.h5
-rw-r--r--src/core/services/qabstractframeadvanceservice_p.h4
-rw-r--r--src/core/services/qabstractframeadvanceservice_p_p.h1
-rw-r--r--src/core/services/qabstractserviceprovider_p.h11
-rw-r--r--src/core/services/qdownloadhelperservice.cpp216
-rw-r--r--src/core/services/qdownloadhelperservice_p.h130
-rw-r--r--src/core/services/qdownloadhelperservice_p_p.h76
-rw-r--r--src/core/services/qdownloadnetworkworker.cpp148
-rw-r--r--src/core/services/qdownloadnetworkworker_p.h101
-rw-r--r--src/core/services/qeventfilterservice.cpp12
-rw-r--r--src/core/services/qeventfilterservice_p.h2
-rw-r--r--src/core/services/qopenglinformationservice.cpp2
-rw-r--r--src/core/services/qopenglinformationservice_p.h6
-rw-r--r--src/core/services/qopenglinformationservice_p_p.h1
-rw-r--r--src/core/services/qservicelocator.cpp33
-rw-r--r--src/core/services/qservicelocator_p.h14
-rw-r--r--src/core/services/qsysteminformationservice_p.h4
-rw-r--r--src/core/services/qsysteminformationservice_p_p.h1
-rw-r--r--src/core/services/qtickclockservice.cpp7
-rw-r--r--src/core/services/qtickclockservice_p.h3
-rw-r--r--src/core/services/services.pri8
21 files changed, 748 insertions, 37 deletions
diff --git a/src/core/services/nullservices_p.h b/src/core/services/nullservices_p.h
index ed7bd3a39..f75c6abc1 100644
--- a/src/core/services/nullservices_p.h
+++ b/src/core/services/nullservices_p.h
@@ -52,8 +52,9 @@
//
#include <Qt3DCore/qt3dcore_global.h>
-#include "qopenglinformationservice_p.h"
-#include "qsysteminformationservice_p.h"
+
+#include <Qt3DCore/private/qopenglinformationservice_p.h>
+#include <Qt3DCore/private/qsysteminformationservice_p.h>
QT_BEGIN_NAMESPACE
diff --git a/src/core/services/qabstractframeadvanceservice_p.h b/src/core/services/qabstractframeadvanceservice_p.h
index 2dde68f06..dac72a98d 100644
--- a/src/core/services/qabstractframeadvanceservice_p.h
+++ b/src/core/services/qabstractframeadvanceservice_p.h
@@ -52,8 +52,9 @@
//
#include <Qt3DCore/qt3dcore_global.h>
+#include <QtCore/QString>
+
#include <Qt3DCore/private/qservicelocator_p.h>
-#include <QString>
QT_BEGIN_NAMESPACE
@@ -63,6 +64,7 @@ class QAbstractFrameAdvanceServicePrivate;
class QT3DCORESHARED_EXPORT QAbstractFrameAdvanceService : public QAbstractServiceProvider
{
+ Q_OBJECT
public:
virtual qint64 waitForNextFrame() = 0;
virtual void start() = 0;
diff --git a/src/core/services/qabstractframeadvanceservice_p_p.h b/src/core/services/qabstractframeadvanceservice_p_p.h
index d73ca3116..c49586b8f 100644
--- a/src/core/services/qabstractframeadvanceservice_p_p.h
+++ b/src/core/services/qabstractframeadvanceservice_p_p.h
@@ -52,6 +52,7 @@
//
#include <Qt3DCore/qt3dcore_global.h>
+
#include <Qt3DCore/private/qabstractserviceprovider_p.h>
#include <Qt3DCore/private/qservicelocator_p.h>
diff --git a/src/core/services/qabstractserviceprovider_p.h b/src/core/services/qabstractserviceprovider_p.h
index 2913cee31..cef6ef034 100644
--- a/src/core/services/qabstractserviceprovider_p.h
+++ b/src/core/services/qabstractserviceprovider_p.h
@@ -51,23 +51,26 @@
// We mean it.
//
+#include <QtCore/private/qobject_p.h>
#include <Qt3DCore/qt3dcore_global.h>
#include <QtCore/qstring.h>
+#include <Qt3DCore/private/qservicelocator_p.h>
+
QT_BEGIN_NAMESPACE
namespace Qt3DCore {
-class QAbstractServiceProviderPrivate
+class QAbstractServiceProviderPrivate : public QObjectPrivate
{
public:
- QAbstractServiceProviderPrivate(int type, const QString &description = QString())
- : m_type(type)
+ explicit QAbstractServiceProviderPrivate(int type, const QString &description = QString())
+ : QObjectPrivate()
+ , m_type(type)
, m_description(description)
{}
Q_DECLARE_PUBLIC(QAbstractServiceProvider)
- QAbstractServiceProvider *q_ptr;
int m_type;
QString m_description;
diff --git a/src/core/services/qdownloadhelperservice.cpp b/src/core/services/qdownloadhelperservice.cpp
new file mode 100644
index 000000000..231e9172b
--- /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()
+{
+ 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/qeventfilterservice.cpp b/src/core/services/qeventfilterservice.cpp
index 489ab9b45..6584c5e24 100644
--- a/src/core/services/qeventfilterservice.cpp
+++ b/src/core/services/qeventfilterservice.cpp
@@ -38,10 +38,12 @@
****************************************************************************/
#include "qeventfilterservice_p.h"
-#include "qabstractserviceprovider_p.h"
-#include <QMap>
-#include <QObject>
-#include <QVector>
+
+#include <QtCore/QMap>
+#include <QtCore/QObject>
+#include <QtCore/QVector>
+
+#include <Qt3DCore/private/qabstractserviceprovider_p.h>
QT_BEGIN_NAMESPACE
@@ -83,6 +85,8 @@ public:
: QAbstractServiceProviderPrivate(QServiceLocator::EventFilterService, QStringLiteral("Default event filter service implementation"))
{}
+ Q_DECLARE_PUBLIC(QEventFilterService)
+
void registerEventFilter(QObject *eventFilter, int priority)
{
for (int i = 0, m = m_eventFilters.size(); i < m; ++i)
diff --git a/src/core/services/qeventfilterservice_p.h b/src/core/services/qeventfilterservice_p.h
index 4962e2af6..58b87d9cc 100644
--- a/src/core/services/qeventfilterservice_p.h
+++ b/src/core/services/qeventfilterservice_p.h
@@ -52,6 +52,7 @@
//
#include <Qt3DCore/qt3dcore_global.h>
+
#include <Qt3DCore/private/qservicelocator_p.h>
QT_BEGIN_NAMESPACE
@@ -62,6 +63,7 @@ class QEventFilterServicePrivate;
class QT3DCORESHARED_EXPORT QEventFilterService : public QAbstractServiceProvider
{
+ Q_OBJECT
public:
QEventFilterService();
~QEventFilterService();
diff --git a/src/core/services/qopenglinformationservice.cpp b/src/core/services/qopenglinformationservice.cpp
index 0f62544c8..c1c05018e 100644
--- a/src/core/services/qopenglinformationservice.cpp
+++ b/src/core/services/qopenglinformationservice.cpp
@@ -62,7 +62,7 @@ namespace Qt3DCore {
instantiate a QOpenGLInformationService object.
*/
QOpenGLInformationService::QOpenGLInformationService(const QString &description)
- : QAbstractServiceProvider(QServiceLocator::OpenGLInformation, description)
+ : QAbstractServiceProvider(*new QOpenGLInformationServicePrivate(description))
{
}
diff --git a/src/core/services/qopenglinformationservice_p.h b/src/core/services/qopenglinformationservice_p.h
index a2c37c29a..2adf73307 100644
--- a/src/core/services/qopenglinformationservice_p.h
+++ b/src/core/services/qopenglinformationservice_p.h
@@ -52,9 +52,10 @@
//
#include <Qt3DCore/qt3dcore_global.h>
-#include <Qt3DCore/private/qservicelocator_p.h>
-#include <QtGui/qsurfaceformat.h>
#include <QtCore/qstring.h>
+#include <QtGui/qsurfaceformat.h>
+
+#include <Qt3DCore/private/qservicelocator_p.h>
QT_BEGIN_NAMESPACE
@@ -64,6 +65,7 @@ class QOpenGLInformationServicePrivate;
class QT3DCORESHARED_EXPORT QOpenGLInformationService : public QAbstractServiceProvider
{
+ Q_OBJECT
public:
virtual QSurfaceFormat format() const = 0;
diff --git a/src/core/services/qopenglinformationservice_p_p.h b/src/core/services/qopenglinformationservice_p_p.h
index 4abef6f18..d10d81d71 100644
--- a/src/core/services/qopenglinformationservice_p_p.h
+++ b/src/core/services/qopenglinformationservice_p_p.h
@@ -52,6 +52,7 @@
//
#include <Qt3DCore/qt3dcore_global.h>
+
#include <Qt3DCore/private/qabstractserviceprovider_p.h>
#include <Qt3DCore/private/qservicelocator_p.h>
diff --git a/src/core/services/qservicelocator.cpp b/src/core/services/qservicelocator.cpp
index 3d3d56386..bdcb4a521 100644
--- a/src/core/services/qservicelocator.cpp
+++ b/src/core/services/qservicelocator.cpp
@@ -38,11 +38,15 @@
****************************************************************************/
#include "qservicelocator_p.h"
-#include "qabstractserviceprovider_p.h"
-#include "nullservices_p.h"
-#include "qtickclockservice_p.h"
-#include "qeventfilterservice_p.h"
-#include <QHash>
+
+#include <QtCore/QHash>
+
+#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
@@ -53,17 +57,15 @@ namespace Qt3DCore {
\inmodule Qt3DCore
*/
-QAbstractServiceProvider::QAbstractServiceProvider(int type, const QString &description)
- : d_ptr(new QAbstractServiceProviderPrivate(type, description))
+QAbstractServiceProvider::QAbstractServiceProvider(int type, const QString &description, QObject *parent)
+ : QObject(*new QAbstractServiceProviderPrivate(type, description), parent)
{
- d_ptr->q_ptr = this;
}
/* \internal */
-QAbstractServiceProvider::QAbstractServiceProvider(QAbstractServiceProviderPrivate &dd)
- : d_ptr(&dd)
+QAbstractServiceProvider::QAbstractServiceProvider(QAbstractServiceProviderPrivate &dd, QObject *parent)
+ : QObject(dd, parent)
{
- d_ptr->q_ptr = this;
}
QAbstractServiceProvider::~QAbstractServiceProvider()
@@ -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 c68b56ffd..9534b33ce 100644
--- a/src/core/services/qservicelocator_p.h
+++ b/src/core/services/qservicelocator_p.h
@@ -52,7 +52,8 @@
//
#include <Qt3DCore/qt3dcore_global.h>
-#include <QScopedPointer>
+#include <QtCore/qobject.h>
+#include <QtCore/qscopedpointer.h>
QT_BEGIN_NAMESPACE
@@ -60,8 +61,9 @@ namespace Qt3DCore {
class QAbstractServiceProviderPrivate;
-class QT3DCORESHARED_EXPORT QAbstractServiceProvider
+class QT3DCORESHARED_EXPORT QAbstractServiceProvider : public QObject
{
+ Q_OBJECT
public:
virtual ~QAbstractServiceProvider();
@@ -69,9 +71,8 @@ public:
QString description() const;
protected:
- QAbstractServiceProvider(int type, const QString &description);
- QAbstractServiceProvider(QAbstractServiceProviderPrivate &dd);
- QScopedPointer<QAbstractServiceProviderPrivate> d_ptr;
+ explicit QAbstractServiceProvider(int type, const QString &description, QObject* parent = nullptr);
+ explicit QAbstractServiceProvider(QAbstractServiceProviderPrivate &dd, QObject* parent = nullptr);
private:
Q_DISABLE_COPY(QAbstractServiceProvider)
@@ -83,6 +84,7 @@ class QOpenGLInformationService;
class QSystemInformationService;
class QServiceLocatorPrivate;
class QEventFilterService;
+class QDownloadHelperService;
class QT3DCORESHARED_EXPORT QServiceLocator
{
@@ -96,6 +98,7 @@ public:
CollisionService,
FrameAdvanceService,
EventFilterService,
+ DownloadHelperService,
#if !defined(Q_QDOC)
DefaultServiceCount, // Add additional default services before here
#endif
@@ -119,6 +122,7 @@ public:
QOpenGLInformationService *openGLInformation();
QAbstractFrameAdvanceService *frameAdvanceService();
QEventFilterService *eventFilterService();
+ QDownloadHelperService *downloadHelperService();
private:
Q_DISABLE_COPY(QServiceLocator)
diff --git a/src/core/services/qsysteminformationservice_p.h b/src/core/services/qsysteminformationservice_p.h
index dc384fb93..01e976b77 100644
--- a/src/core/services/qsysteminformationservice_p.h
+++ b/src/core/services/qsysteminformationservice_p.h
@@ -52,9 +52,10 @@
//
#include <Qt3DCore/qt3dcore_global.h>
-#include <Qt3DCore/private/qservicelocator_p.h>
#include <QtCore/qstringlist.h>
+#include <Qt3DCore/private/qservicelocator_p.h>
+
QT_BEGIN_NAMESPACE
namespace Qt3DCore {
@@ -63,6 +64,7 @@ class QSystemInformationServicePrivate;
class QT3DCORESHARED_EXPORT QSystemInformationService : public QAbstractServiceProvider
{
+ Q_OBJECT
public:
virtual QStringList aspectNames() const = 0;
virtual int threadPoolThreadCount() const = 0;
diff --git a/src/core/services/qsysteminformationservice_p_p.h b/src/core/services/qsysteminformationservice_p_p.h
index 897caf62b..e3ce9fe49 100644
--- a/src/core/services/qsysteminformationservice_p_p.h
+++ b/src/core/services/qsysteminformationservice_p_p.h
@@ -52,6 +52,7 @@
//
#include <Qt3DCore/qt3dcore_global.h>
+
#include <Qt3DCore/private/qabstractserviceprovider_p.h>
#include <Qt3DCore/private/qservicelocator_p.h>
diff --git a/src/core/services/qtickclockservice.cpp b/src/core/services/qtickclockservice.cpp
index 3691959ed..225e70ec2 100644
--- a/src/core/services/qtickclockservice.cpp
+++ b/src/core/services/qtickclockservice.cpp
@@ -38,9 +38,10 @@
****************************************************************************/
#include "qtickclockservice_p.h"
-#include "qtickclock_p.h"
-#include "qabstractframeadvanceservice_p.h"
-#include "qabstractframeadvanceservice_p_p.h"
+
+#include <Qt3DCore/private/qabstractframeadvanceservice_p.h>
+#include <Qt3DCore/private/qabstractframeadvanceservice_p_p.h>
+#include <Qt3DCore/private/qtickclock_p.h>
QT_BEGIN_NAMESPACE
diff --git a/src/core/services/qtickclockservice_p.h b/src/core/services/qtickclockservice_p.h
index b84018d0b..6f02643f4 100644
--- a/src/core/services/qtickclockservice_p.h
+++ b/src/core/services/qtickclockservice_p.h
@@ -51,7 +51,7 @@
// We mean it.
//
-#include "qabstractframeadvanceservice_p.h"
+#include <Qt3DCore/private/qabstractframeadvanceservice_p.h>
QT_BEGIN_NAMESPACE
@@ -61,6 +61,7 @@ class QTickClockServicePrivate;
class QTickClockService : public QAbstractFrameAdvanceService
{
+ Q_OBJECT
public:
QTickClockService();
~QTickClockService();
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