Bitcoin ABC  0.24.10
P2P Digital Currency
utilitydialog.cpp
Go to the documentation of this file.
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.
4 
5 #if defined(HAVE_CONFIG_H)
6 #include <config/bitcoin-config.h>
7 #endif
8 
9 #include <qt/guiutil.h>
10 #include <qt/utilitydialog.h>
11 
12 #include <clientversion.h>
13 #include <init.h>
14 #include <network.h>
15 #include <qt/forms/ui_helpmessagedialog.h>
16 #ifdef ENABLE_BIP70
17 #include <qt/paymentrequestplus.h>
18 #endif
19 #include <util/strencodings.h>
20 #include <util/system.h>
21 
22 #include <QCloseEvent>
23 #include <QLabel>
24 #include <QMainWindow>
25 #include <QRegExp>
26 #include <QTextCursor>
27 #include <QTextTable>
28 #include <QVBoxLayout>
29 
30 #include <cstdio>
31 
33 HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about)
34  : QDialog(parent), ui(new Ui::HelpMessageDialog) {
35  ui->setupUi(this);
36 
37  QString version = QString{PACKAGE_NAME} + " " + tr("version") + " " +
38  QString::fromStdString(FormatFullVersion());
39 
40  if (about) {
41  setWindowTitle(tr("About %1").arg(PACKAGE_NAME));
42 
43  std::string licenseInfo = LicenseInfo();
45  QString licenseInfoHTML = QString::fromStdString(LicenseInfo());
46  // Make URLs clickable
47  QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
48  uri.setMinimal(true); // use non-greedy matching
49  licenseInfoHTML.replace(uri, "<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" +
56  QString::fromStdString(FormatParagraph(licenseInfo));
57  ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
58  ui->aboutMessage->setWordWrap(true);
59  ui->helpMessage->setVisible(false);
60  } else {
61  setWindowTitle(tr("Command-line options"));
62  QString header =
63  "Usage: bitcoin-qt [command-line options] \n";
64  QTextCursor cursor(ui->helpMessage->document());
65  cursor.insertText(version);
66  cursor.insertBlock();
67  cursor.insertText(header);
68  cursor.insertBlock();
69 
70  std::string strUsage = gArgs.GetHelpMessage();
71  QString coreOptions = QString::fromStdString(strUsage);
72  text = version + "\n\n" + header + "\n" + coreOptions;
73 
74  QTextTableFormat tf;
75  tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
76  tf.setCellPadding(2);
77  QVector<QTextLength> widths;
78  widths << QTextLength(QTextLength::PercentageLength, 35);
79  widths << QTextLength(QTextLength::PercentageLength, 65);
80  tf.setColumnWidthConstraints(widths);
81 
82  QTextCharFormat bold;
83  bold.setFontWeight(QFont::Bold);
84 
85  for (const QString &line : coreOptions.split("\n")) {
86  if (line.startsWith(" -")) {
87  cursor.currentTable()->appendRows(1);
88  cursor.movePosition(QTextCursor::PreviousCell);
89  cursor.movePosition(QTextCursor::NextRow);
90  cursor.insertText(line.trimmed());
91  cursor.movePosition(QTextCursor::NextCell);
92  } else if (line.startsWith(" ")) {
93  cursor.insertText(line.trimmed() + ' ');
94  } else if (line.size() > 0) {
95  // Title of a group
96  if (cursor.currentTable()) {
97  cursor.currentTable()->appendRows(1);
98  }
99  cursor.movePosition(QTextCursor::Down);
100  cursor.insertText(line.trimmed(), bold);
101  cursor.insertTable(1, 2, tf);
102  }
103  }
104 
105  ui->helpMessage->moveCursor(QTextCursor::Start);
106  ui->scrollArea->setVisible(false);
107  ui->aboutLogo->setVisible(false);
108  }
109 
111 }
112 
114  delete ui;
115 }
116 
118  // On other operating systems, the expected action is to print the message
119  // to the console.
120  tfm::format(std::cout, "%s\n", qPrintable(text));
121 }
122 
124 #if defined(WIN32)
125  // On Windows, show a message box, as there is no stderr/stdout in windowed
126  // applications
127  exec();
128 #else
129  // On other operating systems, print help text to console
130  printToConsole();
131 #endif
132 }
133 
135  close();
136 }
137 
139 ShutdownWindow::ShutdownWindow(QWidget *parent) : QWidget(parent) {
140  QVBoxLayout *layout = new QVBoxLayout();
141  layout->addWidget(new QLabel(
142  tr("%1 is shutting down...").arg(PACKAGE_NAME) + "<br /><br />" +
143  tr("Do not shut down the computer until this window disappears.")));
144  setLayout(layout);
145 
147 }
148 
149 QWidget *ShutdownWindow::showShutdownWindow(QMainWindow *window) {
150  assert(window != nullptr);
151 
152  // Show a simple window indicating shutdown status
153  QWidget *shutdownWindow = new ShutdownWindow();
154  shutdownWindow->setWindowTitle(window->windowTitle());
155 
156  // Center shutdown window at where main window was
157  const QPoint global = window->mapToGlobal(window->rect().center());
158  shutdownWindow->move(global.x() - shutdownWindow->width() / 2,
159  global.y() - shutdownWindow->height() / 2);
160  shutdownWindow->show();
161  return shutdownWindow;
162 }
163 
164 void ShutdownWindow::closeEvent(QCloseEvent *event) {
165  event->ignore();
166 }
tinyformat::format
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1111
HelpMessageDialog::showOrPrint
void showOrPrint()
Definition: utilitydialog.cpp:123
HelpMessageDialog
"Help message" dialog box
Definition: utilitydialog.h:20
ArgsManager::GetHelpMessage
std::string GetHelpMessage() const
Get the help string.
Definition: system.cpp:682
utilitydialog.h
ShutdownWindow::ShutdownWindow
ShutdownWindow(QWidget *parent=nullptr)
"Shutdown" window
Definition: utilitydialog.cpp:139
LicenseInfo
std::string LicenseInfo()
Returns licensing information (for -version)
Definition: init.cpp:1303
clientversion.h
paymentrequestplus.h
ShutdownWindow::closeEvent
void closeEvent(QCloseEvent *event) override
Definition: utilitydialog.cpp:164
strencodings.h
HelpMessageDialog::HelpMessageDialog
HelpMessageDialog(QWidget *parent, bool about)
"Help message" or "About" dialog box
Definition: utilitydialog.cpp:33
init.h
guiutil.h
system.h
HelpMessageDialog::printToConsole
void printToConsole()
Definition: utilitydialog.cpp:117
Ui
Definition: addressbookpage.h:14
HelpMessageDialog::ui
Ui::HelpMessageDialog * ui
Definition: utilitydialog.h:31
gArgs
ArgsManager gArgs
Definition: system.cpp:76
ShutdownWindow::showShutdownWindow
static QWidget * showShutdownWindow(QMainWindow *window)
Definition: utilitydialog.cpp:149
network.h
HelpMessageDialog::on_okButton_accepted
void on_okButton_accepted()
Definition: utilitydialog.cpp:134
GUIUtil::handleCloseWindowShortcut
void handleCloseWindowShortcut(QWidget *w)
Definition: guiutil.cpp:398
FormatFullVersion
std::string FormatFullVersion()
Definition: clientversion.cpp:58
HelpMessageDialog::~HelpMessageDialog
~HelpMessageDialog()
Definition: utilitydialog.cpp:113
FormatParagraph
std::string FormatParagraph(const std::string &in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
Definition: strencodings.cpp:429
HelpMessageDialog::text
QString text
Definition: utilitydialog.h:32