]> Git Repo - VerusCoin.git/blame - src/qt/utilitydialog.cpp
[Univalue] add univalue over subtree
[VerusCoin.git] / src / qt / utilitydialog.cpp
CommitLineData
f914f1a7 1// Copyright (c) 2011-2014 The Bitcoin Core developers
78253fcb 2// Distributed under the MIT software license, see the accompanying
7b50bb2f
PK
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include "utilitydialog.h"
6
7b50bb2f
PK
7#include "ui_helpmessagedialog.h"
8
9#include "bitcoingui.h"
10#include "clientmodel.h"
11#include "guiutil.h"
12
71697f97 13#include "clientversion.h"
7b50bb2f 14#include "init.h"
851296a7 15#include "util.h"
7b50bb2f 16
ad49c256
WL
17#include <stdio.h>
18
cfc5cfb0 19#include <QCloseEvent>
7b50bb2f 20#include <QLabel>
45615af2 21#include <QRegExp>
e179eb3d
TZ
22#include <QTextTable>
23#include <QTextCursor>
7b50bb2f
PK
24#include <QVBoxLayout>
25
5c97aae6
WL
26/** "Help message" or "About" dialog box */
27HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
7b50bb2f 28 QDialog(parent),
5c97aae6 29 ui(new Ui::HelpMessageDialog)
7b50bb2f
PK
30{
31 ui->setupUi(this);
7b50bb2f 32
5c97aae6
WL
33 QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
34 /* On x86 add a bit specifier to the version so that users can distinguish between
35 * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
36 */
f622232b 37#if defined(__x86_64__)
5c97aae6 38 version += " " + tr("(%1-bit)").arg(64);
f622232b 39#elif defined(__i386__ )
5c97aae6 40 version += " " + tr("(%1-bit)").arg(32);
f622232b 41#endif
45615af2 42
5c97aae6
WL
43 if (about)
44 {
45 setWindowTitle(tr("About Bitcoin Core"));
46
45615af2
WL
47 /// HTML-format the license message from the core
48 QString licenseInfo = QString::fromStdString(LicenseInfo());
5c97aae6 49 QString licenseInfoHTML = licenseInfo;
45615af2
WL
50 // Make URLs clickable
51 QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
52 uri.setMinimal(true); // use non-greedy matching
5c97aae6 53 licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
45615af2 54 // Replace newlines with HTML breaks
5c97aae6
WL
55 licenseInfoHTML.replace("\n\n", "<br><br>");
56
e179eb3d 57 ui->aboutMessage->setTextFormat(Qt::RichText);
5c97aae6
WL
58 ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
59 text = version + "\n" + licenseInfo;
e179eb3d
TZ
60 ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
61 ui->aboutMessage->setWordWrap(true);
62 ui->helpMessage->setVisible(false);
5c97aae6
WL
63 } else {
64 setWindowTitle(tr("Command-line options"));
f7547079
LV
65 QString header = tr("Usage:") + "\n" +
66 " bitcoin-qt [" + tr("command-line options") + "] " + "\n";
e179eb3d
TZ
67 QTextCursor cursor(ui->helpMessage->document());
68 cursor.insertText(version);
69 cursor.insertBlock();
f7547079 70 cursor.insertText(header);
e179eb3d 71 cursor.insertBlock();
f7547079
LV
72
73 QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT));
74 text = version + "\n" + header + "\n" + coreOptions;
75
e179eb3d
TZ
76 QTextTableFormat tf;
77 tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
78 tf.setCellPadding(2);
79 QVector<QTextLength> widths;
98c222b5
JS
80 widths << QTextLength(QTextLength::PercentageLength, 35);
81 widths << QTextLength(QTextLength::PercentageLength, 65);
e179eb3d 82 tf.setColumnWidthConstraints(widths);
5c97aae6 83
e179eb3d
TZ
84 QTextCharFormat bold;
85 bold.setFontWeight(QFont::Bold);
f7547079 86
e092f229 87 Q_FOREACH (const QString &line, coreOptions.split("\n")) {
f7547079
LV
88 if (line.startsWith(" -"))
89 {
90 cursor.currentTable()->appendRows(1);
91 cursor.movePosition(QTextCursor::PreviousCell);
e179eb3d 92 cursor.movePosition(QTextCursor::NextRow);
f7547079
LV
93 cursor.insertText(line.trimmed());
94 cursor.movePosition(QTextCursor::NextCell);
95 } else if (line.startsWith(" ")) {
96 cursor.insertText(line.trimmed()+' ');
97 } else if (line.size() > 0) {
98 //Title of a group
99 if (cursor.currentTable())
100 cursor.currentTable()->appendRows(1);
101 cursor.movePosition(QTextCursor::Down);
102 cursor.insertText(line.trimmed(), bold);
103 cursor.insertTable(1, 2, tf);
e179eb3d 104 }
851296a7 105 }
e179eb3d
TZ
106
107 ui->helpMessage->moveCursor(QTextCursor::Start);
108 ui->scrollArea->setVisible(false);
d67a6423 109 ui->aboutLogo->setVisible(false);
7b50bb2f
PK
110 }
111}
112
7b50bb2f
PK
113HelpMessageDialog::~HelpMessageDialog()
114{
7b50bb2f
PK
115 delete ui;
116}
117
118void HelpMessageDialog::printToConsole()
119{
120 // On other operating systems, the expected action is to print the message to the console.
5c97aae6 121 fprintf(stdout, "%s\n", qPrintable(text));
7b50bb2f
PK
122}
123
124void HelpMessageDialog::showOrPrint()
125{
126#if defined(WIN32)
5c97aae6
WL
127 // On Windows, show a message box, as there is no stderr/stdout in windowed applications
128 exec();
7b50bb2f 129#else
5c97aae6
WL
130 // On other operating systems, print help text to console
131 printToConsole();
7b50bb2f
PK
132#endif
133}
134
135void HelpMessageDialog::on_okButton_accepted()
136{
137 close();
138}
139
140
141/** "Shutdown" window */
cfc5cfb0
WL
142ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
143 QWidget(parent, f)
144{
145 QVBoxLayout *layout = new QVBoxLayout();
146 layout->addWidget(new QLabel(
147 tr("Bitcoin Core is shutting down...") + "<br /><br />" +
148 tr("Do not shut down the computer until this window disappears.")));
149 setLayout(layout);
150}
151
7b50bb2f
PK
152void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
153{
154 if (!window)
155 return;
156
157 // Show a simple window indicating shutdown status
cfc5cfb0
WL
158 QWidget *shutdownWindow = new ShutdownWindow();
159 // We don't hold a direct pointer to the shutdown window after creation, so use
160 // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
161 shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
33c62c9c 162 shutdownWindow->setWindowTitle(window->windowTitle());
7b50bb2f
PK
163
164 // Center shutdown window at where main window was
165 const QPoint global = window->mapToGlobal(window->rect().center());
166 shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
167 shutdownWindow->show();
168}
cfc5cfb0
WL
169
170void ShutdownWindow::closeEvent(QCloseEvent *event)
171{
172 event->ignore();
173}
This page took 0.182469 seconds and 4 git commands to generate.