mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Add basic divecomputer info setup with xml parsing and saving
This also knows how to save and restore multiple dive computers in the XML data, but there's no way to actually *create* that kind of information yet (nor do we display it). Tested by creating fake XML files with multiple dive computers by hand so far. The dive computer information right now contains (apart from the sample and event data that we've always had): - the vendor and product name of the dive computer - the date of the dive according to the dive computer (so if you change the dive date manually, the dive computer date stays around) Note that if the dive computer date matches the dive date, we won't bother saving the redundant information in the XML file. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									8d62f20aa0
								
							
						
					
					
						commit
						c019da8fd5
					
				
					 4 changed files with 115 additions and 19 deletions
				
			
		
							
								
								
									
										52
									
								
								save-xml.c
									
										
									
									
									
								
							
							
						
						
									
										52
									
								
								save-xml.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -323,17 +323,22 @@ static void save_events(FILE *f, struct event *ev)
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void save_trip(FILE *f, dive_trip_t *trip)
 | 
			
		||||
static void show_date(FILE *f, timestamp_t when)
 | 
			
		||||
{
 | 
			
		||||
	struct tm tm;
 | 
			
		||||
 | 
			
		||||
	utc_mkdate(trip->when, &tm);
 | 
			
		||||
	utc_mkdate(when, &tm);
 | 
			
		||||
 | 
			
		||||
	fprintf(f, "<trip");
 | 
			
		||||
	fprintf(f, " date='%04u-%02u-%02u'",
 | 
			
		||||
		tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
 | 
			
		||||
	fprintf(f, " time='%02u:%02u:%02u'",
 | 
			
		||||
		tm.tm_hour, tm.tm_min, tm.tm_sec);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void save_trip(FILE *f, dive_trip_t *trip)
 | 
			
		||||
{
 | 
			
		||||
	fprintf(f, "<trip");
 | 
			
		||||
	show_date(f, trip->when);
 | 
			
		||||
	if (trip->location)
 | 
			
		||||
		show_utf8(f, trip->location, " location=\'","\'", 1);
 | 
			
		||||
	fprintf(f, ">\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -341,12 +346,31 @@ static void save_trip(FILE *f, dive_trip_t *trip)
 | 
			
		|||
		show_utf8(f, trip->notes, "<notes>","</notes>\n", 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void save_dive(FILE *f, struct dive *dive)
 | 
			
		||||
static void save_dc(FILE *f, struct dive *dive, struct divecomputer *dc)
 | 
			
		||||
{
 | 
			
		||||
	int i;
 | 
			
		||||
	struct tm tm;
 | 
			
		||||
	const char *post = "";
 | 
			
		||||
 | 
			
		||||
	utc_mkdate(dive->when, &tm);
 | 
			
		||||
	if (dc->when || dc->vendor || dc->product) {
 | 
			
		||||
		fprintf(f, "<divecomputer");
 | 
			
		||||
		if (dc->vendor)
 | 
			
		||||
			show_utf8(f, dc->vendor, " vendor='", "'", 1);
 | 
			
		||||
		if (dc->product)
 | 
			
		||||
			show_utf8(f, dc->product, " product='", "'", 1);
 | 
			
		||||
		if (dc->when && dc->when != dive->when)
 | 
			
		||||
			show_date(f, dc->when);
 | 
			
		||||
		fprintf(f, ">\n");
 | 
			
		||||
		post = "</divecomputer>\n";
 | 
			
		||||
	}
 | 
			
		||||
	save_events(f, dc->events);
 | 
			
		||||
	for (i = 0; i < dc->samples; i++)
 | 
			
		||||
		save_sample(f, dc->sample+i);
 | 
			
		||||
	fprintf(f, post);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void save_dive(FILE *f, struct dive *dive)
 | 
			
		||||
{
 | 
			
		||||
	struct divecomputer *dc;
 | 
			
		||||
 | 
			
		||||
	fputs("<dive", f);
 | 
			
		||||
	if (dive->number)
 | 
			
		||||
| 
						 | 
				
			
			@ -363,18 +387,20 @@ static void save_dive(FILE *f, struct dive *dive)
 | 
			
		|||
		fprintf(f, " rating='%d'", dive->rating);
 | 
			
		||||
	if (dive->visibility)
 | 
			
		||||
		fprintf(f, " visibility='%d'", dive->visibility);
 | 
			
		||||
	fprintf(f, " date='%04u-%02u-%02u'",
 | 
			
		||||
		tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
 | 
			
		||||
	fprintf(f, " time='%02u:%02u:%02u'",
 | 
			
		||||
		tm.tm_hour, tm.tm_min, tm.tm_sec);
 | 
			
		||||
	show_date(f, dive->when);
 | 
			
		||||
	fprintf(f, " duration='%u:%02u min'>\n",
 | 
			
		||||
		FRACTION(dive->duration.seconds, 60));
 | 
			
		||||
	save_overview(f, dive);
 | 
			
		||||
	save_cylinder_info(f, dive);
 | 
			
		||||
	save_weightsystem_info(f, dive);
 | 
			
		||||
	save_events(f, dive->dc.events);
 | 
			
		||||
	for (i = 0; i < dive->dc.samples; i++)
 | 
			
		||||
		save_sample(f, dive->dc.sample+i);
 | 
			
		||||
 | 
			
		||||
	/* Save the dive computer data */
 | 
			
		||||
	dc = &dive->dc;
 | 
			
		||||
	do {
 | 
			
		||||
		save_dc(f, dive, dc);
 | 
			
		||||
		dc = dc->next;
 | 
			
		||||
	} while (dc);
 | 
			
		||||
 | 
			
		||||
	fprintf(f, "</dive>\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue