diff options
author | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-02-16 17:40:12 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-03-04 13:09:51 +0000 |
commit | c7ac28fa354b96de37dc6cde5e3728da8daaacbb (patch) | |
tree | ba34e8d5e14700a5e786ffbc78204e436cabf2e9 /src/quick | |
parent | 9456832163d3476e8f81440dd2978092a9000b72 (diff) |
QtLite: no_network option for QtDeclarative
This patch adds the support for a no_network option for
QtDeclarative, and the necessary #ifndef all around the
code.
no_network changes the interface of some classes, therefore
using it breaks source compatibility.
Change-Id: Iff612fb07041b8a7db99bd595bf038efaac2dd8a
Reviewed-by: Risto Avila <risto.avila@theqtcompany.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/items/qquickanimatedimage.cpp | 11 | ||||
-rw-r--r-- | src/quick/items/qquickanimatedimage_p_p.h | 11 | ||||
-rw-r--r-- | src/quick/items/qquickborderimage.cpp | 10 | ||||
-rw-r--r-- | src/quick/items/qquickborderimage_p.h | 2 | ||||
-rw-r--r-- | src/quick/items/qquickborderimage_p_p.h | 19 | ||||
-rw-r--r-- | src/quick/quick.pro | 7 | ||||
-rw-r--r-- | src/quick/util/qquickfontloader.cpp | 37 | ||||
-rw-r--r-- | src/quick/util/qquickpixmapcache.cpp | 43 |
8 files changed, 115 insertions, 25 deletions
diff --git a/src/quick/items/qquickanimatedimage.cpp b/src/quick/items/qquickanimatedimage.cpp index 3ae2512c98..42033b6135 100644 --- a/src/quick/items/qquickanimatedimage.cpp +++ b/src/quick/items/qquickanimatedimage.cpp @@ -47,8 +47,10 @@ #include <QtQml/qqmlfile.h> #include <QtQml/qqmlengine.h> #include <QtGui/qmovie.h> +#ifndef QT_NO_NETWORK #include <QtNetwork/qnetworkrequest.h> #include <QtNetwork/qnetworkreply.h> +#endif QT_BEGIN_NAMESPACE @@ -144,8 +146,10 @@ QQuickAnimatedImage::QQuickAnimatedImage(QQuickItem *parent) QQuickAnimatedImage::~QQuickAnimatedImage() { Q_D(QQuickAnimatedImage); +#ifndef QT_NO_NETWORK if (d->reply) d->reply->deleteLater(); +#endif delete d->_movie; qDeleteAll(d->frameMap); d->frameMap.clear(); @@ -264,10 +268,12 @@ void QQuickAnimatedImage::setSource(const QUrl &url) if (url == d->url) return; +#ifndef QT_NO_NETWORK if (d->reply) { d->reply->deleteLater(); d->reply = 0; } +#endif d->setImage(QImage()); qDeleteAll(d->frameMap); @@ -318,6 +324,7 @@ void QQuickAnimatedImage::load() d->_movie = new QMovie(lf); movieRequestFinished(); } else { +#ifndef QT_NO_NETWORK if (d->status != Loading) { d->status = Loading; emit statusChanged(d->status); @@ -334,6 +341,7 @@ void QQuickAnimatedImage::load() this, SLOT(movieRequestFinished())); QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(requestProgress(qint64,qint64))); +#endif } } } @@ -342,8 +350,10 @@ void QQuickAnimatedImage::load() void QQuickAnimatedImage::movieRequestFinished() { + Q_D(QQuickAnimatedImage); +#ifndef QT_NO_NETWORK if (d->reply) { d->redirectCount++; if (d->redirectCount < ANIMATEDIMAGE_MAXIMUM_REDIRECT_RECURSION) { @@ -359,6 +369,7 @@ void QQuickAnimatedImage::movieRequestFinished() d->redirectCount=0; d->_movie = new QMovie(d->reply); } +#endif if (!d->_movie->isValid()) { qmlInfo(this) << "Error Reading Animated Image File " << d->url.toString(); diff --git a/src/quick/items/qquickanimatedimage_p_p.h b/src/quick/items/qquickanimatedimage_p_p.h index 9474254252..9b284f966d 100644 --- a/src/quick/items/qquickanimatedimage_p_p.h +++ b/src/quick/items/qquickanimatedimage_p_p.h @@ -58,7 +58,9 @@ QT_BEGIN_NAMESPACE class QMovie; +#ifndef QT_NO_NETWORK class QNetworkReply; +#endif class QQuickAnimatedImagePrivate : public QQuickImagePrivate { @@ -66,7 +68,10 @@ class QQuickAnimatedImagePrivate : public QQuickImagePrivate public: QQuickAnimatedImagePrivate() - : playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0), redirectCount(0), oldPlaying(false) + : playing(true), paused(false), preset_currentframe(0), _movie(0), oldPlaying(false) +#ifndef QT_NO_NETWORK + , reply(0), redirectCount(0) +#endif { } @@ -76,9 +81,11 @@ public: bool paused; int preset_currentframe; QMovie *_movie; + bool oldPlaying; +#ifndef QT_NO_NETWORK QNetworkReply *reply; int redirectCount; - bool oldPlaying; +#endif QMap<int, QQuickPixmap *> frameMap; }; diff --git a/src/quick/items/qquickborderimage.cpp b/src/quick/items/qquickborderimage.cpp index 66f414d816..5f8dd7b989 100644 --- a/src/quick/items/qquickborderimage.cpp +++ b/src/quick/items/qquickborderimage.cpp @@ -43,7 +43,9 @@ #include <QtQml/qqmlinfo.h> #include <QtQml/qqmlfile.h> #include <QtQml/qqmlengine.h> +#ifndef QT_NO_NETWORK #include <QtNetwork/qnetworkreply.h> +#endif #include <QtCore/qfile.h> #include <QtCore/qmath.h> #include <QtGui/qguiapplication.h> @@ -169,9 +171,11 @@ QQuickBorderImage::QQuickBorderImage(QQuickItem *parent) QQuickBorderImage::~QQuickBorderImage() { +#ifndef QT_NO_NETWORK Q_D(QQuickBorderImage); if (d->sciReply) d->sciReply->deleteLater(); +#endif } /*! @@ -270,10 +274,12 @@ void QQuickBorderImage::setSource(const QUrl &url) if (url == d->url) return; +#ifndef QT_NO_NETWORK if (d->sciReply) { d->sciReply->deleteLater(); d->sciReply = 0; } +#endif d->url = url; d->sciurl = QUrl(); @@ -311,6 +317,7 @@ void QQuickBorderImage::load() setGridScaledImage(QQuickGridScaledImage(&file)); return; } else { +#ifndef QT_NO_NETWORK if (d->progress != 0.0) { d->progress = 0.0; emit progressChanged(d->progress); @@ -320,6 +327,7 @@ void QQuickBorderImage::load() d->sciReply = qmlEngine(this)->networkAccessManager()->get(req); qmlobject_connect(d->sciReply, QNetworkReply, SIGNAL(finished()), this, QQuickBorderImage, SLOT(sciRequestFinished())) +#endif } } else { QQuickPixmap::Options options; @@ -529,6 +537,7 @@ void QQuickBorderImage::requestFinished() pixmapChange(); } +#ifndef QT_NO_NETWORK #define BORDERIMAGE_MAX_REDIRECT 16 void QQuickBorderImage::sciRequestFinished() @@ -558,6 +567,7 @@ void QQuickBorderImage::sciRequestFinished() setGridScaledImage(sci); } } +#endif // QT_NO_NETWORK void QQuickBorderImage::doUpdate() { diff --git a/src/quick/items/qquickborderimage_p.h b/src/quick/items/qquickborderimage_p.h index 7f8b172a21..f2764660f6 100644 --- a/src/quick/items/qquickborderimage_p.h +++ b/src/quick/items/qquickborderimage_p.h @@ -101,7 +101,9 @@ private: private Q_SLOTS: void doUpdate(); void requestFinished() Q_DECL_OVERRIDE; +#ifndef QT_NO_NETWORK void sciRequestFinished(); +#endif private: Q_DISABLE_COPY(QQuickBorderImage) diff --git a/src/quick/items/qquickborderimage_p_p.h b/src/quick/items/qquickborderimage_p_p.h index 478de88a52..1dc530e34e 100644 --- a/src/quick/items/qquickborderimage_p_p.h +++ b/src/quick/items/qquickborderimage_p_p.h @@ -58,17 +58,20 @@ QT_BEGIN_NAMESPACE +#ifndef QT_NO_NETWORK class QNetworkReply; +#endif class QQuickBorderImagePrivate : public QQuickImageBasePrivate { Q_DECLARE_PUBLIC(QQuickBorderImage) public: QQuickBorderImagePrivate() - : border(0), sciReply(0), - horizontalTileMode(QQuickBorderImage::Stretch), - verticalTileMode(QQuickBorderImage::Stretch), - redirectCount(0), pixmapChanged(false) + : border(0), horizontalTileMode(QQuickBorderImage::Stretch), + verticalTileMode(QQuickBorderImage::Stretch), pixmapChanged(false) +#ifndef QT_NO_NETWORK + , sciReply(0), redirectCount(0) +#endif { } @@ -90,12 +93,14 @@ public: QQuickScaleGrid *border; QUrl sciurl; - QNetworkReply *sciReply; QQuickBorderImage::TileMode horizontalTileMode; QQuickBorderImage::TileMode verticalTileMode; - int redirectCount; - bool pixmapChanged : 1; + +#ifndef QT_NO_NETWORK + QNetworkReply *sciReply; + int redirectCount; +#endif }; QT_END_NAMESPACE diff --git a/src/quick/quick.pro b/src/quick/quick.pro index 1c14ff8d57..90ba867ea8 100644 --- a/src/quick/quick.pro +++ b/src/quick/quick.pro @@ -1,7 +1,12 @@ TARGET = QtQuick QT = core-private gui-private qml-private -QT_PRIVATE = network +!no_network { + QT_PRIVATE = network +} +no_network { + DEFINES += QT_NO_NETWORK +} DEFINES += QT_NO_URL_CAST_FROM_STRING QT_NO_INTEGER_EVENT_COORDINATES win32-msvc*:DEFINES *= _CRT_SECURE_NO_WARNINGS diff --git a/src/quick/util/qquickfontloader.cpp b/src/quick/util/qquickfontloader.cpp index 64fd458ef0..b7367f3934 100644 --- a/src/quick/util/qquickfontloader.cpp +++ b/src/quick/util/qquickfontloader.cpp @@ -45,14 +45,18 @@ #include <QStringList> #include <QUrl> #include <QDebug> -#include <QNetworkRequest> -#include <QNetworkReply> + #include <QFontDatabase> #include <private/qobject_p.h> #include <qqmlinfo.h> #include <qqmlfile.h> +#ifndef QT_NO_NETWORK +#include <QNetworkRequest> +#include <QNetworkReply> +#endif + #include <QtCore/QCoreApplication> QT_BEGIN_NAMESPACE @@ -66,28 +70,37 @@ Q_OBJECT public: explicit QQuickFontObject(int _id = -1); +#ifndef QT_NO_NETWORK void download(const QUrl &url, QNetworkAccessManager *manager); Q_SIGNALS: void fontDownloaded(const QString&, QQuickFontLoader::Status); +private: + int redirectCount; + QNetworkReply *reply; + private Q_SLOTS: void replyFinished(); +#endif // QT_NO_NETWORK public: int id; -private: - QNetworkReply *reply; - int redirectCount; - Q_DISABLE_COPY(QQuickFontObject) }; QQuickFontObject::QQuickFontObject(int _id) - : QObject(0), id(_id), reply(0), redirectCount(0) {} + : QObject(0) +#ifndef QT_NO_NETWORK + ,redirectCount(0), reply(0) +#endif + ,id(_id) +{ +} +#ifndef QT_NO_NETWORK void QQuickFontObject::download(const QUrl &url, QNetworkAccessManager *manager) { QNetworkRequest req(url); @@ -128,7 +141,7 @@ void QQuickFontObject::replyFinished() reply = 0; } } - +#endif // QT_NO_NETWORK class QQuickFontLoaderPrivate : public QObjectPrivate { @@ -255,6 +268,7 @@ void QQuickFontLoader::setSource(const QUrl &url) } } else { if (!fontLoaderFonts()->map.contains(d->url)) { +#ifndef QT_NO_NETWORK QQuickFontObject *fo = new QQuickFontObject; fontLoaderFonts()->map[d->url] = fo; fo->download(d->url, qmlEngine(this)->networkAccessManager()); @@ -262,13 +276,20 @@ void QQuickFontLoader::setSource(const QUrl &url) emit statusChanged(); QObject::connect(fo, SIGNAL(fontDownloaded(QString,QQuickFontLoader::Status)), this, SLOT(updateFontInfo(QString,QQuickFontLoader::Status))); +#else +// Silently fail if compiled with no_network +#endif } else { QQuickFontObject *fo = fontLoaderFonts()->map[d->url]; if (fo->id == -1) { +#ifndef QT_NO_NETWORK d->status = Loading; emit statusChanged(); QObject::connect(fo, SIGNAL(fontDownloaded(QString,QQuickFontLoader::Status)), this, SLOT(updateFontInfo(QString,QQuickFontLoader::Status))); +#else +// Silently fail if compiled with no_network +#endif } else updateFontInfo(QFontDatabase::applicationFontFamilies(fo->id).at(0), Ready); diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp index 7d9997b9c8..23b2887fac 100644 --- a/src/quick/util/qquickpixmapcache.cpp +++ b/src/quick/util/qquickpixmapcache.cpp @@ -38,7 +38,6 @@ ****************************************************************************/ #include "qquickpixmapcache_p.h" -#include <qqmlnetworkaccessmanagerfactory.h> #include <qquickimageprovider.h> #include <qqmlengine.h> @@ -55,7 +54,6 @@ #include <QCoreApplication> #include <QImageReader> #include <QHash> -#include <QNetworkReply> #include <QPixmapCache> #include <QFile> #include <QThread> @@ -66,10 +64,15 @@ #include <QWaitCondition> #include <QtCore/qdebug.h> #include <private/qobject_p.h> -#include <QSslError> #include <QQmlFile> #include <QMetaMethod> +#ifndef QT_NO_NETWORK +#include <qqmlnetworkaccessmanagerfactory.h> +#include <QNetworkReply> +#include <QSslError> +#endif + #include <private/qquickprofiler_p.h> #define IMAGEREQUEST_MAX_NETWORK_REQUEST_COUNT 8 @@ -203,7 +206,9 @@ private: friend class QQuickPixmapReaderThreadObject; void processJobs(); void processJob(QQuickPixmapReply *, const QUrl &, const QString &, AutoTransform, QQuickImageProvider::ImageType, QQuickImageProvider *); +#ifndef QT_NO_NETWORK void networkRequestDone(QNetworkReply *); +#endif void asyncResponseFinished(QQuickImageResponse *); QList<QQuickPixmapReply*> jobs; @@ -215,10 +220,11 @@ private: QQuickPixmapReaderThreadObject *threadObject; QWaitCondition waitCondition; +#ifndef QT_NO_NETWORK QNetworkAccessManager *networkAccessManager(); QNetworkAccessManager *accessManager; - QHash<QNetworkReply*,QQuickPixmapReply*> networkJobs; +#endif QHash<QQuickImageResponse*,QQuickPixmapReply*> asyncResponses; static int replyDownloadProgress; @@ -343,6 +349,7 @@ QQuickPixmapReply::Event::~Event() delete textureFactory; } +#ifndef QT_NO_NETWORK QNetworkAccessManager *QQuickPixmapReader::networkAccessManager() { if (!accessManager) { @@ -351,6 +358,7 @@ QNetworkAccessManager *QQuickPixmapReader::networkAccessManager() } return accessManager; } +#endif static void maybeRemoveAlpha(QImage *image) { @@ -421,7 +429,10 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e } QQuickPixmapReader::QQuickPixmapReader(QQmlEngine *eng) -: QThread(eng), engine(eng), threadObject(0), accessManager(0) +: QThread(eng), engine(eng), threadObject(0) +#ifndef QT_NO_NETWORK +, accessManager(0) +#endif { eventLoopQuitHack = new QObject; eventLoopQuitHack->moveToThread(this); @@ -443,6 +454,7 @@ QQuickPixmapReader::~QQuickPixmapReader() delete reply; } jobs.clear(); +#ifndef QT_NO_NETWORK QList<QQuickPixmapReply*> activeJobs = networkJobs.values() + asyncResponses.values(); foreach (QQuickPixmapReply *reply, activeJobs ) { if (reply->loading) { @@ -450,6 +462,7 @@ QQuickPixmapReader::~QQuickPixmapReader() reply->data = 0; } } +#endif if (threadObject) threadObject->processJobs(); mutex.unlock(); @@ -457,6 +470,7 @@ QQuickPixmapReader::~QQuickPixmapReader() wait(); } +#ifndef QT_NO_NETWORK void QQuickPixmapReader::networkRequestDone(QNetworkReply *reply) { QQuickPixmapReply *job = networkJobs.take(reply); @@ -506,6 +520,7 @@ void QQuickPixmapReader::networkRequestDone(QNetworkReply *reply) // kick off event loop again incase we have dropped below max request count threadObject->processJobs(); } +#endif // QT_NO_NETWORK void QQuickPixmapReader::asyncResponseFinished(QQuickImageResponse *response) { @@ -557,8 +572,10 @@ bool QQuickPixmapReaderThreadObject::event(QEvent *e) void QQuickPixmapReaderThreadObject::networkRequestDone() { +#ifndef QT_NO_NETWORK QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); reader->networkRequestDone(reply); +#endif } void QQuickPixmapReaderThreadObject::asyncResponseFinished() @@ -577,6 +594,7 @@ void QQuickPixmapReader::processJobs() // Clean cancelled jobs if (!cancelled.isEmpty()) { +#ifndef QT_NO_NETWORK for (int i = 0; i < cancelled.count(); ++i) { QQuickPixmapReply *job = cancelled.at(i); QNetworkReply *reply = networkJobs.key(job, 0); @@ -599,6 +617,7 @@ void QQuickPixmapReader::processJobs() job->deleteLater(); } cancelled.clear(); +#endif } if (!jobs.isEmpty()) { @@ -619,7 +638,11 @@ void QQuickPixmapReader::processJobs() usableJob = true; } else { localFile = QQmlFile::urlToLocalFileOrQrc(url); - usableJob = !localFile.isEmpty() || networkJobs.count() < IMAGEREQUEST_MAX_NETWORK_REQUEST_COUNT; + usableJob = !localFile.isEmpty() +#ifndef QT_NO_NETWORK + || networkJobs.count() < IMAGEREQUEST_MAX_NETWORK_REQUEST_COUNT +#endif + ; } @@ -744,6 +767,7 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u runningJob->postReply(errorCode, errorStr, readSize, QQuickTextureFactory::textureFactoryForImage(image)); mutex.unlock(); } else { +#ifndef QT_NO_NETWORK // Network resource QNetworkRequest req(url); req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); @@ -753,6 +777,9 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u QMetaObject::connect(reply, replyFinished, threadObject, threadNetworkRequestDone); networkJobs.insert(reply, runningJob); +#else +// Silently fail if compiled with no_network +#endif } } } @@ -809,11 +836,13 @@ void QQuickPixmapReader::cancel(QQuickPixmapReply *reply) void QQuickPixmapReader::run() { if (replyDownloadProgress == -1) { +#ifndef QT_NO_NETWORK replyDownloadProgress = QMetaMethod::fromSignal(&QNetworkReply::downloadProgress).methodIndex(); replyFinished = QMetaMethod::fromSignal(&QNetworkReply::finished).methodIndex(); - downloadProgress = QMetaMethod::fromSignal(&QQuickPixmapReply::downloadProgress).methodIndex(); const QMetaObject *ir = &QQuickPixmapReaderThreadObject::staticMetaObject; threadNetworkRequestDone = ir->indexOfSlot("networkRequestDone()"); +#endif + downloadProgress = QMetaMethod::fromSignal(&QQuickPixmapReply::downloadProgress).methodIndex(); } mutex.lock(); |