diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-09-01 17:52:25 +0200 |
---|---|---|
committer | Robert C. Helling <helling@atdotde.de> | 2019-09-10 21:31:21 +0200 |
commit | 4706b0f11ae335c1d23e1334b3530fce1a2c9279 (patch) | |
tree | ca1cf3663b5ae590d1b191648d02fc1c25ff2fcf | |
parent | 8ac48a96c75bae4fc9dbd5f0c434d6144a8b8502 (diff) | |
download | subsurface-4706b0f11ae335c1d23e1334b3530fce1a2c9279.tar.gz |
Planner: remove planner disclaimer from old notes
There used to be code to remove the old planner notes when replanning
a dive. It used a global variable and seemed rather brittle. Moreover,
the place that set the global variable was inadvertently removed.
Therefore has been effectively dead code.
Reimplement the functionality, but be more robust by considering
that the deco-type may have changed: Split the translated disclaimer
string in two parts, before and after the "%s" place-holder.
Search for these two parts. Remove the disclaimer and everything
after the disclaimer.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/planner.h | 1 | ||||
-rw-r--r-- | core/plannernotes.c | 13 | ||||
-rw-r--r-- | qt-models/diveplannermodel.cpp | 23 |
3 files changed, 28 insertions, 9 deletions
diff --git a/core/planner.h b/core/planner.h index 404fbe3fc..156d39983 100644 --- a/core/planner.h +++ b/core/planner.h @@ -50,6 +50,7 @@ extern int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, du extern int get_gasidx(struct dive *dive, struct gasmix mix); extern bool diveplan_empty(struct diveplan *diveplan); extern void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error); +extern const char *get_planner_disclaimer(); extern void free_dps(struct diveplan *diveplan); extern struct dive *planned_dive; diff --git a/core/plannernotes.c b/core/plannernotes.c index 96c79f9ba..6714d360a 100644 --- a/core/plannernotes.c +++ b/core/plannernotes.c @@ -74,6 +74,14 @@ static void add_icd_entry(struct membuffer *b, struct icd_data *icdvalues, bool ambientpressure_mbar * -icdvalues->dHe / 5e6f, translate("gettextFromC", "bar")); } +const char *get_planner_disclaimer() +{ + return translate("gettextFromC", "DISCLAIMER / WARNING: THIS IMPLEMENTATION OF THE %s " + "ALGORITHM AND A DIVE PLANNER IMPLEMENTATION BASED ON THAT HAS " + "RECEIVED ONLY A LIMITED AMOUNT OF TESTING. WE STRONGLY RECOMMEND NOT TO " + "PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE."); +} + void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error) { struct membuffer buf = { 0 }; @@ -116,10 +124,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d if (show_disclaimer) { put_string(&buf, "<div><b>"); - put_format(&buf, translate("gettextFromC", "DISCLAIMER / WARNING: THIS IMPLEMENTATION OF THE %s " - "ALGORITHM AND A DIVE PLANNER IMPLEMENTATION BASED ON THAT HAS " - "RECEIVED ONLY A LIMITED AMOUNT OF TESTING. WE STRONGLY RECOMMEND NOT TO " - "PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE."), deco); + put_format(&buf, get_planner_disclaimer(), deco); put_string(&buf, "</b><br></div>"); } diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index c2bbdf084..b77534819 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -1127,11 +1127,24 @@ void DivePlannerPointsModel::createPlan(bool replanCopy) QTextDocument notesDocument; notesDocument.setHtml(current_dive->notes); QString oldnotes(notesDocument.toPlainText()); - int disclaimerPosition = oldnotes.indexOf(disclaimer); - if (disclaimerPosition == 0) - oldnotes.clear(); - else if (disclaimerPosition >= 1) - oldnotes.truncate(disclaimerPosition-1); + QString disclaimer = get_planner_disclaimer(); + int disclaimerMid = disclaimer.indexOf("%s"); + QString disclaimerBegin, disclaimerEnd; + if (disclaimerMid >= 0) { + disclaimerBegin = disclaimer.left(disclaimerMid); + disclaimerEnd = disclaimer.mid(disclaimerMid + 2); + } else { + disclaimerBegin = disclaimer; + } + int disclaimerPositionStart = oldnotes.indexOf(disclaimerBegin); + if (disclaimerPositionStart >= 0) { + if (oldnotes.indexOf(disclaimerEnd, disclaimerPositionStart) >= 0) { + // We found a disclaimer according to the current locale. + // Remove the disclaimer and anything after the disclaimer, because + // that's supposedly the old planner notes. + oldnotes = oldnotes.left(disclaimerPositionStart); + } + } // Deal with line breaks oldnotes.replace("\n", "<br>"); oldnotes.append(displayed_dive.notes); |