drop declarative component network support [ci reset]

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-02-19 15:08:27 +02:00
parent 21d7150307
commit 5e74cf5e11
25 changed files with 61 additions and 715 deletions

View file

@ -371,7 +371,6 @@ include/katie/QtDeclarative/QDeclarativeInfo
include/katie/QtDeclarative/QDeclarativeItem
include/katie/QtDeclarative/QDeclarativeListProperty
include/katie/QtDeclarative/QDeclarativeListReference
include/katie/QtDeclarative/QDeclarativeNetworkAccessManagerFactory
include/katie/QtDeclarative/QDeclarativeParserStatus
include/katie/QtDeclarative/QDeclarativeProperties
include/katie/QtDeclarative/QDeclarativeProperty
@ -394,7 +393,6 @@ include/katie/QtDeclarative/qdeclarativeimageprovider.h
include/katie/QtDeclarative/qdeclarativeinfo.h
include/katie/QtDeclarative/qdeclarativeitem.h
include/katie/QtDeclarative/qdeclarativelist.h
include/katie/QtDeclarative/qdeclarativenetworkaccessmanagerfactory.h
include/katie/QtDeclarative/qdeclarativeparserstatus.h
include/katie/QtDeclarative/qdeclarativeprivate.h
include/katie/QtDeclarative/qdeclarativeproperty.h

View file

@ -374,7 +374,6 @@ include/katie/QtDeclarative/QDeclarativeInfo
include/katie/QtDeclarative/QDeclarativeItem
include/katie/QtDeclarative/QDeclarativeListProperty
include/katie/QtDeclarative/QDeclarativeListReference
include/katie/QtDeclarative/QDeclarativeNetworkAccessManagerFactory
include/katie/QtDeclarative/QDeclarativeParserStatus
include/katie/QtDeclarative/QDeclarativeProperties
include/katie/QtDeclarative/QDeclarativeProperty
@ -397,7 +396,6 @@ include/katie/QtDeclarative/qdeclarativeimageprovider.h
include/katie/QtDeclarative/qdeclarativeinfo.h
include/katie/QtDeclarative/qdeclarativeitem.h
include/katie/QtDeclarative/qdeclarativelist.h
include/katie/QtDeclarative/qdeclarativenetworkaccessmanagerfactory.h
include/katie/QtDeclarative/qdeclarativeparserstatus.h
include/katie/QtDeclarative/qdeclarativeprivate.h
include/katie/QtDeclarative/qdeclarativeproperty.h

View file

@ -376,7 +376,6 @@ include/katie/QtDeclarative/QDeclarativeInfo
include/katie/QtDeclarative/QDeclarativeItem
include/katie/QtDeclarative/QDeclarativeListProperty
include/katie/QtDeclarative/QDeclarativeListReference
include/katie/QtDeclarative/QDeclarativeNetworkAccessManagerFactory
include/katie/QtDeclarative/QDeclarativeParserStatus
include/katie/QtDeclarative/QDeclarativeProperties
include/katie/QtDeclarative/QDeclarativeProperty
@ -399,7 +398,6 @@ include/katie/QtDeclarative/qdeclarativeimageprovider.h
include/katie/QtDeclarative/qdeclarativeinfo.h
include/katie/QtDeclarative/qdeclarativeitem.h
include/katie/QtDeclarative/qdeclarativelist.h
include/katie/QtDeclarative/qdeclarativenetworkaccessmanagerfactory.h
include/katie/QtDeclarative/qdeclarativeparserstatus.h
include/katie/QtDeclarative/qdeclarativeprivate.h
include/katie/QtDeclarative/qdeclarativeproperty.h

View file

