From 5d94dd0dbfcff0fdb0482c169cb892e27c68e57c Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Mon, 2 Jun 2025 21:43:39 -0400 Subject: [PATCH] refactor: messages::showErrorDialog, use app name in title construct QString without concat return aftershowing fatal error dialog Enable Translation for user facing strings --- src/lib/gui/Messages.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/lib/gui/Messages.cpp b/src/lib/gui/Messages.cpp index c6371b19c..b3066747f 100644 --- a/src/lib/gui/Messages.cpp +++ b/src/lib/gui/Messages.cpp @@ -36,29 +36,24 @@ void raiseCriticalDialog() void showErrorDialog(const QString &message, const QString &fileLine, QtMsgType type) { - auto title = type == QtFatalMsg ? "Fatal error" : "Critical error"; - QString text; - if (type == QtFatalMsg) { - text = "

Sorry, a fatal error has occurred and the application must " - "now exit.

"; - } else { - text = "

Sorry, a critical error has occurred.

"; - } - - text += QString( - R"(

Please report a bug)" - " and copy/paste the following error:

" + auto errorType = QtFatalMsg ? QObject::tr("fatal error") : QObject::tr("error"); + auto title = QStringLiteral("%1 %2").arg(kAppName, errorType); + auto text = QObject::tr( + R"(

Please report a bug)" + " and copy/paste the following error:

v%3\n%4\n%5
" ) - .arg(kUrlHelp, kColorSecondary); - - text += QString("
v%1\n%2\n%3
").arg(kVersion, message, fileLine); + .arg(kUrlHelp, kColorSecondary, kVersion, message, fileLine); if (type == QtFatalMsg) { + text.prepend(QObject::tr("

Sorry, a fatal error has occurred and the application must now exit.

\n")); // create a blocking message box for fatal errors, as we want to wait // until the dialog is dismissed before aborting the app. - QMessageBox critical(QMessageBox::Critical, title, text, QMessageBox::Abort); - critical.exec(); - } else if (!Errors::s_ignoredErrors.contains(message)) { + QMessageBox::critical(nullptr, title, text, QMessageBox::Abort); + return; + } + + text.prepend(QObject::tr("

Sorry, a critical error has occurred.

\n")); + if (!Errors::s_ignoredErrors.contains(message)) { // prevent message boxes piling up by deleting the last one if it exists. // if none exists yet, then nothing will happen. Errors::s_criticalMessage.reset();