mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cleanup: remove code related to pictures in the cloud-repository
Storing pictures in the cloud never came to be, so remove the code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
d7f5246d6b
commit
b34eeeaba2
2 changed files with 15 additions and 34 deletions
|
@ -15,12 +15,6 @@
|
||||||
|
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
static QUrl cloudImageURL(const char *filename)
|
|
||||||
{
|
|
||||||
QString hash = hashString(filename);
|
|
||||||
return QUrl::fromUserInput(QString("https://cloud.subsurface-divelog.org/images/").append(hash));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: this is a global instead of a function-local variable on purpose.
|
// Note: this is a global instead of a function-local variable on purpose.
|
||||||
// We don't want this to be generated in a different thread context if
|
// We don't want this to be generated in a different thread context if
|
||||||
// ImageDownloader::instance() is called from a worker thread.
|
// ImageDownloader::instance() is called from a worker thread.
|
||||||
|
@ -35,9 +29,9 @@ ImageDownloader::ImageDownloader()
|
||||||
connect(&manager, &QNetworkAccessManager::finished, this, &ImageDownloader::saveImage);
|
connect(&manager, &QNetworkAccessManager::finished, this, &ImageDownloader::saveImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageDownloader::load(QString filename, bool fromHash)
|
void ImageDownloader::load(QString filename)
|
||||||
{
|
{
|
||||||
QUrl url = fromHash ? cloudImageURL(qPrintable(filename)) : QUrl::fromUserInput(filename);
|
QUrl url = QUrl::fromUserInput(filename);
|
||||||
|
|
||||||
// If this is a file, we tried previously -> don't bother trying it again
|
// If this is a file, we tried previously -> don't bother trying it again
|
||||||
if (url.scheme() == "file" || !url.isValid()) {
|
if (url.scheme() == "file" || !url.isValid()) {
|
||||||
|
@ -47,7 +41,6 @@ void ImageDownloader::load(QString filename, bool fromHash)
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setAttribute(QNetworkRequest::User, filename);
|
request.setAttribute(QNetworkRequest::User, filename);
|
||||||
request.setAttribute(static_cast<QNetworkRequest::Attribute>(QNetworkRequest::User + 1), fromHash);
|
|
||||||
manager.get(request);
|
manager.get(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,11 +49,7 @@ void ImageDownloader::saveImage(QNetworkReply *reply)
|
||||||
QString filename = reply->request().attribute(QNetworkRequest::User).toString();
|
QString filename = reply->request().attribute(QNetworkRequest::User).toString();
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
bool fromHash = reply->request().attribute(static_cast<QNetworkRequest::Attribute>(QNetworkRequest::User + 1)).toBool();
|
emit failed(filename);
|
||||||
if (fromHash)
|
|
||||||
load(filename, false);
|
|
||||||
else
|
|
||||||
emit failed(filename);
|
|
||||||
} else {
|
} else {
|
||||||
QByteArray imageData = reply->readAll();
|
QByteArray imageData = reply->readAll();
|
||||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||||
|
@ -84,11 +73,11 @@ void ImageDownloader::saveImage(QNetworkReply *reply)
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadPicture(QString filename, bool fromHash)
|
static void loadPicture(QString filename)
|
||||||
{
|
{
|
||||||
// This has to be done in UI main thread, because QNetworkManager refuses
|
// This has to be done in UI main thread, because QNetworkManager refuses
|
||||||
// to treat requests from other threads.
|
// to treat requests from other threads.
|
||||||
QMetaObject::invokeMethod(ImageDownloader::instance(), "load", Qt::AutoConnection, Q_ARG(QString, filename), Q_ARG(bool, fromHash));
|
QMetaObject::invokeMethod(ImageDownloader::instance(), "load", Qt::AutoConnection, Q_ARG(QString, filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwrite QImage::load() so that we can perform better error reporting.
|
// Overwrite QImage::load() so that we can perform better error reporting.
|
||||||
|
@ -117,24 +106,16 @@ static std::pair<QImage,bool> getHashedImage(const QString &file_in, bool tryDow
|
||||||
// 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
|
||||||
QString filenameLocal = localFilePath(qPrintable(file));
|
QString filenameLocal = localFilePath(qPrintable(file));
|
||||||
qDebug() << QStringLiteral("Translated filename: %1 -> %2").arg(file, filenameLocal);
|
qDebug() << QStringLiteral("Translated filename: %1 -> %2").arg(file, filenameLocal);
|
||||||
if (filenameLocal.isNull()) {
|
// Load locally from translated file name if it is different
|
||||||
// That didn't produce a local filename.
|
if (filenameLocal != file)
|
||||||
// Try the cloud server
|
thumb = loadImage(filenameLocal);
|
||||||
// TODO: This is dead code at the moment.
|
if (!thumb.isNull()) {
|
||||||
loadPicture(file, true);
|
// Make sure the hash still matches the image file
|
||||||
stillLoading = true;
|
hashPicture(filenameLocal);
|
||||||
} else {
|
} else {
|
||||||
// Load locally from translated file name if it is different
|
// Interpret filename as URL
|
||||||
if (filenameLocal != file)
|
loadPicture(filenameLocal);
|
||||||
thumb = loadImage(filenameLocal);
|
stillLoading = true;
|
||||||
if (!thumb.isNull()) {
|
|
||||||
// Make sure the hash still matches the image file
|
|
||||||
hashPicture(filenameLocal);
|
|
||||||
} else {
|
|
||||||
// Interpret filename as URL
|
|
||||||
loadPicture(filenameLocal, false);
|
|
||||||
stillLoading = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { thumb, stillLoading };
|
return { thumb, stillLoading };
|
||||||
|
|
|
@ -13,7 +13,7 @@ public:
|
||||||
static ImageDownloader *instance();
|
static ImageDownloader *instance();
|
||||||
ImageDownloader();
|
ImageDownloader();
|
||||||
public slots:
|
public slots:
|
||||||
void load(QString filename, bool fromHash);
|
void load(QString filename);
|
||||||
signals:
|
signals:
|
||||||
void loaded(QString filename);
|
void loaded(QString filename);
|
||||||
void failed(QString filename);
|
void failed(QString filename);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue