Get trip location from dive's dive site

This adds another useful helper function as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-02-12 12:49:25 -08:00
parent 0ce215e0d9
commit 7fb35c98d3
2 changed files with 11 additions and 4 deletions

8
dive.h
View file

@ -512,6 +512,14 @@ static inline struct dive_site *get_dive_site_for_dive(struct dive *dive)
return NULL; return NULL;
} }
static inline char *get_dive_location(struct dive *dive)
{
struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
if (ds && ds->name)
return ds->name;
return NULL;
}
static inline unsigned int number_of_computers(struct dive *dive) static inline unsigned int number_of_computers(struct dive *dive)
{ {
unsigned int total_number = 0; unsigned int total_number = 0;

View file

@ -678,9 +678,9 @@ void add_dive_to_trip(struct dive *dive, dive_trip_t *trip)
dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive) dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive)
{ {
dive_trip_t *dive_trip = calloc(1, sizeof(dive_trip_t)); dive_trip_t *dive_trip = calloc(1, sizeof(dive_trip_t));
dive_trip->when = dive->when; dive_trip->when = dive->when;
if (dive->location) dive_trip->location = copy_string(get_dive_location(dive));
dive_trip->location = strdup(dive->location);
insert_trip(&dive_trip); insert_trip(&dive_trip);
dive->tripflag = IN_TRIP; dive->tripflag = IN_TRIP;
@ -714,7 +714,7 @@ void autogroup_dives(void)
dive_trip_t *trip = lastdive->divetrip; dive_trip_t *trip = lastdive->divetrip;
add_dive_to_trip(dive, trip); add_dive_to_trip(dive, trip);
if (dive->location && !trip->location) if (dive->location && !trip->location)
trip->location = strdup(dive->location); trip->location = copy_string(get_dive_location(dive));
lastdive = dive; lastdive = dive;
continue; continue;
} }
@ -745,7 +745,6 @@ void delete_single_dive(int idx)
dive_table.dives[--dive_table.nr] = NULL; dive_table.dives[--dive_table.nr] = NULL;
/* free all allocations */ /* free all allocations */
free(dive->dc.sample); free(dive->dc.sample);
free((void *)dive->location);
free((void *)dive->notes); free((void *)dive->notes);
free((void *)dive->divemaster); free((void *)dive->divemaster);
free((void *)dive->buddy); free((void *)dive->buddy);