diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-09-17 17:34:13 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-19 14:44:34 -0700 |
commit | 21b1550739b9a3fe4ab27cabd4a8587249048f71 (patch) | |
tree | 6a7d00658b720a334df0aa16c6999c6704116734 /desktop-widgets/simplewidgets.cpp | |
parent | 92deb7aa70e79db43b143c965c6386a6b06b4a2b (diff) | |
download | subsurface-21b1550739b9a3fe4ab27cabd4a8587249048f71.tar.gz |
Dive media: on import read metadata only once
On import of dive media, the timestamp is read from the
metadata to check if the image belongs to the selected dives.
The pictures are then listed in a dialog.
Currently, the metadata is read twice if images are outside
of a dive: once in picture_check_valid() and if it turns
out that the picture is not valid again in picture_get_time()
to display the proper timestamp.
Even though metadata-extraction is reasonably fast, this is
a bit of an embarrassment.
Instead, read the timestamps only once in the constructor of
the dialog and from then on only used these timestamps. Keep
the timestamps in a QVector. Rename the picture_check_valid()
function to picture_check_valid_time() and pass a timestamp
instead of a filename.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/simplewidgets.cpp')
-rw-r--r-- | desktop-widgets/simplewidgets.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp index 79a3cc069..64845712d 100644 --- a/desktop-widgets/simplewidgets.cpp +++ b/desktop-widgets/simplewidgets.cpp @@ -354,6 +354,11 @@ ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent, QStringList fileNa connect(ui.matchAllImages, SIGNAL(toggled(bool)), this, SLOT(matchAllImagesToggled(bool))); dcImageEpoch = (time_t)0; + // Get times of all files. 0 means that the time couldn't be determined. + int numFiles = fileNames.size(); + timestamps.resize(numFiles); + for (int i = 0; i < numFiles; ++i) + timestamps[i] = picture_get_timestamp(qPrintable(fileNames[i])); updateInvalid(); } @@ -375,7 +380,6 @@ void ShiftImageTimesDialog::setOffset(time_t offset) void ShiftImageTimesDialog::updateInvalid() { - timestamp_t timestamp; bool allValid = true; ui.warningLabel->hide(); ui.invalidFilesText->hide(); @@ -389,17 +393,17 @@ void ShiftImageTimesDialog::updateInvalid() } ui.invalidFilesText->append(tr("\nFiles with inappropriate date/time") + ":"); - Q_FOREACH (const QString &fileName, fileNames) { - if (picture_check_valid(qPrintable(fileName), m_amount)) + int numFiles = fileNames.size(); + for (int i = 0; i < numFiles; ++i) { + if (picture_check_valid_time(timestamps[i], m_amount)) continue; - // We've found invalid image - timestamp = picture_get_timestamp(qPrintable(fileName)); - time_first.setTime_t(timestamp + m_amount); - if (timestamp == 0) - ui.invalidFilesText->append(fileName + " - " + tr("No Exif date/time found")); + // We've found an invalid image + time_first.setTime_t(timestamps[i] + m_amount); + if (timestamps[i] == 0) + ui.invalidFilesText->append(fileNames[i] + " - " + tr("No Exif date/time found")); else - ui.invalidFilesText->append(fileName + " - " + time_first.toString()); + ui.invalidFilesText->append(fileNames[i] + " - " + time_first.toString()); allValid = false; } |