]> git.lyx.org Git - lyx.git/commitdiff
GuiAlert: Convert html to plain text on console output
authorGuillaume Munch <gm@lyx.org>
Sun, 4 Dec 2016 17:28:03 +0000 (18:28 +0100)
committerGuillaume Munch <gm@lyx.org>
Sun, 4 Dec 2016 17:28:03 +0000 (18:28 +0100)
src/frontends/alert.h
src/frontends/qt4/GuiAlert.cpp
src/frontends/qt4/qt_helpers.cpp
src/frontends/qt4/qt_helpers.h

index 2be612acea3c0dade24081cee666dbf411a1bb2f..8770053fbaa3c77dd812e602e6a97abfdcf2e1e6 100644 (file)
@@ -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);
 
index 4c9b1628ff3c760098bb6eaa332361df545ac94e..8e12b3eb97b99053f28bee539c6c094d7dd98824 100644 (file)
@@ -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) {
index 2ad96d9295442c90c432b966130d006410cec0a3..88c4ab9424e6b341b258583df99cbf721511ec52 100644 (file)
@@ -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
index 5574212c26382cfba5f965e7a1b5677c8cc56e25..9569d90f82e5ae3930567489eff5414c70e4f5b1 100644 (file)
@@ -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