diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index eaaa9fc6fd5..2aac9091ad5 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2022 The Bitcoin Core developers +// Copyright (c) 2011-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -260,7 +260,7 @@ bool BitcoinApplication::createOptionsModel(bool resetSettings) error.translated += tr("Settings file %1 might be corrupt or invalid.").arg(QString::fromStdString(quoted_path)).toStdString(); } InitError(error); - QMessageBox::critical(nullptr, CLIENT_NAME, QString::fromStdString(error.translated)); + GUIUtil::ShowMessageBox(QString::fromStdString(error.translated), static_cast(QMessageBox::Critical)); return false; } return true; @@ -440,21 +440,25 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead void BitcoinApplication::handleRunawayException(const QString &message) { - QMessageBox::critical( - nullptr, tr("Runaway exception"), - tr("A fatal error occurred. %1 can no longer continue safely and will quit.").arg(CLIENT_NAME) + - QLatin1String("

") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT)); + const QString qMessage = tr("A fatal error occurred. %1 can no longer continue safely and will quit.").arg(CLIENT_NAME) + + QLatin1String("

") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT); + GUIUtil::ShowMessageBox(/*message=*/qMessage, + /*box_icon=*/static_cast(QMessageBox::Critical), + /*network_style=*/nullptr, + /*title=*/tr("Runaway exception")); ::exit(EXIT_FAILURE); } void BitcoinApplication::handleNonFatalException(const QString& message) { assert(QThread::currentThread() == thread()); - QMessageBox::warning( - nullptr, tr("Internal error"), - tr("An internal error occurred. %1 will attempt to continue safely. This is " - "an unexpected bug which can be reported as described below.").arg(CLIENT_NAME) + - QLatin1String("

") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT)); + const QString qMessage = tr("An internal error occurred. %1 will attempt to continue safely. This is " + "an unexpected bug which can be reported as described below.").arg(CLIENT_NAME) + + QLatin1String("

