From 96b733e99694e74dcd38b16112655f7e1ea2d43b Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 3 Jun 2014 16:12:19 +0200 Subject: [PATCH 1/4] Add `-version` option to get just the version Adds a `-version` or `--version` option to print just the version of the program for bitcoind, bitcoin-cli and bitcoin-qt. Also make it that `-help` can be used to display the help (as well as existing `--help`). Up to now, `-help` was the only option that didn't work with either one or two dashes. --- src/bitcoin-cli.cpp | 18 ++++++++++-------- src/bitcoind.cpp | 25 ++++++++++++++----------- src/qt/bitcoin.cpp | 4 ++-- src/qt/bitcoingui.cpp | 2 +- src/qt/utilitydialog.cpp | 19 ++++++++++--------- src/qt/utilitydialog.h | 5 +---- 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 29efdfa821..0bb71329f5 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -39,16 +39,18 @@ static bool AppInitRPC(int argc, char* argv[]) return false; } - if (argc<2 || mapArgs.count("-?") || mapArgs.count("--help")) + if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) { - // First part of help message is specific to RPC client - std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n\n" + - _("Usage:") + "\n" + - " bitcoin-cli [options] [params] " + _("Send command to Bitcoin Core") + "\n" + - " bitcoin-cli [options] help " + _("List commands") + "\n" + - " bitcoin-cli [options] help " + _("Get help for a command") + "\n"; + std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n"; + if (!mapArgs.count("-version")) + { + strUsage += "\n" + _("Usage:") + "\n" + + " bitcoin-cli [options] [params] " + _("Send command to Bitcoin Core") + "\n" + + " bitcoin-cli [options] help " + _("List commands") + "\n" + + " bitcoin-cli [options] help " + _("Get help for a command") + "\n"; - strUsage += "\n" + HelpMessageCli(true); + strUsage += "\n" + HelpMessageCli(true); + } fprintf(stdout, "%s", strUsage.c_str()); return false; diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 704332c39b..99dc9d726d 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -83,19 +83,22 @@ bool AppInit(int argc, char* argv[]) return false; } - if (mapArgs.count("-?") || mapArgs.count("--help")) + if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) { - // First part of help message is specific to bitcoind / RPC client - std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n\n" + - _("Usage:") + "\n" + - " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n" + - _("Usage (deprecated, use bitcoin-cli):") + "\n" + - " bitcoind [options] [params] " + _("Send command to Bitcoin Core") + "\n" + - " bitcoind [options] help " + _("List commands") + "\n" + - " bitcoind [options] help " + _("Get help for a command") + "\n"; + std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n"; - strUsage += "\n" + HelpMessage(HMM_BITCOIND); - strUsage += "\n" + HelpMessageCli(false); + if (!mapArgs.count("-version")) + { + strUsage += "\n" + _("Usage:") + "\n" + + " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n" + + _("Usage (deprecated, use bitcoin-cli):") + "\n" + + " bitcoind [options] [params] " + _("Send command to Bitcoin Core") + "\n" + + " bitcoind [options] help " + _("List commands") + "\n" + + " bitcoind [options] help " + _("Get help for a command") + "\n"; + + strUsage += "\n" + HelpMessage(HMM_BITCOIND); + strUsage += "\n" + HelpMessageCli(false); + } fprintf(stdout, "%s", strUsage.c_str()); return false; diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 2be8191eb5..387f6ede4b 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -503,9 +503,9 @@ int main(int argc, char *argv[]) // Show help message immediately after parsing command-line options (for "-lang") and setting locale, // but before showing splash screen. - if (mapArgs.count("-?") || mapArgs.count("--help")) + if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) { - HelpMessageDialog help(NULL); + HelpMessageDialog help(NULL, mapArgs.count("-version")); help.showOrPrint(); return 1; } diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 3469f990ac..847a3ab8f1 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -556,7 +556,7 @@ void BitcoinGUI::aboutClicked() void BitcoinGUI::showHelpMessageClicked() { - HelpMessageDialog *help = new HelpMessageDialog(this); + HelpMessageDialog *help = new HelpMessageDialog(this, false); help->setAttribute(Qt::WA_DeleteOnClose); help->show(); } diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 01b710e876..435c6a4368 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -57,21 +57,20 @@ void AboutDialog::on_buttonBox_accepted() } /** "Help message" dialog box */ -HelpMessageDialog::HelpMessageDialog(QWidget *parent) : +HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool versionOnly) : QDialog(parent), ui(new Ui::HelpMessageDialog) { ui->setupUi(this); GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this); - header = tr("Bitcoin Core") + " " + tr("version") + " " + - QString::fromStdString(FormatFullVersion()) + "\n\n" + - tr("Usage:") + "\n" + + QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); + QString header = tr("Usage:") + "\n" + " bitcoin-qt [" + tr("command-line options") + "] " + "\n"; - coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); + QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); - uiOptions = tr("UI options") + ":\n" + + QString uiOptions = tr("UI options") + ":\n" + " -choosedatadir " + tr("Choose data directory on startup (default: 0)") + "\n" + " -lang= " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" + " -min " + tr("Start minimized") + "\n" + @@ -81,7 +80,10 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent) : ui->helpMessageLabel->setFont(GUIUtil::bitcoinAddressFont()); // Set help message text - ui->helpMessageLabel->setText(header + "\n" + coreOptions + "\n" + uiOptions); + if(versionOnly) + ui->helpMessageLabel->setText(version); + else + ui->helpMessageLabel->setText(version + "\n" + header + "\n" + coreOptions + "\n" + uiOptions); } HelpMessageDialog::~HelpMessageDialog() @@ -93,8 +95,7 @@ HelpMessageDialog::~HelpMessageDialog() void HelpMessageDialog::printToConsole() { // On other operating systems, the expected action is to print the message to the console. - QString strUsage = header + "\n" + coreOptions + "\n" + uiOptions + "\n"; - fprintf(stdout, "%s", strUsage.toStdString().c_str()); + fprintf(stdout, "%s\n", qPrintable(ui->helpMessageLabel->text())); } void HelpMessageDialog::showOrPrint() diff --git a/src/qt/utilitydialog.h b/src/qt/utilitydialog.h index 874daf6a7f..cc23420169 100644 --- a/src/qt/utilitydialog.h +++ b/src/qt/utilitydialog.h @@ -40,7 +40,7 @@ class HelpMessageDialog : public QDialog Q_OBJECT public: - explicit HelpMessageDialog(QWidget *parent); + explicit HelpMessageDialog(QWidget *parent, bool versionOnly); ~HelpMessageDialog(); void printToConsole(); @@ -48,9 +48,6 @@ public: private: Ui::HelpMessageDialog *ui; - QString header; - QString coreOptions; - QString uiOptions; private slots: void on_okButton_accepted(); From 97789d374c40f4f7fc8feb19c1235ca09ad2e06e Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 10 Jun 2014 16:02:29 +0200 Subject: [PATCH 2/4] util: Add function FormatParagraph to format paragraph to fixed-width This is to be used for the `-version` and `-help` messages. --- src/test/util_tests.cpp | 11 +++++++++++ src/util.cpp | 35 +++++++++++++++++++++++++++++++++++ src/util.h | 5 +++++ 3 files changed, 51 insertions(+) diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 0e53a57593..0b071361d8 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -351,4 +351,15 @@ BOOST_AUTO_TEST_CASE(test_ParseInt32) BOOST_CHECK(!ParseInt32("32482348723847471234", NULL)); } +BOOST_AUTO_TEST_CASE(test_FormatParagraph) +{ + BOOST_CHECK_EQUAL(FormatParagraph("", 79, 0), ""); + BOOST_CHECK_EQUAL(FormatParagraph("test", 79, 0), "test"); + BOOST_CHECK_EQUAL(FormatParagraph(" test", 79, 0), "test"); + BOOST_CHECK_EQUAL(FormatParagraph("test test", 79, 0), "test test"); + BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 0), "test\ntest"); + BOOST_CHECK_EQUAL(FormatParagraph("testerde test ", 4, 0), "testerde\ntest"); + BOOST_CHECK_EQUAL(FormatParagraph("test test", 4, 4), "test\n test"); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/util.cpp b/src/util.cpp index cccf2df484..3e3dabb678 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1407,3 +1407,38 @@ std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime) ss << boost::posix_time::from_time_t(nTime); return ss.str(); } + +std::string FormatParagraph(const std::string in, size_t width, size_t indent) +{ + std::stringstream out; + size_t col = 0; + size_t ptr = 0; + while(ptr < in.size()) + { + // Find beginning of next word + ptr = in.find_first_not_of(' ', ptr); + if (ptr == std::string::npos) + break; + // Find end of next word + size_t endword = in.find_first_of(' ', ptr); + if (endword == std::string::npos) + endword = in.size(); + // Add newline and indentation if this wraps over the allowed width + if (col > 0) + { + if ((col + endword - ptr) > width) + { + out << '\n'; + for(size_t i=0; i Date: Tue, 10 Jun 2014 16:02:46 +0200 Subject: [PATCH 3/4] Add 'about' information to `-version` output Adds a copyright and attribution message to the `-version` output (the same as shown in the About dialog in the GUI). Move the message to a function LicenseInfo in init.cpp. --- src/bitcoind.cpp | 6 +++- src/init.cpp | 13 ++++++- src/init.h | 3 ++ src/qt/forms/aboutdialog.ui | 70 +++---------------------------------- src/qt/utilitydialog.cpp | 20 +++++++---- 5 files changed, 38 insertions(+), 74 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 99dc9d726d..b7d8ee7f90 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -87,7 +87,11 @@ bool AppInit(int argc, char* argv[]) { std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n"; - if (!mapArgs.count("-version")) + if (mapArgs.count("-version")) + { + strUsage += LicenseInfo(); + } + else { strUsage += "\n" + _("Usage:") + "\n" + " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n" + diff --git a/src/init.cpp b/src/init.cpp index 528c3df064..39453da9c8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -195,7 +195,6 @@ bool static Bind(const CService &addr, unsigned int flags) { return true; } -// Core-specific options shared between UI, daemon and RPC client std::string HelpMessage(HelpMessageMode hmm) { string strUsage = _("Options:") + "\n"; @@ -330,6 +329,18 @@ std::string HelpMessage(HelpMessageMode hmm) return strUsage; } +std::string LicenseInfo() +{ + return FormatParagraph(strprintf(_("Copyright (C) 2009-%i The Bitcoin Core Developers"), COPYRIGHT_YEAR)) + "\n" + + "\n" + + FormatParagraph(_("This is experimental software.")) + "\n" + + "\n" + + FormatParagraph(_("Distributed under the MIT/X11 software license, see the accompanying file COPYING or .")) + "\n" + + "\n" + + FormatParagraph(_("This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit and cryptographic software written by Eric Young and UPnP software written by Thomas Bernard.")) + + "\n"; +} + struct CImportingNow { CImportingNow() { diff --git a/src/init.h b/src/init.h index 4a967bea37..52daa47616 100644 --- a/src/init.h +++ b/src/init.h @@ -28,6 +28,9 @@ enum HelpMessageMode HMM_BITCOIN_QT }; +/** Help for options shared between UI and daemon (for -help) */ std::string HelpMessage(HelpMessageMode mode); +/** Returns licensing information (for -version) */ +std::string LicenseInfo(); #endif diff --git a/src/qt/forms/aboutdialog.ui b/src/qt/forms/aboutdialog.ui index fec63f737a..51dabf2c30 100644 --- a/src/qt/forms/aboutdialog.ui +++ b/src/qt/forms/aboutdialog.ui @@ -43,76 +43,14 @@ - - - - - IBeamCursor - - - <b>Bitcoin Core</b> version - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - IBeamCursor - - - 0.3.666-beta - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + IBeamCursor - Copyright &copy; 2009-YYYY The Bitcoin Core developers - - - Qt::RichText - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - IBeamCursor - - - -This is experimental software. - -Distributed under the MIT/X11 software license, see the accompanying file COPYING or <a href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a>. - -This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (<a href="https://www.openssl.org/">https://www.openssl.org/</a>) and cryptographic software written by Eric Young (<a href="mailto:eay@cryptsoft.com">eay@cryptsoft.com</a>) and UPnP software written by Thomas Bernard. + +(placeholder for version message) + Qt::RichText diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index 435c6a4368..a34ebd3a37 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -16,6 +16,7 @@ #include "util.h" #include +#include #include /** "About" dialog box */ @@ -24,16 +25,13 @@ AboutDialog::AboutDialog(QWidget *parent) : ui(new Ui::AboutDialog) { ui->setupUi(this); - - // Set current copyright year - ui->copyrightLabel->setText(tr("Copyright") + QString(" © 2009-%1 ").arg(COPYRIGHT_YEAR) + tr("The Bitcoin Core developers")); } void AboutDialog::setModel(ClientModel *model) { if(model) { - QString version = model->formatFullVersion(); + QString version = tr("Bitcoin Core") + " " + tr("version") + " " + model->formatFullVersion(); /* On x86 add a bit specifier to the version so that users can distinguish between * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious. */ @@ -42,7 +40,17 @@ void AboutDialog::setModel(ClientModel *model) #elif defined(__i386__ ) version += " " + tr("(%1-bit)").arg(32); #endif - ui->versionLabel->setText(version); + + /// HTML-format the license message from the core + QString licenseInfo = QString::fromStdString(LicenseInfo()); + // Make URLs clickable + QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); + uri.setMinimal(true); // use non-greedy matching + licenseInfo = licenseInfo.replace(uri, "\\1"); + // Replace newlines with HTML breaks + licenseInfo = licenseInfo.replace("\n\n", "

