mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Debug: sprinkle debug messages in thumbnailing code
To ease trouble-shooting of the picture thumbnailer add a number of debug- and info-messages. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
028f53c63b
commit
376b737891
2 changed files with 12 additions and 1 deletions
|
@ -44,6 +44,7 @@ bool ImageDownloader::loadFromUrl(const QUrl &url)
|
||||||
connect(&manager, &QNetworkAccessManager::finished, this,
|
connect(&manager, &QNetworkAccessManager::finished, this,
|
||||||
[this,&success] (QNetworkReply *reply) { saveImage(reply, success); });
|
[this,&success] (QNetworkReply *reply) { saveImage(reply, success); });
|
||||||
connect(&manager, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
|
connect(&manager, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
|
||||||
|
qDebug() << "Downloading image from" << url;
|
||||||
QNetworkReply *reply = manager.get(request);
|
QNetworkReply *reply = manager.get(request);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
delete reply;
|
delete reply;
|
||||||
|
@ -68,6 +69,7 @@ void ImageDownloader::saveImage(QNetworkReply *reply, bool &success)
|
||||||
dir.mkpath(path);
|
dir.mkpath(path);
|
||||||
QFile imageFile(path.append("/").append(hash.result().toHex()));
|
QFile imageFile(path.append("/").append(hash.result().toHex()));
|
||||||
if (imageFile.open(QIODevice::WriteOnly)) {
|
if (imageFile.open(QIODevice::WriteOnly)) {
|
||||||
|
qDebug() << "Write image to" << imageFile.fileName();
|
||||||
QDataStream stream(&imageFile);
|
QDataStream stream(&imageFile);
|
||||||
stream.writeRawData(imageData.data(), imageData.length());
|
stream.writeRawData(imageData.data(), imageData.length());
|
||||||
imageFile.waitForBytesWritten(-1);
|
imageFile.waitForBytesWritten(-1);
|
||||||
|
@ -103,12 +105,18 @@ static void loadPicture(struct picture *picture, bool fromHash)
|
||||||
SHashedImage::SHashedImage(struct picture *picture) : QImage()
|
SHashedImage::SHashedImage(struct picture *picture) : QImage()
|
||||||
{
|
{
|
||||||
QUrl url = QUrl::fromUserInput(localFilePath(QString(picture->filename)));
|
QUrl url = QUrl::fromUserInput(localFilePath(QString(picture->filename)));
|
||||||
if(url.isLocalFile())
|
if (url.isLocalFile()) {
|
||||||
load(url.toLocalFile());
|
load(url.toLocalFile());
|
||||||
|
if (isNull())
|
||||||
|
qInfo() << "Failed loading picture" << url.toLocalFile();
|
||||||
|
else
|
||||||
|
qDebug() << "Loaded picture" << url.toLocalFile();
|
||||||
|
}
|
||||||
if (isNull()) {
|
if (isNull()) {
|
||||||
// This did not load anything. Let's try to get the image from other sources
|
// 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
|
// Let's try to load it locally via its hash
|
||||||
QString filename = localFilePath(picture->filename);
|
QString filename = localFilePath(picture->filename);
|
||||||
|
qDebug() << QStringLiteral("Translated filename: %1 -> %2").arg(picture->filename, filename);
|
||||||
if (filename.isNull()) {
|
if (filename.isNull()) {
|
||||||
// That didn't produce a local filename.
|
// That didn't produce a local filename.
|
||||||
// Try the cloud server
|
// Try the cloud server
|
||||||
|
@ -119,9 +127,11 @@ SHashedImage::SHashedImage(struct picture *picture) : QImage()
|
||||||
load(filename);
|
load(filename);
|
||||||
if (!isNull()) {
|
if (!isNull()) {
|
||||||
// Make sure the hash still matches the image file
|
// Make sure the hash still matches the image file
|
||||||
|
qDebug() << "Loaded picture from translated filename" << filename;
|
||||||
QtConcurrent::run(hashPicture, clone_picture(picture));
|
QtConcurrent::run(hashPicture, clone_picture(picture));
|
||||||
} else {
|
} else {
|
||||||
// Interpret filename as URL
|
// Interpret filename as URL
|
||||||
|
qInfo() << "Failed loading picture from translated filename" << filename;
|
||||||
QtConcurrent::run(loadPicture, clone_picture(picture), false);
|
QtConcurrent::run(loadPicture, clone_picture(picture), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ static void scaleImages(PictureEntry &entry, int size, int maxSize)
|
||||||
// If thumbnails were written by an earlier version, they might be smaller than needed.
|
// If thumbnails were written by an earlier version, they might be smaller than needed.
|
||||||
// Rescale in such a case to avoid resizing artifacts.
|
// Rescale in such a case to avoid resizing artifacts.
|
||||||
if (thumbnail.isNull() || (thumbnail.size().width() < maxSize && thumbnail.size().height() < maxSize)) {
|
if (thumbnail.isNull() || (thumbnail.size().width() < maxSize && thumbnail.size().height() < maxSize)) {
|
||||||
|
qDebug() << "No thumbnail in cache for" << entry.filename;
|
||||||
thumbnail = SHashedImage(entry.picture).scaled(maxSize, maxSize, Qt::KeepAspectRatio);
|
thumbnail = SHashedImage(entry.picture).scaled(maxSize, maxSize, Qt::KeepAspectRatio);
|
||||||
QMutexLocker l(&thumbnailMutex);
|
QMutexLocker l(&thumbnailMutex);
|
||||||
thumbnailCache.insert(entry.filename, thumbnail);
|
thumbnailCache.insert(entry.filename, thumbnail);
|
||||||
|
|
Loading…
Add table
Reference in a new issue