Raven Core  3.0.0
P2P Digital Currency
utilitydialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #if defined(HAVE_CONFIG_H)
7 #include "config/raven-config.h"
8 #endif
9 
10 #include "utilitydialog.h"
11 
12 #include "ui_helpmessagedialog.h"
13 
14 #include "ravengui.h"
15 #include "clientmodel.h"
16 #include "guiconstants.h"
17 #include "intro.h"
18 #include "paymentrequestplus.h"
19 #include "guiutil.h"
20 
21 #include "clientversion.h"
22 #include "init.h"
23 #include "util.h"
24 
25 #include <stdio.h>
26 
27 #include <QCloseEvent>
28 #include <QLabel>
29 #include <QRegExp>
30 #include <QTextTable>
31 #include <QTextCursor>
32 #include <QVBoxLayout>
33 
35 HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
36  QDialog(parent),
37  ui(new Ui::HelpMessageDialog)
38 {
39  ui->setupUi(this);
40 
41  QString version = tr(PACKAGE_NAME) + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
42  /* On x86 add a bit specifier to the version so that users can distinguish between
43  * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambiguous.
44  */
45 #if defined(__x86_64__)
46  version += " " + tr("(%1-bit)").arg(64);
47 #elif defined(__i386__ )
48  version += " " + tr("(%1-bit)").arg(32);
49 #endif
50 
51  if (about)
52  {
53  setWindowTitle(tr("About %1").arg(tr(PACKAGE_NAME)));
54 
56  QString licenseInfo = QString::fromStdString(LicenseInfo());
57  QString licenseInfoHTML = licenseInfo;
58  // Make URLs clickable
59  QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
60  uri.setMinimal(true); // use non-greedy matching
61  licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
62  // Replace newlines with HTML breaks
63  licenseInfoHTML.replace("\n", "<br>");
64 
65  ui->aboutMessage->setTextFormat(Qt::RichText);
66  ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
67  text = version + "\n" + licenseInfo;
68  ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
69  ui->aboutMessage->setWordWrap(true);
70  ui->helpMessage->setVisible(false);
71  } else {
72  setWindowTitle(tr("Command-line options"));
73  QString header = tr("Usage:") + "\n" +
74  " raven-qt [" + tr("command-line options") + "] " + "\n";
75  QTextCursor cursor(ui->helpMessage->document());
76  cursor.insertText(version);
77  cursor.insertBlock();
78  cursor.insertText(header);
79  cursor.insertBlock();
80 
81  std::string strUsage = HelpMessage(HMM_RAVEN_QT);
82  const bool showDebug = gArgs.GetBoolArg("-help-debug", false);
83  strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
84  if (showDebug) {
85  strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS));
86  }
87  strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR));
88  strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString());
89  strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString());
90  strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString());
91  strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN));
92  strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString());
93  if (showDebug) {
94  strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", RavenGUI::DEFAULT_UIPLATFORM));
95  }
96  QString coreOptions = QString::fromStdString(strUsage);
97  text = version + "\n" + header + "\n" + coreOptions;
98 
99  QTextTableFormat tf;
100  tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
101  tf.setCellPadding(2);
102  QVector<QTextLength> widths;
103  widths << QTextLength(QTextLength::PercentageLength, 35);
104  widths << QTextLength(QTextLength::PercentageLength, 65);
105  tf.setColumnWidthConstraints(widths);
106 
107  QTextCharFormat bold;
108  bold.setFontWeight(QFont::Bold);
109 
110  for (const QString &line : coreOptions.split("\n")) {
111  if (line.startsWith(" -"))
112  {
113  cursor.currentTable()->appendRows(1);
114  cursor.movePosition(QTextCursor::PreviousCell);
115  cursor.movePosition(QTextCursor::NextRow);
116  cursor.insertText(line.trimmed());
117  cursor.movePosition(QTextCursor::NextCell);
118  } else if (line.startsWith(" ")) {
119  cursor.insertText(line.trimmed()+' ');
120  } else if (line.size() > 0) {
121  //Title of a group
122  if (cursor.currentTable())
123  cursor.currentTable()->appendRows(1);
124  cursor.movePosition(QTextCursor::Down);
125  cursor.insertText(line.trimmed(), bold);
126  cursor.insertTable(1, 2, tf);
127  }
128  }
129 
130  ui->helpMessage->moveCursor(QTextCursor::Start);
131  ui->scrollArea->setVisible(false);
132  ui->aboutLogo->setVisible(false);
133  }
134 }
135 
137 {
138  delete ui;
139 }
140 
142 {
143  // On other operating systems, the expected action is to print the message to the console.
144  fprintf(stdout, "%s\n", qPrintable(text));
145 }
146 
148 {
149 #if defined(WIN32)
150  // On Windows, show a message box, as there is no stderr/stdout in windowed applications
151  exec();
152 #else
153  // On other operating systems, print help text to console
154  printToConsole();
155 #endif
156 }
157 
159 {
160  close();
161 }
162 
163 
165 ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
166  QWidget(parent, f)
167 {
168  QVBoxLayout *layout = new QVBoxLayout();
169  layout->addWidget(new QLabel(
170  tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "<br /><br />" +
171  tr("Do not shut down the computer until this window disappears.")));
172  setLayout(layout);
173 }
174 
176 {
177  if (!window)
178  return nullptr;
179 
180  // Show a simple window indicating shutdown status
181  QWidget *shutdownWindow = new ShutdownWindow();
182  shutdownWindow->setWindowTitle(window->windowTitle());
183 
184  // Center shutdown window at where main window was
185  const QPoint global = window->mapToGlobal(window->rect().center());
186  shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
187  shutdownWindow->show();
188  return shutdownWindow;
189 }
190 
191 void ShutdownWindow::closeEvent(QCloseEvent *event)
192 {
193  event->ignore();
194 }
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:511
#define strprintf
Definition: tinyformat.h:1054
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0)
"Shutdown" window
HelpMessageDialog(QWidget *parent, bool about)
"Help message" or "About" dialog box
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: util.cpp:470
#define PACKAGE_NAME
Definition: raven-config.h:350
std::string LicenseInfo()
Returns licensing information (for -version)
Definition: init.cpp:597
void closeEvent(QCloseEvent *event)
std::string HelpMessage(HelpMessageMode mode)
Help for options shared between UI and daemon (for -help)
Definition: init.cpp:391
static QWidget * showShutdownWindow(RavenGUI *window)
static const std::string DEFAULT_UIPLATFORM
Definition: ravengui.h:53
std::string FormatFullVersion()
Ui::HelpMessageDialog * ui
Definition: utilitydialog.h:31
ArgsManager gArgs
Definition: util.cpp:94
Raven GUI main class.
Definition: ravengui.h:47
"Help message" dialog box
Definition: utilitydialog.h:19
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: util.cpp:506