"); + + ui->versionLabel->setText(version + "

" + licenseInfo); } } @@ -81,7 +89,7 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool versionOnly) : // Set help message text if(versionOnly) - ui->helpMessageLabel->setText(version); + ui->helpMessageLabel->setText(version + "\n" + QString::fromStdString(LicenseInfo())); else ui->helpMessageLabel->setText(version + "\n" + header + "\n" + coreOptions + "\n" + uiOptions); } From 5c97aae6da813ce4873651b31f75b26ea6f1352f Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 11 Jun 2014 21:44:47 +0200 Subject: [PATCH 4/4] qt: Unify AboutDialog and HelpMessageDialog They share so much code and functionality that they may as well be one class. --- src/Makefile.qt.include | 1 - src/qt/bitcoingui.cpp | 3 +- src/qt/forms/aboutdialog.ui | 130 ------------------------------ src/qt/forms/helpmessagedialog.ui | 7 +- src/qt/utilitydialog.cpp | 117 +++++++++++---------------- src/qt/utilitydialog.h | 22 +---- 6 files changed, 53 insertions(+), 227 deletions(-) delete mode 100644 src/qt/forms/aboutdialog.ui diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 72c7486258..647434e1ef 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -76,7 +76,6 @@ QT_TS = \ qt/locale/bitcoin_zh_TW.ts QT_FORMS_UI = \ - qt/forms/aboutdialog.ui \ qt/forms/addressbookpage.ui \ qt/forms/askpassphrasedialog.ui \ qt/forms/coincontroldialog.ui \ diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 847a3ab8f1..30f5ec8939 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -549,8 +549,7 @@ void BitcoinGUI::aboutClicked() if(!clientModel) return; - AboutDialog dlg(this); - dlg.setModel(clientModel); + HelpMessageDialog dlg(this, true); dlg.exec(); } diff --git a/src/qt/forms/aboutdialog.ui b/src/qt/forms/aboutdialog.ui deleted file mode 100644 index 51dabf2c30..0000000000 --- a/src/qt/forms/aboutdialog.ui +++ /dev/null @@ -1,130 +0,0 @@ - - - AboutDialog - - - - 0 - 0 - 593 - 319 - - - - About Bitcoin Core - - - - - - - 0 - 0 - - - - :/images/about - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - IBeamCursor - - - -(placeholder for version message) - - - - Qt::RichText - - - true - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Ok - - - - - - - - - - - - - buttonBox - accepted() - AboutDialog - accept() - - - 20 - 20 - - - 20 - 20 - - - - - buttonBox - rejected() - AboutDialog - reject() - - - 20 - 20 - - - 20 - 20 - - - - - diff --git a/src/qt/forms/helpmessagedialog.ui b/src/qt/forms/helpmessagedialog.ui index f68fea7e64..d8ab27c238 100644 --- a/src/qt/forms/helpmessagedialog.ui +++ b/src/qt/forms/helpmessagedialog.ui @@ -16,7 +16,7 @@
- Bitcoin Core - Command-line options + Bitcoin Core - Command-line options @@ -54,11 +54,6 @@ - - - Terminal - - IBeamCursor diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp index a34ebd3a37..eb647d0170 100644 --- a/src/qt/utilitydialog.cpp +++ b/src/qt/utilitydialog.cpp @@ -4,7 +4,6 @@ #include "utilitydialog.h" -#include "ui_aboutdialog.h" #include "ui_helpmessagedialog.h" #include "bitcoingui.h" @@ -19,53 +18,8 @@ #include #include -/** "About" dialog box */ -AboutDialog::AboutDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::AboutDialog) -{ - ui->setupUi(this); -} - -void AboutDialog::setModel(ClientModel *model) -{ - if(model) - { - QString version = tr("Bitcoin Core") + " " + tr("version") + " " + model->formatFullVersion(); - /* On x86 add a bit specifier to the version so that users can distinguish between - * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious. - */ -#if defined(__x86_64__) - version += " " + tr("(%1-bit)").arg(64); -#elif defined(__i386__ ) - version += " " + tr("(%1-bit)").arg(32); -#endif - - /// HTML-format the license message from the core - QString licenseInfo = QString::fromStdString(LicenseInfo()); - // Make URLs clickable - QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); - uri.setMinimal(true); // use non-greedy matching - licenseInfo = licenseInfo.replace(uri, "\\1"); - // Replace newlines with HTML breaks - licenseInfo = licenseInfo.replace("\n\n", "

