Dash Core  0.12.2.1
P2P Digital Currency
utilitydialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 The Bitcoin Core developers
2 // Copyright (c) 2014-2017 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 #include "utilitydialog.h"
7 
8 #include "ui_helpmessagedialog.h"
9 
10 #include "bitcoingui.h"
11 #include "clientmodel.h"
12 #include "guiconstants.h"
13 #include "intro.h"
14 #include "paymentrequestplus.h"
15 #include "guiutil.h"
16 
17 #include "clientversion.h"
18 #include "init.h"
19 #include "util.h"
20 
21 #include <stdio.h>
22 
23 #include <QCloseEvent>
24 #include <QLabel>
25 #include <QRegExp>
26 #include <QTextTable>
27 #include <QTextCursor>
28 #include <QVBoxLayout>
29 
31 HelpMessageDialog::HelpMessageDialog(QWidget *parent, HelpMode helpMode) :
32  QDialog(parent),
33  ui(new Ui::HelpMessageDialog)
34 {
35  ui->setupUi(this);
36 
37  QString version = tr("Dash Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
38  /* On x86 add a bit specifier to the version so that users can distinguish between
39  * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
40  */
41 #if defined(__x86_64__)
42  version += " " + tr("(%1-bit)").arg(64);
43 #elif defined(__i386__ )
44  version += " " + tr("(%1-bit)").arg(32);
45 #endif
46 
47  if (helpMode == about)
48  {
49  setWindowTitle(tr("About Dash Core"));
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 if (helpMode == cmdline) {
69  setWindowTitle(tr("Command-line options"));
70  QString header = tr("Usage:") + "\n" +
71  " dash-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  const bool showDebug = GetBoolArg("-help-debug", false);
80  strUsage += HelpMessageGroup(tr("UI Options:").toStdString());
81  if (showDebug) {
82  strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS));
83  }
84  strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR));
85  strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString());
86  strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString());
87  strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString());
88  strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN));
89  strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString());
90  if (showDebug) {
91  strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM));
92  }
93  QString coreOptions = QString::fromStdString(strUsage);
94  text = version + "\n" + header + "\n" + coreOptions;
95 
96  QTextTableFormat tf;
97  tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
98  tf.setCellPadding(2);
99  QVector<QTextLength> widths;
100  widths << QTextLength(QTextLength::PercentageLength, 35);
101  widths << QTextLength(QTextLength::PercentageLength, 65);
102  tf.setColumnWidthConstraints(widths);
103 
104  QTextCharFormat bold;
105  bold.setFontWeight(QFont::Bold);
106 
107  Q_FOREACH (const QString &line, coreOptions.split("\n")) {
108  if (line.startsWith(" -"))
109  {
110  cursor.currentTable()->appendRows(1);
111  cursor.movePosition(QTextCursor::PreviousCell);
112  cursor.movePosition(QTextCursor::NextRow);
113  cursor.insertText(line.trimmed());
114  cursor.movePosition(QTextCursor::NextCell);
115  } else if (line.startsWith(" ")) {
116  cursor.insertText(line.trimmed()+' ');
117  } else if (line.size() > 0) {
118  //Title of a group
119  if (cursor.currentTable())
120  cursor.currentTable()->appendRows(1);
121  cursor.movePosition(QTextCursor::Down);
122  cursor.insertText(line.trimmed(), bold);
123  cursor.insertTable(1, 2, tf);
124  }
125  }
126 
127  ui->helpMessage->moveCursor(QTextCursor::Start);
128  ui->scrollArea->setVisible(false);
129  ui->aboutLogo->setVisible(false);
130  } else if (helpMode == pshelp) {
131  setWindowTitle(tr("PrivateSend information"));
132 
133  ui->aboutMessage->setTextFormat(Qt::RichText);
134  ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
135  ui->aboutMessage->setText(tr("\
136 <h3>PrivateSend Basics</h3> \
137 PrivateSend gives you true financial privacy by obscuring the origins of your funds. \
138 All the Dash in your wallet is comprised of different \"inputs\" which you can think of as separate, discrete coins.<br> \
139 PrivateSend uses an innovative process to mix your inputs with the inputs of two other people, without having your coins ever leave your wallet. \
140 You retain control of your money at all times..<hr> \
141 <b>The PrivateSend process works like this:</b>\
142 <ol type=\"1\"> \
143 <li>PrivateSend begins by breaking your transaction inputs down into standard denominations. \
144 These denominations are 0.01 DASH, 0.1 DASH, 1 DASH and 10 DASH -- sort of like the paper money you use every day.</li> \
145 <li>Your wallet then sends requests to specially configured software nodes on the network, called \"masternodes.\" \
146 These masternodes are informed then that you are interested in mixing a certain denomination. \
147 No identifiable information is sent to the masternodes, so they never know \"who\" you are.</li> \
148 <li>When two other people send similar messages, indicating that they wish to mix the same denomination, a mixing session begins. \
149 The masternode mixes up the inputs and instructs all three users' wallets to pay the now-transformed input back to themselves. \
150 Your wallet pays that denomination directly to itself, but in a different address (called a change address).</li> \
151 <li>In order to fully obscure your funds, your wallet must repeat this process a number of times with each denomination. \
152 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> \
153 <li>This mixing process happens in the background without any intervention on your part. When you wish to make a transaction, \
154 your funds will already be anonymized. No additional waiting is required.</li> \
155 </ol> <hr>\
156 <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. \
157 This means those 1000 addresses last for about 100 mixing events. When 900 of them are used, your wallet must create more addresses. \
158 It can only do this, however, if you have automatic backups enabled.<br> \
159 Consequently, users who have backups disabled will also have PrivateSend disabled. <hr>\
160 For more info see <a href=\"https://dashpay.atlassian.net/wiki/display/DOC/PrivateSend\">https://dashpay.atlassian.net/wiki/display/DOC/PrivateSend</a> \
161  "));
162  ui->aboutMessage->setWordWrap(true);
163  ui->helpMessage->setVisible(false);
164  ui->aboutLogo->setVisible(false);
165  }
166  // Theme dependent Gfx in About popup
167  QString helpMessageGfx = ":/images/" + GUIUtil::getThemeName() + "/about";
168  QPixmap pixmap = QPixmap(helpMessageGfx);
169  ui->aboutLogo->setPixmap(pixmap);
170 }
171 
173 {
174  delete ui;
175 }
176 
178 {
179  // On other operating systems, the expected action is to print the message to the console.
180  fprintf(stdout, "%s\n", qPrintable(text));
181 }
182 
184 {
185 #if defined(WIN32)
186  // On Windows, show a message box, as there is no stderr/stdout in windowed applications
187  exec();
188 #else
189  // On other operating systems, print help text to console
190  printToConsole();
191 #endif
192 }
193 
195 {
196  close();
197 }
198 
199 
201 ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
202  QWidget(parent, f)
203 {
204  QVBoxLayout *layout = new QVBoxLayout();
205  layout->addWidget(new QLabel(
206  tr("Dash Core is shutting down...") + "<br /><br />" +
207  tr("Do not shut down the computer until this window disappears.")));
208  setLayout(layout);
209 }
210 
212 {
213  if (!window)
214  return nullptr;
215 
216  // Show a simple window indicating shutdown status
217  QWidget *shutdownWindow = new ShutdownWindow();
218  shutdownWindow->setWindowTitle(window->windowTitle());
219 
220  // Center shutdown window at where main window was
221  const QPoint global = window->mapToGlobal(window->rect().center());
222  shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
223  shutdownWindow->show();
224  return shutdownWindow;
225 }
226 
227 void ShutdownWindow::closeEvent(QCloseEvent *event)
228 {
229  event->ignore();
230 }
static const bool DEFAULT_CHOOSE_DATADIR
Definition: intro.h:12
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Definition: util.cpp:486
#define strprintf
Definition: tinyformat.h:1011
void setupUi(QDialog *HelpMessageDialog)
static const bool DEFAULT_SELFSIGNED_ROOTCERTS
HelpMessageDialog(QWidget *parent, HelpMode helpMode)
std::string LicenseInfo()
Definition: init.cpp:637
static const bool DEFAULT_SPLASHSCREEN
Definition: guiconstants.h:18
std::string HelpMessage(HelpMessageMode mode)
Definition: init.cpp:384
Ui::HelpMessageDialog * ui
Definition: utilitydialog.h:37
bool GetBoolArg(const std::string &strArg, bool fDefault)
Definition: util.cpp:455
void closeEvent(QCloseEvent *event)
std::string FormatFullVersion()
tuple bold
Definition: rpc-tests.py:51
version
Definition: setup.py:3
static QWidget * showShutdownWindow(BitcoinGUI *window)
static const std::string DEFAULT_UIPLATFORM
Definition: bitcoingui.h:54
QString getThemeName()
Definition: guiutil.cpp:902
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0)
std::string HelpMessageGroup(const std::string &message)
Definition: util.cpp:482