Add MSG_NOPREFIX flag for user messages

It forces do not prepend error/warning prefix.
This commit is contained in:
Hennadii Stepanov 2019-04-30 20:55:12 +03:00
parent f0641f274f
commit 96fd4ee02f
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
3 changed files with 28 additions and 20 deletions

View file

@ -18,26 +18,30 @@ bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& ca
{ {
bool fSecure = style & CClientUIInterface::SECURE; bool fSecure = style & CClientUIInterface::SECURE;
style &= ~CClientUIInterface::SECURE; style &= ~CClientUIInterface::SECURE;
bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX);
style &= ~CClientUIInterface::MSG_NOPREFIX;
std::string strCaption; std::string strCaption;
// Check for usage of predefined caption if (prefix) {
switch (style) { switch (style) {
case CClientUIInterface::MSG_ERROR: case CClientUIInterface::MSG_ERROR:
strCaption += _("Error"); strCaption = "Error: ";
break; break;
case CClientUIInterface::MSG_WARNING: case CClientUIInterface::MSG_WARNING:
strCaption += _("Warning"); strCaption = "Warning: ";
break; break;
case CClientUIInterface::MSG_INFORMATION: case CClientUIInterface::MSG_INFORMATION:
strCaption += _("Information"); strCaption = "Information: ";
break; break;
default: default:
strCaption += caption; // Use supplied caption (can be empty) strCaption = caption + ": "; // Use supplied caption (can be empty)
}
} }
if (!fSecure) if (!fSecure) {
LogPrintf("%s: %s\n", strCaption, message); LogPrintf("%s%s\n", strCaption, message);
tfm::format(std::cerr, "%s: %s\n", strCaption.c_str(), message.c_str()); }
tfm::format(std::cerr, "%s%s\n", strCaption.c_str(), message.c_str());
return false; return false;
} }

View file

@ -1046,20 +1046,21 @@ void BitcoinGUI::message(const QString& title, QString message, unsigned int sty
int nMBoxIcon = QMessageBox::Information; int nMBoxIcon = QMessageBox::Information;
int nNotifyIcon = Notificator::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()) { if (!title.isEmpty()) {
msgType = title; msgType = title;
} else { } else {
switch (style) { switch (style) {
case CClientUIInterface::MSG_ERROR: case CClientUIInterface::MSG_ERROR:
msgType = tr("Error"); msgType = tr("Error");
message = tr("Error: %1").arg(message); if (prefix) message = tr("Error: %1").arg(message);
break; break;
case CClientUIInterface::MSG_WARNING: case CClientUIInterface::MSG_WARNING:
msgType = tr("Warning"); msgType = tr("Warning");
message = tr("Warning: %1").arg(message); if (prefix) message = tr("Warning: %1").arg(message);
break; break;
case CClientUIInterface::MSG_INFORMATION: case CClientUIInterface::MSG_INFORMATION:
msgType = tr("Information"); msgType = tr("Information");

View file

@ -69,6 +69,9 @@ public:
/** Force blocking, modal message box dialog (not just OS notification) */ /** Force blocking, modal message box dialog (not just OS notification) */
MODAL = 0x10000000U, MODAL = 0x10000000U,
/** Do not prepend error/warning prefix */
MSG_NOPREFIX = 0x20000000U,
/** Do not print contents of message to debug log */ /** Do not print contents of message to debug log */
SECURE = 0x40000000U, SECURE = 0x40000000U,