Skip to content

Commit e2bbdcb

Browse files
gui: Update QMessageBox::Icon with chaintype image
Introducing a new helper GUIUtil::ShowMessageBox() in order to incorporate the chaintype image in the message box window icon.
1 parent 0011c78 commit e2bbdcb

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

src/qt/bitcoin.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ bool BitcoinApplication::createOptionsModel(bool resetSettings)
260260
error.translated += tr("Settings file %1 might be corrupt or invalid.").arg(QString::fromStdString(quoted_path)).toStdString();
261261
}
262262
InitError(error);
263-
QMessageBox::critical(nullptr, CLIENT_NAME, QString::fromStdString(error.translated));
263+
GUIUtil::ShowMessageBox(QString::fromStdString(error.translated), static_cast<QMessageBox::Icon>(QMessageBox::Critical));
264264
return false;
265265
}
266266
return true;
@@ -440,21 +440,25 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead
440440

441441
void BitcoinApplication::handleRunawayException(const QString &message)
442442
{
443-
QMessageBox::critical(
444-
nullptr, tr("Runaway exception"),
445-
tr("A fatal error occurred. %1 can no longer continue safely and will quit.").arg(CLIENT_NAME) +
446-
QLatin1String("<br><br>") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT));
443+
const QString qMessage = tr("A fatal error occurred. %1 can no longer continue safely and will quit.").arg(CLIENT_NAME) +
444+
QLatin1String("<br><br>") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT);
445+
GUIUtil::ShowMessageBox(/*message=*/qMessage,
446+
/*box_icon=*/static_cast<QMessageBox::Icon>(QMessageBox::Critical),
447+
/*network_style=*/nullptr,
448+
/*title=*/tr("Runaway exception"));
447449
::exit(EXIT_FAILURE);
448450
}
449451

450452
void BitcoinApplication::handleNonFatalException(const QString& message)
451453
{
452454
assert(QThread::currentThread() == thread());
453-
QMessageBox::warning(
454-
nullptr, tr("Internal error"),
455-
tr("An internal error occurred. %1 will attempt to continue safely. This is "
456-
"an unexpected bug which can be reported as described below.").arg(CLIENT_NAME) +
457-
QLatin1String("<br><br>") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT));
455+
const QString qMessage = tr("An internal error occurred. %1 will attempt to continue safely. This is "
456+
"an unexpected bug which can be reported as described below.").arg(CLIENT_NAME) +
457+
QLatin1String("<br><br>") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT);
458+
GUIUtil::ShowMessageBox(/*message=*/qMessage,
459+
/*box_icon=*/static_cast<QMessageBox::Icon>(QMessageBox::Warning),
460+
/*network_style=*/nullptr,
461+
/*title=*/tr("Internal error"));
458462
}
459463

460464
WId BitcoinApplication::getMainWinId() const
@@ -529,11 +533,11 @@ int GuiMain(int argc, char* argv[])
529533
SetupUIArgs(gArgs);
530534
std::string error;
531535
if (!gArgs.ParseParameters(argc, argv, error)) {
532-
InitError(Untranslated(strprintf("Error parsing command line arguments: %s", error)));
536+
const std::string message = tfm::format("Error parsing command line arguments: %s", error);
537+
// message cannot be translated because translations have not been initialized
538+
InitError(Untranslated(message));
533539
// Create a message box, because the gui has neither been created nor has subscribed to core signals
534-
QMessageBox::critical(nullptr, CLIENT_NAME,
535-
// message cannot be translated because translations have not been initialized
536-
QString::fromStdString("Error parsing command line arguments: %1.").arg(QString::fromStdString(error)));
540+
GUIUtil::ShowMessageBox(QString::fromStdString(message), static_cast<QMessageBox::Icon>(QMessageBox::Critical));
537541
return EXIT_FAILURE;
538542
}
539543

