diff --git a/core/dive.c b/core/dive.c index 88f4f036e..5d43ce2d7 100644 --- a/core/dive.c +++ b/core/dive.c @@ -2333,8 +2333,8 @@ static int likely_same_dive(const struct dive *a, const struct dive *b) int match, fuzz = 20 * 60; /* don't merge manually added dives with anything */ - if (same_string(a->dc.model, "manually added dive") || - same_string(b->dc.model, "manually added dive")) + if (is_manually_added_dc(&a->dc) || + is_manually_added_dc(&b->dc)) return 0; /* diff --git a/core/divecomputer.c b/core/divecomputer.c index 6f8964601..0a488fa01 100644 --- a/core/divecomputer.c +++ b/core/divecomputer.c @@ -548,3 +548,9 @@ void free_dc(struct divecomputer *dc) free_dc_contents(dc); free(dc); } + +bool is_manually_added_dc(const struct divecomputer *dc) +{ + return dc && dc->samples <= 50 && + same_string(dc->model, "manually added dive"); +} diff --git a/core/divecomputer.h b/core/divecomputer.h index 8bb571c44..adaa30c57 100644 --- a/core/divecomputer.h +++ b/core/divecomputer.h @@ -69,6 +69,7 @@ extern void remove_event_from_dc(struct divecomputer *dc, struct event *event); extern void add_extra_data(struct divecomputer *dc, const char *key, const char *value); extern bool is_dc_planner(const struct divecomputer *dc); extern uint32_t calculate_string_hash(const char *str); +extern bool is_manually_added_dc(const struct divecomputer *dc); /* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */ extern int match_one_dc(const struct divecomputer *a, const struct divecomputer *b); diff --git a/desktop-widgets/profilewidget.cpp b/desktop-widgets/profilewidget.cpp index e6fc9b098..9582d1bba 100644 --- a/desktop-widgets/profilewidget.cpp +++ b/desktop-widgets/profilewidget.cpp @@ -192,7 +192,7 @@ void ProfileWidget::plotCurrentDive() if (current_dive && !editedDive && DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING) { struct divecomputer *dc = get_dive_dc(current_dive, dc_number); - if (dc && same_string(dc->model, "manually added dive") && dc->samples) + if (dc && is_manually_added_dc(dc) && dc->samples) editDive(); } diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index 7a620a4d3..89643e09f 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -210,7 +210,7 @@ void TabDiveInformation::updateData() } int salinity_value; - manualDive = same_string(current_dive->dc.model, "manually added dive"); + manualDive = is_manually_added_dc(¤t_dive->dc); updateWaterTypeWidget(); updateProfile(); updateWhen(); diff --git a/desktop-widgets/tab-widgets/TabDiveNotes.cpp b/desktop-widgets/tab-widgets/TabDiveNotes.cpp index 4d052fb2f..9bc94e371 100644 --- a/desktop-widgets/tab-widgets/TabDiveNotes.cpp +++ b/desktop-widgets/tab-widgets/TabDiveNotes.cpp @@ -251,7 +251,7 @@ void TabDiveNotes::updateData() ui.LocationLabel->setText(tr("Location")); ui.NotesLabel->setText(tr("Notes")); ui.tagWidget->setText(get_taglist_string(current_dive->tag_list)); - bool isManual = same_string(current_dive->dc.model, "manually added dive"); + bool isManual = is_manually_added_dc(¤t_dive->dc); ui.depth->setVisible(isManual); ui.depthLabel->setVisible(isManual); ui.duration->setVisible(isManual); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index c47bec59e..1f37ecb96 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1127,7 +1127,7 @@ bool QMLManager::checkDuration(struct dive *d, QString duration) m = m6.captured(1).toInt(); } d->dc.duration.seconds = d->duration.seconds = h * 3600 + m * 60 + s; - if (same_string(d->dc.model, "manually added dive")) + if (is_manually_added_dc(&d->dc)) free_samples(&d->dc); else appendTextToLog("Cannot change the duration on a dive that wasn't manually added"); @@ -1145,7 +1145,7 @@ bool QMLManager::checkDepth(dive *d, QString depth) // the depth <= 500m if (0 <= depthValue && depthValue <= 500000) { d->maxdepth.mm = depthValue; - if (same_string(d->dc.model, "manually added dive")) { + if (is_manually_added_dc(&d->dc)) { d->dc.maxdepth.mm = d->maxdepth.mm; free_samples(&d->dc); } @@ -1351,7 +1351,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt if (diveChanged) { if (d->maxdepth.mm == d->dc.maxdepth.mm && d->maxdepth.mm > 0 && - same_string(d->dc.model, "manually added dive") && + is_manually_added_dc(&d->dc) && d->dc.samples == 0) { // so we have depth > 0, a manually added dive and no samples // let's create an actual profile so the desktop version can work it