subsurface/core/imagedownloader.h
Berthold Stoeger 4c19d3da1d Dive pictures: Make failure of loading images less noisy
For debug reasons, failure to load the original image was spilled
to the console, even if the local file was then found.

Only print a message, when also the local image failed loading.
This needed a bit of code reshuffling. To know when to print a
failed-loading message, the URL is now checked at the Thumbnailer
level, not the ImageDownloader level. The ImageDownloader is
passed the URL and the original filename (if different). The
image is loaded from the URL, but the signals send the original
filename, so that the thumbnail can be associated to the proper
image.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-13 08:35:23 -07:00

63 lines
1.7 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef IMAGEDOWNLOADER_H
#define IMAGEDOWNLOADER_H
#include <QImage>
#include <QFuture>
#include <QNetworkReply>
#include <QThreadPool>
class ImageDownloader : public QObject {
Q_OBJECT
public:
static ImageDownloader *instance();
ImageDownloader();
public slots:
void load(QUrl url, QString filename);
signals:
void loaded(QString filename);
void failed(QString filename);
private:
QNetworkAccessManager manager;
void loadFromUrl(const QString &filename, const QUrl &);
void saveImage(QNetworkReply *reply);
};
struct PictureEntry;
class Thumbnailer : public QObject {
Q_OBJECT
public:
static Thumbnailer *instance();
// Schedule a thumbnail for fetching or calculation.
// Returns a placehlder thumbnail. The actual thumbnail will be sent
// via a signal later.
QImage fetchThumbnail(PictureEntry &entry);
// Schedule multiple thumbnails for forced recalculation
void calculateThumbnails(const QVector<QString> &filenames);
// If we change dive, clear all unfinished thumbnail creations
void clearWorkQueue();
static int maxThumbnailSize();
static int defaultThumbnailSize();
static int thumbnailSize(double zoomLevel);
public slots:
void imageDownloaded(QString filename);
void imageDownloadFailed(QString filename);
signals:
void thumbnailChanged(QString filename, QImage thumbnail);
private:
Thumbnailer();
void recalculate(QString filename);
void processItem(QString filename, bool tryDownload);
mutable QMutex lock;
QThreadPool pool;
QImage failImage; // Shown when image-fetching fails
QImage dummyImage; // Shown before thumbnail is fetched
QMap<QString,QFuture<void>> workingOn;
};
#endif // IMAGEDOWNLOADER_H