From 46978a808c7e0309ca4a88f0028669d49eb177a7 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 16 Apr 2025 19:56:48 +0500 Subject: [PATCH] Disable rich text for `ui_msgbox()`-generated dialogs No strings that gets passed to `ui_msgbox()` use HTML, and it causes newlines to be ignored unless replaced by
`MainWindow::showMessage()` can still accept rich text, but it's now optional and disabled by default --- src/network/network.c | 2 +- src/qt/qt_mainwindow.cpp | 13 +++++++------ src/qt/qt_mainwindow.hpp | 6 +++--- src/qt/qt_openglrenderer.cpp | 10 +++++----- src/qt/qt_ui.cpp | 3 +-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/network/network.c b/src/network/network.c index 047642085..52b686c7e 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -501,7 +501,7 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin if(net_cards_conf[net_card_current].net_type != NET_TYPE_NONE) { // We're here because of a failure - swprintf(tempmsg, sizeof_w(tempmsg), L"%ls:

%s

%ls", plat_get_string(STRING_NET_ERROR), net_drv_error, plat_get_string(STRING_NET_ERROR_DESC)); + swprintf(tempmsg, sizeof_w(tempmsg), L"%ls:\n\n%s\n\n%ls", plat_get_string(STRING_NET_ERROR), net_drv_error, plat_get_string(STRING_NET_ERROR_DESC)); ui_msgbox(MBX_ERROR, tempmsg); net_cards_conf[net_card_current].net_type = NET_TYPE_NONE; } diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 886f84dcd..760ca7d9b 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -1342,17 +1342,17 @@ MainWindow::refreshMediaMenu() } void -MainWindow::showMessage(int flags, const QString &header, const QString &message) +MainWindow::showMessage(int flags, const QString &header, const QString &message, bool richText) { if (QThread::currentThread() == this->thread()) { if (!cpu_thread_running) { - showMessageForNonQtThread(flags, header, message, nullptr); + showMessageForNonQtThread(flags, header, message, richText, nullptr); } else - showMessage_(flags, header, message); + showMessage_(flags, header, message, richText); } else { std::atomic_bool done = false; - emit showMessageForNonQtThread(flags, header, message, &done); + emit showMessageForNonQtThread(flags, header, message, richText, &done); while (!done) { QThread::msleep(1); } @@ -1360,7 +1360,7 @@ MainWindow::showMessage(int flags, const QString &header, const QString &message } void -MainWindow::showMessage_(int flags, const QString &header, const QString &message, std::atomic_bool *done) +MainWindow::showMessage_(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool *done) { if (done) { *done = false; @@ -1372,7 +1372,8 @@ MainWindow::showMessage_(int flags, const QString &header, const QString &messag } else if (!(flags & (MBX_ERROR | MBX_WARNING))) { box.setIcon(QMessageBox::Warning); } - box.setTextFormat(Qt::TextFormat::RichText); + if (richText) + box.setTextFormat(Qt::TextFormat::RichText); box.exec(); if (done) { *done = true; diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 4b3f9ecae..739d179ff 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -26,7 +26,7 @@ public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); - void showMessage(int flags, const QString &header, const QString &message); + void showMessage(int flags, const QString &header, const QString &message, bool richText); void getTitle(wchar_t *title); void blitToWidget(int x, int y, int w, int h, int monitor_index); QSize getRenderWidgetSize(); @@ -55,7 +55,7 @@ signals: void setFullscreen(bool state); void setMouseCapture(bool state); - void showMessageForNonQtThread(int flags, const QString &header, const QString &message, std::atomic_bool* done); + void showMessageForNonQtThread(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool* done); void getTitleForNonQtThread(wchar_t *title); public slots: void showSettings(); @@ -123,7 +123,7 @@ private slots: void on_actionRenderer_options_triggered(); void refreshMediaMenu(); - void showMessage_(int flags, const QString &header, const QString &message, std::atomic_bool* done = nullptr); + void showMessage_(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool* done = nullptr); void getTitle_(wchar_t *title); void on_actionMCA_devices_triggered(); diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 53d29f9a8..45bae6ea7 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -200,7 +200,7 @@ OpenGLRenderer::create_program(struct shader_program *program) glw.glGetProgramiv(program->id, GL_INFO_LOG_LENGTH, &maxLength); char *log = (char *) malloc(maxLength); glw.glGetProgramInfoLog(program->id, maxLength, &length, log); - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Program not linked:\n\n%1").arg(log).replace("\n", "
")); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Program not linked:\n\n%1").arg(log), false); // wx_simple_messagebox("GLSL Error", "Program not linked:\n%s", log); free(log); return 0; @@ -247,7 +247,7 @@ OpenGLRenderer::compile_shader(GLenum shader_type, const char *prepend, const ch glw.glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); char *log = (char *) malloc(length); glw.glGetShaderInfoLog(shader, length, &length, log); - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not compile shader:\n\n%1").arg(log).replace("\n", "
")); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not compile shader:\n\n%1").arg(log), false); // wx_simple_messagebox("GLSL Error", "Could not compile shader:\n%s", log); ogl3_log("Could not compile shader: %s\n", log); @@ -651,7 +651,7 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) if (!load_texture(file, &tex->texture)) { //QMessageBox::critical(main_window, tr("GLSL Error"), tr("Could not load texture: %s").arg(file)); - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load texture: %1").arg(file)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load texture: %1").arg(file), false); ogl3_log("Could not load texture %s!\n", file); failed = 1; break; @@ -697,7 +697,7 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) ogl3_log("Creating pass %u (%s)\n", (i + 1), pass->alias); ogl3_log("Loading shader %s...\n", shader->shader_fn); if (!shader->shader_program) { - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load shader: %1").arg(shader->shader_fn)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load shader: %1").arg(shader->shader_fn), false); // wx_simple_messagebox("GLSL Error", "Could not load shader: %s", shader->shader_fn); ogl3_log("Could not load shader %s\n", shader->shader_fn); failed = 1; @@ -1115,7 +1115,7 @@ OpenGLRenderer::initialize() for (auto &flag : buf_usage) flag.test_and_set(); - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("Error initializing OpenGL"), e.what() + tr("\nFalling back to software rendering.")); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("Error initializing OpenGL"), e.what() + tr("\nFalling back to software rendering."), false); context->doneCurrent(); isFinalized = true; diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index b9253663b..57f8001dc 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -142,11 +142,10 @@ ui_msgbox_header(int flags, void *header, void *message) // any error in early init if (main_window == nullptr) { QMessageBox msgBox(QMessageBox::Icon::Critical, hdr, msg); - msgBox.setTextFormat(Qt::TextFormat::RichText); msgBox.exec(); } else { // else scope it to main_window - main_window->showMessage(flags, hdr, msg); + main_window->showMessage(flags, hdr, msg, false); } return 0; }