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