Cleanup: Improve the Use of 'Planned dive' and 'Manually added dive'.

- standardise the naming;
- use it consistently;
- apply the 'samples < 50' only when putting manually added dives into
  edit mode - everywhere else manually added dives should be treated as
  such;
- do not show a warning before editing a manually added dive in planner.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-05-23 16:06:23 +12:00 committed by bstoeger
parent ecc6f64d10
commit 1aa5438b2d
10 changed files with 47 additions and 34 deletions

View file

@ -2309,8 +2309,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 (is_manually_added_dc(&a->dc) ||
is_manually_added_dc(&b->dc))
if (is_dc_manually_added_dive(&a->dc) ||
is_dc_manually_added_dive(&b->dc))
return 0;
/*
@ -3244,11 +3244,11 @@ extern "C" int depth_to_mbar(int depth, const struct dive *dive)
extern "C" double depth_to_mbarf(int depth, const struct dive *dive)
{
// To downloaded and planned dives, use DC's values
// For downloaded and planned dives, use DC's values
int salinity = dive->dc.salinity;
pressure_t surface_pressure = dive->dc.surface_pressure;
if (is_manually_added_dc(&dive->dc)) { // To manual dives, salinity and pressure in another place...
if (is_dc_manually_added_dive(&dive->dc)) { // For manual dives, salinity and pressure in another place...
surface_pressure = dive->surface_pressure;
salinity = dive->user_salinity;
}
@ -3271,8 +3271,8 @@ extern "C" double depth_to_atm(int depth, const struct dive *dive)
* take care of this, but the Uemis we support natively */
extern "C" int rel_mbar_to_depth(int mbar, const struct dive *dive)
{
// To downloaded and planned dives, use DC's salinity. Manual dives, use user's salinity
int salinity = is_manually_added_dc(&dive->dc) ? dive->user_salinity : dive->dc.salinity;
// For downloaded and planned dives, use DC's salinity. Manual dives, use user's salinity
int salinity = is_dc_manually_added_dive(&dive->dc) ? dive->user_salinity : dive->dc.salinity;
if (!salinity)
salinity = SEAWATER_SALINITY;
@ -3283,8 +3283,8 @@ extern "C" int rel_mbar_to_depth(int mbar, const struct dive *dive)
extern "C" int mbar_to_depth(int mbar, const struct dive *dive)
{
// To downloaded and planned dives, use DC's pressure. Manual dives, use user's pressure
pressure_t surface_pressure = is_manually_added_dc(&dive->dc)
// For downloaded and planned dives, use DC's pressure. Manual dives, use user's pressure
pressure_t surface_pressure = is_dc_manually_added_dive(&dive->dc)
? dive->surface_pressure
: dive->dc.surface_pressure;

View file

@ -492,11 +492,6 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
}
}
bool is_dc_planner(const struct divecomputer *dc)
{
return same_string(dc->model, "planned dive");
}
/*
* Match two dive computer entries against each other, and
* tell if it's the same dive. Return 0 if "don't know",
@ -548,14 +543,27 @@ 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)
static const char *planner_dc_name = "planned dive";
bool is_dc_planner(const struct divecomputer *dc)
{
return dc && dc->samples <= 50 &&
same_string(dc->model, manual_dc_name);
return dc && same_string(dc->model, planner_dc_name);
}
void make_manually_added_dc(struct divecomputer *dc)
void make_planner_dc(struct divecomputer *dc)
{
free((void *)dc->model);
dc->model = strdup(planner_dc_name);
}
const char *manual_dc_name = "manually added dive";
bool is_dc_manually_added_dive(const struct divecomputer *dc)
{
return dc && same_string(dc->model, manual_dc_name);
}
void make_manually_added_dive_dc(struct divecomputer *dc)
{
free((void *)dc->model);
dc->model = strdup(manual_dc_name);

View file

@ -67,10 +67,12 @@ extern void add_event_to_dc(struct divecomputer *dc, struct event *ev);
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name);
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);
extern void make_manually_added_dc(struct divecomputer *dc);
extern bool is_dc_planner(const struct divecomputer *dc);
extern void make_planner_dc(struct divecomputer *dc);
extern const char *manual_dc_name;
extern bool is_dc_manually_added_dive(const struct divecomputer *dc);
extern void make_manually_added_dive_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);