commit f9528c63c8482fcaa9325b1df262b9356f4e63b9
Author: Guillaume Munch <[email protected]>
Date: Sun Dec 4 18:28:03 2016 +0100
GuiAlert: Convert html to plain text on console output
---
src/frontends/alert.h | 4 ++++
src/frontends/qt4/GuiAlert.cpp | 24 +++++++++++++++---------
src/frontends/qt4/qt_helpers.cpp | 10 ++++++++++
src/frontends/qt4/qt_helpers.h | 5 +++++
4 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/src/frontends/alert.h b/src/frontends/alert.h
index 2be612a..8770053 100644
--- a/src/frontends/alert.h
+++ b/src/frontends/alert.h
@@ -41,6 +41,8 @@ int prompt(docstring const & title, docstring const &
question,
* Only use this if the user cannot perform some remedial action.
* \p askshowagain will display a check box where the user can turn off the
* warning for future cases. Ponder carefully if this is feasible.
+ *
+ * The console output takes care of converting any Qt html to plain text.
*/
void warning(docstring const & title, docstring const & message,
bool const & askshowagain = false);
@@ -49,6 +51,8 @@ void warning(docstring const & title, docstring const &
message,
* Display a warning to the user. Title should be a short (general) summary.
* Only use this if the user cannot perform some remedial action.
* On some systems it is possible to show a backtrace.
+ *
+ * The console output takes care of converting any Qt html to plain text.
*/
void error(docstring const & title, docstring const & message, bool backtrace
= false);
diff --git a/src/frontends/qt4/GuiAlert.cpp b/src/frontends/qt4/GuiAlert.cpp
index 4c9b162..8e12b3e 100644
--- a/src/frontends/qt4/GuiAlert.cpp
+++ b/src/frontends/qt4/GuiAlert.cpp
@@ -69,6 +69,12 @@ void noAppDialog(QString const & title, QString const & msg,
QMessageBox::Icon m
namespace Alert {
+docstring toPlainText(docstring const & msg)
+{
+ return qstring_to_ucs4(qtHtmlToPlainText(toqstr(msg)));
+}
+
+
int doPrompt(docstring const & title0, docstring const & question,
int default_button, int cancel_button,
docstring const & b1, docstring const & b2,
@@ -76,9 +82,9 @@ int doPrompt(docstring const & title0, docstring const &
question,
{
//lyxerr << "PROMPT" << title0 << "FOCUS: " << qApp->focusWidget() <<
endl;
if (!use_gui || lyxerr.debugging()) {
- lyxerr << title0 << '\n'
+ lyxerr << toPlainText(title0) << '\n'
<< "----------------------------------------\n"
- << question << endl;
+ << toPlainText(question) << endl;
lyxerr << "Assuming answer is ";
switch (default_button) {
@@ -148,9 +154,9 @@ int prompt(docstring const & title0, docstring const &
question,
void doWarning(docstring const & title0, docstring const & message,
bool const & askshowagain)
{
- lyxerr << "Warning: " << title0 << '\n'
+ lyxerr << "Warning: " << toPlainText(title0) << '\n'
<< "----------------------------------------\n"
- << message << endl;
+ << toPlainText(message) << endl;
if (!use_gui)
return;
@@ -200,9 +206,9 @@ void warning(docstring const & title0, docstring const &
message,
void doError(docstring const & title0, docstring const & message, bool
backtrace)
{
- lyxerr << "Error: " << title0 << '\n'
+ lyxerr << "Error: " << toPlainText(title0) << '\n'
<< "----------------------------------------\n"
- << message << endl;
+ << toPlainText(message) << endl;
QString details;
if (backtrace) {
@@ -251,9 +257,9 @@ void error(docstring const & title0, docstring const &
message, bool backtrace)
void doInformation(docstring const & title0, docstring const & message)
{
if (!use_gui || lyxerr.debugging())
- lyxerr << title0 << '\n'
+ lyxerr << toPlainText(title0) << '\n'
<< "----------------------------------------\n"
- << message << endl;
+ << toPlainText(message) << endl;
if (!use_gui)
return;
@@ -298,7 +304,7 @@ bool doAskForText(docstring & response, docstring const &
msg,
{
if (!use_gui || lyxerr.debugging()) {
lyxerr << "----------------------------------------\n"
- << msg << '\n'
+ << toPlainText(msg) << '\n'
<< "Assuming answer is " << dflt << '\n'
<< "----------------------------------------" << endl;
if (!use_gui) {
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
index 2ad96d9..88c4ab9 100644
--- a/src/frontends/qt4/qt_helpers.cpp
+++ b/src/frontends/qt4/qt_helpers.cpp
@@ -683,4 +683,14 @@ QString formatToolTip(QString text, int em)
}
+QString qtHtmlToPlainText(QString const & html)
+{
+ if (!Qt::mightBeRichText(html))
+ return html;
+ QTextDocument td;
+ td.setHtml(html);
+ return td.toPlainText();
+}
+
+
} // namespace lyx
diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h
index 5574212..9569d90 100644
--- a/src/frontends/qt4/qt_helpers.h
+++ b/src/frontends/qt4/qt_helpers.h
@@ -231,6 +231,11 @@ private:
#endif
+// Check if qstr is understood as rich text (Qt HTML) and if so, produce a
+// rendering in plain text.
+QString qtHtmlToPlainText(QString const & qstr);
+
+
} // namespace lyx
#endif // QTHELPERS_H