PIVX Core  5.6.99
P2P Digital Currency
utilitydialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2014-2015 The Dash developers
3 // Copyright (c) 2015-2021 The PIVX Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #if defined(HAVE_CONFIG_H)
8 #include "config/pivx-config.h"
9 #endif
10 
11 #include "utilitydialog.h"
12 
13 #include "ui_helpmessagedialog.h"
14 
15 #include "clientmodel.h"
16 #include "clientversion.h"
17 #include "guiconstants.h"
18 #include "guiutil.h"
19 #include "init.h"
20 #include "intro.h"
21 #include "qtutils.h"
22 #include "util/system.h"
23 
24 #include <stdio.h>
25 
26 #include <QCloseEvent>
27 #include <QLabel>
28 #include <QRegExp>
29 #include <QTextTable>
30 #include <QTextCursor>
31 #include <QVBoxLayout>
32 
34 HelpMessageDialog::HelpMessageDialog(QWidget* parent, bool about) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
35  ui(new Ui::HelpMessageDialog)
36 {
37  ui->setupUi(this);
38  if (parent) this->setStyleSheet(parent->styleSheet());
39  GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this);
40 
41  QString version = QString{PACKAGE_NAME} + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
42 
43  setCssBtnPrimary(ui->pushButtonOk);
44  connect(ui->pushButtonOk, &QPushButton::clicked, this, &HelpMessageDialog::close);
45  if (about) {
46  setWindowTitle(tr("About %1").arg(PACKAGE_NAME));
47 
49  QString licenseInfo = QString::fromStdString(LicenseInfo());
50  QString licenseInfoHTML = licenseInfo;
51 
52  // Make URLs clickable
53  QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
54  uri.setMinimal(true); // use non-greedy matching
55  licenseInfoHTML.replace(uri, "<a style='color: #b088ff;text-decoration:none' href=\"\\1\">\\1</a>");
56  // Replace newlines with HTML breaks
57  licenseInfoHTML.replace("\n\n", "<br><br>");
58 
59  ui->aboutMessage->setTextFormat(Qt::RichText);
60  ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
61  text = version + "\n" + licenseInfo;
62  ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
63  ui->aboutMessage->setWordWrap(true);
64  ui->helpMessage->setVisible(false);
65  } else {
66  setWindowTitle(tr("Command-line options"));
67  QString header = "Usage: pivx-qt [command-line options] \n";
68  QTextCursor cursor(ui->helpMessage->document());
69  cursor.insertText(version);
70  cursor.insertBlock();
71  cursor.insertText(header);
72  cursor.insertBlock();
73 
74  std::string strUsage = HelpMessage(HMM_BITCOIN_QT);
75  strUsage += HelpMessageGroup("UI Options:");
76  strUsage += HelpMessageOpt("-choosedatadir", strprintf("Choose data directory on startup (default: %u)", DEFAULT_CHOOSE_DATADIR));
77  strUsage += HelpMessageOpt("-lang=<lang>", "Set language, for example \"de_DE\" (default: system locale)");
78  strUsage += HelpMessageOpt("-min", "Start minimized");
79  strUsage += HelpMessageOpt("-splash", strprintf("Show splash screen on startup (default: %u)", DEFAULT_SPLASHSCREEN));
80  strUsage += HelpMessageOpt("-hidecharts", strprintf("Hide QT staking charts on startup (default: %u)", false));
81  QString coreOptions = QString::fromStdString(strUsage);
82  text = version + "\n\n" + header + "\n" + coreOptions;
83 
84  QTextTableFormat tf;
85  tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
86  tf.setCellPadding(2);
87  QVector<QTextLength> widths;
88  widths << QTextLength(QTextLength::PercentageLength, 35);
89  widths << QTextLength(QTextLength::PercentageLength, 65);
90  tf.setColumnWidthConstraints(widths);
91 
92  QTextCharFormat bold;
93  bold.setFontWeight(QFont::Bold);
94 
95  for (const QString &line : coreOptions.split("\n")) {
96  if (line.startsWith(" -"))
97  {
98  cursor.currentTable()->appendRows(1);
99  cursor.movePosition(QTextCursor::PreviousCell);
100  cursor.movePosition(QTextCursor::NextRow);
101  cursor.insertText(line.trimmed());
102  cursor.movePosition(QTextCursor::NextCell);
103  } else if (line.startsWith(" ")) {
104  cursor.insertText(line.trimmed()+' ');
105  } else if (line.size() > 0) {
106  //Title of a group
107  if (cursor.currentTable())
108  cursor.currentTable()->appendRows(1);
109  cursor.movePosition(QTextCursor::Down);
110  cursor.insertText(line.trimmed(), bold);
111  cursor.insertTable(1, 2, tf);
112  }
113  }
114 
115  ui->helpMessage->moveCursor(QTextCursor::Start);
116  ui->scrollArea->setVisible(false);
117  }
118 }
119 
121 {
122  GUIUtil::saveWindowGeometry("nHelpMessageDialogWindow", this);
123  delete ui;
124 }
125 
127 {
128  // On other operating systems, the expected action is to print the message to the console.
129  fprintf(stdout, "%s\n", qPrintable(text));
130 }
131 
133 {
134 #if defined(WIN32)
135  // On Windows, show a message box, as there is no stderr/stdout in windowed applications
136  exec();
137 #else
138  // On other operating systems, print help text to console
139  printToConsole();
140 #endif
141 }
142 
143 
145 ShutdownWindow::ShutdownWindow(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f)
146 {
147  QVBoxLayout* layout = new QVBoxLayout();
148  layout->addWidget(new QLabel(
149  tr("%1 is shutting down...").arg(PACKAGE_NAME) + "<br /><br />" +
150  tr("Do not shut down the computer until this window disappears.")));
151  setLayout(layout);
152 }
153 
154 void ShutdownWindow::showShutdownWindow(QMainWindow* window)
155 {
156  if (!window)
157  return;
158 
159  // Show a simple window indicating shutdown status
160  QWidget* shutdownWindow = new ShutdownWindow();
161  // We don't hold a direct pointer to the shutdown window after creation, so use
162  // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
163  shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
164  shutdownWindow->setWindowTitle(window->windowTitle());
165 
166  // Center shutdown window at where main window was
167  const QPoint global = window->mapToGlobal(window->rect().center());
168  shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
169  shutdownWindow->show();
170 }
171 
172 void ShutdownWindow::closeEvent(QCloseEvent* event)
173 {
174  event->ignore();
175 }
"Help message" dialog box
Definition: utilitydialog.h:22
HelpMessageDialog(QWidget *parent, bool about)
"Help message" or "About" dialog box
Ui::HelpMessageDialog * ui
Definition: utilitydialog.h:33
static void showShutdownWindow(QMainWindow *window)
ShutdownWindow(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::Widget)
"Shutdown" window
void closeEvent(QCloseEvent *event)
std::string FormatFullVersion()
std::string HelpMessage(HelpMessageMode mode)
Help for options shared between UI and daemon (for -help)
Definition: init.cpp:381
std::string LicenseInfo()
Returns licensing information (for -version)
Definition: init.cpp:570
@ HMM_BITCOIN_QT
Definition: init.h:55
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
Definition: guiutil.cpp:606
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Definition: guiutil.cpp:613
#define PACKAGE_NAME
Definition: pivx-config.h:366
void setCssBtnPrimary(QPushButton *btn, bool forceUpdate)
Definition: qtutils.cpp:302
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: system.cpp:499
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: system.cpp:503
#define strprintf
Definition: tinyformat.h:1056