mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-10 17:13:39 +01:00
Make image requests follow redirects
This commit is contained in:
parent
b0322e7e7d
commit
a80e241bbe
@ -33,6 +33,8 @@
|
||||
#include <QtConcurrentRun>
|
||||
|
||||
#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;
|
||||
|
@ -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<QImage> future);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user