"); - - ui->versionLabel->setText(version + "

" + licenseInfo); - } -} - -AboutDialog::~AboutDialog() -{ - delete ui; -} - -void AboutDialog::on_buttonBox_accepted() -{ - close(); -} - -/** "Help message" dialog box */ -HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool versionOnly) : +/** "Help message" or "About" dialog box */ +HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : QDialog(parent), ui(new Ui::HelpMessageDialog) { @@ -73,25 +27,52 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool versionOnly) : GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this); QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); - QString header = tr("Usage:") + "\n" + - " bitcoin-qt [" + tr("command-line options") + "] " + "\n"; + /* On x86 add a bit specifier to the version so that users can distinguish between + * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious. + */ +#if defined(__x86_64__) + version += " " + tr("(%1-bit)").arg(64); +#elif defined(__i386__ ) + version += " " + tr("(%1-bit)").arg(32); +#endif - QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); + if (about) + { + setWindowTitle(tr("About Bitcoin Core")); - QString uiOptions = tr("UI options") + ":\n" + - " -choosedatadir " + tr("Choose data directory on startup (default: 0)") + "\n" + - " -lang= " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" + - " -min " + tr("Start minimized") + "\n" + - " -rootcertificates= " + tr("Set SSL root certificates for payment request (default: -system-)") + "\n" + - " -splash " + tr("Show splash screen on startup (default: 1)"); + /// HTML-format the license message from the core + QString licenseInfo = QString::fromStdString(LicenseInfo()); + QString licenseInfoHTML = licenseInfo; + // Make URLs clickable + QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); + uri.setMinimal(true); // use non-greedy matching + licenseInfoHTML.replace(uri, "\\1"); + // Replace newlines with HTML breaks + licenseInfoHTML.replace("\n\n", "