") + GUIUtil::MakeHtmlLink(message, CLIENT_BUGREPORT); + GUIUtil::ShowMessageBox(/*message=*/qMessage, + /*box_icon=*/static_cast(QMessageBox::Warning), + /*network_style=*/nullptr, + /*title=*/tr("Internal error")); } WId BitcoinApplication::getMainWinId() const @@ -529,11 +533,11 @@ int GuiMain(int argc, char* argv[]) SetupUIArgs(gArgs); std::string error; if (!gArgs.ParseParameters(argc, argv, error)) { - InitError(Untranslated(strprintf("Error parsing command line arguments: %s", error))); + const std::string message = tfm::format("Error parsing command line arguments: %s", error); + // message cannot be translated because translations have not been initialized + InitError(Untranslated(message)); // Create a message box, because the gui has neither been created nor has subscribed to core signals - QMessageBox::critical(nullptr, CLIENT_NAME, - // message cannot be translated because translations have not been initialized - QString::fromStdString("Error parsing command line arguments: %1.").arg(QString::fromStdString(error))); + GUIUtil::ShowMessageBox(QString::fromStdString(message), static_cast(QMessageBox::Critical)); return EXIT_FAILURE; } @@ -550,17 +554,17 @@ int GuiMain(int argc, char* argv[]) } #endif if (payment_server_token_seen && arg.startsWith("-")) { - InitError(Untranslated(strprintf("Options ('%s') cannot follow a BIP-21 payment URI", argv[i]))); - QMessageBox::critical(nullptr, CLIENT_NAME, - // message cannot be translated because translations have not been initialized - QString::fromStdString("Options ('%1') cannot follow a BIP-21 payment URI").arg(QString::fromStdString(argv[i]))); + const std::string message = tfm::format("Options ('%s') cannot follow a BIP-21 payment URI", argv[i]); + // message cannot be translated because translations have not been initialized + InitError(Untranslated(message)); + GUIUtil::ShowMessageBox(QString::fromStdString(message), static_cast(QMessageBox::Critical)); return EXIT_FAILURE; } if (invalid_token) { - InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoin-qt -h for a list of options.", argv[i]))); - QMessageBox::critical(nullptr, CLIENT_NAME, - // message cannot be translated because translations have not been initialized - QString::fromStdString("Command line contains unexpected token '%1', see bitcoin-qt -h for a list of options.").arg(QString::fromStdString(argv[i]))); + const std::string message = tfm::format("Command line contains unexpected token '%s', see bitcoin-qt -h for a list of options.", argv[i]); + // message cannot be translated because translations have not been initialized + InitError(Untranslated(message)); + GUIUtil::ShowMessageBox(QString::fromStdString(message), static_cast(QMessageBox::Critical)); return EXIT_FAILURE; } } @@ -583,7 +587,7 @@ int GuiMain(int argc, char* argv[]) // Show help message immediately after parsing command-line options (for "-lang") and setting locale, // but before showing splash screen. if (HelpRequested(gArgs) || gArgs.GetBoolArg("-version", false)) { - HelpMessageDialog help(nullptr, gArgs.GetBoolArg("-version", false)); + HelpMessageDialog help(/*parent=*/nullptr, /*about=*/gArgs.GetBoolArg("-version", false)); help.showOrPrint(); return EXIT_SUCCESS; } @@ -613,7 +617,9 @@ int GuiMain(int argc, char* argv[]) } else if (error->status != common::ConfigStatus::ABORTED) { // Show a generic message in other cases, and no additional error // message in the case of a read error if the user decided to abort. - QMessageBox::critical(nullptr, CLIENT_NAME, QObject::tr("Error: %1").arg(QString::fromStdString(error->message.translated))); + GUIUtil::ShowMessageBox( + QObject::tr("Error: %1").arg(QString::fromStdString(error->message.translated)), + static_cast(QMessageBox::Critical)); } return EXIT_FAILURE; } diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index f899a524f45..2f16ddc80e3 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2022 The Bitcoin Core developers +// Copyright (c) 2011-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -105,7 +105,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty updateWindowTitle(); rpcConsole = new RPCConsole(node, _platformStyle, nullptr); - helpMessageDialog = new HelpMessageDialog(this, false); + helpMessageDialog = new HelpMessageDialog(/*parent=*/this, /*about=*/false, /*network_style=*/m_network_style); #ifdef ENABLE_WALLET if(enableWallet) { @@ -936,7 +936,7 @@ void BitcoinGUI::aboutClicked() if(!clientModel) return; - auto dlg = new HelpMessageDialog(this, /*about=*/true); + auto dlg = new HelpMessageDialog(/*parent=*/this, /*about=*/true, /*network_style=*/m_network_style); GUIUtil::ShowModalDialogAsynchronously(dlg); } diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 2369f6b6312..81a969a4492 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -1,7 +1,9 @@ -// Copyright (c) 2011-2022 The Bitcoin Core developers +// Copyright (c) 2011-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include // IWYU pragma: keep + #include #include @@ -1008,6 +1010,29 @@ void ShowModalDialogAsynchronously(QDialog* dialog) dialog->show(); } +void ShowMessageBox(const QString& message, + QMessageBox::Icon box_icon, + const NetworkStyle* network_style, + const QString& title) +{ + QString qTitle = CLIENT_NAME; + if (!title.isEmpty()) qTitle = title; + QMessageBox mBox(box_icon, qTitle, message); + + mBox.setTextFormat(Qt::PlainText); + + if (network_style) { + mBox.setWindowIcon(network_style->getTrayAndWindowIcon()); + } else if (!gArgs.GetChainTypeString().empty()) { + std::unique_ptr fallback(NetworkStyle::instantiate(gArgs.GetChainType())); + if (fallback) { + mBox.setWindowIcon(fallback->getTrayAndWindowIcon()); + } + } + + mBox.exec(); +} + QString WalletDisplayName(const QString& name) { return name.isEmpty() ? "[" + QObject::tr("default wallet") + "]" : name; diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 45251987943..80c42b14ee0 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2022 The Bitcoin Core developers +// Copyright (c) 2011-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -427,6 +428,11 @@ namespace GUIUtil */ void ShowModalDialogAsynchronously(QDialog* dialog); + void ShowMessageBox(const QString& message, + QMessageBox::Icon box_icon, + const NetworkStyle* network_style = nullptr, + const QString& title = ""); + inline bool IsEscapeOrBack(int key) { if (key == Qt::Key_Escape) return true; diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 86c37704078..99d3312b4e9 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2022 The Bitcoin Core developers +// Copyright (c) 2011-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -10,6 +10,8 @@ #include +#include + #include #include #include @@ -27,7 +29,7 @@ #include /** "Help message" or "About" dialog box */ -HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : +HelpMessageDialog::HelpMessageDialog(QWidget* parent, bool about, const NetworkStyle* network_style) : QDialog(parent, GUIUtil::dialog_flags), ui(new Ui::HelpMessageDialog) { @@ -37,8 +39,8 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : if (about) { - setWindowTitle(tr("About %1").arg(CLIENT_NAME)); - + this->setAboutWindowTitle(network_style); + this->setChainTypeIconOnAboutLogo(network_style); std::string licenseInfo = LicenseInfo(); /// HTML-format the license message from the core QString licenseInfoHTML = QString::fromStdString(LicenseInfo()); @@ -137,6 +139,21 @@ void HelpMessageDialog::on_okButton_accepted() close(); } +void HelpMessageDialog::setAboutWindowTitle(const NetworkStyle* network_style) +{ + QString aboutTitle = tr("About %1").arg(CLIENT_NAME); + if (network_style && Params().GetChainType() != ChainType::MAIN) { + aboutTitle.append(" " + network_style->getTitleAddText()); + } + setWindowTitle(aboutTitle); +} + +void HelpMessageDialog::setChainTypeIconOnAboutLogo(const NetworkStyle* network_style) +{ + const QSize requiredSize(1024, 1024); + if (network_style) ui->aboutLogo->setPixmap(network_style->getAppIcon().pixmap(requiredSize)); +} + /** "Shutdown" window */ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f): diff --git a/src/qt/utilitydialog.h b/src/qt/utilitydialog.h index d2a5d5f67f2..6b8a13628df 100644 --- a/src/qt/utilitydialog.h +++ b/src/qt/utilitydialog.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2020 The Bitcoin Core developers +// Copyright (c) 2011-present The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -8,6 +8,8 @@ #include #include +class NetworkStyle; + QT_BEGIN_NAMESPACE class QMainWindow; QT_END_NAMESPACE @@ -22,7 +24,7 @@ class HelpMessageDialog : public QDialog Q_OBJECT public: - explicit HelpMessageDialog(QWidget *parent, bool about); + explicit HelpMessageDialog(QWidget* parent, bool about, const NetworkStyle* network_style = nullptr); ~HelpMessageDialog(); void printToConsole(); @@ -31,6 +33,8 @@ class HelpMessageDialog : public QDialog private: Ui::HelpMessageDialog *ui; QString text; + void setAboutWindowTitle(const NetworkStyle* network_style = nullptr); + void setChainTypeIconOnAboutLogo(const NetworkStyle* network_style = nullptr); private Q_SLOTS: void on_okButton_accepted();