mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive pictures: give user option to recalculate thumbnails
Even though hashes of image contents are calculated, the hashes are not compared to actual file contents in routine-operation. Therefore give the user the option to recalculate thumbnails, should they have edited the picture. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f265504dab
commit
23d38a982d
4 changed files with 52 additions and 7 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue