From 63ac95323b3fb8884f8d7ede0ebf4e360393f658 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 10 Mar 2010 15:10:10 +1000 Subject: URL redirection for AnimatedImage Task-number: QTBUG-7515 --- .../graphicsitems/qdeclarativeanimatedimage.cpp | 16 ++++++++++++++++ .../graphicsitems/qdeclarativeanimatedimage_p_p.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp index 20b1de3..2c2e034 100644 --- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp @@ -247,9 +247,25 @@ void QDeclarativeAnimatedImage::setSource(const QUrl &url) emit statusChanged(d->status); } +#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()){ qWarning() << "Error Reading Animated Image File " << d->url; diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h index 39bb3e5..273c1d6 100644 --- a/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage_p_p.h @@ -66,7 +66,7 @@ class QDeclarativeAnimatedImagePrivate : public QDeclarativeImagePrivate public: QDeclarativeAnimatedImagePrivate() - : playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0) + : playing(true), paused(false), preset_currentframe(0), _movie(0), reply(0), redirectCount(0) { } @@ -75,6 +75,7 @@ public: int preset_currentframe; QMovie *_movie; QNetworkReply *reply; + int redirectCount; }; QT_END_NAMESPACE -- cgit v0.12