PRCYCoin  2.0.0.7rc1
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-2018 The PIVX developers
4 // Copyright (c) 2018-2020 The DAPS Project developers
5 // Distributed under the MIT/X11 software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #include "utilitydialog.h"
9 
10 #include "ui_helpmessagedialog.h"
11 
12 #include "bitcoingui.h"
13 #include "clientmodel.h"
14 #include "guiconstants.h"
15 #include "intro.h"
16 #include "guiutil.h"
17 
18 #include "clientversion.h"
19 #include "init.h"
20 #include "util.h"
21 
22 #include <stdio.h>
23 
24 #include <QCloseEvent>
25 #include <QLabel>
26 #include <QRegExp>
27 #include <QTextTable>
28 #include <QTextCursor>
29 #include <QVBoxLayout>
30 
32 HelpMessageDialog::HelpMessageDialog(QWidget* parent, bool about) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
33  ui(new Ui::HelpMessageDialog)
34 {
35  ui->setupUi(this);
36  GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this);
37 
38  QString version = tr("PRCY") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
39 /* On x86 add a bit specifier to the version so that users can distinguish between
40  * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
41  */
42 #if defined(__x86_64__)
43  version += " " + tr("(%1-bit)").arg(64);
44 #elif defined(__i386__)
45  version += " " + tr("(%1-bit)").arg(32);
46 #endif
47 
48  if (about) {
49  setWindowTitle(tr("About PRCY"));
50 
52  QString licenseInfo = QString::fromStdString(LicenseInfo());
53  QString licenseInfoHTML = licenseInfo;
54 
55  // Make URLs clickable
56  QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
57  uri.setMinimal(true); // use non-greedy matching
58  licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
59  // Replace newlines with HTML breaks
60  licenseInfoHTML.replace("\n\n", "<br><br>");
61 
62  ui->aboutMessage->setTextFormat(Qt::RichText);
63  ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
64  text = version + "\n" + licenseInfo;
65  ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
66  ui->aboutMessage->setWordWrap(true);
67  ui->helpMessage->setVisible(false);
68  } else {
69  setWindowTitle(tr("Command-line options"));
70  QString header = tr("Usage:") + "\n" +
71  " prcycoin-qt [" + tr("command-line options") + "] " + "\n";
72  QTextCursor cursor(ui->helpMessage->document());
73  cursor.insertText(version);
74  cursor.insertBlock();
75  cursor.insertText(header);
76  cursor.insertBlock();
77 
78  std::string strUsage = HelpMessage(HMM_BITCOIN_QT);
79  strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
80  strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR));
81  strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString());
82  strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString());
83  strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN));
84  QString coreOptions = QString::fromStdString(strUsage);
85  text = version + "\n" + header + "\n" + coreOptions;
86 
87  QTextTableFormat tf;
88  tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
89  tf.setCellPadding(2);
90  QVector<QTextLength> widths;
91  widths << QTextLength(QTextLength::PercentageLength, 35);
92  widths << QTextLength(QTextLength::PercentageLength, 65);
93  tf.setColumnWidthConstraints(widths);
94 
95  QTextCharFormat bold;
96  bold.setFontWeight(QFont::Bold);
97 
98  Q_FOREACH (const QString &line, coreOptions.split("\n")) {
99  if (line.startsWith(" -"))
100  {
101  cursor.currentTable()->appendRows(1);
102  cursor.movePosition(QTextCursor::PreviousCell);
103  cursor.movePosition(QTextCursor::NextRow);
104  cursor.insertText(line.trimmed());
105  cursor.movePosition(QTextCursor::NextCell);
106  } else if (line.startsWith(" ")) {
107  cursor.insertText(line.trimmed()+' ');
108  } else if (line.size() > 0) {
109  //Title of a group
110  if (cursor.currentTable())
111  cursor.currentTable()->appendRows(1);
112  cursor.movePosition(QTextCursor::Down);
113  cursor.insertText(line.trimmed(), bold);
114  cursor.insertTable(1, 2, tf);
115  }
116  }
117 
118  ui->helpMessage->moveCursor(QTextCursor::Start);
119  ui->scrollArea->setVisible(false);
120  }
121 }
122 
124 {
125  GUIUtil::saveWindowGeometry("nHelpMessageDialogWindow", this);
126  delete ui;
127 }
128 
130 {
131  // On other operating systems, the expected action is to print the message to the console.
132  fprintf(stdout, "%s\n", qPrintable(text));
133 }
134 
136 {
137 #if defined(WIN32)
138  // On Windows, show a message box, as there is no stderr/stdout in windowed applications
139  exec();
140 #else
141  // On other operating systems, print help text to console
142  printToConsole();
143 #endif
144 }
145 
147 {
148  close();
149 }
150 
151 
153 ShutdownWindow::ShutdownWindow(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f)
154 {
155  QVBoxLayout* layout = new QVBoxLayout();
156  layout->addWidget(new QLabel(
157  tr("PRCY is shutting down...") + "<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;
166 
167  // Show a simple window indicating shutdown status
168  QWidget* shutdownWindow = new ShutdownWindow();
169  // We don't hold a direct pointer to the shutdown window after creation, so use
170  // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
171  shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
172  shutdownWindow->setWindowTitle(window->windowTitle());
173 
174  // Center shutdown window at where main window was
175  const QPoint global = window->mapToGlobal(window->rect().center());
176  shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
177  shutdownWindow->show();
178 }
179 
180 void ShutdownWindow::closeEvent(QCloseEvent* event)
181 {
182  event->ignore();
183 }
HelpMessageDialog::showOrPrint
void showOrPrint()
Definition: utilitydialog.cpp:135
HelpMessageDialog
"Help message" dialog box
Definition: utilitydialog.h:20
HelpMessageGroup
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: util.cpp:282
intro.h
utilitydialog.h
HelpMessageOpt
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
Definition: util.cpp:286
LicenseInfo
std::string LicenseInfo()
Returns licensing information (for -version)
Definition: init.cpp:574
clientversion.h
HelpMessageDialog::HelpMessageDialog
HelpMessageDialog(QWidget *parent, bool about)
"Help message" or "About" dialog box
Definition: utilitydialog.cpp:32
init.h
GUIUtil::saveWindowGeometry
void saveWindowGeometry(const QString &strSetting, QWidget *parent)
Save window size and position.
Definition: guiutil.cpp:691
HelpMessage
std::string HelpMessage(HelpMessageMode mode)
Help for options shared between UI and daemon (for -help)
Definition: init.cpp:354
guiutil.h
ShutdownWindow::ShutdownWindow
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0)
"Shutdown" window
Definition: utilitydialog.cpp:153
HelpMessageDialog::printToConsole
void printToConsole()
Definition: utilitydialog.cpp:129
strprintf
#define strprintf
Definition: tinyformat.h:1056
Ui
Definition: 2faconfirmdialog.h:7
guiconstants.h
HelpMessageDialog::ui
Ui::HelpMessageDialog * ui
Definition: utilitydialog.h:32
bitcoingui.h
HelpMessageDialog::on_okButton_accepted
void on_okButton_accepted()
Definition: utilitydialog.cpp:146
ShutdownWindow::showShutdownWindow
static void showShutdownWindow(BitcoinGUI *window)
Definition: utilitydialog.cpp:162
FormatFullVersion
std::string FormatFullVersion()
Definition: clientversion.cpp:80
HelpMessageDialog::~HelpMessageDialog
~HelpMessageDialog()
Definition: utilitydialog.cpp:123
BitcoinGUI
Bitcoin GUI main class.
Definition: bitcoingui.h:48
ShutdownWindow::closeEvent
void closeEvent(QCloseEvent *event)
Definition: utilitydialog.cpp:180
HMM_BITCOIN_QT
@ HMM_BITCOIN_QT
Definition: init.h:40
clientmodel.h
GUIUtil::restoreWindowGeometry
void restoreWindowGeometry(const QString &strSetting, const QSize &defaultSize, QWidget *parent)
Restore window size and position.
Definition: guiutil.cpp:704
HelpMessageDialog::text
QString text
Definition: utilitydialog.h:33