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