From 9f7c79557e0fe2add48eacdddd1f0a559faf2ccf Mon Sep 17 00:00:00 2001 From: Henrik Brautaset Aronsen Date: Sun, 22 Jun 2014 19:28:08 +0200 Subject: CSS and translation improvements to dive plan Use CSS styling to format the dive plan instead of deprecated HTML tags. Also make sure that we aren't sending HTML tags to translate() Signed-off-by: Henrik Brautaset Aronsen Signed-off-by: Dirk Hohndel --- planner.c | 91 +++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 35 deletions(-) (limited to 'planner.c') diff --git a/planner.c b/planner.c index 43cd09056..3168f0ff9 100644 --- a/planner.c +++ b/planner.c @@ -513,31 +513,38 @@ static unsigned int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer) { - char buffer[20000]; + char buffer[20000], temp[1000]; int len, gasidx, lastdepth = 0, lasttime = 0; struct divedatapoint *dp = diveplan->dp; - const char *empty = ""; bool gaschange = !plan_verbatim; struct divedatapoint *nextdp = NULL; - disclaimer = translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN " + disclaimer = translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN " "ALGORITHM AND A DIVE PLANNER IMPLEMENTION BASED ON THAT WHICH HAS " "RECEIVED ONLY A LIMITED AMOUNT OF TESTING. WE STRONGLY RECOMMEND NOT TO " - "PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE.
"); + "PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE."); if (!dp) return; - len = snprintf(buffer, sizeof(buffer), - translate("gettextFromC", "%s
Subsurface dive plan
based on GFlow = %d and GFhigh = %d

"), - show_disclaimer ? disclaimer : empty, diveplan->gflow, diveplan->gfhigh); + len = show_disclaimer ? snprintf(buffer, sizeof(buffer), "
%s

", disclaimer) : 0; + snprintf(temp, sizeof(temp), translate("gettextFromC", "based on GFlow = %d and GFhigh = %d"), + diveplan->gflow, diveplan->gfhigh); + len += snprintf(buffer + len, sizeof(buffer) - len, "
%s
%s

