diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/imagedownloader.cpp | 28 | ||||
-rw-r--r-- | core/imagedownloader.h | 4 |
2 files changed, 32 insertions, 0 deletions
diff --git a/core/imagedownloader.cpp b/core/imagedownloader.cpp index 1d82c50c5..0c72f3381 100644 --- a/core/imagedownloader.cpp +++ b/core/imagedownloader.cpp @@ -184,6 +184,23 @@ static void addThumbnailToCache(const QImage &thumbnail, const QString &picture_ file.commit(); } +void Thumbnailer::recalculate(QString filename) +{ + auto res = getHashedImage(filename, true); + + // If we couldn't load the image from disk -> leave old thumbnail. + // The case "load from web" is a bit inconsistent: it will call into processItem() later + // and therefore a "broken" image symbol may be shown. + if (res.second || res.first.isNull()) + return; + QImage thumbnail = res.first; + addThumbnailToCache(thumbnail, filename); + + QMutexLocker l(&lock); + emit thumbnailChanged(filename, thumbnail); + workingOn.remove(filename); +} + void Thumbnailer::processItem(QString filename, bool tryDownload) { QImage thumbnail = getThumbnailFromCache(filename); @@ -236,6 +253,17 @@ QImage Thumbnailer::fetchThumbnail(PictureEntry &entry) return dummyImage; } +void Thumbnailer::calculateThumbnails(const QVector<QString> &filenames) +{ + QMutexLocker l(&lock); + for (const QString &filename: filenames) { + if (!workingOn.contains(filename)) { + workingOn.insert(filename, + QtConcurrent::run(&pool, [this, filename]() { recalculate(filename); })); + } + } +} + void Thumbnailer::clearWorkQueue() { QMutexLocker l(&lock); diff --git a/core/imagedownloader.h b/core/imagedownloader.h index 22ef8f5eb..d91dbcaad 100644 --- a/core/imagedownloader.h +++ b/core/imagedownloader.h @@ -34,6 +34,9 @@ public: // 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(); @@ -46,6 +49,7 @@ signals: void thumbnailChanged(QString filename, QImage thumbnail); private: Thumbnailer(); + void recalculate(QString filename); void processItem(QString filename, bool tryDownload); mutable QMutex lock; |