From 261f07dfa4b854cb0baca93fa8b61038a02a47c4 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 21 Oct 2022 18:12:11 +0200 Subject: [PATCH] core: add make_manually_added_dc() function For reasons of symmetry (there is a is_manually_added_dc() function), create a make_manually_added_dc() function. Signed-off-by: Berthold Stoeger --- core/divecomputer.c | 9 ++++++++- core/divecomputer.h | 1 + desktop-widgets/mainwindow.cpp | 2 +- mobile-widgets/qmlmanager.cpp | 2 +- smtk-import/smartrak.c | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/divecomputer.c b/core/divecomputer.c index 0a488fa01..94de56f66 100644 --- a/core/divecomputer.c +++ b/core/divecomputer.c @@ -549,8 +549,15 @@ void free_dc(struct divecomputer *dc) free(dc); } +static const char *manual_dc_name = "manually added dive"; bool is_manually_added_dc(const struct divecomputer *dc) { return dc && dc->samples <= 50 && - same_string(dc->model, "manually added dive"); + same_string(dc->model, manual_dc_name); +} + +void make_manually_added_dc(struct divecomputer *dc) +{ + free((void *)dc->model); + dc->model = strdup(manual_dc_name); } diff --git a/core/divecomputer.h b/core/divecomputer.h index adaa30c57..3f3d1bf64 100644 --- a/core/divecomputer.h +++ b/core/divecomputer.h @@ -70,6 +70,7 @@ extern void add_extra_data(struct divecomputer *dc, const char *key, const char 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); +extern void make_manually_added_dc(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/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index c00dced6d..2aeafeace 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -690,7 +690,7 @@ void MainWindow::on_actionAddDive_triggered() d.dc.duration.seconds = 40 * 60; d.dc.maxdepth.mm = M_OR_FT(15, 45); d.dc.meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop - d.dc.model = strdup("manually added dive"); // don't translate! this is stored in the XML file + make_manually_added_dc(&d.dc); fake_dc(&d.dc); fixup_dive(&d); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 1f37ecb96..d028383e8 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1716,7 +1716,7 @@ int QMLManager::addDive() d.dc.duration.seconds = 40 * 60; d.dc.maxdepth.mm = M_OR_FT(15, 45); d.dc.meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop - d.dc.model = strdup("manually added dive"); // don't translate! this is stored in the XML file + make_manually_added_dc(&d.dc); fake_dc(&d.dc); fixup_dive(&d); diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c index 9e44f0295..61c8d080a 100644 --- a/smtk-import/smartrak.c +++ b/smtk-import/smartrak.c @@ -868,7 +868,7 @@ static int prepare_data(int data_model, char *serial, dc_family_t dc_fam, device { dev_data->device = NULL; dev_data->context = NULL; - if (!data_model){ + if (!data_model) { dev_data->model = copy_string("manually added dive"); dev_data->descriptor = NULL; return DC_STATUS_NODEVICE;