Add checkbox to force images to match dives

Give the user the possibility to attach images to a dive even
when the times do not match

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2015-09-11 11:31:02 +02:00 committed by Dirk Hohndel
parent 5a1c041b78
commit 654a7be834
6 changed files with 25 additions and 4 deletions

4
dive.c
View file

@ -2989,12 +2989,12 @@ bool picture_check_valid(char *filename, int shift_time)
return false; return false;
} }
void dive_create_picture(struct dive *dive, char *filename, int shift_time) void dive_create_picture(struct dive *dive, char *filename, int shift_time, bool match_all)
{ {
timestamp_t timestamp = picture_get_timestamp(filename); timestamp_t timestamp = picture_get_timestamp(filename);
if (!new_picture_for_dive(dive, filename)) if (!new_picture_for_dive(dive, filename))
return; return;
if (!dive_check_picture_time(dive, shift_time, timestamp)) if (!match_all && !dive_check_picture_time(dive, shift_time, timestamp))
return; return;
struct picture *picture = alloc_picture(); struct picture *picture = alloc_picture();

2
dive.h
View file

@ -377,7 +377,7 @@ struct picture {
extern struct picture *alloc_picture(); extern struct picture *alloc_picture();
extern bool dive_check_picture_time(struct dive *d, int shift_time, timestamp_t timestamp); extern bool dive_check_picture_time(struct dive *d, int shift_time, timestamp_t timestamp);
extern void dive_create_picture(struct dive *d, char *filename, int shift_time); extern void dive_create_picture(struct dive *d, char *filename, int shift_time, bool match_all);
extern void dive_add_picture(struct dive *d, struct picture *newpic); extern void dive_add_picture(struct dive *d, struct picture *newpic);
extern void dive_remove_picture(char *filename); extern void dive_remove_picture(char *filename);
extern unsigned int dive_get_picture_count(struct dive *d); extern unsigned int dive_get_picture_count(struct dive *d);

View file

@ -925,7 +925,7 @@ void DiveListView::matchImagesToDives(QStringList fileNames)
for_each_dive (j, dive) { for_each_dive (j, dive) {
if (!dive->selected) if (!dive->selected)
continue; continue;
dive_create_picture(dive, copy_string(fileName.toUtf8().data()), shiftDialog.amount()); dive_create_picture(dive, copy_string(fileName.toUtf8().data()), shiftDialog.amount(), shiftDialog.matchAll());
} }
} }

View file

@ -131,6 +131,13 @@ Not all images have timestamps in the range between
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="matchAllImages">
<property name="text">
<string>Load images even if the time does not match the dive time</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="invalidLabel"> <widget class="QLabel" name="invalidLabel">
<property name="styleSheet"> <property name="styleSheet">

View file

@ -312,12 +312,23 @@ void ShiftImageTimesDialog::dcDateTimeChanged(const QDateTime &newDateTime)
setOffset(newDateTime.toTime_t() - dcImageEpoch); setOffset(newDateTime.toTime_t() - dcImageEpoch);
} }
void ShiftImageTimesDialog::matchAllImagesToggled(bool state)
{
matchAllImages = state;
}
bool ShiftImageTimesDialog::matchAll()
{
return matchAllImages;
}
ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent, QStringList fileNames) : QDialog(parent), fileNames(fileNames), m_amount(0) ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent, QStringList fileNames) : QDialog(parent), fileNames(fileNames), m_amount(0)
{ {
ui.setupUi(this); ui.setupUi(this);
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked())); connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked()));
connect(ui.timeEdit, SIGNAL(timeChanged(const QTime &)), this, SLOT(timeEditChanged(const QTime &))); connect(ui.timeEdit, SIGNAL(timeChanged(const QTime &)), this, SLOT(timeEditChanged(const QTime &)));
connect(ui.matchAllImages, SIGNAL(toggled(bool)), this, SLOT(matchAllImagesToggled(bool)));
dcImageEpoch = (time_t)0; dcImageEpoch = (time_t)0;
} }

View file

@ -101,6 +101,7 @@ public:
explicit ShiftImageTimesDialog(QWidget *parent, QStringList fileNames); explicit ShiftImageTimesDialog(QWidget *parent, QStringList fileNames);
time_t amount() const; time_t amount() const;
void setOffset(time_t offset); void setOffset(time_t offset);
bool matchAll();
private private
slots: slots:
void buttonClicked(QAbstractButton *button); void buttonClicked(QAbstractButton *button);
@ -108,12 +109,14 @@ slots:
void dcDateTimeChanged(const QDateTime &); void dcDateTimeChanged(const QDateTime &);
void timeEditChanged(const QTime &time); void timeEditChanged(const QTime &time);
void updateInvalid(); void updateInvalid();
void matchAllImagesToggled(bool);
private: private:
QStringList fileNames; QStringList fileNames;
Ui::ShiftImageTimesDialog ui; Ui::ShiftImageTimesDialog ui;
time_t m_amount; time_t m_amount;
time_t dcImageEpoch; time_t dcImageEpoch;
bool matchAllImages;
}; };
class URLDialog : public QDialog { class URLDialog : public QDialog {