@ -120,7 +120,6 @@ classlist = [
"QDeclarativeItem",
"QDeclarativeListProperty",
"QDeclarativeListReference",
"QDeclarativeNetworkAccessManagerFactory",
"QDeclarativeParserStatus",
"QDeclarativeProperties",
"QDeclarativeProperty",

View file

@ -16,7 +16,6 @@ set(DECLARATIVE_PUBLIC_HEADERS
QDeclarativeImageProvider
QDeclarativeInfo
QDeclarativeItem
QDeclarativeNetworkAccessManagerFactory
QDeclarativeParserStatus
QDeclarativeProperty
QDeclarativePropertyMap
@ -147,7 +146,6 @@ set(DECLARATIVE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeworkerscript_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeguard_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeimageprovider.h
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativenetworkaccessmanagerfactory.h
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativedirparser_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeextensioninterface.h
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeimport_p.h
@ -274,7 +272,6 @@ set(DECLARATIVE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativelistscriptclass.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeworkerscript.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeimageprovider.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativenetworkaccessmanagerfactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativedirparser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeextensionplugin.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qml/qdeclarativeimport.cpp

View file

@ -28,8 +28,6 @@
#include "qdeclarativeengine_p.h"
#include <QMovie>
#include <QNetworkRequest>
#include <QNetworkReply>
QT_BEGIN_NAMESPACE
@ -221,11 +219,6 @@ void QDeclarativeAnimatedImage::setSource(const QUrl &url)
delete d->_movie;
d->_movie = 0;
if (d->reply) {
d->reply->deleteLater();
d->reply = 0;
}
d->url = url;
emit sourceChanged(d->url);
@ -250,103 +243,37 @@ void QDeclarativeAnimatedImage::load()
if (d->progress != oldProgress)
emit progressChanged(d->progress);
} else {
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
QString lf = QDeclarativeEnginePrivate::urlToLocalFile(d->url);
if (!lf.isEmpty()) {
//### should be unified with movieRequestFinished
d->_movie = new QMovie(lf);
if (!d->_movie->isValid()){
qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString();
delete d->_movie;
d->_movie = 0;
d->status = Error;
if (d->status != oldStatus)
emit statusChanged(d->status);
return;
}
connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)),
this, SLOT(playingStatusChanged()));
connect(d->_movie, SIGNAL(frameChanged(int)),
this, SLOT(movieUpdate()));
d->_movie->setCacheMode(QMovie::CacheAll);
if(d->playing)
d->_movie->start();
else
d->_movie->jumpToFrame(0);
if(d->paused)
d->_movie->setPaused(true);
d->setPixmap(d->_movie->currentPixmap());
d->status = Ready;
d->progress = 1.0;
d->_movie = new QMovie(QDeclarativeEnginePrivate::urlToLocalFile(d->url));
if (!d->_movie->isValid()){
qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString();
delete d->_movie;
d->_movie = 0;
d->status = Error;
if (d->status != oldStatus)
emit statusChanged(d->status);
if (d->progress != oldProgress)
emit progressChanged(d->progress);
return;
}
#endif
d->status = Loading;
d->progress = 0;
emit statusChanged(d->status);
emit progressChanged(d->progress);
QNetworkRequest req(d->url);
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
d->reply = qmlEngine(this)->networkAccessManager()->get(req);
QObject::connect(d->reply, SIGNAL(finished()),
this, SLOT(movieRequestFinished()));
QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(requestProgress(qint64,qint64)));
connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)),
this, SLOT(playingStatusChanged()));
connect(d->_movie, SIGNAL(frameChanged(int)),
this, SLOT(movieUpdate()));
d->_movie->setCacheMode(QMovie::CacheAll);
if(d->playing)
d->_movie->start();
else
d->_movie->jumpToFrame(0);
if(d->paused)
d->_movie->setPaused(true);
d->setPixmap(d->_movie->currentPixmap());
d->status = Ready;
d->progress = 1.0;
if (d->status != oldStatus)
emit statusChanged(d->status);
if (d->progress != oldProgress)
emit progressChanged(d->progress);
}
}
#define ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION 16
void QDeclarativeAnimatedImage::movieRequestFinished()
{
Q_D(QDeclarativeAnimatedImage);
d->redirectCount++;
if (d->redirectCount < ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION) {
QVariant redirect = d->reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (redirect.isValid()) {
QUrl url = d->reply->url().resolved(redirect.toUrl());
d->reply->deleteLater();
d->reply = 0;
setSource(url);
return;
}
}
d->redirectCount=0;
d->_movie = new QMovie(d->reply);
if (!d->_movie->isValid()){
#ifndef QT_NO_DEBUG_STREAM
qmlInfo(this) << "Error Reading Animated Image File " << d->url;
#endif
delete d->_movie;
d->_movie = 0;
d->status = Error;
emit statusChanged(d->status);
return;
}
connect(d->_movie, SIGNAL(stateChanged(QMovie::MovieState)),
this, SLOT(playingStatusChanged()));
connect(d->_movie, SIGNAL(frameChanged(int)),
this, SLOT(movieUpdate()));
d->_movie->setCacheMode(QMovie::CacheAll);
if(d->playing)
d->_movie->start();
if (d->paused || !d->playing) {
d->_movie->jumpToFrame(d->preset_currentframe);
d->preset_currentframe = 0;
}
if(d->paused)
d->_movie->setPaused(true);
d->setPixmap(d->_movie->currentPixmap());
d->status = Ready;
emit statusChanged(d->status);
}
void QDeclarativeAnimatedImage::movieUpdate()
{
Q_D(QDeclarativeAnimatedImage);
@ -373,10 +300,8 @@ void QDeclarativeAnimatedImage::componentComplete()
QDeclarativeItem::componentComplete(); // NOT QDeclarativeImage
if (d->url.isValid())
load();
if (!d->reply) {
setCurrentFrame(d->preset_currentframe);
d->preset_currentframe = 0;
}
setCurrentFrame(d->preset_currentframe);
d->preset_currentframe = 0;
}
QT_END_NAMESPACE

View file

@ -71,7 +71,6 @@ Q_SIGNALS:
private Q_SLOTS:
void movieUpdate();
void movieRequestFinished();
void playingStatusChanged();
protected:

View file

@ -40,7 +40,6 @@
QT_BEGIN_NAMESPACE
class QMovie;
class QNetworkReply;
class QDeclarativeAnimatedImagePrivate : public QDeclarativeImagePrivate
{
@ -48,7 +47,7 @@ class QDeclarativeAnimatedImagePrivate : public QDeclarativeImagePrivate
public:
QDeclarativeAnimatedImagePrivate()
: playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0), redirectCount(0)
: playing(true), paused(false), preset_currentframe(0), _movie(0)
{
}
@ -56,8 +55,6 @@ public:
bool paused;
int preset_currentframe;
QMovie *_movie;
QNetworkReply *reply;
int redirectCount;
};
QT_END_NAMESPACE

View file

@ -25,8 +25,6 @@
#include "qdeclarativeinfo.h"
#include "qdeclarativeengine_p.h"
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QFile>
QT_BEGIN_NAMESPACE

View file

