Skip to content

Commit 10b3cd1

Browse files
refactor: Implement HelpMessageDialog using Modes enum
1 parent 29c2c90 commit 10b3cd1

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

src/qt/bitcoin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ int GuiMain(int argc, char* argv[])
593593
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
594594
// but before showing splash screen.
595595
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
596-
HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version"));
596+
bool about = gArgs.IsArgSet("-version");
597+
HelpMessageDialog help(nullptr, about ? HelpMessageDialog::AboutMode : HelpMessageDialog::CommandLineOptionsMode);
597598
help.showOrPrint();
598599
return EXIT_SUCCESS;
599600
}

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
103103
updateWindowTitle();
104104

105105
rpcConsole = new RPCConsole(node, _platformStyle, nullptr);
106-
helpMessageDialog = new HelpMessageDialog(this, false);
106+
helpMessageDialog = new HelpMessageDialog(this, HelpMessageDialog::CommandLineOptionsMode);
107107
#ifdef ENABLE_WALLET
108108
if(enableWallet)
109109
{
@@ -911,7 +911,7 @@ void BitcoinGUI::aboutClicked()
911911
if(!clientModel)
912912
return;
913913

914-
auto dlg = new HelpMessageDialog(this, /*about=*/true);
914+
auto dlg = new HelpMessageDialog(this, HelpMessageDialog::AboutMode);
915915
GUIUtil::ShowModalDialogAsynchronously(dlg);
916916
}
917917

src/qt/utilitydialog.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,39 @@
2929
#include <QVBoxLayout>
3030

3131
/** "Help message" or "About" dialog box */
32-
HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
32+
HelpMessageDialog::HelpMessageDialog(QWidget *parent, Mode _mode) :
3333
QDialog(parent, GUIUtil::dialog_flags),
34-
ui(new Ui::HelpMessageDialog)
34+
ui(new Ui::HelpMessageDialog),
35+
mode(_mode)
3536
{
3637
ui->setupUi(this);
3738

3839
QString version = QString{PACKAGE_NAME} + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
3940

40-
if (about)
41+
switch(mode)
4142
{
42-
setWindowTitle(tr("About %1").arg(PACKAGE_NAME));
43-
44-
std::string licenseInfo = LicenseInfo();
45-
/// HTML-format the license message from the core
46-
QString licenseInfoHTML = QString::fromStdString(LicenseInfo());
47-
// Make URLs clickable
48-
QRegularExpression uri(QStringLiteral("<(.*)>"), QRegularExpression::InvertedGreedinessOption);
49-
licenseInfoHTML.replace(uri, QStringLiteral("<a href=\"\\1\">\\1</a>"));
50-
// Replace newlines with HTML breaks
51-
licenseInfoHTML.replace("\n", "<br>");
52-
53-
ui->aboutMessage->setTextFormat(Qt::RichText);
54-
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
55-
text = version + "\n" + QString::fromStdString(FormatParagraph(licenseInfo));
56-
ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
57-
ui->aboutMessage->setWordWrap(true);
58-
ui->helpMessage->setVisible(false);
59-
} else {
43+
case AboutMode:
44+
{
45+
setWindowTitle(tr("About %1").arg(PACKAGE_NAME));
46+
47+
std::string licenseInfo = LicenseInfo();
48+
/// HTML-format the license message from the core
49+
QString licenseInfoHTML = QString::fromStdString(LicenseInfo());
50+
// Make URLs clickable
51+
QRegularExpression uri(QStringLiteral("<(.*)>"), QRegularExpression::InvertedGreedinessOption);
52+
licenseInfoHTML.replace(uri, QStringLiteral("<a href=\"\\1\">\\1</a>"));
53+
// Replace newlines with HTML breaks
54+
licenseInfoHTML.replace("\n", "<br>");
55+
56+
ui->aboutMessage->setTextFormat(Qt::RichText);
57+
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
58+
text = version + "\n" + QString::fromStdString(FormatParagraph(licenseInfo));
59+
ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
60+
ui->aboutMessage->setWordWrap(true);
61+
ui->helpMessage->setVisible(false);
62+
break;
63+
}
64+
case CommandLineOptionsMode:
6065
setWindowTitle(tr("Command-line options"));
6166
QString header = "Usage: bitcoin-qt [command-line options] \n";
6267
QTextCursor cursor(ui->helpMessage->document());
@@ -103,6 +108,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
103108
ui->helpMessage->moveCursor(QTextCursor::Start);
104109
ui->scrollArea->setVisible(false);
105110
ui->aboutLogo->setVisible(false);
111+
break;
106112
}
107113

108114
GUIUtil::handleCloseWindowShortcut(this);

src/qt/utilitydialog.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ class HelpMessageDialog : public QDialog
2222
Q_OBJECT
2323

2424
public:
25-
explicit HelpMessageDialog(QWidget *parent, bool about);
25+
enum Mode {
26+
AboutMode,
27+
CommandLineOptionsMode
28+
};
29+
30+
explicit HelpMessageDialog(QWidget *parent, Mode _mode);
2631
~HelpMessageDialog();
2732

2833
void printToConsole();
@@ -31,6 +36,7 @@ class HelpMessageDialog : public QDialog
3136
private:
3237
Ui::HelpMessageDialog *ui;
3338
QString text;
39+
Mode mode;
3440

3541
private Q_SLOTS:
3642
void on_okButton_accepted();

0 commit comments

Comments
 (0)