diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-06-11 21:44:47 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-06-12 16:11:56 +0200 |
commit | 5c97aae6da813ce4873651b31f75b26ea6f1352f (patch) | |
tree | 49a097ba2ee9219b1b1ae5b0bfb8f48897a4dbfe /src/qt/utilitydialog.cpp | |
parent | 45615af26fe374fa996c116984a05f0a632a0e79 (diff) |
qt: Unify AboutDialog and HelpMessageDialog
They share so much code and functionality that they may as well
be one class.
Diffstat (limited to 'src/qt/utilitydialog.cpp')
-rw-r--r-- | src/qt/utilitydialog.cpp | 109 |
1 files changed, 45 insertions, 64 deletions
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,81 +18,63 @@ #include <QRegExp> #include <QVBoxLayout> -/** "About" dialog box */ -AboutDialog::AboutDialog(QWidget *parent) : +/** "Help message" or "About" dialog box */ +HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : QDialog(parent), - ui(new Ui::AboutDialog) + ui(new Ui::HelpMessageDialog) { ui->setupUi(this); -} + GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), 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. - */ + QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(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); + version += " " + tr("(%1-bit)").arg(64); #elif defined(__i386__ ) - version += " " + tr("(%1-bit)").arg(32); + version += " " + tr("(%1-bit)").arg(32); #endif + if (about) + { + setWindowTitle(tr("About Bitcoin Core")); + /// 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 - licenseInfo = licenseInfo.replace(uri, "<a href=\"\\1\">\\1</a>"); + licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>"); // Replace newlines with HTML breaks - licenseInfo = licenseInfo.replace("\n\n", "<br><br>"); - - ui->versionLabel->setText(version + "<br><br>" + licenseInfo); + licenseInfoHTML.replace("\n\n", "<br><br>"); + + ui->helpMessageLabel->setTextFormat(Qt::RichText); + ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + text = version + "\n" + licenseInfo; + ui->helpMessageLabel->setText(version + "<br><br>" + licenseInfoHTML); + ui->helpMessageLabel->setWordWrap(true); + } else { + setWindowTitle(tr("Command-line options")); + QString header = tr("Usage:") + "\n" + + " bitcoin-qt [" + tr("command-line options") + "] " + "\n"; + + 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=<lang> " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" + + " -min " + tr("Start minimized") + "\n" + + " -rootcertificates=<file> " + 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); } } -AboutDialog::~AboutDialog() -{ - delete ui; -} - -void AboutDialog::on_buttonBox_accepted() -{ - close(); -} - -/** "Help message" dialog box */ -HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool versionOnly) : - QDialog(parent), - ui(new Ui::HelpMessageDialog) -{ - ui->setupUi(this); - 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"; - - 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=<lang> " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" + - " -min " + tr("Start minimized") + "\n" + - " -rootcertificates=<file> " + 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()); - - // 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); -} - HelpMessageDialog::~HelpMessageDialog() { GUIUtil::saveWindowGeometry("nHelpMessageDialogWindow", this); @@ -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 } |