@@ -550,17 +554,17 @@ int GuiMain(int argc, char* argv[])
550554
}
551555
#endif
552556
if (payment_server_token_seen && arg.startsWith("-")) {
553-
InitError(Untranslated(strprintf("Options ('%s') cannot follow a BIP-21 payment URI", argv[i])));
554-
QMessageBox::critical(nullptr, CLIENT_NAME,
555-
// message cannot be translated because translations have not been initialized
556-
QString::fromStdString("Options ('%1') cannot follow a BIP-21 payment URI").arg(QString::fromStdString(argv[i])));
557+
const std::string message = tfm::format("Options ('%s') cannot follow a BIP-21 payment URI", argv[i]);
558+
// message cannot be translated because translations have not been initialized
559+
InitError(Untranslated(message));
560+
GUIUtil::ShowMessageBox(QString::fromStdString(message), static_cast<QMessageBox::Icon>(QMessageBox::Critical));
557561
return EXIT_FAILURE;
558562
}
559563
if (invalid_token) {
560-
InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoin-qt -h for a list of options.", argv[i])));
561-
QMessageBox::critical(nullptr, CLIENT_NAME,
562-
// message cannot be translated because translations have not been initialized
563-
QString::fromStdString("Command line contains unexpected token '%1', see bitcoin-qt -h for a list of options.").arg(QString::fromStdString(argv[i])));
564+
const std::string message = tfm::format("Command line contains unexpected token '%s', see bitcoin-qt -h for a list of options.", argv[i]);
565+
// message cannot be translated because translations have not been initialized
566+
InitError(Untranslated(message));
567+
GUIUtil::ShowMessageBox(QString::fromStdString(message), static_cast<QMessageBox::Icon>(QMessageBox::Critical));
564568
return EXIT_FAILURE;
565569
}
566570
}
@@ -613,7 +617,9 @@ int GuiMain(int argc, char* argv[])
613617
} else if (error->status != common::ConfigStatus::ABORTED) {
614618
// Show a generic message in other cases, and no additional error
615619
// message in the case of a read error if the user decided to abort.
616-
QMessageBox::critical(nullptr, CLIENT_NAME, QObject::tr("Error: %1").arg(QString::fromStdString(error->message.translated)));
620+
GUIUtil::ShowMessageBox(
621+
QObject::tr("Error: %1").arg(QString::fromStdString(error->message.translated)),
622+
static_cast<QMessageBox::Icon>(QMessageBox::Critical));
617623
}
618624
return EXIT_FAILURE;
619625
}

src/qt/guiutil.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2011-2022 The Bitcoin Core developers
1+
// Copyright (c) 2011-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -1008,6 +1008,29 @@ void ShowModalDialogAsynchronously(QDialog* dialog)
10081008
dialog->show();
10091009
}
10101010

1011+
void ShowMessageBox(const QString& message,
1012+
QMessageBox::Icon box_icon,
1013+
const NetworkStyle* network_style,
1014+
const QString& title)
1015+
{
1016+
QString qTitle = CLIENT_NAME;
1017+
if (!title.isEmpty()) qTitle = title;
1018+
QMessageBox mBox(box_icon, qTitle, message);
1019+
1020+
mBox.setTextFormat(Qt::PlainText);
1021+
1022+
if (network_style) {
1023+
mBox.setWindowIcon(network_style->getTrayAndWindowIcon());
1024+
} else if (!gArgs.GetChainTypeString().empty()) {
1025+
std::unique_ptr<const NetworkStyle> fallback(NetworkStyle::instantiate(gArgs.GetChainType()));
1026+
if (fallback) {
1027+
mBox.setWindowIcon(fallback->getTrayAndWindowIcon());
1028+
}
1029+
}
1030+
1031+
mBox.exec();
1032+
}
1033+
10111034
QString WalletDisplayName(const QString& name)
10121035
{
10131036
return name.isEmpty() ? "[" + QObject::tr("default wallet") + "]" : name;

src/qt/guiutil.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
// Copyright (c) 2011-2022 The Bitcoin Core developers
1+
// Copyright (c) 2011-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#ifndef BITCOIN_QT_GUIUTIL_H
66
#define BITCOIN_QT_GUIUTIL_H
77

8+
#include <bitcoin-build-config.h> // IWYU pragma: keep
9+
810
#include <consensus/amount.h>
911
#include <net.h>
1012
#include <netaddress.h>
13+
#include <qt/networkstyle.h>
1114
#include <util/check.h>
1215
#include <util/fs.h>
1316

@@ -427,6 +430,11 @@ namespace GUIUtil
427430
*/
428431
void ShowModalDialogAsynchronously(QDialog* dialog);
429432

433+
void ShowMessageBox(const QString& message,
434+
QMessageBox::Icon box_icon,
435+
const NetworkStyle* network_style = nullptr,
436+
const QString& title = "");
437+
430438
inline bool IsEscapeOrBack(int key)
431439
{
432440
if (key == Qt::Key_Escape) return true;

0 commit comments

Comments
 (0)