", + translate("gettextFromC", "Subsurface dive plan"), temp); + if (!plan_verbatim) { - len += snprintf(buffer + len, sizeof(buffer) - len, "%s", translate("gettextFromC", "")); + len += snprintf(buffer + len, sizeof(buffer) - len, "
depth
", + translate("gettextFromC", "depth")); if (plan_display_runtime) - len += snprintf(buffer + len, sizeof(buffer) - len, "%s", translate("gettextFromC", " ")); + len += snprintf(buffer + len, sizeof(buffer) - len, "", + translate("gettextFromC", "runtime")); if (plan_display_duration) - len += snprintf(buffer + len, sizeof(buffer) - len, "%s", translate("gettextFromC", " ")); - len += snprintf(buffer + len, sizeof(buffer) - len, "%s", translate("gettextFromC"," ")); + len += snprintf(buffer + len, sizeof(buffer) - len, "", + translate("gettextFromC", "duration")); + len += snprintf(buffer + len, sizeof(buffer) - len, + "", + translate("gettextFromC", "gas")); } do { struct gasmix gasmix, newgasmix; @@ -574,35 +581,42 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool if (plan_verbatim) { if (dp->depth != lastdepth) { if (plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) { - len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s
"), - decimals, depthvalue, depth_unit, - FRACTION(dp->time - lasttime, 60), - FRACTION(dp->time, 60), - gasname(&gasmix)); + snprintf(temp, sizeof(temp), translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s"), + decimals, depthvalue, depth_unit, + FRACTION(dp->time - lasttime, 60), + FRACTION(dp->time, 60), + gasname(&gasmix)); + len += snprintf(buffer + len, sizeof(buffer) - len, "%s
", temp); lasttime = dp->time; } } else { if (dp->depth != nextdp->depth) { - len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s
"), + snprintf(temp, sizeof(temp), translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s"), decimals, depthvalue, depth_unit, FRACTION(dp->time - lasttime, 60), FRACTION(dp->time, 60), gasname(&gasmix)); + len += snprintf(buffer + len, sizeof(buffer) - len, "%s
", temp); lasttime = dp->time; } } } else { if ((dp->depth == lastdepth && dp->depth != nextdp->depth) || plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) { - len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", ""), depthvalue, depth_unit); - if (plan_display_runtime) - len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " "), (dp->time + 30) / 60); - if (plan_display_duration) - len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " "), (dp->time - lasttime + 30) / 60); + snprintf(temp, sizeof(temp), translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit); + len += snprintf(buffer + len, sizeof(buffer) - len, "", temp); + if (plan_display_runtime) { + snprintf(temp, sizeof(temp), translate("gettextFromC", "%3dmin"), (dp->time + 30) / 60); + len += snprintf(buffer + len, sizeof(buffer) - len, "", temp); + } + if (plan_display_duration) { + snprintf(temp, sizeof(temp), translate("gettextFromC", "%3dmin"), (dp->time - lasttime + 30) / 60); + len += snprintf(buffer + len, sizeof(buffer) - len, "", temp); + } if (gaschange) { - len += snprintf(buffer + len, sizeof(buffer) - len, " ", gasname(&newgasmix)); + len += snprintf(buffer + len, sizeof(buffer) - len, "", gasname(&newgasmix)); gaschange = false; } else { - len += snprintf(buffer + len, sizeof(buffer) - len, " "); } len += snprintf(buffer + len, sizeof(buffer) - len, ""); lasttime = dp->time; @@ -611,51 +625,58 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool if (gaschange) { // gas switch at this waypoint if (plan_verbatim) { - snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s
"), gasname(&newgasmix)); + snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s"), gasname(&newgasmix)); + len += snprintf(buffer + len, sizeof(buffer) - len, "%s
", temp); gaschange = false; } gasmix = newgasmix; } lastdepth = dp->depth; } while ((dp = nextdp) != NULL); - len = strlen(buffer); - snprintf(buffer + len, sizeof(buffer) - len, "%s", translate("gettextFromC", "
%sruntime%sdurationgas
%s%s
%3.0f%s%3dmin%3dmin
%s%s%s%s%s "); + len += snprintf(buffer + len, sizeof(buffer) - len, " 

Gas consumption:
")); + + snprintf(temp, sizeof(temp), translate("gettextFromC", "Gas consumption:")); + len += snprintf(buffer + len, sizeof(buffer) - len, "

%s
", temp); for (gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) { double volume; const char *unit; - const char *warning = ""; + char warning[1000] = ""; cylinder_t *cyl = &dive->cylinder[gasidx]; if (cylinder_none(cyl)) break; - len = strlen(buffer); + volume = get_volume_units(cyl->gas_used.mliter, NULL, &unit); if (cyl->type.size.mliter) { /* Warn if the plan uses more gas than is available in a cylinder * This only works if we have working pressure for the cylinder * 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */ if (cyl->end.mbar < 10000) - warning = translate("gettextFromC", " — WARNING: " - "this is more gas than available in the specified cylinder!
"); + snprintf(warning, sizeof(warning), " — %s %s", + translate("gettextFromC", "Warning:"), + translate("gettextFromC", "this is more gas than available in the specified cylinder!")); } - snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s%s
"), volume, unit, gasname(&cyl->gasmix), warning); + snprintf(temp, sizeof(temp), translate("gettextFromC", "%.0f%s of %s"), volume, unit, gasname(&cyl->gasmix)); + len += snprintf(buffer + len, sizeof(buffer) - len, "%s%s
", temp, warning); } dp = diveplan->dp; while (dp) { if (dp->time != 0) { int pO2 = depth_to_atm(dp->depth, dive) * dp->gasmix.o2.permille; + if (pO2 > 1600) { const char *depth_unit; int decimals; double depth_value = get_depth_units(dp->depth, &decimals, &depth_unit); len = strlen(buffer); - snprintf(buffer + len, sizeof(buffer) - len, - translate("gettextFromC", "Warning: " - "high pO2 value %.2f at %d:%02u with gas %s at depth %.*f %s
"), + snprintf(temp, sizeof(temp), + translate("gettextFromC", "high pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), pO2 / 1000.0, FRACTION(dp->time, 60), gasname(&dp->gasmix), decimals, depth_value, depth_unit); + len += snprintf(buffer + len, sizeof(buffer) - len, "%s %s
", + translate("gettextFromC", "Warning:"), temp); } } dp = dp->next; } + snprintf(buffer + len, sizeof(buffer) - len, "
"); dive->notes = strdup(buffer); } -- cgit v1.2.3-70-g09d2