Changeset dfe50922 in subsurface


Ignore:
Timestamp:
Apr 20, 2017, 10:57:47 AM (3 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
6a249bd
Parents:
ff5c04e
git-author:
Robert C. Helling <helling@…> (04/19/17 06:40:59)
git-committer:
Dirk Hohndel <dirk@…> (04/20/17 10:57:47)
Message:

Identify user provided notes in plain text in replan

This is another attept at the problem if identifying a potentially
user supplied text in the dive notes upon replannig a dive.

It gets rid of the user visable position markers (*!* and *) and
cirumvents problems with mark-up by first converting the old notes
to plan text (assuming that user only enters plain text in the notes
field as we do in other places as well). Then the automatically added
part is identified by locating the disclaimer in the text (if the user
edited/delted the disclaimer or changed langue in between it is her
problem to manually delete the old plan).

Everything from the disclaimer on is deleted and replaced by the new plan.

If the disclaimer is not found, the new plan is appended to the old notes.
This way we make sure no information gets automatically deleted.

Signed-off-by: Robert C. Helling <helling@…>

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/planner.c

    r9b8fc9f rdfe50922  
    589589        }
    590590
    591         len = show_disclaimer ? snprintf(buffer, sz_buffer, "<div>*!* <b>%s</b><br></div>", disclaimer) : 0;
     591        len = show_disclaimer ? snprintf(buffer, sz_buffer, "<div><b>%s</b><br></div>", disclaimer) : 0;
    592592
    593593        if (diveplan->surface_interval > 60) {
    594                 len += snprintf(buffer + len, sz_buffer - len, "<div>*** <b>%s (%s) %s %d:%02d) %s %s<br>",
     594                len += snprintf(buffer + len, sz_buffer - len, "<div><b>%s (%s) %s %d:%02d) %s %s<br>",
    595595                                translate("gettextFromC", "Subsurface"),
    596596                                subsurface_canonical_version(),
     
    600600                                get_current_date());
    601601        } else {
    602                 len += snprintf(buffer + len, sz_buffer - len, "<div>*** <b>%s (%s) %s %s</b><br>",
     602                len += snprintf(buffer + len, sz_buffer - len, "<div><b>%s (%s) %s %s</b><br>",
    603603                                translate("gettextFromC", "Subsurface"),
    604604                                subsurface_canonical_version(),
  • qt-models/diveplannermodel.cpp

    rabbb0a2 rdfe50922  
    88#include "core/subsurface-qt/SettingsObjectWrapper.h"
    99#include <QApplication>
     10#include <QTextDocument>
    1011
    1112/* TODO: Port this to CleanerTableModel to remove a bit of boilerplate and
     
    889890                fixup_dive(&displayed_dive);
    890891                // Try to identify old planner output and remove only this part
    891                 // If we don't manage to identify old plan start but there is a
    892                 // table, delete everything
    893                 QString oldnotes(current_dive->notes);
    894                 if (oldnotes.indexOf(QString("*!*")) >= 0)
    895                         oldnotes.truncate(oldnotes.indexOf(QString("*!*")));
    896                 else if (oldnotes.indexOf(QString("***")) >= 0)
    897                         oldnotes.truncate(oldnotes.indexOf(QString("***")));
    898                 else if (oldnotes.indexOf(QString("<table")) >= 0)
    899                         oldnotes.truncate(0);
     892                // Treat user provided text as plain text.
     893                QTextDocument notesDocument;
     894                notesDocument.setHtml(current_dive->notes);
     895                QString oldnotes(notesDocument.toPlainText());
     896                int disclaimerPosition = oldnotes.indexOf(disclaimer);
     897                if (disclaimerPosition >= 0)
     898                        oldnotes.truncate(disclaimerPosition);
     899                // Deal with line breaks
     900                notesDocument.setPlainText(oldnotes);
     901                oldnotes = notesDocument.toHtml();
    900902                oldnotes.append(displayed_dive.notes);
    901903                displayed_dive.notes = strdup(oldnotes.toUtf8().data());
Note: See TracChangeset for help on using the changeset viewer.