[test] Replace check_output with low level version
[bitcoinplatinum.git] / src / qt / utilitydialog.cpp
blob5d8c23d13c11f64805f8681e940ca09e73427777
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #if defined(HAVE_CONFIG_H)
6 #include "config/bitcoin-config.h"
7 #endif
9 #include "utilitydialog.h"
11 #include "ui_helpmessagedialog.h"
13 #include "bitcoingui.h"
14 #include "clientmodel.h"
15 #include "guiconstants.h"
16 #include "intro.h"
17 #include "paymentrequestplus.h"
18 #include "guiutil.h"
20 #include "clientversion.h"
21 #include "init.h"
22 #include "util.h"
24 #include <stdio.h>
26 #include <QCloseEvent>
27 #include <QLabel>
28 #include <QRegExp>
29 #include <QTextTable>
30 #include <QTextCursor>
31 #include <QVBoxLayout>
33 /** "Help message" or "About" dialog box */
34 HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
35 QDialog(parent),
36 ui(new Ui::HelpMessageDialog)
38 ui->setupUi(this);
40 QString version = tr(PACKAGE_NAME) + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
41 /* On x86 add a bit specifier to the version so that users can distinguish between
42 * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambiguous.
44 #if defined(__x86_64__)
45 version += " " + tr("(%1-bit)").arg(64);
46 #elif defined(__i386__ )
47 version += " " + tr("(%1-bit)").arg(32);
48 #endif
50 if (about)
52 setWindowTitle(tr("About %1").arg(tr(PACKAGE_NAME)));
54 /// HTML-format the license message from the core
55 QString licenseInfo = QString::fromStdString(LicenseInfo());
56 QString licenseInfoHTML = licenseInfo;
57 // Make URLs clickable
58 QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
59 uri.setMinimal(true); // use non-greedy matching
60 licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
61 // Replace newlines with HTML breaks
62 licenseInfoHTML.replace("\n", "<br>");
64 ui->aboutMessage->setTextFormat(Qt::RichText);
65 ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
66 text = version + "\n" + licenseInfo;
67 ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
68 ui->aboutMessage->setWordWrap(true);
69 ui->helpMessage->setVisible(false);
70 } else {
71 setWindowTitle(tr("Command-line options"));
72 QString header = tr("Usage:") + "\n" +
73 " bitcoin-qt [" + tr("command-line options") + "] " + "\n";
74 QTextCursor cursor(ui->helpMessage->document());
75 cursor.insertText(version);
76 cursor.insertBlock();
77 cursor.insertText(header);
78 cursor.insertBlock();
80 std::string strUsage = HelpMessage(HMM_BITCOIN_QT);
81 const bool showDebug = gArgs.GetBoolArg("-help-debug", false);
82 strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
83 if (showDebug) {
84 strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS));
86 strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR));
87 strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString());
88 strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString());
89 strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString());
90 strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN));
91 strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString());
92 if (showDebug) {
93 strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM));
95 QString coreOptions = QString::fromStdString(strUsage);
96 text = version + "\n" + header + "\n" + coreOptions;
98 QTextTableFormat tf;
99 tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
100 tf.setCellPadding(2);
101 QVector<QTextLength> widths;
102 widths << QTextLength(QTextLength::PercentageLength, 35);
103 widths << QTextLength(QTextLength::PercentageLength, 65);
104 tf.setColumnWidthConstraints(widths);
106 QTextCharFormat bold;
107 bold.setFontWeight(QFont::Bold);
109 for (const QString &line : coreOptions.split("\n")) {
110 if (line.startsWith(" -"))
112 cursor.currentTable()->appendRows(1);
113 cursor.movePosition(QTextCursor::PreviousCell);
114 cursor.movePosition(QTextCursor::NextRow);
115 cursor.insertText(line.trimmed());
116 cursor.movePosition(QTextCursor::NextCell);
117 } else if (line.startsWith(" ")) {
118 cursor.insertText(line.trimmed()+' ');
119 } else if (line.size() > 0) {
120 //Title of a group
121 if (cursor.currentTable())
122 cursor.currentTable()->appendRows(1);
123 cursor.movePosition(QTextCursor::Down);
124 cursor.insertText(line.trimmed(), bold);
125 cursor.insertTable(1, 2, tf);
129 ui->helpMessage->moveCursor(QTextCursor::Start);
130 ui->scrollArea->setVisible(false);
131 ui->aboutLogo->setVisible(false);
135 HelpMessageDialog::~HelpMessageDialog()
137 delete ui;
140 void HelpMessageDialog::printToConsole()
142 // On other operating systems, the expected action is to print the message to the console.
143 fprintf(stdout, "%s\n", qPrintable(text));
146 void HelpMessageDialog::showOrPrint()
148 #if defined(WIN32)
149 // On Windows, show a message box, as there is no stderr/stdout in windowed applications
150 exec();
151 #else
152 // On other operating systems, print help text to console
153 printToConsole();
154 #endif
157 void HelpMessageDialog::on_okButton_accepted()
159 close();
163 /** "Shutdown" window */
164 ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
165 QWidget(parent, f)
167 QVBoxLayout *layout = new QVBoxLayout();
168 layout->addWidget(new QLabel(
169 tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "<br /><br />" +
170 tr("Do not shut down the computer until this window disappears.")));
171 setLayout(layout);
174 QWidget *ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
176 if (!window)
177 return nullptr;
179 // Show a simple window indicating shutdown status
180 QWidget *shutdownWindow = new ShutdownWindow();
181 shutdownWindow->setWindowTitle(window->windowTitle());
183 // Center shutdown window at where main window was
184 const QPoint global = window->mapToGlobal(window->rect().center());
185 shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
186 shutdownWindow->show();
187 return shutdownWindow;
190 void ShutdownWindow::closeEvent(QCloseEvent *event)
192 event->ignore();