Only use HTML if the text has a <table>

The text we generate for the diveplan has a table inside, and
we must use HTML only for the dive plan. so I treat all text
as HTML, look for a table item, if it doesn't have, I treat
it as Simple text and set it on the notes. Works and makes
linus loves me again.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-07-21 20:34:15 -03:00 committed by Dirk Hohndel
parent 607d450cd6
commit 99922722d2

View file

@ -331,7 +331,7 @@ void MainTab::clearStats()
#define UPDATE_TEXT(d, field) \
if (clear || !d.field) \
ui.field->setText(""); \
ui.field->setText(QString()); \
else \
ui.field->setText(d.field)
@ -370,6 +370,16 @@ void MainTab::updateDiveInfo(bool clear)
process_all_dives(&displayed_dive, &prevd);
divePictureModel->updateDivePictures();
ui.notes->setText(QString());
if (!clear) {
QString tmp(displayed_dive.notes);
if (tmp.indexOf("<table") != -1)
ui.notes->setHtml(tmp);
else
ui.notes->setPlainText(tmp);
}
UPDATE_TEXT(displayed_dive, notes);
UPDATE_TEXT(displayed_dive, location);
UPDATE_TEXT(displayed_dive, suit);
@ -1004,7 +1014,10 @@ void MainTab::on_notes_textChanged()
if (editMode == IGNORE)
return;
free(displayed_dive.notes);
displayed_dive.notes = strdup(ui.notes->toHtml().toUtf8().data());
if (ui.notes->toHtml().indexOf("<table") != -1)
displayed_dive.notes = strdup(ui.notes->toHtml().toUtf8().data());
else
displayed_dive.notes = strdup(ui.notes->toPlainText().toUtf8().data());
markChangedWidget(ui.notes);
}