Launcher: more robust preview downloading.
Tolerate download failures, which seem to happen due to Ibiblio rate- limiting, more gracefully.
This commit is contained in:
parent
67dfff9a84
commit
aef9bc4e06
2 changed files with 16 additions and 7 deletions
|
@ -25,10 +25,10 @@ void PreviewWindow::setUrls(QVariantList urls)
|
|||
|
||||
Q_FOREACH (QVariant v, urls) {
|
||||
QUrl url = v.toUrl();
|
||||
qWarning() << v;
|
||||
m_urls.append(url);
|
||||
QNetworkReply* reply = m_netAccess->get(QNetworkRequest(url));
|
||||
qInfo() << "requesting:" << url;
|
||||
connect(reply, &QNetworkReply::finished, this, &PreviewWindow::onDownloadFinished);
|
||||
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onDownloadError(QNetworkReply::NetworkError)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,6 @@ void PreviewWindow::paintEvent(QPaintEvent *pe)
|
|||
{
|
||||
QUrl key = m_urls.at(m_currentPreview);
|
||||
QPixmap pm = m_cache.value(key.toString());
|
||||
if (pm.isNull()) {
|
||||
qWarning() << "null pixmap";
|
||||
}
|
||||
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), Qt::black);
|
||||
|
@ -94,11 +91,12 @@ void PreviewWindow::onDownloadFinished()
|
|||
|
||||
QImage img;
|
||||
if (!img.load(reply, nullptr)) {
|
||||
qWarning() << "failed to read image data from" << reply->url();
|
||||
qWarning() << Q_FUNC_INFO << "failed to read image data from" << reply->url();
|
||||
return;
|
||||
}
|
||||
|
||||
m_cache.insert(reply->url().toString(), QPixmap::fromImage(img));
|
||||
m_urls.append(reply->url());
|
||||
|
||||
if (!isVisible()) {
|
||||
QSize winSize(img.width() + BORDER_SIZE * 2, img.height() + BORDER_SIZE * 2);
|
||||
|
@ -107,3 +105,11 @@ void PreviewWindow::onDownloadFinished()
|
|||
show();
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewWindow::onDownloadError(QNetworkReply::NetworkError errorCode)
|
||||
{
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
|
||||
qWarning() << "failed to download:" << reply->url();
|
||||
qWarning() << reply->errorString();
|
||||
m_urls.removeOne(reply->url());
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <QVariant>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QMap>
|
||||
#include <QNetworkReply>
|
||||
|
||||
class PreviewWindow : public QDialog
|
||||
{
|
||||
|
@ -24,10 +25,12 @@ protected:
|
|||
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onDownloadError(QNetworkReply::NetworkError errorCode);
|
||||
|
||||
private:
|
||||
void onDownloadFinished();
|
||||
|
||||
|
||||
unsigned int m_currentPreview = 0;
|
||||
QNetworkAccessManager* m_netAccess;
|
||||
QList<QUrl> m_urls;
|
||||
|
|
Loading…
Add table
Reference in a new issue