@ -24,8 +24,6 @@
#include "qdeclarativeimagebase_p.h"
#include <QtNetwork/qnetworkreply.h>
QT_BEGIN_NAMESPACE

View file

@ -24,8 +24,6 @@
#include "qdeclarativeimagebase_p.h"
#include <QtNetwork/qnetworkreply.h>
QT_BEGIN_NAMESPACE

View file

@ -40,7 +40,6 @@
QT_BEGIN_NAMESPACE
class QNetworkReply;
class QDeclarativeImageBasePrivate : public QDeclarativeImplicitSizeItemPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeImageBase)

View file

@ -52,7 +52,6 @@
QT_BEGIN_NAMESPACE
class QNetworkReply;
class QDeclarativeItemKeyFilter;
class QDeclarativeLayoutMirroringAttached;

View file

@ -39,7 +39,6 @@
#include "qdeclarativeglobal_p.h"
#include "qdeclarativeworkerscript_p.h"
#include "qdeclarativecomponent_p.h"
#include "qdeclarativenetworkaccessmanagerfactory.h"
#include "qdeclarativeimageprovider.h"
#include "qdeclarativedirparser_p.h"
#include "qdeclarativeextensioninterface.h"
@ -52,9 +51,6 @@
#include <QtCore/qmetaobject.h>
#include <QScriptClass>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QNetworkAccessManager>
#include <QStandardPaths>
#include <QTimer>
#include <QList>
@ -300,8 +296,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
outputWarningsToStdErr(true), contextClass(0), sharedContext(0), sharedScope(0),
objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0),
inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttached(0),
inBeginCreate(false), networkAccessManager(0), networkAccessManagerFactory(0),
typeLoader(e), importDatabase(e)
inBeginCreate(false), typeLoader(e), importDatabase(e)
{
if (!qt_QmlQtModule_registered) {
qt_QmlQtModule_registered = true;
@ -407,11 +402,6 @@ QScriptValue QDeclarativeScriptEngine::resolvedUrl(QScriptContext *ctxt, QScript
return QScriptValue(r.toString());
}
QNetworkAccessManager *QDeclarativeScriptEngine::networkAccessManager()
{
return p->getNetworkAccessManager();
}
QDeclarativeEnginePrivate::~QDeclarativeEnginePrivate()
{
Q_ASSERT(inProgressCreations == 0);
@ -617,69 +607,6 @@ QDeclarativeContext *QDeclarativeEngine::rootContext() const
return d->rootContext;
}
/*!
Sets the \a factory to use for creating QNetworkAccessManager(s).
QNetworkAccessManager is used for all network access by QML. By
implementing a factory it is possible to create custom
QNetworkAccessManager with specialized caching, proxy and cookie
support.
The factory must be set before executing the engine.
*/
void QDeclarativeEngine::setNetworkAccessManagerFactory(QDeclarativeNetworkAccessManagerFactory *factory)
{
Q_D(QDeclarativeEngine);
QMutexLocker locker(&d->mutex);
d->networkAccessManagerFactory = factory;
}
/*!
Returns the current QDeclarativeNetworkAccessManagerFactory.
\sa setNetworkAccessManagerFactory()
*/
QDeclarativeNetworkAccessManagerFactory *QDeclarativeEngine::networkAccessManagerFactory() const
{
Q_D(const QDeclarativeEngine);
return d->networkAccessManagerFactory;
}
QNetworkAccessManager *QDeclarativeEnginePrivate::createNetworkAccessManager(QObject *parent) const
{
if (networkAccessManagerFactory) {
return networkAccessManagerFactory->create(parent);
}
return new QNetworkAccessManager(parent);
}
QNetworkAccessManager *QDeclarativeEnginePrivate::getNetworkAccessManager() const
{
Q_Q(const QDeclarativeEngine);
if (!networkAccessManager)
networkAccessManager = createNetworkAccessManager(const_cast<QDeclarativeEngine*>(q));
return networkAccessManager;
}
/*!
Returns a common QNetworkAccessManager which can be used by any QML
element instantiated by this engine.
If a QDeclarativeNetworkAccessManagerFactory has been set and a
QNetworkAccessManager has not yet been created, the
QDeclarativeNetworkAccessManagerFactory will be used to create the
QNetworkAccessManager; otherwise the returned QNetworkAccessManager
will have no proxy or cache set.
\sa setNetworkAccessManagerFactory()
*/
QNetworkAccessManager *QDeclarativeEngine::networkAccessManager() const
{
Q_D(const QDeclarativeEngine);
return d->getNetworkAccessManager();
}
/*!
Sets the \a provider to use for images requested via the \e

View file

@ -42,8 +42,7 @@ class QUrl;
class QScriptEngine;
class QScriptContext;
class QDeclarativeImageProvider;
class QNetworkAccessManager;
class QDeclarativeNetworkAccessManagerFactory;
class Q_DECLARATIVE_EXPORT QDeclarativeEngine : public QObject
{
Q_OBJECT
@ -65,11 +64,6 @@ public:
bool importPlugin(const QString &filePath, const QString &uri, QString *errorString);
void setNetworkAccessManagerFactory(QDeclarativeNetworkAccessManagerFactory *);
QDeclarativeNetworkAccessManagerFactory *networkAccessManagerFactory() const;
QNetworkAccessManager *networkAccessManager() const;
void addImageProvider(const QString &id, QDeclarativeImageProvider *);
QDeclarativeImageProvider *imageProvider(const QString &id) const;
void removeImageProvider(const QString &id);

View file

@ -75,9 +75,6 @@ class QDeclarativeImportDatabase;
class QDeclarativeObjectScriptClass;
class QDeclarativeTypeNameScriptClass;
class QDeclarativeValueTypeScriptClass;
class QNetworkReply;
class QNetworkAccessManager;
class QDeclarativeNetworkAccessManagerFactory;
class QDeclarativeAbstractBinding;
class QScriptDeclarativeClass;
class QDeclarativeTypeNameScriptClass;
@ -104,8 +101,6 @@ public:
QDeclarativeEnginePrivate *p;
QUrl baseUrl;
virtual QNetworkAccessManager *networkAccessManager();
};
class Q_AUTOTEST_EXPORT QDeclarativeEnginePrivate : public QObjectPrivate
@ -196,11 +191,6 @@ public:
bool inBeginCreate;
QNetworkAccessManager *createNetworkAccessManager(QObject *parent) const;
QNetworkAccessManager *getNetworkAccessManager() const;
mutable QNetworkAccessManager *networkAccessManager;
QDeclarativeNetworkAccessManagerFactory *networkAccessManagerFactory;
QHash<QString,QSharedPointer<QDeclarativeImageProvider> > imageProviders;
QDeclarativeImageProvider::ImageType getImageProviderType(const QUrl &url) const;
QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size) const;

View file

@ -22,8 +22,6 @@
#include "qdeclarativeinclude_p.h"
#include <QtScript/qscriptengine.h>
#include <QtNetwork/qnetworkrequest.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtCore/qfile.h>
#include "qdeclarativeengine_p.h"
@ -32,9 +30,9 @@
QT_BEGIN_NAMESPACE
QDeclarativeInclude::QDeclarativeInclude(const QUrl &url,
QDeclarativeEngine *engine,
QScriptContext *ctxt)
: QObject(engine), m_engine(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0)
QDeclarativeEngine *engine,
QScriptContext *ctxt)
: QObject(engine), m_engine(engine), m_url(url)
{
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
m_context = ep->contextClass->contextFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
@ -43,20 +41,14 @@ QDeclarativeInclude::QDeclarativeInclude(const QUrl &url,
m_scope[1] = QScriptDeclarativeClass::scopeChainValue(ctxt, -5);
m_scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
m_network = QDeclarativeScriptEngine::get(m_scriptEngine)->networkAccessManager();
m_result = resultValue(m_scriptEngine);
QNetworkRequest request;
request.setUrl(url);
m_reply = m_network->get(request);
QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
include(ctxt, m_scriptEngine);
}
QDeclarativeInclude::~QDeclarativeInclude()
{
delete m_reply;
}
QScriptValue QDeclarativeInclude::resultValue(QScriptEngine *engine, Status status)
@ -86,63 +78,6 @@ QScriptValue QDeclarativeInclude::callback() const
return m_callback;
}
#define INCLUDE_MAXIMUM_REDIRECT_RECURSION 15
void QDeclarativeInclude::finished()
{
m_redirectCount++;
if (m_redirectCount < INCLUDE_MAXIMUM_REDIRECT_RECURSION) {
QVariant redirect = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (redirect.isValid()) {
m_url = m_url.resolved(redirect.toUrl());
delete m_reply;
QNetworkRequest request;
request.setUrl(m_url);
m_reply = m_network->get(request);
QObject::connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
return;
}
}
if (m_reply->error() == QNetworkReply::NoError) {
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(m_engine);
QByteArray data = m_reply->readAll();
QString code = QString::fromUtf8(data);
QString urlString = m_url.toString();
QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(m_scriptEngine);
scriptContext->pushScope(ep->contextClass->newUrlContext(m_context, 0, urlString));
scriptContext->pushScope(m_scope[0]);
scriptContext->pushScope(m_scope[1]);
scriptContext->setActivationObject(m_scope[1]);
QDeclarativeScriptParser::extractPragmas(code);
m_scriptEngine->evaluate(code, urlString, 1);
m_scriptEngine->popContext();
if (m_scriptEngine->hasUncaughtException()) {
m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, Exception));
m_result.setProperty(QLatin1String("exception"), m_scriptEngine->uncaughtException());
m_scriptEngine->clearExceptions();
} else {
m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, Ok));
}
} else {
m_result.setProperty(QLatin1String("status"), QScriptValue(m_scriptEngine, NetworkError));
}
callback(m_scriptEngine, m_callback, m_result);
disconnect();
deleteLater();
}
void QDeclarativeInclude::callback(QScriptEngine *engine, QScriptValue &callback, QScriptValue &status)
{
if (callback.isValid()) {

View file

@ -45,8 +45,6 @@ QT_BEGIN_NAMESPACE
class QDeclarativeEngine;
class QScriptContext;
class QScriptEngine;
class QNetworkAccessManager;
class QNetworkReply;
class QDeclarativeInclude : public QObject
{
Q_OBJECT
@ -72,17 +70,11 @@ public:
static QScriptValue include(QScriptContext *ctxt, QScriptEngine *engine);
static QScriptValue worker_include(QScriptContext *ctxt, QScriptEngine *engine);
public slots:
void finished();
private:
QDeclarativeEngine *m_engine;
QScriptEngine *m_scriptEngine;
QNetworkAccessManager *m_network;
QDeclarativeGuard<QNetworkReply> m_reply;
QUrl m_url;
int m_redirectCount;
QScriptValue m_callback;
QScriptValue m_result;
QDeclarativeGuardedContextData m_context;

View file

@ -1,83 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016 Ivailo Monev
**
** This file is part of the QtDeclarative module of the Katie Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qdeclarativenetworkaccessmanagerfactory.h"
QT_BEGIN_NAMESPACE
/*!
\class QDeclarativeNetworkAccessManagerFactory
\since 4.7
\brief The QDeclarativeNetworkAccessManagerFactory class creates QNetworkAccessManager instances for a QML engine.
A QML engine uses QNetworkAccessManager for all network access.
By implementing a factory, it is possible to provide the QML engine
with custom QNetworkAccessManager instances with specialized caching,
proxy and cookies support.
To implement a factory, subclass QDeclarativeNetworkAccessManagerFactory and
implement the virtual create() method, then assign it to the relevant QML
engine using QDeclarativeEngine::setNetworkAccessManagerFactory().
Note the QML engine may create QNetworkAccessManager instances
from multiple threads. Because of this, the implementation of the create()
method must be \l{Reentrancy and Thread-Safety}{reentrant}. In addition,
the developer should be careful if the signals of the object to be
returned from create() are connected to the slots of an object that may
be created in a different thread:
\list
\o The QML engine internally handles all requests, and cleans up any
QNetworkReply objects it creates. Receiving the
QNetworkAccessManager::finished() signal in another thread may not
provide the receiver with a valid reply object if it has already
been deleted.
\o Authentication details provided to QNetworkAccessManager::authenticationRequired()
must be provided immediately, so this signal cannot be connected as a
Qt::QueuedConnection (or as the default Qt::AutoConnection from another
thread).
\endlist
For more information about signals and threads, see
\l {Threads and QObjects} and \l {Signals and Slots Across Threads}.
\sa {declarative/cppextensions/networkaccessmanagerfactory}{NetworkAccessManagerFactory example}
*/
/*!
Destroys the factory. The default implementation does nothing.
*/
QDeclarativeNetworkAccessManagerFactory::~QDeclarativeNetworkAccessManagerFactory()
{
}
/*!
\fn QNetworkAccessManager *QDeclarativeNetworkAccessManagerFactory::create(QObject *parent)
Creates and returns a network access manager with the specified \a parent.
This method must return a new QNetworkAccessManager instance each time
it is called.
Note: this method may be called by multiple threads, so ensure the
implementation of this method is reentrant.
*/
QT_END_NAMESPACE

View file

@ -1,43 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016 Ivailo Monev
**
** This file is part of the QtDeclarative module of the Katie Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QDECLARATIVENETWORKACCESSMANAGERFACTORY_H
#define QDECLARATIVENETWORKACCESSMANAGERFACTORY_H
#include <QtCore/qobject.h>
QT_BEGIN_NAMESPACE
class QNetworkAccessManager;
class Q_DECLARATIVE_EXPORT QDeclarativeNetworkAccessManagerFactory
{
public:
virtual ~QDeclarativeNetworkAccessManagerFactory();
virtual QNetworkAccessManager *create(QObject *parent) = 0;
};
QT_END_NAMESPACE
#endif // QDECLARATIVENETWORKACCESSMANAGERFACTORY_H

View file

@ -293,50 +293,11 @@ Invoked if there is a network error while fetching this blob.
The default implementation sets an appropriate QDeclarativeError.
*/
void QDeclarativeDataBlob::networkError(QNetworkReply::NetworkError networkError)
void QDeclarativeDataBlob::networkError()
{
Q_UNUSED(networkError);
QDeclarativeError error;
error.setUrl(m_finalUrl);
const char *errorString = 0;
switch (networkError) {
default:
errorString = "Network error";
break;
case QNetworkReply::ConnectionRefusedError:
errorString = "Connection refused";
break;
case QNetworkReply::RemoteHostClosedError:
errorString = "Remote host closed the connection";
break;
case QNetworkReply::HostNotFoundError:
errorString = "Host not found";
break;
case QNetworkReply::TimeoutError:
errorString = "Timeout";
break;
case QNetworkReply::ProxyConnectionRefusedError:
case QNetworkReply::ProxyConnectionClosedError:
case QNetworkReply::ProxyNotFoundError:
case QNetworkReply::ProxyTimeoutError:
case QNetworkReply::ProxyAuthenticationRequiredError:
case QNetworkReply::UnknownProxyError:
errorString = "Proxy error";
break;
case QNetworkReply::ContentAccessDenied:
errorString = "Access denied";
break;
case QNetworkReply::ContentNotFoundError:
errorString = "File not found";
break;
case QNetworkReply::AuthenticationRequiredError:
errorString = "Authentication required";
break;
};
error.setDescription(QLatin1String(errorString));
error.setDescription(QLatin1String("File not found"));
setError(error);
}
@ -481,8 +442,6 @@ QDeclarativeDataLoader::QDeclarativeDataLoader(QDeclarativeEngine *engine)
/*! \internal */
QDeclarativeDataLoader::~QDeclarativeDataLoader()
{
for (NetworkReplies::Iterator iter = m_networkReplies.begin(); iter != m_networkReplies.end(); ++iter)
(*iter)->release();
}
/*!
@ -502,100 +461,17 @@ void QDeclarativeDataLoader::load(QDeclarativeDataBlob *blob)
return;
}
QString lf = QDeclarativeEnginePrivate::urlToLocalFile(blob->m_url);
QFile file(QDeclarativeEnginePrivate::urlToLocalFile(blob->m_url));
if (file.open(QFile::ReadOnly)) {
QByteArray data = file.readAll();
if (!lf.isEmpty()) {
QFile file(lf);
if (file.open(QFile::ReadOnly)) {
QByteArray data = file.readAll();
blob->m_progress = 1.;
blob->downloadProgressChanged(1.);
blob->m_progress = 1.;
blob->downloadProgressChanged(1.);
setData(blob, data);
} else {
blob->networkError(QNetworkReply::ContentNotFoundError);
}
} else {
blob->m_manager = this;
QNetworkReply *reply = m_engine->networkAccessManager()->get(QNetworkRequest(blob->m_url));
m_networkReplies.insert(reply, blob);
blob->addref();
if (reply->isFinished()) {
// Short-circuit synchronous replies.
qint64 size = reply->size();
networkReplyProgress(reply, size, size);
networkReplyFinished(reply);
} else {
QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(networkReplyProgress(qint64,qint64)));
QObject::connect(reply, SIGNAL(finished()),
this, SLOT(networkReplyFinished()));
}
}
}
#define DATALOADER_MAXIMUM_REDIRECT_RECURSION 16
void QDeclarativeDataLoader::networkReplyFinished(QNetworkReply *reply)
{
reply->deleteLater();
QDeclarativeDataBlob *blob = m_networkReplies.take(reply);
Q_ASSERT(blob);
blob->m_redirectCount++;
if (blob->m_redirectCount < DATALOADER_MAXIMUM_REDIRECT_RECURSION) {
QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (redirect.isValid()) {
QUrl url = reply->url().resolved(redirect.toUrl());
blob->m_finalUrl = url;
QNetworkReply *reply = m_engine->networkAccessManager()->get(QNetworkRequest(url));
QObject::connect(reply, SIGNAL(finished()), this, SLOT(networkReplyFinished()));
m_networkReplies.insert(reply, blob);
return;
}
}
if (reply->error()) {
blob->networkError(reply->error());
} else {
QByteArray data = reply->readAll();
setData(blob, data);
} else {
blob->networkError();
}
blob->release();
}
void QDeclarativeDataLoader::networkReplyFinished()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
networkReplyFinished(reply);
}
void QDeclarativeDataLoader::networkReplyProgress(QNetworkReply *reply, qint64 bytesReceived, qint64 bytesTotal)
{
QDeclarativeDataBlob *blob = m_networkReplies.value(reply);
Q_ASSERT(blob);
if (bytesTotal != 0) {
blob->m_progress = bytesReceived / bytesTotal;
blob->downloadProgressChanged(blob->m_progress);
}
}
void QDeclarativeDataLoader::networkReplyProgress(qint64 bytesReceived, qint64 bytesTotal)
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
networkReplyProgress(reply, bytesReceived, bytesTotal);
}
/*!

View file

@ -34,7 +34,6 @@
//
#include <QtCore/qobject.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtDeclarative/qdeclarativeerror.h>
#include <QtDeclarative/qdeclarativeengine.h>
#include "qdeclarativescriptparser_p.h"
@ -97,7 +96,7 @@ protected:
virtual void dataReceived(const QByteArray &) = 0;
virtual void done();
virtual void networkError(QNetworkReply::NetworkError);
virtual void networkError();
virtual void dependencyError(QDeclarativeDataBlob *);
virtual void dependencyComplete(QDeclarativeDataBlob *);
@ -146,18 +145,10 @@ public:
QDeclarativeEngine *engine() const;
private slots:
void networkReplyFinished();
void networkReplyProgress(qint64,qint64);
private:
void setData(QDeclarativeDataBlob *, const QByteArray &);
void networkReplyFinished(QNetworkReply *);
void networkReplyProgress(QNetworkReply *, qint64, qint64);
QDeclarativeEngine *m_engine;
typedef QHash<QNetworkReply *, QDeclarativeDataBlob *> NetworkReplies;
NetworkReplies m_networkReplies;
};

View file

@ -34,10 +34,7 @@
#include <QtScript/qscriptvalueiterator.h>
#include <QtCore/qfile.h>
#include <QtCore/qdatetime.h>
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtDeclarative/qdeclarativeinfo.h>
#include "qdeclarativenetworkaccessmanagerfactory.h"
QT_BEGIN_NAMESPACE
@ -110,21 +107,9 @@ public:
struct ScriptEngine : public QDeclarativeScriptEngine
{
ScriptEngine(QDeclarativeWorkerScriptEnginePrivate *parent) : QDeclarativeScriptEngine(0), p(parent), accessManager(0) {}
~ScriptEngine() { delete accessManager; }
ScriptEngine(QDeclarativeWorkerScriptEnginePrivate *parent) : QDeclarativeScriptEngine(0), p(parent) {}
~ScriptEngine() { }
QDeclarativeWorkerScriptEnginePrivate *p;
QNetworkAccessManager *accessManager;
virtual QNetworkAccessManager *networkAccessManager() {
if (!accessManager) {
if (p->qmlengine && p->qmlengine->networkAccessManagerFactory()) {
accessManager = p->qmlengine->networkAccessManagerFactory()->create(this);
} else {
accessManager = new QNetworkAccessManager(this);
}
}
return accessManager;
}
};
ScriptEngine *workerEngine;
static QDeclarativeWorkerScriptEnginePrivate *get(QScriptEngine *e) {

View file

@ -20,7 +20,6 @@
****************************************************************************/
#include "qdeclarativepixmapcache_p.h"
#include "qdeclarativenetworkaccessmanagerfactory.h"
#include "qdeclarativeimageprovider.h"
#include "qdeclarativeengine.h"
@ -30,7 +29,6 @@
#include <QCoreApplication>
#include <QImageReader>
#include <QHash>
#include <QNetworkReply>
#include <QPixmapCache>
#include <QFile>
#include <QThread>
@ -104,8 +102,6 @@ public:
QDeclarativePixmapReaderThreadObject(QDeclarativePixmapReader *);
void processJobs();
virtual bool event(QEvent *e);
private slots:
void networkRequestDone();
private:
QDeclarativePixmapReader *reader;
};
@ -131,7 +127,6 @@ private:
friend class QDeclarativePixmapReaderThreadObject;
void processJobs();
void processJob(QDeclarativePixmapReply *, const QUrl &, const QSize &);
void networkRequestDone(QNetworkReply *);
QList<QDeclarativePixmapReply*> jobs;
QList<QDeclarativePixmapReply*> cancelled;
@ -142,16 +137,6 @@ private:
QDeclarativePixmapReaderThreadObject *threadObject;
QWaitCondition waitCondition;
QNetworkAccessManager *networkAccessManager();
QNetworkAccessManager *accessManager;
QHash<QNetworkReply*,QDeclarativePixmapReply*> replies;
static int replyDownloadProgress;
static int replyFinished;
static int downloadProgress;
static int threadNetworkRequestDone;
static QHash<QDeclarativeEngine *,QDeclarativePixmapReader*> readers;
public:
static QMutex readerMutex;
@ -220,11 +205,6 @@ int QDeclarativePixmapReply::downloadProgressIndex = -1;
QHash<QDeclarativeEngine *,QDeclarativePixmapReader*> QDeclarativePixmapReader::readers;
QMutex QDeclarativePixmapReader::readerMutex;
int QDeclarativePixmapReader::replyDownloadProgress = -1;
int QDeclarativePixmapReader::replyFinished = -1;
int QDeclarativePixmapReader::downloadProgress = -1;
int QDeclarativePixmapReader::threadNetworkRequestDone = -1;
void QDeclarativePixmapReply::postReply(ReadError error, const QString &errorString,
const QSize &implicitSize, const QImage &image)
@ -238,15 +218,6 @@ QDeclarativePixmapReply::Event::Event(ReadError e, const QString &s, const QSize
{
}
QNetworkAccessManager *QDeclarativePixmapReader::networkAccessManager()
{
if (!accessManager) {
Q_ASSERT(threadObject);
accessManager = QDeclarativeEnginePrivate::get(engine)->createNetworkAccessManager(threadObject);
}
return accessManager;
}
static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize,
const QSize &requestSize)
{
@ -292,8 +263,7 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e
QDeclarativePixmapReader::QDeclarativePixmapReader(QDeclarativeEngine *eng)
: QThread(eng),
engine(eng),
threadObject(0),
accessManager(0)
threadObject(0)
{
eventLoopQuitHack = new QObject;
eventLoopQuitHack->moveToThread(this);
@ -314,13 +284,6 @@ QDeclarativePixmapReader::~QDeclarativePixmapReader()
delete reply;
}
jobs.clear();
QList<QDeclarativePixmapReply*> activeJobs = replies.values();
foreach (QDeclarativePixmapReply *reply, activeJobs) {
if (reply->loading) {
cancelled.append(reply);
reply->data = 0;
}
}
if (threadObject) {
threadObject->processJobs();
}
@ -330,56 +293,6 @@ QDeclarativePixmapReader::~QDeclarativePixmapReader()
wait();
}
void QDeclarativePixmapReader::networkRequestDone(QNetworkReply *reply)
{
QDeclarativePixmapReply *job = replies.take(reply);
if (job) {
job->redirectCount++;
if (job->redirectCount < IMAGEREQUEST_MAX_REDIRECT_RECURSION) {
QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (redirect.isValid()) {
QUrl url = reply->url().resolved(redirect.toUrl());
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
reply->deleteLater();
reply = networkAccessManager()->get(req);
QMetaObject::connect(reply, replyDownloadProgress, job, downloadProgress);
QMetaObject::connect(reply, replyFinished, threadObject, threadNetworkRequestDone);
replies.insert(reply, job);
return;
}
}
QImage image;
QDeclarativePixmapReply::ReadError error = QDeclarativePixmapReply::NoError;
QString errorString;
QSize readSize;
if (reply->error()) {
error = QDeclarativePixmapReply::Loading;
errorString = reply->errorString();
} else {
QByteArray all = reply->readAll();
QBuffer buff(&all);
buff.open(QIODevice::ReadOnly);
if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, job->requestSize)) {
error = QDeclarativePixmapReply::Decoding;
}
}
// send completion event to the QDeclarativePixmapReply
mutex.lock();
if (!cancelled.contains(job)) job->postReply(error, errorString, readSize, image);
mutex.unlock();
}
reply->deleteLater();
// kick off event loop again incase we have dropped below max request count
threadObject->processJobs();
}
QDeclarativePixmapReaderThreadObject::QDeclarativePixmapReaderThreadObject(QDeclarativePixmapReader *i)
: reader(i)
{
@ -400,37 +313,25 @@ bool QDeclarativePixmapReaderThreadObject::event(QEvent *e)
}
}
void QDeclarativePixmapReaderThreadObject::networkRequestDone()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
reader->networkRequestDone(reply);
}
void QDeclarativePixmapReader::processJobs()
{
QMutexLocker locker(&mutex);
while (true) {
if (cancelled.isEmpty() && (jobs.isEmpty() || replies.count() >= IMAGEREQUEST_MAX_REQUEST_COUNT))
if (cancelled.isEmpty() && jobs.isEmpty())
return; // Nothing else to do
// Clean cancelled jobs
if (cancelled.count()) {
for (int i = 0; i < cancelled.count(); ++i) {
QDeclarativePixmapReply *job = cancelled.at(i);
QNetworkReply *reply = replies.key(job, 0);
if (reply && reply->isRunning()) {
// cancel any jobs already started
replies.remove(reply);
reply->close();
}
// deleteLater, since not owned by this thread
job->deleteLater();
}
cancelled.clear();
}
if (!jobs.isEmpty() && replies.count() < IMAGEREQUEST_MAX_REQUEST_COUNT) {
if (!jobs.isEmpty()) {
QDeclarativePixmapReply *runningJob = jobs.takeLast();
runningJob->loading = true;
QUrl url = runningJob->url;
@ -462,33 +363,22 @@ void QDeclarativePixmapReader::processJob(QDeclarativePixmapReply *runningJob, c
if (!cancelled.contains(runningJob)) runningJob->postReply(errorCode, errorStr, readSize, image);
mutex.unlock();
} else {
QString lf = QDeclarativeEnginePrivate::urlToLocalFile(url);
if (!lf.isEmpty()) {
// Image is local - load/decode immediately
QImage image;
QDeclarativePixmapReply::ReadError errorCode = QDeclarativePixmapReply::NoError;
QString errorStr;
QFile f(lf);
QSize readSize;
if (f.open(QIODevice::ReadOnly)) {
if (!readImage(url, &f, &image, &errorStr, &readSize, requestSize))
errorCode = QDeclarativePixmapReply::Loading;
} else {
errorStr = QDeclarativePixmap::tr("Cannot open: %1").arg(url.toString());
// Image is local - load/decode immediately
QImage image;
QDeclarativePixmapReply::ReadError errorCode = QDeclarativePixmapReply::NoError;
QString errorStr;
QFile f(QDeclarativeEnginePrivate::urlToLocalFile(url));
QSize readSize;
if (f.open(QIODevice::ReadOnly)) {
if (!readImage(url, &f, &image, &errorStr, &readSize, requestSize))
errorCode = QDeclarativePixmapReply::Loading;
}
mutex.lock();
if (!cancelled.contains(runningJob)) runningJob->postReply(errorCode, errorStr, readSize, image);
mutex.unlock();
} else {
// Network resource
QNetworkRequest req(url);
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
QNetworkReply *reply = networkAccessManager()->get(req);
QMetaObject::connect(reply, replyDownloadProgress, runningJob, downloadProgress);
QMetaObject::connect(reply, replyFinished, threadObject, threadNetworkRequestDone);
replies.insert(reply, runningJob);
errorStr = QDeclarativePixmap::tr("Cannot open: %1").arg(url.toString());
errorCode = QDeclarativePixmapReply::Loading;
}
mutex.lock();
if (!cancelled.contains(runningJob)) runningJob->postReply(errorCode, errorStr, readSize, image);
mutex.unlock();
}
}
@ -539,16 +429,6 @@ void QDeclarativePixmapReader::cancel(QDeclarativePixmapReply *reply)
void QDeclarativePixmapReader::run()
{
if (replyDownloadProgress == -1) {
const QMetaObject *nr = &QNetworkReply::staticMetaObject;
const QMetaObject *pr = &QDeclarativePixmapReply::staticMetaObject;
const QMetaObject *ir = &QDeclarativePixmapReaderThreadObject::staticMetaObject;
replyDownloadProgress = nr->indexOfSignal("downloadProgress(qint64,qint64)");
replyFinished = nr->indexOfSignal("finished()");
downloadProgress = pr->indexOfSignal("downloadProgress(qint64,qint64)");
threadNetworkRequestDone = ir->indexOfSlot("networkRequestDone()");
}
mutex.lock();
threadObject = new QDeclarativePixmapReaderThreadObject(this);
mutex.unlock();

View file

@ -165,7 +165,6 @@ static const struct ClassTblData {
{ QLatin1String("QDeclarativeInfo"), QLatin1String("QtDeclarative/qdeclarativeinfo.h") },
{ QLatin1String("QDeclarativeItem"), QLatin1String("QtDeclarative/qdeclarativeitem.h") },
{ QLatin1String("QDeclarativeListReference"), QLatin1String("QtDeclarative/qdeclarativelist.h") },
{ QLatin1String("QDeclarativeNetworkAccessManagerFactory"), QLatin1String("QtDeclarative/qdeclarativenetworkaccessmanagerfactory.h") },
{ QLatin1String("QDeclarativeParserStatus"), QLatin1String("QtDeclarative/qdeclarativeparserstatus.h") },
{ QLatin1String("QDeclarativeProperty"), QLatin1String("QtDeclarative/qdeclarativeproperty.h") },
{ QLatin1String("QDeclarativePropertyMap"), QLatin1String("QtDeclarative/qdeclarativepropertymap.h") },