Skip to content

Commit 5648658

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 5648658

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: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
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

5+
#include <bitcoin-build-config.h> // IWYU pragma: keep
6+
57
#include <qt/guiutil.h>
68

79
#include <qt/bitcoinaddressvalidator.h>
@@ -1008,6 +1010,29 @@ void ShowModalDialogAsynchronously(QDialog* dialog)
10081010
dialog->show();
10091011
}
10101012

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

src/qt/guiutil.h

Lines changed: 7 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

@@ -8,6 +8,7 @@
88
#include <consensus/amount.h>
99
#include <net.h>
1010
#include <netaddress.h>
11+
#include <qt/networkstyle.h>
1112
#include <util/check.h>
1213
#include <util/fs.h>
1314

@@ -427,6 +428,11 @@ namespace GUIUtil
427428
*/
428429
void ShowModalDialogAsynchronously(QDialog* dialog);
429430

431+
void ShowMessageBox(const QString& message,
432+
QMessageBox::Icon box_icon,
433+
const NetworkStyle* network_style = nullptr,
434+
const QString& title = "");
435+
430436
inline bool IsEscapeOrBack(int key)
431437
{
432438
if (key == Qt::Key_Escape) return true;

0 commit comments

Comments
 (0)