From 0d77b921eb11a2a013555078569c766e4d36a84f Mon Sep 17 00:00:00 2001 From: Jan Darowski Date: Sat, 14 Mar 2015 17:44:24 +0100 Subject: Added warning when not all images can be added. Added label in the ShiftImageTimesDialog which appears when not all of the selected images have timestamp in the checked range. Made cancel button in this widget actually work. Signed-off-by: Jan Darowski Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 7 ++++--- qt-ui/shiftimagetimes.ui | 25 +++++++++++++++++++++++++ qt-ui/simplewidgets.cpp | 38 +++++++++++++++++++++++++++++++++++++- qt-ui/simplewidgets.h | 5 ++++- 4 files changed, 70 insertions(+), 5 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index e4ccb7208..b905e9c3c 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -850,9 +850,10 @@ void DiveListView::loadImages() return; updateLastUsedImageDir(QFileInfo(fileNames[0]).dir().path()); - ShiftImageTimesDialog shiftDialog(this); + ShiftImageTimesDialog shiftDialog(this, fileNames); shiftDialog.setOffset(lastImageTimeOffset()); - shiftDialog.exec(); + if (!shiftDialog.exec()) + return; updateLastImageTimeOffset(shiftDialog.amount()); Q_FOREACH (const QString &fileName, fileNames) { @@ -861,7 +862,7 @@ void DiveListView::loadImages() for_each_dive (j, dive) { if (!dive->selected) continue; - dive_create_picture(dive, qstrdup(fileName.toUtf8().data()), shiftDialog.amount()); + dive_create_picture(dive, copy_string(fileName.toUtf8().data()), shiftDialog.amount()); } } diff --git a/qt-ui/shiftimagetimes.ui b/qt-ui/shiftimagetimes.ui index cce51e888..56a222856 100644 --- a/qt-ui/shiftimagetimes.ui +++ b/qt-ui/shiftimagetimes.ui @@ -116,6 +116,31 @@ + + + + true + + + color: red; + + + Warning! +Not all images have timestamps in the range between +30 minutes before the start and 30 minutes after the end of any selected dive. + + + + + + + color: red; + + + + + + diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index 8a0f2b090..58959c1f0 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -303,11 +303,12 @@ void ShiftImageTimesDialog::dcDateTimeChanged(const QDateTime &newDateTime) setOffset(newDateTime.toTime_t() - dcImageEpoch); } -ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent) : QDialog(parent), m_amount(0) +ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent, QStringList fileNames) : QDialog(parent), m_amount(0), fileNames(fileNames) { ui.setupUi(this); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked())); + connect(ui.timeEdit, SIGNAL(timeChanged(const QTime &)), this, SLOT(timeEditChanged(const QTime &))); dcImageEpoch = (time_t)0; } @@ -327,6 +328,41 @@ void ShiftImageTimesDialog::setOffset(time_t offset) ui.timeEdit->setTime(QTime(offset / 3600, (offset % 3600) / 60, offset % 60)); } +void ShiftImageTimesDialog::updateInvalid() +{ + timestamp_t timestamp; + QDateTime time; + bool allValid = true; + ui.warningLabel->hide(); + ui.invalidLabel->hide(); + ui.invalidLabel->clear(); + + Q_FOREACH (const QString &fileName, fileNames) { + if (picture_check_valid(fileName.toUtf8().data(), m_amount)) + continue; + + // We've found invalid image + picture_get_timestamp(fileName.toUtf8().data(), ×tamp); + dcImageEpoch = timestamp; + time.setTime_t(timestamp + m_amount); + ui.invalidLabel->setText(ui.invalidLabel->text() + fileName + " " + time.toString() + "\n"); + allValid = false; + } + + if (!allValid){ + ui.warningLabel->show(); + ui.invalidLabel->show(); + } +} + +void ShiftImageTimesDialog::timeEditChanged(const QTime &time) +{ + m_amount = time.hour() * 3600 + time.minute() * 60; + if (ui.backwards->isChecked()) + m_amount *= -1; + updateInvalid(); +} + bool isGnome3Session() { #if defined(QT_OS_WIW) || defined(QT_OS_MAC) diff --git a/qt-ui/simplewidgets.h b/qt-ui/simplewidgets.h index 75b1df402..5f2402a86 100644 --- a/qt-ui/simplewidgets.h +++ b/qt-ui/simplewidgets.h @@ -97,7 +97,7 @@ private: class ShiftImageTimesDialog : public QDialog { Q_OBJECT public: - explicit ShiftImageTimesDialog(QWidget *parent); + explicit ShiftImageTimesDialog(QWidget *parent, QStringList fileNames); time_t amount() const; void setOffset(time_t offset); private @@ -105,8 +105,11 @@ slots: void buttonClicked(QAbstractButton *button); void syncCameraClicked(); void dcDateTimeChanged(const QDateTime &); + void timeEditChanged(const QTime &time); + void updateInvalid(); private: + QStringList fileNames; Ui::ShiftImageTimesDialog ui; time_t m_amount; time_t dcImageEpoch; -- cgit v1.2.3-70-g09d2