"); - ui->helpMessageLabel->setFont(GUIUtil::bitcoinAddressFont()); + ui->helpMessageLabel->setTextFormat(Qt::RichText); + ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + text = version + "\n" + licenseInfo; + ui->helpMessageLabel->setText(version + "

" + licenseInfoHTML); + ui->helpMessageLabel->setWordWrap(true); + } else { + setWindowTitle(tr("Command-line options")); + QString header = tr("Usage:") + "\n" + + " bitcoin-qt [" + tr("command-line options") + "] " + "\n"; - // Set help message text - if(versionOnly) - ui->helpMessageLabel->setText(version + "\n" + QString::fromStdString(LicenseInfo())); - else - ui->helpMessageLabel->setText(version + "\n" + header + "\n" + coreOptions + "\n" + uiOptions); + QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); + + QString uiOptions = tr("UI options") + ":\n" + + " -choosedatadir " + tr("Choose data directory on startup (default: 0)") + "\n" + + " -lang= " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" + + " -min " + tr("Start minimized") + "\n" + + " -rootcertificates= " + tr("Set SSL root certificates for payment request (default: -system-)") + "\n" + + " -splash " + tr("Show splash screen on startup (default: 1)"); + + ui->helpMessageLabel->setFont(GUIUtil::bitcoinAddressFont()); + text = version + "\n" + header + "\n" + coreOptions + "\n" + uiOptions; + ui->helpMessageLabel->setText(text); + } } HelpMessageDialog::~HelpMessageDialog() @@ -103,17 +84,17 @@ HelpMessageDialog::~HelpMessageDialog() void HelpMessageDialog::printToConsole() { // On other operating systems, the expected action is to print the message to the console. - fprintf(stdout, "%s\n", qPrintable(ui->helpMessageLabel->text())); + fprintf(stdout, "%s\n", qPrintable(text)); } void HelpMessageDialog::showOrPrint() { #if defined(WIN32) - // On Windows, show a message box, as there is no stderr/stdout in windowed applications - exec(); + // On Windows, show a message box, as there is no stderr/stdout in windowed applications + exec(); #else - // On other operating systems, print help text to console - printToConsole(); + // On other operating systems, print help text to console + printToConsole(); #endif } diff --git a/src/qt/utilitydialog.h b/src/qt/utilitydialog.h index cc23420169..154bb70b8b 100644 --- a/src/qt/utilitydialog.h +++ b/src/qt/utilitydialog.h @@ -12,35 +12,16 @@ class BitcoinGUI; class ClientModel; namespace Ui { - class AboutDialog; class HelpMessageDialog; } -/** "About" dialog box */ -class AboutDialog : public QDialog -{ - Q_OBJECT - -public: - explicit AboutDialog(QWidget *parent); - ~AboutDialog(); - - void setModel(ClientModel *model); - -private: - Ui::AboutDialog *ui; - -private slots: - void on_buttonBox_accepted(); -}; - /** "Help message" dialog box */ class HelpMessageDialog : public QDialog { Q_OBJECT public: - explicit HelpMessageDialog(QWidget *parent, bool versionOnly); + explicit HelpMessageDialog(QWidget *parent, bool about); ~HelpMessageDialog(); void printToConsole(); @@ -48,6 +29,7 @@ public: private: Ui::HelpMessageDialog *ui; + QString text; private slots: void on_okButton_accepted();