mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Dive site: add dive site table parameter to dive site functions
To enable undo of dive site functions, it is crucial to work with different dive site tables. Therefore add a dive site table parameter to dive site functions. For now, always pass the global dive site table. Thus, this commit shouldn't alter any functionality. After this change, a simple search for dive_site_table reveals all places where the global dive site table is accessed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									36644dc9f7
								
							
						
					
					
						commit
						f6e7bdc5ef
					
				
					 22 changed files with 118 additions and 118 deletions
				
			
		|  | @ -193,10 +193,10 @@ static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive | ||||||
| 	 * Locality and Dive points. | 	 * Locality and Dive points. | ||||||
| 	 */ | 	 */ | ||||||
| 	snprintf(buffer, sizeof(buffer), "%s, %s", locality, dive_point); | 	snprintf(buffer, sizeof(buffer), "%s, %s", locality, dive_point); | ||||||
| 	ds = get_dive_site_by_name(buffer); | 	ds = get_dive_site_by_name(buffer, &dive_site_table); | ||||||
| 	dt_dive->dive_site = ds; | 	dt_dive->dive_site = ds; | ||||||
| 	if (!dt_dive->dive_site) | 	if (!dt_dive->dive_site) | ||||||
| 		dt_dive->dive_site = create_dive_site(buffer, dt_dive->when); | 		dt_dive->dive_site = create_dive_site(buffer, dt_dive->when, &dive_site_table); | ||||||
| 	free(locality); | 	free(locality); | ||||||
| 	locality = NULL; | 	locality = NULL; | ||||||
| 	free(dive_point); | 	free(dive_point); | ||||||
|  |  | ||||||
|  | @ -4026,14 +4026,14 @@ bool picture_check_valid_time(timestamp_t timestamp, int shift_time) | ||||||
| 	return false; | 	return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture) | static void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture, struct dive_site_table *table) | ||||||
| { | { | ||||||
| 	struct dive_site *ds = dive->dive_site; | 	struct dive_site *ds = dive->dive_site; | ||||||
| 	if (!dive_site_has_gps_location(ds) && has_location(&picture->location)) { | 	if (!dive_site_has_gps_location(ds) && has_location(&picture->location)) { | ||||||
| 		if (ds) { | 		if (ds) { | ||||||
| 			ds->location = picture->location; | 			ds->location = picture->location; | ||||||
| 		} else { | 		} else { | ||||||
| 			dive->dive_site = create_dive_site_with_gps("", &picture->location, dive->when); | 			dive->dive_site = create_dive_site_with_gps("", &picture->location, dive->when, table); | ||||||
| 			invalidate_dive_cache(dive); | 			invalidate_dive_cache(dive); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | @ -4062,7 +4062,7 @@ void create_picture(const char *filename, int shift_time, bool match_all) | ||||||
| 	picture->location = metadata.location; | 	picture->location = metadata.location; | ||||||
| 
 | 
 | ||||||
| 	dive_add_picture(dive, picture); | 	dive_add_picture(dive, picture); | ||||||
| 	dive_set_geodata_from_picture(dive, picture); | 	dive_set_geodata_from_picture(dive, picture, &dive_site_table); | ||||||
| 	invalidate_dive_cache(dive); | 	invalidate_dive_cache(dive); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1823,7 +1823,7 @@ void clear_dive_file_data() | ||||||
| 	while (dive_table.nr) | 	while (dive_table.nr) | ||||||
| 		delete_single_dive(0); | 		delete_single_dive(0); | ||||||
| 	while (dive_site_table.nr) | 	while (dive_site_table.nr) | ||||||
| 		delete_dive_site(get_dive_site(0)); | 		delete_dive_site(get_dive_site(0, &dive_site_table), &dive_site_table); | ||||||
| 	if (trip_table.nr != 0) { | 	if (trip_table.nr != 0) { | ||||||
| 		fprintf(stderr, "Warning: trip table not empty in clear_dive_file_data()!\n"); | 		fprintf(stderr, "Warning: trip table not empty in clear_dive_file_data()!\n"); | ||||||
| 		trip_table.nr = 0; | 		trip_table.nr = 0; | ||||||
|  |  | ||||||
|  | @ -10,35 +10,35 @@ | ||||||
| 
 | 
 | ||||||
| struct dive_site_table dive_site_table; | struct dive_site_table dive_site_table; | ||||||
| 
 | 
 | ||||||
| int get_divesite_idx(const struct dive_site *ds) | int get_divesite_idx(const struct dive_site *ds, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
| 	const struct dive_site *d; | 	const struct dive_site *d; | ||||||
| 	// tempting as it may be, don't die when called with dive=NULL
 | 	// tempting as it may be, don't die when called with dive=NULL
 | ||||||
| 	if (ds) | 	if (ds) | ||||||
| 		for_each_dive_site(i, d) { | 		for_each_dive_site(i, d, ds_table) { | ||||||
| 			if (d->uuid == ds->uuid) // don't compare pointers, we could be passing in a copy of the dive
 | 			if (d->uuid == ds->uuid) // don't compare pointers, we could be passing in a copy of the dive
 | ||||||
| 				return i; | 				return i; | ||||||
| 		} | 		} | ||||||
| 	return -1; | 	return -1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct dive_site *get_dive_site_by_uuid(uint32_t uuid) | struct dive_site *get_dive_site_by_uuid(uint32_t uuid, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 	for_each_dive_site (i, ds) | 	for_each_dive_site (i, ds, ds_table) | ||||||
| 		if (ds->uuid == uuid) | 		if (ds->uuid == uuid) | ||||||
| 			return get_dive_site(i); | 			return get_dive_site(i, ds_table); | ||||||
| 	return NULL; | 	return NULL; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* there could be multiple sites of the same name - return the first one */ | /* there could be multiple sites of the same name - return the first one */ | ||||||
| struct dive_site *get_dive_site_by_name(const char *name) | struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 	for_each_dive_site (i, ds) { | 	for_each_dive_site (i, ds, ds_table) { | ||||||
| 		if (same_string(ds->name, name)) | 		if (same_string(ds->name, name)) | ||||||
| 			return ds; | 			return ds; | ||||||
| 	} | 	} | ||||||
|  | @ -46,11 +46,11 @@ struct dive_site *get_dive_site_by_name(const char *name) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* there could be multiple sites at the same GPS fix - return the first one */ | /* there could be multiple sites at the same GPS fix - return the first one */ | ||||||
| struct dive_site *get_dive_site_by_gps(const location_t *loc) | struct dive_site *get_dive_site_by_gps(const location_t *loc, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 	for_each_dive_site (i, ds) { | 	for_each_dive_site (i, ds, ds_table) { | ||||||
| 		if (same_location(loc, &ds->location)) | 		if (same_location(loc, &ds->location)) | ||||||
| 			return ds; | 			return ds; | ||||||
| 	} | 	} | ||||||
|  | @ -60,11 +60,11 @@ struct dive_site *get_dive_site_by_gps(const location_t *loc) | ||||||
| /* to avoid a bug where we have two dive sites with different name and the same GPS coordinates
 | /* to avoid a bug where we have two dive sites with different name and the same GPS coordinates
 | ||||||
|  * and first get the gps coordinates (reading a V2 file) and happen to get back "the other" name, |  * and first get the gps coordinates (reading a V2 file) and happen to get back "the other" name, | ||||||
|  * this function allows us to verify if a very specific name/GPS combination already exists */ |  * this function allows us to verify if a very specific name/GPS combination already exists */ | ||||||
| struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *loc) | struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *loc, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 	for_each_dive_site (i, ds) { | 	for_each_dive_site (i, ds, ds_table) { | ||||||
| 		if (same_location(loc, &ds->location) && same_string(ds->name, name)) | 		if (same_location(loc, &ds->location) && same_string(ds->name, name)) | ||||||
| 			return ds; | 			return ds; | ||||||
| 	} | 	} | ||||||
|  | @ -87,12 +87,12 @@ unsigned int get_distance(const location_t *loc1, const location_t *loc2) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* find the closest one, no more than distance meters away - if more than one at same distance, pick the first */ | /* find the closest one, no more than distance meters away - if more than one at same distance, pick the first */ | ||||||
| struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int distance) | struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int distance, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
| 	struct dive_site *ds, *res = NULL; | 	struct dive_site *ds, *res = NULL; | ||||||
| 	unsigned int cur_distance, min_distance = distance; | 	unsigned int cur_distance, min_distance = distance; | ||||||
| 	for_each_dive_site (i, ds) { | 	for_each_dive_site (i, ds, ds_table) { | ||||||
| 		if (dive_site_has_gps_location(ds) && | 		if (dive_site_has_gps_location(ds) && | ||||||
| 		    (cur_distance = get_distance(&ds->location, loc)) < min_distance) { | 		    (cur_distance = get_distance(&ds->location, loc)) < min_distance) { | ||||||
| 			min_distance = cur_distance; | 			min_distance = cur_distance; | ||||||
|  | @ -103,11 +103,11 @@ struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int dist | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* try to create a uniqe ID - fingers crossed */ | /* try to create a uniqe ID - fingers crossed */ | ||||||
| static uint32_t dive_site_getUniqId() | static uint32_t dive_site_getUniqId(struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	uint32_t id = 0; | 	uint32_t id = 0; | ||||||
| 
 | 
 | ||||||
| 	while (id == 0 || get_dive_site_by_uuid(id)) { | 	while (id == 0 || get_dive_site_by_uuid(id, ds_table)) { | ||||||
| 		id = rand() & 0xff; | 		id = rand() & 0xff; | ||||||
| 		id |= (rand() & 0xff) << 8; | 		id |= (rand() & 0xff) << 8; | ||||||
| 		id |= (rand() & 0xff) << 16; | 		id |= (rand() & 0xff) << 16; | ||||||
|  | @ -118,30 +118,30 @@ static uint32_t dive_site_getUniqId() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* we never allow a second dive site with the same uuid */ | /* we never allow a second dive site with the same uuid */ | ||||||
| struct dive_site *alloc_or_get_dive_site(uint32_t uuid) | struct dive_site *alloc_or_get_dive_site(uint32_t uuid, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 
 | 
 | ||||||
| 	if (uuid && (ds = get_dive_site_by_uuid(uuid)) != NULL) | 	if (uuid && (ds = get_dive_site_by_uuid(uuid, ds_table)) != NULL) | ||||||
| 		return ds; | 		return ds; | ||||||
| 
 | 
 | ||||||
| 	int nr = dive_site_table.nr; | 	int nr = ds_table->nr; | ||||||
| 	int allocated = dive_site_table.allocated; | 	int allocated = ds_table->allocated; | ||||||
| 	struct dive_site **sites = dive_site_table.dive_sites; | 	struct dive_site **sites = ds_table->dive_sites; | ||||||
| 
 | 
 | ||||||
| 	if (nr >= allocated) { | 	if (nr >= allocated) { | ||||||
| 		allocated = (nr + 32) * 3 / 2; | 		allocated = (nr + 32) * 3 / 2; | ||||||
| 		sites = realloc(sites, allocated * sizeof(struct dive_site *)); | 		sites = realloc(sites, allocated * sizeof(struct dive_site *)); | ||||||
| 		if (!sites) | 		if (!sites) | ||||||
| 			exit(1); | 			exit(1); | ||||||
| 		dive_site_table.dive_sites = sites; | 		ds_table->dive_sites = sites; | ||||||
| 		dive_site_table.allocated = allocated; | 		ds_table->allocated = allocated; | ||||||
| 	} | 	} | ||||||
| 	ds = calloc(1, sizeof(*ds)); | 	ds = calloc(1, sizeof(*ds)); | ||||||
| 	if (!ds) | 	if (!ds) | ||||||
| 		exit(1); | 		exit(1); | ||||||
| 	sites[nr] = ds; | 	sites[nr] = ds; | ||||||
| 	dive_site_table.nr = nr + 1; | 	ds_table->nr = nr + 1; | ||||||
| 	// we should always be called with a valid uuid except in the special
 | 	// we should always be called with a valid uuid except in the special
 | ||||||
| 	// case where we want to copy a dive site into the memory we allocated
 | 	// case where we want to copy a dive site into the memory we allocated
 | ||||||
| 	// here - then we need to pass in 0 and create a temporary uuid here
 | 	// here - then we need to pass in 0 and create a temporary uuid here
 | ||||||
|  | @ -149,7 +149,7 @@ struct dive_site *alloc_or_get_dive_site(uint32_t uuid) | ||||||
| 	if (uuid) | 	if (uuid) | ||||||
| 		ds->uuid = uuid; | 		ds->uuid = uuid; | ||||||
| 	else | 	else | ||||||
| 		ds->uuid = dive_site_getUniqId(); | 		ds->uuid = dive_site_getUniqId(ds_table); | ||||||
| 	return ds; | 	return ds; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -195,17 +195,17 @@ void free_dive_site(struct dive_site *ds) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void delete_dive_site(struct dive_site *ds) | void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int nr = dive_site_table.nr; | 	int nr = ds_table->nr; | ||||||
| 	for (int i = 0; i < nr; i++) { | 	for (int i = 0; i < nr; i++) { | ||||||
| 		if (ds == get_dive_site(i)) { | 		if (ds == get_dive_site(i, ds_table)) { | ||||||
| 			free_dive_site(ds); | 			free_dive_site(ds); | ||||||
| 			if (nr - 1 > i) | 			if (nr - 1 > i) | ||||||
| 				memmove(&dive_site_table.dive_sites[i], | 				memmove(&ds_table->dive_sites[i], | ||||||
| 					&dive_site_table.dive_sites[i+1], | 					&ds_table->dive_sites[i+1], | ||||||
| 					(nr - 1 - i) * sizeof(dive_site_table.dive_sites[0])); | 					(nr - 1 - i) * sizeof(ds_table->dive_sites[0])); | ||||||
| 			dive_site_table.nr = nr - 1; | 			ds_table->nr = nr - 1; | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | @ -229,19 +229,19 @@ static uint32_t create_divesite_uuid(const char *name, timestamp_t divetime) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* allocate a new site and add it to the table */ | /* allocate a new site and add it to the table */ | ||||||
| struct dive_site *create_dive_site(const char *name, timestamp_t divetime) | struct dive_site *create_dive_site(const char *name, timestamp_t divetime, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	uint32_t uuid = create_divesite_uuid(name, divetime); | 	uint32_t uuid = create_divesite_uuid(name, divetime); | ||||||
| 	struct dive_site *ds = alloc_or_get_dive_site(uuid); | 	struct dive_site *ds = alloc_or_get_dive_site(uuid, ds_table); | ||||||
| 	ds->name = copy_string(name); | 	ds->name = copy_string(name); | ||||||
| 	return ds; | 	return ds; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* same as before, but with GPS data */ | /* same as before, but with GPS data */ | ||||||
| struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, timestamp_t divetime) | struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, timestamp_t divetime, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	uint32_t uuid = create_divesite_uuid(name, divetime); | 	uint32_t uuid = create_divesite_uuid(name, divetime); | ||||||
| 	struct dive_site *ds = alloc_or_get_dive_site(uuid); | 	struct dive_site *ds = alloc_or_get_dive_site(uuid, ds_table); | ||||||
| 	ds->name = copy_string(name); | 	ds->name = copy_string(name); | ||||||
| 	ds->location = *loc; | 	ds->location = *loc; | ||||||
| 
 | 
 | ||||||
|  | @ -323,32 +323,32 @@ void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int | ||||||
| 	for(i = 0; i < count; i++) { | 	for(i = 0; i < count; i++) { | ||||||
| 		if (dive_sites[i] == ref) | 		if (dive_sites[i] == ref) | ||||||
| 			continue; | 			continue; | ||||||
| 		delete_dive_site(dive_sites[i]); | 		delete_dive_site(dive_sites[i], &dive_site_table); | ||||||
| 	} | 	} | ||||||
| 	mark_divelist_changed(true); | 	mark_divelist_changed(true); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime) | struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 	for_each_dive_site(i,ds) { | 	for_each_dive_site(i,ds, ds_table) { | ||||||
| 		if (same_string(name, ds->name)) | 		if (same_string(name, ds->name)) | ||||||
| 			break; | 			break; | ||||||
| 	} | 	} | ||||||
| 	if (ds) | 	if (ds) | ||||||
| 		return ds; | 		return ds; | ||||||
| 	return create_dive_site(name, divetime); | 	return create_dive_site(name, divetime, ds_table); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void purge_empty_dive_sites() | void purge_empty_dive_sites(struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	int i, j; | 	int i, j; | ||||||
| 	struct dive *d; | 	struct dive *d; | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 
 | 
 | ||||||
| 	for (i = 0; i < dive_site_table.nr; i++) { | 	for (i = 0; i < ds_table->nr; i++) { | ||||||
| 		ds = get_dive_site(i); | 		ds = get_dive_site(i, ds_table); | ||||||
| 		if (!dive_site_is_empty(ds)) | 		if (!dive_site_is_empty(ds)) | ||||||
| 			continue; | 			continue; | ||||||
| 		for_each_dive(j, d) { | 		for_each_dive(j, d) { | ||||||
|  | @ -365,7 +365,7 @@ static int compare_sites(const void *_a, const void *_b) | ||||||
| 	return a->uuid > b->uuid ? 1 : a->uuid == b->uuid ? 0 : -1; | 	return a->uuid > b->uuid ? 1 : a->uuid == b->uuid ? 0 : -1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void dive_site_table_sort() | void dive_site_table_sort(struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	qsort(dive_site_table.dive_sites, dive_site_table.nr, sizeof(struct dive_site *), compare_sites); | 	qsort(ds_table->dive_sites, ds_table->nr, sizeof(struct dive_site *), compare_sites); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -31,39 +31,39 @@ struct dive_site_table { | ||||||
| 
 | 
 | ||||||
| extern struct dive_site_table dive_site_table; | extern struct dive_site_table dive_site_table; | ||||||
| 
 | 
 | ||||||
| static inline struct dive_site *get_dive_site(int nr) | static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds_table) | ||||||
| { | { | ||||||
| 	if (nr >= dive_site_table.nr || nr < 0) | 	if (nr >= ds_table->nr || nr < 0) | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	return dive_site_table.dive_sites[nr]; | 	return ds_table->dive_sites[nr]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* iterate over each dive site */ | /* iterate over each dive site */ | ||||||
| #define for_each_dive_site(_i, _x) \ | #define for_each_dive_site(_i, _x, _ds_table) \ | ||||||
| 	for ((_i) = 0; ((_x) = get_dive_site(_i)) != NULL; (_i)++) | 	for ((_i) = 0; ((_x) = get_dive_site(_i, _ds_table)) != NULL; (_i)++) | ||||||
| 
 | 
 | ||||||
| int get_divesite_idx(const struct dive_site *ds); | int get_divesite_idx(const struct dive_site *ds, struct dive_site_table *ds_table); | ||||||
| struct dive_site *get_dive_site_by_uuid(uint32_t uuid); | struct dive_site *get_dive_site_by_uuid(uint32_t uuid, struct dive_site_table *ds_table); | ||||||
| void dive_site_table_sort(); | void dive_site_table_sort(struct dive_site_table *ds_table); | ||||||
| struct dive_site *alloc_or_get_dive_site(uint32_t uuid); | struct dive_site *alloc_or_get_dive_site(uint32_t uuid, struct dive_site_table *ds_table); | ||||||
| int nr_of_dives_at_dive_site(struct dive_site *ds, bool select_only); | int nr_of_dives_at_dive_site(struct dive_site *ds, bool select_only); | ||||||
| bool is_dive_site_used(struct dive_site *ds, bool select_only); | bool is_dive_site_used(struct dive_site *ds, bool select_only); | ||||||
| void free_dive_site(struct dive_site *ds); | void free_dive_site(struct dive_site *ds); | ||||||
| void delete_dive_site(struct dive_site *ds); | void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table); | ||||||
| struct dive_site *create_dive_site(const char *name, timestamp_t divetime); | struct dive_site *create_dive_site(const char *name, timestamp_t divetime, struct dive_site_table *ds_table); | ||||||
| struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, timestamp_t divetime); | struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, timestamp_t divetime, struct dive_site_table *ds_table); | ||||||
| struct dive_site *get_dive_site_by_name(const char *name); | struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table); | ||||||
| struct dive_site *get_dive_site_by_gps(const location_t *); | struct dive_site *get_dive_site_by_gps(const location_t *, struct dive_site_table *ds_table); | ||||||
| struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *); | struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *, struct dive_site_table *ds_table); | ||||||
| struct dive_site *get_dive_site_by_gps_proximity(const location_t *, int distance); | struct dive_site *get_dive_site_by_gps_proximity(const location_t *, int distance, struct dive_site_table *ds_table); | ||||||
| bool dive_site_is_empty(struct dive_site *ds); | bool dive_site_is_empty(struct dive_site *ds); | ||||||
| void copy_dive_site_taxonomy(struct dive_site *orig, struct dive_site *copy); | void copy_dive_site_taxonomy(struct dive_site *orig, struct dive_site *copy); | ||||||
| void copy_dive_site(struct dive_site *orig, struct dive_site *copy); | void copy_dive_site(struct dive_site *orig, struct dive_site *copy); | ||||||
| void merge_dive_site(struct dive_site *a, struct dive_site *b); | void merge_dive_site(struct dive_site *a, struct dive_site *b); | ||||||
| unsigned int get_distance(const location_t *loc1, const location_t *loc2); | unsigned int get_distance(const location_t *loc1, const location_t *loc2); | ||||||
| struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime); | struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime, struct dive_site_table *ds_table); | ||||||
| void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int count); | void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int count); | ||||||
| void purge_empty_dive_sites(); | void purge_empty_dive_sites(struct dive_site_table *ds_table); | ||||||
| 
 | 
 | ||||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -211,7 +211,7 @@ static void copy_gps_location(struct gpsTracker &gps, struct dive *d) | ||||||
| { | { | ||||||
| 	struct dive_site *ds = d->dive_site; | 	struct dive_site *ds = d->dive_site; | ||||||
| 	if (!ds) { | 	if (!ds) { | ||||||
| 		ds = create_dive_site(qPrintable(gps.name), gps.when); | 		ds = create_dive_site(qPrintable(gps.name), gps.when, &dive_site_table); | ||||||
| 		d->dive_site = ds; | 		d->dive_site = ds; | ||||||
| 	} | 	} | ||||||
| 	ds->location = gps.location; | 	ds->location = gps.location; | ||||||
|  |  | ||||||
|  | @ -197,7 +197,7 @@ static int cobalt_dive(void *param, int columns, char **data, char **column) | ||||||
| 			return 1; | 			return 1; | ||||||
| 		} | 		} | ||||||
| 		sprintf(tmp, "%s / %s", location, location_site); | 		sprintf(tmp, "%s / %s", location, location_site); | ||||||
| 		state->cur_dive->dive_site = find_or_create_dive_site_with_name(tmp, state->cur_dive->when); | 		state->cur_dive->dive_site = find_or_create_dive_site_with_name(tmp, state->cur_dive->when, &dive_site_table); | ||||||
| 		free(tmp); | 		free(tmp); | ||||||
| 	} | 	} | ||||||
| 	free(location); | 	free(location); | ||||||
|  |  | ||||||
|  | @ -287,7 +287,7 @@ static int divinglog_dive(void *param, int columns, char **data, char **column) | ||||||
| 	state->cur_dive->when = (time_t)(atol(data[1])); | 	state->cur_dive->when = (time_t)(atol(data[1])); | ||||||
| 
 | 
 | ||||||
| 	if (data[2]) | 	if (data[2]) | ||||||
| 		state->cur_dive->dive_site = find_or_create_dive_site_with_name(data[2], state->cur_dive->when); | 		state->cur_dive->dive_site = find_or_create_dive_site_with_name(data[2], state->cur_dive->when, &dive_site_table); | ||||||
| 
 | 
 | ||||||
| 	if (data[3]) | 	if (data[3]) | ||||||
| 		utf8_string(data[3], &state->cur_dive->buddy); | 		utf8_string(data[3], &state->cur_dive->buddy); | ||||||
|  |  | ||||||
|  | @ -596,7 +596,7 @@ static void parse_string_field(struct dive *dive, dc_field_string_t *str) | ||||||
| 		parse_location(line, &location); | 		parse_location(line, &location); | ||||||
| 
 | 
 | ||||||
| 		if (location.lat.udeg && location.lon.udeg) | 		if (location.lat.udeg && location.lon.udeg) | ||||||
| 			dive->dive_site = create_dive_site_with_gps(str->value, &location, time(NULL)); | 			dive->dive_site = create_dive_site_with_gps(str->value, &location, time(NULL), &dive_site_table); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -227,7 +227,7 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int | ||||||
| 		// now that we have the dive time we can store the divesite
 | 		// now that we have the dive time we can store the divesite
 | ||||||
| 		// (we need the dive time to create deterministic uuids)
 | 		// (we need the dive time to create deterministic uuids)
 | ||||||
| 		if (found_divesite) { | 		if (found_divesite) { | ||||||
| 			dive->dive_site = find_or_create_dive_site_with_name(location, dive->when); | 			dive->dive_site = find_or_create_dive_site_with_name(location, dive->when, &dive_site_table); | ||||||
| 			free(location); | 			free(location); | ||||||
| 		} | 		} | ||||||
| 		//unsigned int end_time = array_uint32_le(buf + ptr);
 | 		//unsigned int end_time = array_uint32_le(buf + ptr);
 | ||||||
|  |  | ||||||
|  | @ -157,9 +157,9 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive) | ||||||
| 
 | 
 | ||||||
| 	parse_location(line, &location); | 	parse_location(line, &location); | ||||||
| 	if (!ds) { | 	if (!ds) { | ||||||
| 		ds = get_dive_site_by_gps(&location); | 		ds = get_dive_site_by_gps(&location, &dive_site_table); | ||||||
| 		if (!ds) | 		if (!ds) | ||||||
| 			dive->dive_site = create_dive_site_with_gps("", &location, dive->when); | 			dive->dive_site = create_dive_site_with_gps("", &location, dive->when, &dive_site_table); | ||||||
| 		else | 		else | ||||||
| 			dive->dive_site = ds; | 			dive->dive_site = ds; | ||||||
| 	} else { | 	} else { | ||||||
|  | @ -181,9 +181,9 @@ static void parse_dive_location(char *line, struct membuffer *str, void *_dive) | ||||||
| 	struct dive *dive = _dive; | 	struct dive *dive = _dive; | ||||||
| 	struct dive_site *ds = get_dive_site_for_dive(dive); | 	struct dive_site *ds = get_dive_site_for_dive(dive); | ||||||
| 	if (!ds) { | 	if (!ds) { | ||||||
| 		ds = get_dive_site_by_name(name); | 		ds = get_dive_site_by_name(name, &dive_site_table); | ||||||
| 		if (!ds) | 		if (!ds) | ||||||
| 			dive->dive_site = create_dive_site(name, dive->when); | 			dive->dive_site = create_dive_site(name, dive->when, &dive_site_table); | ||||||
| 		else | 		else | ||||||
| 			dive->dive_site = ds; | 			dive->dive_site = ds; | ||||||
| 	} else { | 	} else { | ||||||
|  | @ -212,7 +212,7 @@ static void parse_dive_notes(char *line, struct membuffer *str, void *_dive) | ||||||
| { UNUSED(line); struct dive *dive = _dive; dive->notes = get_utf8(str); } | { UNUSED(line); struct dive *dive = _dive; dive->notes = get_utf8(str); } | ||||||
| 
 | 
 | ||||||
| static void parse_dive_divesiteid(char *line, struct membuffer *str, void *_dive) | static void parse_dive_divesiteid(char *line, struct membuffer *str, void *_dive) | ||||||
| { UNUSED(str); struct dive *dive = _dive; dive->dive_site = get_dive_site_by_uuid(get_hex(line)); } | { UNUSED(str); struct dive *dive = _dive; dive->dive_site = get_dive_site_by_uuid(get_hex(line), &dive_site_table); } | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  * We can have multiple tags in the membuffer. They are separated by |  * We can have multiple tags in the membuffer. They are separated by | ||||||
|  | @ -1504,7 +1504,7 @@ static int parse_site_entry(git_repository *repo, const git_tree_entry *entry, c | ||||||
| 	if (*suffix == '\0') | 	if (*suffix == '\0') | ||||||
| 		return report_error("Dive site without uuid"); | 		return report_error("Dive site without uuid"); | ||||||
| 	uint32_t uuid = strtoul(suffix, NULL, 16); | 	uint32_t uuid = strtoul(suffix, NULL, 16); | ||||||
| 	struct dive_site *ds = alloc_or_get_dive_site(uuid); | 	struct dive_site *ds = alloc_or_get_dive_site(uuid, &dive_site_table); | ||||||
| 	git_blob *blob = git_tree_entry_blob(repo, entry); | 	git_blob *blob = git_tree_entry_blob(repo, entry); | ||||||
| 	if (!blob) | 	if (!blob) | ||||||
| 		return report_error("Unable to read dive site file"); | 		return report_error("Unable to read dive site file"); | ||||||
|  |  | ||||||
|  | @ -562,7 +562,7 @@ static void dive_site(char *buffer, struct dive_site **ds) | ||||||
| { | { | ||||||
| 	uint32_t uuid; | 	uint32_t uuid; | ||||||
| 	hex_value(buffer, &uuid); | 	hex_value(buffer, &uuid); | ||||||
| 	*ds = get_dive_site_by_uuid(uuid); | 	*ds = get_dive_site_by_uuid(uuid, &dive_site_table); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void get_notrip(char *buffer, bool *notrip) | static void get_notrip(char *buffer, bool *notrip) | ||||||
|  | @ -983,9 +983,9 @@ static void divinglog_place(char *place, struct dive_site **ds, struct parser_st | ||||||
| 		 state->city ? state->city : "", | 		 state->city ? state->city : "", | ||||||
| 		 state->country ? ", " : "", | 		 state->country ? ", " : "", | ||||||
| 		 state->country ? state->country : ""); | 		 state->country ? state->country : ""); | ||||||
| 	*ds = get_dive_site_by_name(buffer); | 	*ds = get_dive_site_by_name(buffer, &dive_site_table); | ||||||
| 	if (!*ds) | 	if (!*ds) | ||||||
| 		*ds = create_dive_site(buffer, state->cur_dive->when); | 		*ds = create_dive_site(buffer, state->cur_dive->when, &dive_site_table); | ||||||
| 
 | 
 | ||||||
| 	// TODO: capture the country / city info in the taxonomy instead
 | 	// TODO: capture the country / city info in the taxonomy instead
 | ||||||
| 	free(state->city); | 	free(state->city); | ||||||
|  | @ -1137,7 +1137,7 @@ static void gps_lat(char *buffer, struct dive *dive) | ||||||
| 
 | 
 | ||||||
| 	location.lat = parse_degrees(buffer, &end); | 	location.lat = parse_degrees(buffer, &end); | ||||||
| 	if (!ds) { | 	if (!ds) { | ||||||
| 		dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when); | 		dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, &dive_site_table); | ||||||
| 	} else { | 	} else { | ||||||
| 		if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg) | 		if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg) | ||||||
| 			fprintf(stderr, "Oops, changing the latitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)"); | 			fprintf(stderr, "Oops, changing the latitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)"); | ||||||
|  | @ -1153,7 +1153,7 @@ static void gps_long(char *buffer, struct dive *dive) | ||||||
| 
 | 
 | ||||||
| 	location.lon = parse_degrees(buffer, &end); | 	location.lon = parse_degrees(buffer, &end); | ||||||
| 	if (!ds) { | 	if (!ds) { | ||||||
| 		dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when); | 		dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, &dive_site_table); | ||||||
| 	} else { | 	} else { | ||||||
| 		if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg) | 		if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg) | ||||||
| 			fprintf(stderr, "Oops, changing the longitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)"); | 			fprintf(stderr, "Oops, changing the longitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)"); | ||||||
|  | @ -1184,7 +1184,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st | ||||||
| 	parse_location(buffer, &location); | 	parse_location(buffer, &location); | ||||||
| 	if (!ds) { | 	if (!ds) { | ||||||
| 		// check if we have a dive site within 20 meters of that gps fix
 | 		// check if we have a dive site within 20 meters of that gps fix
 | ||||||
| 		ds = get_dive_site_by_gps_proximity(&location, 20); | 		ds = get_dive_site_by_gps_proximity(&location, 20, &dive_site_table); | ||||||
| 
 | 
 | ||||||
| 		if (ds) { | 		if (ds) { | ||||||
| 			// found a site nearby; in case it turns out this one had a different name let's
 | 			// found a site nearby; in case it turns out this one had a different name let's
 | ||||||
|  | @ -1192,7 +1192,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st | ||||||
| 			state->cur_location = location; | 			state->cur_location = location; | ||||||
| 			dive->dive_site = ds; | 			dive->dive_site = ds; | ||||||
| 		} else { | 		} else { | ||||||
| 			dive->dive_site = create_dive_site_with_gps("", &location, dive->when); | 			dive->dive_site = create_dive_site_with_gps("", &location, dive->when, &dive_site_table); | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		if (dive_site_has_gps_location(ds) && | 		if (dive_site_has_gps_location(ds) && | ||||||
|  | @ -2120,7 +2120,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl | ||||||
| 				/* Measure GPS */ | 				/* Measure GPS */ | ||||||
| 				state.cur_location.lat.udeg =  (int)((ptr[7]  << 24) + (ptr[6]  << 16) + (ptr[5] << 8) + (ptr[4] << 0)); | 				state.cur_location.lat.udeg =  (int)((ptr[7]  << 24) + (ptr[6]  << 16) + (ptr[5] << 8) + (ptr[4] << 0)); | ||||||
| 				state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0)); | 				state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0)); | ||||||
| 				state.cur_dive->dive_site = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when); | 				state.cur_dive->dive_site = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when, &dive_site_table); | ||||||
| 				break; | 				break; | ||||||
| 			default: | 			default: | ||||||
| 				break; | 				break; | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								core/parse.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								core/parse.c
									
										
									
									
									
								
							|  | @ -225,7 +225,7 @@ void dive_site_end(struct parser_state *state) | ||||||
| 		state->cur_dive_site->taxonomy.category = NULL; | 		state->cur_dive_site->taxonomy.category = NULL; | ||||||
| 	} | 	} | ||||||
| 	if (state->cur_dive_site->uuid) { | 	if (state->cur_dive_site->uuid) { | ||||||
| 		struct dive_site *ds = alloc_or_get_dive_site(state->cur_dive_site->uuid); | 		struct dive_site *ds = alloc_or_get_dive_site(state->cur_dive_site->uuid, &dive_site_table); | ||||||
| 		merge_dive_site(ds, state->cur_dive_site); | 		merge_dive_site(ds, state->cur_dive_site); | ||||||
| 
 | 
 | ||||||
| 		if (verbose > 3) | 		if (verbose > 3) | ||||||
|  | @ -419,7 +419,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) | ||||||
| 		struct dive_site *ds = dive->dive_site; | 		struct dive_site *ds = dive->dive_site; | ||||||
| 		if (!ds) { | 		if (!ds) { | ||||||
| 			// if the dive doesn't have a uuid, check if there's already a dive site by this name
 | 			// if the dive doesn't have a uuid, check if there's already a dive site by this name
 | ||||||
| 			ds = get_dive_site_by_name(buffer); | 			ds = get_dive_site_by_name(buffer, &dive_site_table); | ||||||
| 		} | 		} | ||||||
| 		if (ds) { | 		if (ds) { | ||||||
| 			// we have a uuid, let's hope there isn't a different name
 | 			// we have a uuid, let's hope there isn't a different name
 | ||||||
|  | @ -430,11 +430,11 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) | ||||||
| 				// but wait, we could have gotten this one based on GPS coords and could
 | 				// but wait, we could have gotten this one based on GPS coords and could
 | ||||||
| 				// have had two different names for the same site... so let's search the other
 | 				// have had two different names for the same site... so let's search the other
 | ||||||
| 				// way around
 | 				// way around
 | ||||||
| 				struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location); | 				struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location, &dive_site_table); | ||||||
| 				if (exact_match) { | 				if (exact_match) { | ||||||
| 					dive->dive_site = exact_match; | 					dive->dive_site = exact_match; | ||||||
| 				} else { | 				} else { | ||||||
| 					struct dive_site *newds = create_dive_site(buffer, dive->when); | 					struct dive_site *newds = create_dive_site(buffer, dive->when, &dive_site_table); | ||||||
| 					dive->dive_site = newds; | 					dive->dive_site = newds; | ||||||
| 					if (has_location(&state->cur_location)) { | 					if (has_location(&state->cur_location)) { | ||||||
| 						// we started this uuid with GPS data, so lets use those
 | 						// we started this uuid with GPS data, so lets use those
 | ||||||
|  | @ -449,7 +449,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) | ||||||
| 				dive->dive_site = ds; | 				dive->dive_site = ds; | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			dive->dive_site = create_dive_site(buffer, dive->when); | 			dive->dive_site = create_dive_site(buffer, dive->when, &dive_site_table); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	free(to_free); | 	free(to_free); | ||||||
|  |  | ||||||
|  | @ -879,10 +879,10 @@ static void save_divesites(git_repository *repo, struct dir *tree) | ||||||
| 	subdir = new_directory(repo, tree, &dirname); | 	subdir = new_directory(repo, tree, &dirname); | ||||||
| 	free_buffer(&dirname); | 	free_buffer(&dirname); | ||||||
| 
 | 
 | ||||||
| 	purge_empty_dive_sites(); | 	purge_empty_dive_sites(&dive_site_table); | ||||||
| 	for (int i = 0; i < dive_site_table.nr; i++) { | 	for (int i = 0; i < dive_site_table.nr; i++) { | ||||||
| 		struct membuffer b = { 0 }; | 		struct membuffer b = { 0 }; | ||||||
| 		struct dive_site *ds = get_dive_site(i); | 		struct dive_site *ds = get_dive_site(i, &dive_site_table); | ||||||
| 		/* Only write used dive sites */ | 		/* Only write used dive sites */ | ||||||
| 		if (!is_dive_site_used(ds, false)) | 		if (!is_dive_site_used(ds, false)) | ||||||
| 			continue; | 			continue; | ||||||
|  |  | ||||||
|  | @ -591,11 +591,11 @@ void save_dives_buffer(struct membuffer *b, const bool select_only, bool anonymi | ||||||
| 	put_format(b, "</settings>\n"); | 	put_format(b, "</settings>\n"); | ||||||
| 
 | 
 | ||||||
| 	/* save the dive sites - to make the output consistent let's sort the table, first */ | 	/* save the dive sites - to make the output consistent let's sort the table, first */ | ||||||
| 	dive_site_table_sort(); | 	dive_site_table_sort(&dive_site_table); | ||||||
| 	purge_empty_dive_sites(); | 	purge_empty_dive_sites(&dive_site_table); | ||||||
| 	put_format(b, "<divesites>\n"); | 	put_format(b, "<divesites>\n"); | ||||||
| 	for (i = 0; i < dive_site_table.nr; i++) { | 	for (i = 0; i < dive_site_table.nr; i++) { | ||||||
| 		struct dive_site *ds = get_dive_site(i); | 		struct dive_site *ds = get_dive_site(i, &dive_site_table); | ||||||
| 		/* Only write used dive sites */ | 		/* Only write used dive sites */ | ||||||
| 		if (!is_dive_site_used(ds, false)) | 		if (!is_dive_site_used(ds, false)) | ||||||
| 			continue; | 			continue; | ||||||
|  |  | ||||||
|  | @ -993,7 +993,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char * | ||||||
| 		} else if (!is_log && dive && !strcmp(tag, "divespot_id")) { | 		} else if (!is_log && dive && !strcmp(tag, "divespot_id")) { | ||||||
| 			int divespot_id = atoi(val); | 			int divespot_id = atoi(val); | ||||||
| 			if (divespot_id != -1) { | 			if (divespot_id != -1) { | ||||||
| 				struct dive_site *ds = create_dive_site("from Uemis", dive->when); | 				struct dive_site *ds = create_dive_site("from Uemis", dive->when, &dive_site_table); | ||||||
| 				dive->dive_site = ds; | 				dive->dive_site = ds; | ||||||
| 				uemis_mark_divelocation(dive->dc.diveid, divespot_id, ds); | 				uemis_mark_divelocation(dive->dc.diveid, divespot_id, ds); | ||||||
| 			} | 			} | ||||||
|  | @ -1191,11 +1191,11 @@ static void get_uemis_divespot(const char *mountpath, int divespot_id, struct di | ||||||
| 			 * we search all existing divesites if we have one with the same name already. The function | 			 * we search all existing divesites if we have one with the same name already. The function | ||||||
| 			 * returns the first found which is luckily not the newly created. | 			 * returns the first found which is luckily not the newly created. | ||||||
| 			 */ | 			 */ | ||||||
| 			ods = get_dive_site_by_name(nds->name); | 			ods = get_dive_site_by_name(nds->name, &dive_site_table); | ||||||
| 			if (ods) { | 			if (ods) { | ||||||
| 				/* if the uuid's are the same, the new site is a duplicate and can be deleted */ | 				/* if the uuid's are the same, the new site is a duplicate and can be deleted */ | ||||||
| 				if (nds->uuid != ods->uuid) { | 				if (nds->uuid != ods->uuid) { | ||||||
| 					delete_dive_site(nds); | 					delete_dive_site(nds, &dive_site_table); | ||||||
| 					dive->dive_site = ods; | 					dive->dive_site = ods; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | @ -1204,7 +1204,7 @@ static void get_uemis_divespot(const char *mountpath, int divespot_id, struct di | ||||||
| 			/* if we can't load the dive site details, delete the site we
 | 			/* if we can't load the dive site details, delete the site we
 | ||||||
| 			* created in process_raw_buffer | 			* created in process_raw_buffer | ||||||
| 			*/ | 			*/ | ||||||
| 			delete_dive_site(dive->dive_site); | 			delete_dive_site(dive->dive_site, &dive_site_table); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -198,7 +198,7 @@ void LocationInformationWidget::acceptChanges() | ||||||
| 	if (!ui.diveSiteCoordinates->text().isEmpty()) | 	if (!ui.diveSiteCoordinates->text().isEmpty()) | ||||||
| 		parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location); | 		parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location); | ||||||
| 	if (dive_site_is_empty(diveSite)) { | 	if (dive_site_is_empty(diveSite)) { | ||||||
| 		LocationInformationModel::instance()->removeRow(get_divesite_idx(diveSite)); | 		LocationInformationModel::instance()->removeRow(get_divesite_idx(diveSite, &dive_site_table)); | ||||||
| 		displayed_dive.dive_site = nullptr; | 		displayed_dive.dive_site = nullptr; | ||||||
| 		diveSite = nullptr; | 		diveSite = nullptr; | ||||||
| 	} | 	} | ||||||
|  | @ -388,7 +388,7 @@ QVariant DiveLocationModel::data(const QModelIndex &index, int role) const | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// The dive sites are -2 because of the first two items.
 | 	// The dive sites are -2 because of the first two items.
 | ||||||
| 	struct dive_site *ds = get_dive_site(index.row() - 2); | 	struct dive_site *ds = get_dive_site(index.row() - 2, &dive_site_table); | ||||||
| 	return LocationInformationModel::getDiveSiteData(ds, index.column(), role); | 	return LocationInformationModel::getDiveSiteData(ds, index.column(), role); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -522,7 +522,7 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString &str) | ||||||
| { | { | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 	int i; | 	int i; | ||||||
| 	for_each_dive_site (i, ds) { | 	for_each_dive_site (i, ds, &dive_site_table) { | ||||||
| 		QString dsName(ds->name); | 		QString dsName(ds->name); | ||||||
| 		if (dsName.toLower().startsWith(str.toLower())) { | 		if (dsName.toLower().startsWith(str.toLower())) { | ||||||
| 			return ds; | 			return ds; | ||||||
|  |  | ||||||
|  | @ -658,7 +658,7 @@ struct dive_site *MainTab::updateDiveSite(struct dive_site *pickedDs, dive *d) | ||||||
| 
 | 
 | ||||||
| 	if (pickedDs == RECENTLY_ADDED_DIVESITE) { | 	if (pickedDs == RECENTLY_ADDED_DIVESITE) { | ||||||
| 		QString name = ui.location->text().isEmpty() ? tr("New dive site") : ui.location->text(); | 		QString name = ui.location->text().isEmpty() ? tr("New dive site") : ui.location->text(); | ||||||
| 		pickedDs = create_dive_site(qPrintable(name), displayed_dive.when); | 		pickedDs = create_dive_site(qPrintable(name), displayed_dive.when, &dive_site_table); | ||||||
| 		createdNewDive = true; | 		createdNewDive = true; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -856,7 +856,7 @@ void MainTab::acceptChanges() | ||||||
| 		if (oldDs && !is_dive_site_used(oldDs, false)) { | 		if (oldDs && !is_dive_site_used(oldDs, false)) { | ||||||
| 			if (verbose) | 			if (verbose) | ||||||
| 				qDebug() << "delete now unused dive site" << (oldDs->name ? oldDs->name : "without name"); | 				qDebug() << "delete now unused dive site" << (oldDs->name ? oldDs->name : "without name"); | ||||||
| 			delete_dive_site(oldDs); | 			delete_dive_site(oldDs, &dive_site_table); | ||||||
| 			MapWidget::instance()->reload(); | 			MapWidget::instance()->reload(); | ||||||
| 		} | 		} | ||||||
| 		// the code above can change the correct uuid for the displayed dive site - and the
 | 		// the code above can change the correct uuid for the displayed dive site - and the
 | ||||||
|  |  | ||||||
|  | @ -773,7 +773,7 @@ static void setupDivesite(struct dive *d, struct dive_site *ds, double lat, doub | ||||||
| 	if (ds) { | 	if (ds) { | ||||||
| 		ds->location = location; | 		ds->location = location; | ||||||
| 	} else { | 	} else { | ||||||
| 		d->dive_site = create_dive_site_with_gps(locationtext, &location, d->when); | 		d->dive_site = create_dive_site_with_gps(locationtext, &location, d->when, &dive_site_table); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -889,9 +889,9 @@ bool QMLManager::checkLocation(DiveObjectHelper *myDive, struct dive *d, QString | ||||||
| 	qDebug() << "checkLocation" << location << "gps" << gps << "dive had" << myDive->location() << "gps" << myDive->gas(); | 	qDebug() << "checkLocation" << location << "gps" << gps << "dive had" << myDive->location() << "gps" << myDive->gas(); | ||||||
| 	if (myDive->location() != location) { | 	if (myDive->location() != location) { | ||||||
| 		diveChanged = true; | 		diveChanged = true; | ||||||
| 		ds = get_dive_site_by_name(qPrintable(location)); | 		ds = get_dive_site_by_name(qPrintable(location), &dive_site_table); | ||||||
| 		if (!ds && !location.isEmpty()) | 		if (!ds && !location.isEmpty()) | ||||||
| 			ds = create_dive_site(qPrintable(location), d->when); | 			ds = create_dive_site(qPrintable(location), d->when, &dive_site_table); | ||||||
| 		d->dive_site = ds; | 		d->dive_site = ds; | ||||||
| 	} | 	} | ||||||
| 	// now make sure that the GPS coordinates match - if the user changed the name but not
 | 	// now make sure that the GPS coordinates match - if the user changed the name but not
 | ||||||
|  | @ -1597,11 +1597,11 @@ QString QMLManager::getVersion() const | ||||||
| 	return versionRe.cap(1); | 	return versionRe.cap(1); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QString QMLManager::getGpsFromSiteName(const QString& siteName) | QString QMLManager::getGpsFromSiteName(const QString &siteName) | ||||||
| { | { | ||||||
| 	struct dive_site *ds; | 	struct dive_site *ds; | ||||||
| 
 | 
 | ||||||
| 	ds = get_dive_site_by_name(qPrintable(siteName)); | 	ds = get_dive_site_by_name(qPrintable(siteName), &dive_site_table); | ||||||
| 	if (!ds) | 	if (!ds) | ||||||
| 		return QString(); | 		return QString(); | ||||||
| 	return printGPSCoords(&ds->location); | 	return printGPSCoords(&ds->location); | ||||||
|  |  | ||||||
|  | @ -70,7 +70,7 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons | ||||||
| 	if (!index.isValid()) | 	if (!index.isValid()) | ||||||
| 		return QVariant(); | 		return QVariant(); | ||||||
| 
 | 
 | ||||||
| 	struct dive_site *ds = get_dive_site(index.row()); | 	struct dive_site *ds = get_dive_site(index.row(), &dive_site_table); | ||||||
| 	return getDiveSiteData(ds, index.column(), role); | 	return getDiveSiteData(ds, index.column(), role); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -95,9 +95,9 @@ bool LocationInformationModel::removeRows(int row, int, const QModelIndex&) | ||||||
| 		return false; | 		return false; | ||||||
| 
 | 
 | ||||||
| 	beginRemoveRows(QModelIndex(), row, row); | 	beginRemoveRows(QModelIndex(), row, row); | ||||||
| 	struct dive_site *ds = get_dive_site(row); | 	struct dive_site *ds = get_dive_site(row, &dive_site_table); | ||||||
| 	if (ds) | 	if (ds) | ||||||
| 		delete_dive_site(ds); | 		delete_dive_site(ds, &dive_site_table); | ||||||
| 	endRemoveRows(); | 	endRemoveRows(); | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -373,12 +373,12 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, timestamp_t when, str | ||||||
| 		str = smtk_concat_str(str, ", ", "%s", col[1]->bind_ptr); // Locality
 | 		str = smtk_concat_str(str, ", ", "%s", col[1]->bind_ptr); // Locality
 | ||||||
| 	str =  smtk_concat_str(str, ", ", "%s", site); | 	str =  smtk_concat_str(str, ", ", "%s", site); | ||||||
| 
 | 
 | ||||||
| 	ds = get_dive_site_by_name(str); | 	ds = get_dive_site_by_name(str, &dive_site_table); | ||||||
| 	if (!ds) { | 	if (!ds) { | ||||||
| 		if (!has_location(&loc)) | 		if (!has_location(&loc)) | ||||||
| 			ds = create_dive_site(str, when); | 			ds = create_dive_site(str, when, &dive_site_table); | ||||||
| 		else | 		else | ||||||
| 			ds = create_dive_site_with_gps(str, &loc, when); | 			ds = create_dive_site_with_gps(str, &loc, when, &dive_site_table); | ||||||
| 	} | 	} | ||||||
| 	*location = ds; | 	*location = ds; | ||||||
| 	smtk_free(bound_values, table->num_cols); | 	smtk_free(bound_values, table->num_cols); | ||||||
|  |  | ||||||
|  | @ -113,7 +113,7 @@ int TestParse::parseCSV(int units, std::string file) | ||||||
| int TestParse::parseDivingLog() | int TestParse::parseDivingLog() | ||||||
| { | { | ||||||
| 	// Parsing of DivingLog import from SQLite database
 | 	// Parsing of DivingLog import from SQLite database
 | ||||||
| 	struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef); | 	struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef, &dive_site_table); | ||||||
| 	ds->name = copy_string("Suomi -  - Hälvälä"); | 	ds->name = copy_string("Suomi -  - Hälvälä"); | ||||||
| 
 | 
 | ||||||
| 	int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle); | 	int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue