mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive pictures: automatically recalculate thumbnails
If a thumbnail and the original picture can be accessed and the modification date of the thumbnail is before the modification date of the picture, recalculate the thumbnail. This causes more disk access and might give strange effects for picture files with messed up file timestamps (i.e. lying in the future) or messed up computer clocks (i.e. running in the past). Therefore, add a preference option to disable the new behavior. Default is set to enabled. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
23d38a982d
commit
308e079ad6
7 changed files with 64 additions and 15 deletions
|
@ -151,8 +151,24 @@ static QImage getThumbnailFromCache(const QString &picture_filename)
|
|||
QString filename = thumbnailFileName(picture_filename);
|
||||
if (filename.isEmpty())
|
||||
return QImage();
|
||||
|
||||
QFile file(filename);
|
||||
|
||||
if (prefs.auto_recalculate_thumbnails) {
|
||||
// Check if thumbnails is older than the (local) image file
|
||||
QString filenameLocal = localFilePath(qPrintable(picture_filename));
|
||||
QFileInfo pictureInfo(filenameLocal);
|
||||
QFileInfo thumbnailInfo(file);
|
||||
if (pictureInfo.exists() && thumbnailInfo.exists()) {
|
||||
QDateTime pictureTime = pictureInfo.lastModified();
|
||||
QDateTime thumbnailTime = thumbnailInfo.lastModified();
|
||||
if (pictureTime.isValid() && thumbnailTime.isValid() && thumbnailTime < pictureTime) {
|
||||
// Both files exist, have valid timestamps and thumbnail was calculated before picture.
|
||||
// Return an empty thumbnail to signal recalculation of the thumbnail
|
||||
return QImage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return QImage();
|
||||
QDataStream stream(&file);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue