From a80e241bbe2d51e3e01641c53758a37d3909fa81 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Wed, 17 Feb 2016 13:51:08 +0000 Subject: [PATCH] Make image requests follow redirects --- src/widgets/prettyimage.cpp | 12 +++++++++--- src/widgets/prettyimage.h | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/widgets/prettyimage.cpp b/src/widgets/prettyimage.cpp index dbb22de00..3b8536d83 100644 --- a/src/widgets/prettyimage.cpp +++ b/src/widgets/prettyimage.cpp @@ -33,6 +33,8 @@ #include #include "core/closure.h" +#include "core/logging.h" +#include "core/network.h" #include "ui/iconloader.h" const int PrettyImage::kTotalHeight = 200; @@ -61,9 +63,10 @@ void PrettyImage::LazyLoad() { // Start fetching the image QNetworkReply* reply = network_->get(QNetworkRequest(url_)); + RedirectFollower* follower = new RedirectFollower(reply); state_ = State_Fetching; - NewClosure(reply, SIGNAL(finished()), this, - SLOT(ImageFetched(QNetworkReply*)), reply); + NewClosure(follower, SIGNAL(finished()), this, + SLOT(ImageFetched(RedirectFollower*)), follower); } QSize PrettyImage::image_size() const { @@ -78,11 +81,14 @@ QSize PrettyImage::sizeHint() const { return QSize(image_size().width(), kTotalHeight); } -void PrettyImage::ImageFetched(QNetworkReply* reply) { +void PrettyImage::ImageFetched(RedirectFollower* follower) { + follower->deleteLater(); + QNetworkReply* reply = follower->reply(); reply->deleteLater(); QImage image = QImage::fromData(reply->readAll()); if (image.isNull()) { + qLog(Debug) << "Image failed to load" << reply->request().url(); deleteLater(); } else { state_ = State_CreatingThumbnail; diff --git a/src/widgets/prettyimage.h b/src/widgets/prettyimage.h index ceee4a1de..5a2de0e66 100644 --- a/src/widgets/prettyimage.h +++ b/src/widgets/prettyimage.h @@ -24,7 +24,7 @@ class QMenu; class QNetworkAccessManager; -class QNetworkReply; +class RedirectFollower; class PrettyImage : public QWidget { Q_OBJECT @@ -57,7 +57,7 @@ signals: void paintEvent(QPaintEvent*); private slots: - void ImageFetched(QNetworkReply* reply); + void ImageFetched(RedirectFollower* reply); void ImageScaled(QFuture future); private: