BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
utilitydialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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)
7 #endif
8 
9 #include <qt/utilitydialog.h>
10 
11 #include <qt/forms/ui_helpmessagedialog.h>
12 
13 #include <qt/bitcoingui.h>
14 #include <qt/clientmodel.h>
15 #include <qt/guiconstants.h>
16 #include <qt/intro.h>
17 #ifdef ENABLE_BIP70
18 #include <qt/paymentrequestplus.h>
19 #endif
20 #include <qt/guiutil.h>
21 
22 #include <clientversion.h>
23 #include <init.h>
24 #include <interfaces/node.h>
25 #include <util.h>
26 
27 #include <stdio.h>
28 
29 #include <QCloseEvent>
30 #include <QLabel>
31 #include <QRegExp>
32 #include <QTextTable>
33 #include <QTextCursor>
34 #include <QVBoxLayout>
35 
37 HelpMessageDialog::HelpMessageDialog(interfaces::Node& node, QWidget *parent, bool about) :
38  QDialog(parent),
39  ui(new Ui::HelpMessageDialog)
40 {
41  ui->setupUi(this);
42 
43  QString version = tr(PACKAGE_NAME) + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
44  /* On x86 add a bit specifier to the version so that users can distinguish between
45  * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambiguous.
46  */
47 #if defined(__x86_64__)
48  version += " " + tr("(%1-bit)").arg(64);
49 #elif defined(__i386__ )
50  version += " " + tr("(%1-bit)").arg(32);
51 #endif
52 
53  if (about)
54  {
55  setWindowTitle(tr("About %1").arg(tr(PACKAGE_NAME)));
56 
58  QString licenseInfo = QString::fromStdString(LicenseInfo());
59  QString licenseInfoHTML = licenseInfo;
60  // Make URLs clickable
61  QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
62  uri.setMinimal(true); // use non-greedy matching
63  licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
64  // Replace newlines with HTML breaks
65  licenseInfoHTML.replace("\n", "<br>");
66 
67  ui->aboutMessage->setTextFormat(Qt::RichText);
68  ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
69  text = version + "\n" + licenseInfo;
70  ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
71  ui->aboutMessage->setWordWrap(true);
72  ui->helpMessage->setVisible(false);
73  } else {
74  setWindowTitle(tr("Command-line options"));
75  QString header = "Usage: bsha3-qt [command-line options] \n";
76  QTextCursor cursor(ui->helpMessage->document());
77  cursor.insertText(version);
78  cursor.insertBlock();
79  cursor.insertText(header);
80  cursor.insertBlock();
81 
82  std::string strUsage = gArgs.GetHelpMessage();
83  QString coreOptions = QString::fromStdString(strUsage);
84  text = version + "\n\n" + header + "\n" + coreOptions;
85 
86  QTextTableFormat tf;
87  tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
88  tf.setCellPadding(2);
89  QVector<QTextLength> widths;
90  widths << QTextLength(QTextLength::PercentageLength, 35);
91  widths << QTextLength(QTextLength::PercentageLength, 65);
92  tf.setColumnWidthConstraints(widths);
93 
94  QTextCharFormat bold;
95  bold.setFontWeight(QFont::Bold);
96 
97  for (const QString &line : coreOptions.split("\n")) {
98  if (line.startsWith(" -"))
99  {
100  cursor.currentTable()->appendRows(1);
101  cursor.movePosition(QTextCursor::PreviousCell);
102  cursor.movePosition(QTextCursor::NextRow);
103  cursor.insertText(line.trimmed());
104  cursor.movePosition(QTextCursor::NextCell);
105  } else if (line.startsWith(" ")) {
106  cursor.insertText(line.trimmed()+' ');
107  } else if (line.size() > 0) {
108  //Title of a group
109  if (cursor.currentTable())
110  cursor.currentTable()->appendRows(1);
111  cursor.movePosition(QTextCursor::Down);
112  cursor.insertText(line.trimmed(), bold);
113  cursor.insertTable(1, 2, tf);
114  }
115  }
116 
117  ui->helpMessage->moveCursor(QTextCursor::Start);
118  ui->scrollArea->setVisible(false);
119  ui->aboutLogo->setVisible(false);
120  }
121 }
122 
124 {
125  delete ui;
126 }
127 
129 {
130  // On other operating systems, the expected action is to print the message to the console.
131  fprintf(stdout, "%s\n", qPrintable(text));
132 }
133 
135 {
136 #if defined(WIN32)
137  // On Windows, show a message box, as there is no stderr/stdout in windowed applications
138  exec();
139 #else
140  // On other operating systems, print help text to console
141  printToConsole();
142 #endif
143 }
144 
146 {
147  close();
148 }
149 
150 
152 ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
153  QWidget(parent, f)
154 {
155  QVBoxLayout *layout = new QVBoxLayout();
156  layout->addWidget(new QLabel(
157  tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "<br /><br />" +
158  tr("Do not shut down the computer until this window disappears.")));
159  setLayout(layout);
160 }
161 
163 {
164  if (!window)
165  return nullptr;
166 
167  // Show a simple window indicating shutdown status
168  QWidget *shutdownWindow = new ShutdownWindow();
169  shutdownWindow->setWindowTitle(window->windowTitle());
170 
171  // Center shutdown window at where main window was
172  const QPoint global = window->mapToGlobal(window->rect().center());
173  shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
174  shutdownWindow->show();
175  return shutdownWindow;
176 }
177 
178 void ShutdownWindow::closeEvent(QCloseEvent *event)
179 {
180  event->ignore();
181 }
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0)
"Shutdown" window
#define PACKAGE_NAME
Bitcoin GUI main class.
Definition: bitcoingui.h:59
std::string LicenseInfo()
Returns licensing information (for -version)
Definition: init.cpp:509
void closeEvent(QCloseEvent *event)
std::string GetHelpMessage() const
Get the help string.
Definition: util.cpp:593
std::string FormatFullVersion()
Ui::HelpMessageDialog * ui
Definition: utilitydialog.h:34
ArgsManager gArgs
Definition: util.cpp:88
static QWidget * showShutdownWindow(BitcoinGUI *window)
"Help message" dialog box
Definition: utilitydialog.h:22
HelpMessageDialog(interfaces::Node &node, QWidget *parent, bool about)
"Help message" or "About" dialog box
Top-level interface for a bitcoin node (bsha3d process).
Definition: node.h:35