mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fix picture hashing logic for pictures on the web.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
ca1349241b
commit
10b8bda662
2 changed files with 7 additions and 1 deletions
|
@ -100,6 +100,8 @@ SHashedImage::SHashedImage(struct picture *picture) : QImage()
|
|||
// This did not load anything. Let's try to get the image from other sources
|
||||
// Let's try to load it locally via its hash
|
||||
QString filename = fileFromHash(picture->hash);
|
||||
if (filename.isNull())
|
||||
filename = QString(picture->filename);
|
||||
if (filename.isNull()) {
|
||||
// That didn't produce a local filename.
|
||||
// Try the cloud server
|
||||
|
|
|
@ -1075,6 +1075,8 @@ QByteArray hashFile(const QString filename)
|
|||
|
||||
void learnHash(struct picture *picture, QByteArray hash)
|
||||
{
|
||||
if (hash.isNull())
|
||||
return;
|
||||
if (picture->hash)
|
||||
free(picture->hash);
|
||||
QMutexLocker locker(&hashOfMutex);
|
||||
|
@ -1100,6 +1102,8 @@ QString localFilePath(const QString originalFilename)
|
|||
|
||||
QString fileFromHash(char *hash)
|
||||
{
|
||||
if (!hash || !*hash)
|
||||
return "";
|
||||
QMutexLocker locker(&hashOfMutex);
|
||||
|
||||
return localFilenameOf[QByteArray::fromHex(hash)];
|
||||
|
@ -1120,7 +1124,7 @@ void hashPicture(struct picture *picture)
|
|||
if (!picture)
|
||||
return;
|
||||
char *oldHash = copy_string(picture->hash);
|
||||
learnHash(picture, hashFile(QString(picture->filename)));
|
||||
learnHash(picture, hashFile(localFilePath(picture->filename)));
|
||||
if (!same_string(picture->hash, "") && !same_string(picture->hash, oldHash))
|
||||
mark_divelist_changed((true));
|
||||
free(oldHash);
|
||||
|
|
Loading…
Add table
Reference in a new issue