]>
Commit | Line | Data |
---|---|---|
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" |
7b50bb2f | 15 | |
ad49c256 WL |
16 | #include <stdio.h> |
17 | ||
cfc5cfb0 | 18 | #include <QCloseEvent> |
7b50bb2f | 19 | #include <QLabel> |
45615af2 | 20 | #include <QRegExp> |
7b50bb2f PK |
21 | #include <QVBoxLayout> |
22 | ||
5c97aae6 WL |
23 | /** "Help message" or "About" dialog box */ |
24 | HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : | |
7b50bb2f | 25 | QDialog(parent), |
5c97aae6 | 26 | ui(new Ui::HelpMessageDialog) |
7b50bb2f PK |
27 | { |
28 | ui->setupUi(this); | |
5c97aae6 | 29 | GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this); |
7b50bb2f | 30 | |
5c97aae6 WL |
31 | QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); |
32 | /* On x86 add a bit specifier to the version so that users can distinguish between | |
33 | * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious. | |
34 | */ | |
f622232b | 35 | #if defined(__x86_64__) |
5c97aae6 | 36 | version += " " + tr("(%1-bit)").arg(64); |
f622232b | 37 | #elif defined(__i386__ ) |
5c97aae6 | 38 | version += " " + tr("(%1-bit)").arg(32); |
f622232b | 39 | #endif |
45615af2 | 40 | |
5c97aae6 WL |
41 | if (about) |
42 | { | |
43 | setWindowTitle(tr("About Bitcoin Core")); | |
44 | ||
45615af2 WL |
45 | /// HTML-format the license message from the core |
46 | QString licenseInfo = QString::fromStdString(LicenseInfo()); | |
5c97aae6 | 47 | QString licenseInfoHTML = licenseInfo; |
45615af2 WL |
48 | // Make URLs clickable |
49 | QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); | |
50 | uri.setMinimal(true); // use non-greedy matching | |
5c97aae6 | 51 | licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>"); |
45615af2 | 52 | // Replace newlines with HTML breaks |
5c97aae6 WL |
53 | licenseInfoHTML.replace("\n\n", "<br><br>"); |
54 | ||
55 | ui->helpMessageLabel->setTextFormat(Qt::RichText); | |
56 | ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); | |
57 | text = version + "\n" + licenseInfo; | |
58 | ui->helpMessageLabel->setText(version + "<br><br>" + licenseInfoHTML); | |
59 | ui->helpMessageLabel->setWordWrap(true); | |
60 | } else { | |
61 | setWindowTitle(tr("Command-line options")); | |
62 | QString header = tr("Usage:") + "\n" + | |
63 | " bitcoin-qt [" + tr("command-line options") + "] " + "\n"; | |
64 | ||
65 | QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); | |
66 | ||
67 | QString uiOptions = tr("UI options") + ":\n" + | |
68 | " -choosedatadir " + tr("Choose data directory on startup (default: 0)") + "\n" + | |
69 | " -lang=<lang> " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" + | |
70 | " -min " + tr("Start minimized") + "\n" + | |
71 | " -rootcertificates=<file> " + tr("Set SSL root certificates for payment request (default: -system-)") + "\n" + | |
72 | " -splash " + tr("Show splash screen on startup (default: 1)"); | |
73 | ||
74 | ui->helpMessageLabel->setFont(GUIUtil::bitcoinAddressFont()); | |
75 | text = version + "\n" + header + "\n" + coreOptions + "\n" + uiOptions; | |
76 | ui->helpMessageLabel->setText(text); | |
7b50bb2f PK |
77 | } |
78 | } | |
79 | ||
7b50bb2f PK |
80 | HelpMessageDialog::~HelpMessageDialog() |
81 | { | |
82 | GUIUtil::saveWindowGeometry("nHelpMessageDialogWindow", this); | |
83 | delete ui; | |
84 | } | |
85 | ||
86 | void HelpMessageDialog::printToConsole() | |
87 | { | |
88 | // On other operating systems, the expected action is to print the message to the console. | |
5c97aae6 | 89 | fprintf(stdout, "%s\n", qPrintable(text)); |
7b50bb2f PK |
90 | } |
91 | ||
92 | void HelpMessageDialog::showOrPrint() | |
93 | { | |
94 | #if defined(WIN32) | |
5c97aae6 WL |
95 | // On Windows, show a message box, as there is no stderr/stdout in windowed applications |
96 | exec(); | |
7b50bb2f | 97 | #else |
5c97aae6 WL |
98 | // On other operating systems, print help text to console |
99 | printToConsole(); | |
7b50bb2f PK |
100 | #endif |
101 | } | |
102 | ||
103 | void HelpMessageDialog::on_okButton_accepted() | |
104 | { | |
105 | close(); | |
106 | } | |
107 | ||
108 | ||
109 | /** "Shutdown" window */ | |
cfc5cfb0 WL |
110 | ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f): |
111 | QWidget(parent, f) | |
112 | { | |
113 | QVBoxLayout *layout = new QVBoxLayout(); | |
114 | layout->addWidget(new QLabel( | |
115 | tr("Bitcoin Core is shutting down...") + "<br /><br />" + | |
116 | tr("Do not shut down the computer until this window disappears."))); | |
117 | setLayout(layout); | |
118 | } | |
119 | ||
7b50bb2f PK |
120 | void ShutdownWindow::showShutdownWindow(BitcoinGUI *window) |
121 | { | |
122 | if (!window) | |
123 | return; | |
124 | ||
125 | // Show a simple window indicating shutdown status | |
cfc5cfb0 WL |
126 | QWidget *shutdownWindow = new ShutdownWindow(); |
127 | // We don't hold a direct pointer to the shutdown window after creation, so use | |
128 | // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually. | |
129 | shutdownWindow->setAttribute(Qt::WA_DeleteOnClose); | |
33c62c9c | 130 | shutdownWindow->setWindowTitle(window->windowTitle()); |
7b50bb2f PK |
131 | |
132 | // Center shutdown window at where main window was | |
133 | const QPoint global = window->mapToGlobal(window->rect().center()); | |
134 | shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2); | |
135 | shutdownWindow->show(); | |
136 | } | |
cfc5cfb0 WL |
137 | |
138 | void ShutdownWindow::closeEvent(QCloseEvent *event) | |
139 | { | |
140 | event->ignore(); | |
141 | } |