summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/imagedownloader.cpp18
-rw-r--r--core/pref.h1
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp18
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h32
-rw-r--r--core/subsurfacestartup.c1
5 files changed, 55 insertions, 15 deletions
diff --git a/core/imagedownloader.cpp b/core/imagedownloader.cpp
index 0c72f3381..da5c86b99 100644
--- a/core/imagedownloader.cpp
+++ b/core/imagedownloader.cpp
@@ -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);
diff --git a/core/pref.h b/core/pref.h
index 2628c3677..8ca763ce8 100644
--- a/core/pref.h
+++ b/core/pref.h
@@ -154,6 +154,7 @@ struct preferences {
int distance_threshold;
bool git_local_only;
short cloud_timeout;
+ bool auto_recalculate_thumbnails;
locale_prefs_t locale; //: TODO: move the rest of locale based info here.
update_manager_prefs_t update_manager;
dive_computer_prefs_t dive_computer;
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index d88df5cba..60473ec1a 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -1802,6 +1802,11 @@ int GeneralSettingsObjectWrapper::pscrRatio() const
return prefs.pscr_ratio;
}
+bool GeneralSettingsObjectWrapper::autoRecalculateThumbnails() const
+{
+ return prefs.auto_recalculate_thumbnails;
+}
+
void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value)
{
if (value == prefs.default_filename)
@@ -1895,6 +1900,18 @@ void GeneralSettingsObjectWrapper::setPscrRatio(int value)
emit pscrRatioChanged(value);
}
+void GeneralSettingsObjectWrapper::setAutoRecalculateThumbnails(bool value)
+{
+ if (value == prefs.auto_recalculate_thumbnails)
+ return;
+
+ QSettings s;
+ s.beginGroup(group);
+ s.setValue("auto_recalculate_thumbnails", value);
+ prefs.auto_recalculate_thumbnails = value;
+ emit autoRecalculateThumbnailsChanged(value);
+}
+
DisplaySettingsObjectWrapper::DisplaySettingsObjectWrapper(QObject *parent) :
QObject(parent)
{
@@ -2266,6 +2283,7 @@ void SettingsObjectWrapper::load()
GET_INT("defaultsetpoint", defaultsetpoint);
GET_INT("o2consumption", o2consumption);
GET_INT("pscr_ratio", pscr_ratio);
+ GET_BOOL("auto_recalculate_thumbnails", auto_recalculate_thumbnails);
s.endGroup();
s.beginGroup("Display");
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index f2c6745d8..a56175ea7 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -552,13 +552,14 @@ private:
class GeneralSettingsObjectWrapper : public QObject {
Q_OBJECT
- Q_PROPERTY(QString default_filename READ defaultFilename WRITE setDefaultFilename NOTIFY defaultFilenameChanged)
- Q_PROPERTY(QString default_cylinder READ defaultCylinder WRITE setDefaultCylinder NOTIFY defaultCylinderChanged)
- Q_PROPERTY(short default_file_behavior READ defaultFileBehavior WRITE setDefaultFileBehavior NOTIFY defaultFileBehaviorChanged)
- Q_PROPERTY(bool use_default_file READ useDefaultFile WRITE setUseDefaultFile NOTIFY useDefaultFileChanged)
- Q_PROPERTY(int defaultsetpoint READ defaultSetPoint WRITE setDefaultSetPoint NOTIFY defaultSetPointChanged)
- Q_PROPERTY(int o2consumption READ o2Consumption WRITE setO2Consumption NOTIFY o2ConsumptionChanged)
- Q_PROPERTY(int pscr_ratio READ pscrRatio WRITE setPscrRatio NOTIFY pscrRatioChanged)
+ Q_PROPERTY(QString default_filename READ defaultFilename WRITE setDefaultFilename NOTIFY defaultFilenameChanged)
+ Q_PROPERTY(QString default_cylinder READ defaultCylinder WRITE setDefaultCylinder NOTIFY defaultCylinderChanged)
+ Q_PROPERTY(short default_file_behavior READ defaultFileBehavior WRITE setDefaultFileBehavior NOTIFY defaultFileBehaviorChanged)
+ Q_PROPERTY(bool use_default_file READ useDefaultFile WRITE setUseDefaultFile NOTIFY useDefaultFileChanged)
+ Q_PROPERTY(int defaultsetpoint READ defaultSetPoint WRITE setDefaultSetPoint NOTIFY defaultSetPointChanged)
+ Q_PROPERTY(int o2consumption READ o2Consumption WRITE setO2Consumption NOTIFY o2ConsumptionChanged)
+ Q_PROPERTY(int pscr_ratio READ pscrRatio WRITE setPscrRatio NOTIFY pscrRatioChanged)
+ Q_PROPERTY(bool auto_recalculate_thumbnails READ autoRecalculateThumbnails WRITE setAutoRecalculateThumbnails NOTIFY autoRecalculateThumbnailsChanged)
public:
GeneralSettingsObjectWrapper(QObject *parent);
@@ -569,15 +570,17 @@ public:
int defaultSetPoint() const;
int o2Consumption() const;
int pscrRatio() const;
+ bool autoRecalculateThumbnails() const;
public slots:
- void setDefaultFilename (const QString& value);
- void setDefaultCylinder (const QString& value);
- void setDefaultFileBehavior (short value);
- void setUseDefaultFile (bool value);
- void setDefaultSetPoint (int value);
- void setO2Consumption (int value);
- void setPscrRatio (int value);
+ void setDefaultFilename (const QString& value);
+ void setDefaultCylinder (const QString& value);
+ void setDefaultFileBehavior (short value);
+ void setUseDefaultFile (bool value);
+ void setDefaultSetPoint (int value);
+ void setO2Consumption (int value);
+ void setPscrRatio (int value);
+ void setAutoRecalculateThumbnails (bool value);
signals:
void defaultFilenameChanged(const QString& value);
@@ -587,6 +590,7 @@ signals:
void defaultSetPointChanged(int value);
void o2ConsumptionChanged(int value);
void pscrRatioChanged(int value);
+ void autoRecalculateThumbnailsChanged(int value);
private:
const QString group = QStringLiteral("GeneralSettings");
};
diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c
index 18332742b..65b30e7d6 100644
--- a/core/subsurfacestartup.c
+++ b/core/subsurfacestartup.c
@@ -99,6 +99,7 @@ struct preferences default_prefs = {
#else
.cloud_timeout = 5,
#endif
+ .auto_recalculate_thumbnails = true,
};
int run_survey;