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);
|
QString filename = thumbnailFileName(picture_filename);
|
||||||
if (filename.isEmpty())
|
if (filename.isEmpty())
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
QFile file(filename);
|
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))
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
return QImage();
|
return QImage();
|
||||||
QDataStream stream(&file);
|
QDataStream stream(&file);
|
||||||
|
|
|
@ -154,6 +154,7 @@ struct preferences {
|
||||||
int distance_threshold;
|
int distance_threshold;
|
||||||
bool git_local_only;
|
bool git_local_only;
|
||||||
short cloud_timeout;
|
short cloud_timeout;
|
||||||
|
bool auto_recalculate_thumbnails;
|
||||||
locale_prefs_t locale; //: TODO: move the rest of locale based info here.
|
locale_prefs_t locale; //: TODO: move the rest of locale based info here.
|
||||||
update_manager_prefs_t update_manager;
|
update_manager_prefs_t update_manager;
|
||||||
dive_computer_prefs_t dive_computer;
|
dive_computer_prefs_t dive_computer;
|
||||||
|
|
|
@ -1802,6 +1802,11 @@ int GeneralSettingsObjectWrapper::pscrRatio() const
|
||||||
return prefs.pscr_ratio;
|
return prefs.pscr_ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GeneralSettingsObjectWrapper::autoRecalculateThumbnails() const
|
||||||
|
{
|
||||||
|
return prefs.auto_recalculate_thumbnails;
|
||||||
|
}
|
||||||
|
|
||||||
void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value)
|
void GeneralSettingsObjectWrapper::setDefaultFilename(const QString& value)
|
||||||
{
|
{
|
||||||
if (value == prefs.default_filename)
|
if (value == prefs.default_filename)
|
||||||
|
@ -1895,6 +1900,18 @@ void GeneralSettingsObjectWrapper::setPscrRatio(int value)
|
||||||
emit pscrRatioChanged(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) :
|
DisplaySettingsObjectWrapper::DisplaySettingsObjectWrapper(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
@ -2266,6 +2283,7 @@ void SettingsObjectWrapper::load()
|
||||||
GET_INT("defaultsetpoint", defaultsetpoint);
|
GET_INT("defaultsetpoint", defaultsetpoint);
|
||||||
GET_INT("o2consumption", o2consumption);
|
GET_INT("o2consumption", o2consumption);
|
||||||
GET_INT("pscr_ratio", pscr_ratio);
|
GET_INT("pscr_ratio", pscr_ratio);
|
||||||
|
GET_BOOL("auto_recalculate_thumbnails", auto_recalculate_thumbnails);
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
s.beginGroup("Display");
|
s.beginGroup("Display");
|
||||||
|
|
|
@ -559,6 +559,7 @@ class GeneralSettingsObjectWrapper : public QObject {
|
||||||
Q_PROPERTY(int defaultsetpoint READ defaultSetPoint WRITE setDefaultSetPoint NOTIFY defaultSetPointChanged)
|
Q_PROPERTY(int defaultsetpoint READ defaultSetPoint WRITE setDefaultSetPoint NOTIFY defaultSetPointChanged)
|
||||||
Q_PROPERTY(int o2consumption READ o2Consumption WRITE setO2Consumption NOTIFY o2ConsumptionChanged)
|
Q_PROPERTY(int o2consumption READ o2Consumption WRITE setO2Consumption NOTIFY o2ConsumptionChanged)
|
||||||
Q_PROPERTY(int pscr_ratio READ pscrRatio WRITE setPscrRatio NOTIFY pscrRatioChanged)
|
Q_PROPERTY(int pscr_ratio READ pscrRatio WRITE setPscrRatio NOTIFY pscrRatioChanged)
|
||||||
|
Q_PROPERTY(bool auto_recalculate_thumbnails READ autoRecalculateThumbnails WRITE setAutoRecalculateThumbnails NOTIFY autoRecalculateThumbnailsChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GeneralSettingsObjectWrapper(QObject *parent);
|
GeneralSettingsObjectWrapper(QObject *parent);
|
||||||
|
@ -569,6 +570,7 @@ public:
|
||||||
int defaultSetPoint() const;
|
int defaultSetPoint() const;
|
||||||
int o2Consumption() const;
|
int o2Consumption() const;
|
||||||
int pscrRatio() const;
|
int pscrRatio() const;
|
||||||
|
bool autoRecalculateThumbnails() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setDefaultFilename (const QString& value);
|
void setDefaultFilename (const QString& value);
|
||||||
|
@ -578,6 +580,7 @@ public slots:
|
||||||
void setDefaultSetPoint (int value);
|
void setDefaultSetPoint (int value);
|
||||||
void setO2Consumption (int value);
|
void setO2Consumption (int value);
|
||||||
void setPscrRatio (int value);
|
void setPscrRatio (int value);
|
||||||
|
void setAutoRecalculateThumbnails (bool value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void defaultFilenameChanged(const QString& value);
|
void defaultFilenameChanged(const QString& value);
|
||||||
|
@ -587,6 +590,7 @@ signals:
|
||||||
void defaultSetPointChanged(int value);
|
void defaultSetPointChanged(int value);
|
||||||
void o2ConsumptionChanged(int value);
|
void o2ConsumptionChanged(int value);
|
||||||
void pscrRatioChanged(int value);
|
void pscrRatioChanged(int value);
|
||||||
|
void autoRecalculateThumbnailsChanged(int value);
|
||||||
private:
|
private:
|
||||||
const QString group = QStringLiteral("GeneralSettings");
|
const QString group = QStringLiteral("GeneralSettings");
|
||||||
};
|
};
|
||||||
|
|
|
@ -99,6 +99,7 @@ struct preferences default_prefs = {
|
||||||
#else
|
#else
|
||||||
.cloud_timeout = 5,
|
.cloud_timeout = 5,
|
||||||
#endif
|
#endif
|
||||||
|
.auto_recalculate_thumbnails = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
int run_survey;
|
int run_survey;
|
||||||
|
|
|
@ -47,6 +47,7 @@ void PreferencesGraph::refreshSettings()
|
||||||
|
|
||||||
ui->display_unused_tanks->setChecked(prefs.display_unused_tanks);
|
ui->display_unused_tanks->setChecked(prefs.display_unused_tanks);
|
||||||
ui->show_average_depth->setChecked(prefs.show_average_depth);
|
ui->show_average_depth->setChecked(prefs.show_average_depth);
|
||||||
|
ui->auto_recalculate_thumbnails->setChecked(prefs.auto_recalculate_thumbnails);
|
||||||
ui->show_icd->setChecked(prefs.show_icd);
|
ui->show_icd->setChecked(prefs.show_icd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ void PreferencesGraph::syncSettings()
|
||||||
general->setDefaultSetPoint(lrint(ui->defaultSetpoint->value() * 1000.0));
|
general->setDefaultSetPoint(lrint(ui->defaultSetpoint->value() * 1000.0));
|
||||||
general->setO2Consumption(lrint(ui->psro2rate->value() *1000.0));
|
general->setO2Consumption(lrint(ui->psro2rate->value() *1000.0));
|
||||||
general->setPscrRatio(lrint(1000.0 / ui->pscrfactor->value()));
|
general->setPscrRatio(lrint(1000.0 / ui->pscrfactor->value()));
|
||||||
|
general->setAutoRecalculateThumbnails(ui->auto_recalculate_thumbnails->isChecked());
|
||||||
|
|
||||||
auto pp_gas = SettingsObjectWrapper::instance()->pp_gas;
|
auto pp_gas = SettingsObjectWrapper::instance()->pp_gas;
|
||||||
pp_gas->setPheThreshold(ui->pheThreshold->value());
|
pp_gas->setPheThreshold(ui->pheThreshold->value());
|
||||||
|
|
|
@ -368,6 +368,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="auto_recalculate_thumbnails">
|
||||||
|
<property name="text">
|
||||||
|
<string>Recalculate thumbnails if older than image</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue