Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

utilitydialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 The Bitcoin Core developers
2 // Copyright (c) 2014-2019 The Dash 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/dash-config.h>
8 #endif
9 
10 #include <qt/utilitydialog.h>
11 
12 #include <qt/forms/ui_helpmessagedialog.h>
13 
14 #include <qt/bitcoingui.h>
15 #include <qt/clientmodel.h>
16 #include <qt/guiconstants.h>
17 #include <qt/guiutil.h>
18 #include <qt/intro.h>
19 #include <qt/paymentrequestplus.h>
20 #include <qt/guiutil.h>
21 
22 #include <clientversion.h>
23 #include <init.h>
24 #include <util.h>
25 
26 #include <stdio.h>
27 
28 #include <QCloseEvent>
29 #include <QLabel>
30 #include <QRegExp>
31 #include <QTextTable>
32 #include <QTextCursor>
33 #include <QVBoxLayout>
34 
36 HelpMessageDialog::HelpMessageDialog(QWidget *parent, HelpMode helpMode) :
37  QDialog(parent),
38  ui(new Ui::HelpMessageDialog)
39 {
40  ui->setupUi(this);
41 
43 
44  QString version = tr(PACKAGE_NAME) + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
45  /* On x86 add a bit specifier to the version so that users can distinguish between
46  * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambiguous.
47  */
48 #if defined(__x86_64__)
49  version += " " + tr("(%1-bit)").arg(64);
50 #elif defined(__i386__ )
51  version += " " + tr("(%1-bit)").arg(32);
52 #endif
53 
54  if (helpMode == about)
55  {
56  setWindowTitle(tr("About %1").arg(tr(PACKAGE_NAME)));
57 
59  QString licenseInfo = QString::fromStdString(LicenseInfo());
60  QString licenseInfoHTML = licenseInfo;
61 
62  // Make URLs clickable
63  QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
64  uri.setMinimal(true); // use non-greedy matching
65  licenseInfoHTML.replace(uri, QString("<a style=\"%1\"href=\"\\1\">\\1</a>").arg(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_COMMAND)));
66  // Replace newlines with HTML breaks
67  licenseInfoHTML.replace("\n", "<br>");
68 
69  ui->aboutMessage->setTextFormat(Qt::RichText);
70  ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
71  text = version + "\n" + licenseInfo;
72  ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
73  ui->aboutMessage->setWordWrap(true);
74  ui->helpMessage->setVisible(false);
75  } else if (helpMode == cmdline) {
76  setWindowTitle(tr("Command-line options"));
77  QString header = tr("Usage:") + "\n" +
78  " dash-qt [" + tr("command-line options") + "] " + "\n";
79  QTextCursor cursor(ui->helpMessage->document());
80  cursor.insertText(version);
81  cursor.insertBlock();
82  cursor.insertText(header);
83  cursor.insertBlock();
84 
85  std::string strUsage = HelpMessage(HMM_BITCOIN_QT);
86  const bool showDebug = gArgs.GetBoolArg("-help-debug", false);
87  strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
88  if (showDebug) {
89  strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS));
90  }
91  strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR));
92  strUsage += HelpMessageOpt("-custom-css-dir", "Set a directory which contains custom css files. Those will be used as stylesheets for the UI.");
93  strUsage += HelpMessageOpt("-font-family", tr("Set the font family. Possible values: %1. (default: %2)").arg("SystemDefault, Montserrat").arg(GUIUtil::fontFamilyToString(GUIUtil::getFontFamilyDefault())).toStdString());
94  strUsage += HelpMessageOpt("-font-scale", tr("Set a scale factor which gets applied to the base font size. Possible range %1 (smallest fonts) to %2 (largest fonts). (default: %3)").arg(-100).arg(100).arg(GUIUtil::getFontScaleDefault()).toStdString());
95  strUsage += HelpMessageOpt("-font-weight-bold", tr("Set the font weight for bold texts. Possible range %1 to %2 (default: %3)").arg(0).arg(8).arg(GUIUtil::weightToArg(GUIUtil::getFontWeightBoldDefault())).toStdString());
96  strUsage += HelpMessageOpt("-font-weight-normal", tr("Set the font weight for normal texts. Possible range %1 to %2 (default: %3)").arg(0).arg(8).arg(GUIUtil::weightToArg(GUIUtil::getFontWeightNormalDefault())).toStdString());
97  strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString());
98  strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString());
99  strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString());
100  strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN));
101  strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString());
102  if (showDebug) {
103  strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM));
104  strUsage += HelpMessageOpt("-debug-ui", "Updates the UI's stylesheets in realtime with changes made to the css files in -custom-css-dir and forces some widgets to show up which are usually only visible under certain circumstances. (default: 0)");
105  }
106  QString coreOptions = QString::fromStdString(strUsage);
107  text = version + "\n" + header + "\n" + coreOptions;
108 
109  QTextTableFormat tf;
110  tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
111  tf.setCellPadding(2);
112  QVector<QTextLength> widths;
113  widths << QTextLength(QTextLength::PercentageLength, 35);
114  widths << QTextLength(QTextLength::PercentageLength, 65);
115  tf.setColumnWidthConstraints(widths);
116 
117  QTextCharFormat bold;
118  bold.setFontWeight(QFont::Bold);
119 
120  for (const QString &line : coreOptions.split("\n")) {
121  if (line.startsWith(" -"))
122  {
123  cursor.currentTable()->appendRows(1);
124  cursor.movePosition(QTextCursor::PreviousCell);
125  cursor.movePosition(QTextCursor::NextRow);
126  cursor.insertText(line.trimmed());
127  cursor.movePosition(QTextCursor::NextCell);
128  } else if (line.startsWith(" ")) {
129  cursor.insertText(line.trimmed()+' ');
130  } else if (line.size() > 0) {
131  //Title of a group
132  if (cursor.currentTable())
133  cursor.currentTable()->appendRows(1);
134  cursor.movePosition(QTextCursor::Down);
135  cursor.insertText(line.trimmed(), bold);
136  cursor.insertTable(1, 2, tf);
137  }
138  }
139 
140  ui->helpMessage->moveCursor(QTextCursor::Start);
141  ui->scrollArea->setVisible(false);
142  } else if (helpMode == pshelp) {
143  setWindowTitle(tr("PrivateSend information"));
144 
145  ui->aboutMessage->setTextFormat(Qt::RichText);
146  ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
147  ui->aboutMessage->setText(tr("\
148 <h3>PrivateSend Basics</h3> \
149 PrivateSend gives you true financial privacy by obscuring the origins of your funds. \
150 All the Dash in your wallet is comprised of different \"inputs\" which you can think of as separate, discrete coins.<br> \
151 PrivateSend uses an innovative process to mix your inputs with the inputs of two or more other people, without having your coins ever leave your wallet. \
152 You retain control of your money at all times.<hr> \
153 <b>The PrivateSend process works like this:</b>\
154 <ol type=\"1\"> \
155 <li>PrivateSend begins by breaking your transaction inputs down into standard denominations. \
156 These denominations are 0.001 DASH, 0.01 DASH, 0.1 DASH, 1 DASH and 10 DASH -- sort of like the paper money you use every day.</li> \
157 <li>Your wallet then sends requests to specially configured software nodes on the network, called \"masternodes.\" \
158 These masternodes are informed then that you are interested in mixing a certain denomination. \
159 No identifiable information is sent to the masternodes, so they never know \"who\" you are.</li> \
160 <li>When two or more other people send similar messages, indicating that they wish to mix the same denomination, a mixing session begins. \
161 The masternode mixes up the inputs and instructs all three users' wallets to pay the now-transformed input back to themselves. \
162 Your wallet pays that denomination directly to itself, but in a different address (called a change address).</li> \
163 <li>In order to fully obscure your funds, your wallet must repeat this process a number of times with each denomination. \
164 Each time the process is completed, it's called a \"round.\" Each round of PrivateSend makes it exponentially more difficult to determine where your funds originated.</li> \
165 <li>This mixing process happens in the background without any intervention on your part. When you wish to make a transaction, \
166 your funds will already be mixed. No additional waiting is required.</li> \
167 </ol> <hr>\
168 <b>IMPORTANT:</b> Your wallet only contains 1000 of these \"change addresses.\" Every time a mixing event happens, up to 9 of your addresses are used up. \
169 This means those 1000 addresses last for about 100 mixing events. When 900 of them are used, your wallet must create more addresses. \
170 It can only do this, however, if you have automatic backups enabled.<br> \
171 Consequently, users who have backups disabled will also have PrivateSend disabled. <hr>\
172 For more information, see the <a style=\"%1\" href=\"https://docs.dash.org/en/stable/wallets/dashcore/privatesend-instantsend.html\">PrivateSend documentation</a>."
174  ui->aboutMessage->setWordWrap(true);
175  ui->helpMessage->setVisible(false);
176  }
177 }
178 
180 {
181  delete ui;
182 }
183 
185 {
186  // On other operating systems, the expected action is to print the message to the console.
187  fprintf(stdout, "%s\n", qPrintable(text));
188 }
189 
191 {
192 #if defined(WIN32)
193  // On Windows, show a message box, as there is no stderr/stdout in windowed applications
194  exec();
195 #else
196  // On other operating systems, print help text to console
197  printToConsole();
198 #endif
199 }
200 
202 {
203  close();
204 }
205 
206 
208 ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
209  QWidget(parent, f)
210 {
211  setObjectName("ShutdownWindow");
212 
214 
215  QVBoxLayout *layout = new QVBoxLayout();
216  layout->addWidget(new QLabel(
217  tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "<br /><br />" +
218  tr("Do not shut down the computer until this window disappears.")));
219  setLayout(layout);
220 
222 }
223 
225 {
226  if (!window)
227  return nullptr;
228 
229  // Show a simple window indicating shutdown status
230  QWidget *shutdownWindow = new ShutdownWindow();
231  shutdownWindow->setWindowTitle(window->windowTitle());
232 
233  // Center shutdown window at where main window was
234  const QPoint global = window->mapToGlobal(window->rect().center());
235  shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
236  shutdownWindow->show();
237  return shutdownWindow;
238 }
239 
240 void ShutdownWindow::closeEvent(QCloseEvent *event)
241 {
242  event->ignore();
243 }
static const bool DEFAULT_CHOOSE_DATADIR
Definition: intro.h:12
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:884
FontFamily getFontFamilyDefault()
set/get font family: GUIUtil::fontFamily
Definition: guiutil.cpp:1303
int weightToArg(const QFont::Weight weight)
Convert QFont::Weight to an arg value (0-8)
Definition: guiutil.cpp:1334
#define strprintf
Definition: tinyformat.h:1066
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0)
"Shutdown" window
QFont::Weight getFontWeightNormalDefault()
set/get normal font weight: GUIUtil::fontWeightNormal
Definition: guiutil.cpp:1351
static const bool DEFAULT_SELFSIGNED_ROOTCERTS
QFont::Weight getFontWeightBoldDefault()
set/get bold font weight: GUIUtil::fontWeightBold
Definition: guiutil.cpp:1372
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: util.cpp:824
Bitcoin GUI main class.
Definition: bitcoingui.h:49
std::string LicenseInfo()
Returns licensing information (for -version)
Definition: init.cpp:669
void closeEvent(QCloseEvent *event)
static const bool DEFAULT_SPLASHSCREEN
Definition: guiconstants.h:21
std::string HelpMessage(HelpMessageMode mode)
Help for options shared between UI and daemon (for -help)
Definition: init.cpp:449
void updateFonts()
Update the font of all widgets where a custom font has been set with GUIUtil::setFont.
Definition: guiutil.cpp:1563
QString fontFamilyToString(FontFamily family)
Definition: guiutil.cpp:1284
std::string FormatFullVersion()
Ui::HelpMessageDialog * ui
Definition: utilitydialog.h:36
ArgsManager gArgs
Definition: util.cpp:108
int getFontScaleDefault()
set/get font scale: GUIUtil::fontScale
Definition: guiutil.cpp:1388
QString getThemedStyleQString(ThemedStyle style)
Helper to get css style strings which are injected into rich text through qt.
Definition: guiutil.cpp:210
static QWidget * showShutdownWindow(BitcoinGUI *window)
HelpMessageDialog(QWidget *parent, HelpMode helpMode)
"Help message" or "About" dialog box
"Help message" dialog box
Definition: utilitydialog.h:18
void loadStyleSheet(QWidget *widget, bool fForceUpdate)
Updates the widgets stylesheet and adds it to the list of ui debug elements.
Definition: guiutil.cpp:1155
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:55
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
Definition: util.cpp:880
Released under the MIT license