From 96fd4ee02f6c3be21cade729b95a85c60634b0f8 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 30 Apr 2019 20:55:12 +0300 Subject: [PATCH] Add MSG_NOPREFIX flag for user messages It forces do not prepend error/warning prefix. --- src/noui.cpp | 36 ++++++++++++++++++++---------------- src/qt/bitcoingui.cpp | 9 +++++---- src/ui_interface.h | 3 +++ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/noui.cpp b/src/noui.cpp index 0c18b0e23..caab9f326 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -18,26 +18,30 @@ bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& ca { bool fSecure = style & CClientUIInterface::SECURE; style &= ~CClientUIInterface::SECURE; + bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX); + style &= ~CClientUIInterface::MSG_NOPREFIX; std::string strCaption; - // Check for usage of predefined caption - switch (style) { - case CClientUIInterface::MSG_ERROR: - strCaption += _("Error"); - break; - case CClientUIInterface::MSG_WARNING: - strCaption += _("Warning"); - break; - case CClientUIInterface::MSG_INFORMATION: - strCaption += _("Information"); - break; - default: - strCaption += caption; // Use supplied caption (can be empty) + if (prefix) { + switch (style) { + case CClientUIInterface::MSG_ERROR: + strCaption = "Error: "; + break; + case CClientUIInterface::MSG_WARNING: + strCaption = "Warning: "; + break; + case CClientUIInterface::MSG_INFORMATION: + strCaption = "Information: "; + break; + default: + strCaption = caption + ": "; // Use supplied caption (can be empty) + } } - if (!fSecure) - LogPrintf("%s: %s\n", strCaption, message); - tfm::format(std::cerr, "%s: %s\n", strCaption.c_str(), message.c_str()); + if (!fSecure) { + LogPrintf("%s%s\n", strCaption, message); + } + tfm::format(std::cerr, "%s%s\n", strCaption.c_str(), message.c_str()); return false; } diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 59fe58a1e..ee0680429 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1046,20 +1046,21 @@ void BitcoinGUI::message(const QString& title, QString message, unsigned int sty int nMBoxIcon = QMessageBox::Information; int nNotifyIcon = Notificator::Information; - QString msgType; + bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX); + style &= ~CClientUIInterface::MSG_NOPREFIX; - // Prefer supplied title over style based title + QString msgType; if (!title.isEmpty()) { msgType = title; } else { switch (style) { case CClientUIInterface::MSG_ERROR: msgType = tr("Error"); - message = tr("Error: %1").arg(message); + if (prefix) message = tr("Error: %1").arg(message); break; case CClientUIInterface::MSG_WARNING: msgType = tr("Warning"); - message = tr("Warning: %1").arg(message); + if (prefix) message = tr("Warning: %1").arg(message); break; case CClientUIInterface::MSG_INFORMATION: msgType = tr("Information"); diff --git a/src/ui_interface.h b/src/ui_interface.h index d408f6f88..5e0380dc4 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -69,6 +69,9 @@ public: /** Force blocking, modal message box dialog (not just OS notification) */ MODAL = 0x10000000U, + /** Do not prepend error/warning prefix */ + MSG_NOPREFIX = 0x20000000U, + /** Do not print contents of message to debug log */ SECURE = 0x40000000U,