You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utilitydialog.cpp 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // Copyright (c) 2011-2014 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. #include "utilitydialog.h"
  5. #include "ui_helpmessagedialog.h"
  6. #include "bitcoingui.h"
  7. #include "clientmodel.h"
  8. #include "guiconstants.h"
  9. #include "intro.h"
  10. #include "paymentrequestplus.h"
  11. #include "guiutil.h"
  12. #include "clientversion.h"
  13. #include "init.h"
  14. #include "util.h"
  15. #include <stdio.h>
  16. #include <QCloseEvent>
  17. #include <QLabel>
  18. #include <QRegExp>
  19. #include <QTextTable>
  20. #include <QTextCursor>
  21. #include <QVBoxLayout>
  22. /** "Help message" or "About" dialog box */
  23. HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
  24. QDialog(parent),
  25. ui(new Ui::HelpMessageDialog)
  26. {
  27. ui->setupUi(this);
  28. QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
  29. /* On x86 add a bit specifier to the version so that users can distinguish between
  30. * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambigious.
  31. */
  32. #if defined(__x86_64__)
  33. version += " " + tr("(%1-bit)").arg(64);
  34. #elif defined(__i386__ )
  35. version += " " + tr("(%1-bit)").arg(32);
  36. #endif
  37. if (about)
  38. {
  39. setWindowTitle(tr("About Bitcoin Core"));
  40. /// HTML-format the license message from the core
  41. QString licenseInfo = QString::fromStdString(LicenseInfo());
  42. QString licenseInfoHTML = licenseInfo;
  43. // Make URLs clickable
  44. QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
  45. uri.setMinimal(true); // use non-greedy matching
  46. licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
  47. // Replace newlines with HTML breaks
  48. licenseInfoHTML.replace("\n\n", "<br><br>");
  49. ui->aboutMessage->setTextFormat(Qt::RichText);
  50. ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  51. text = version + "\n" + licenseInfo;
  52. ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
  53. ui->aboutMessage->setWordWrap(true);
  54. ui->helpMessage->setVisible(false);
  55. } else {
  56. setWindowTitle(tr("Command-line options"));
  57. QString header = tr("Usage:") + "\n" +
  58. " bitcoin-qt [" + tr("command-line options") + "] " + "\n";
  59. QTextCursor cursor(ui->helpMessage->document());
  60. cursor.insertText(version);
  61. cursor.insertBlock();
  62. cursor.insertText(header);
  63. cursor.insertBlock();
  64. std::string strUsage = HelpMessage(HMM_BITCOIN_QT);
  65. const bool showDebug = GetBoolArg("-help-debug", false);
  66. strUsage += HelpMessageGroup(_("UI Options:"));
  67. if (showDebug) {
  68. strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS));
  69. }
  70. strUsage += HelpMessageOpt("-choosedatadir", strprintf(_("Choose data directory on startup (default: %u)"), DEFAULT_CHOOSE_DATADIR));
  71. strUsage += HelpMessageOpt("-lang=<lang>", _("Set language, for example \"de_DE\" (default: system locale)"));
  72. strUsage += HelpMessageOpt("-min", _("Start minimized"));
  73. strUsage += HelpMessageOpt("-rootcertificates=<file>", _("Set SSL root certificates for payment request (default: -system-)"));
  74. strUsage += HelpMessageOpt("-splash", strprintf(_("Show splash screen on startup (default: %u)"), DEFAULT_SPLASHSCREEN));
  75. strUsage += HelpMessageOpt("-resetguisettings", _("Reset all settings changes made over the GUI"));
  76. if (showDebug) {
  77. strUsage += HelpMessageOpt("-uiplatform", "Select platform to customize UI for (one of windows, macosx, other; default: platform compiled on)");
  78. }
  79. QString coreOptions = QString::fromStdString(strUsage);
  80. text = version + "\n" + header + "\n" + coreOptions;
  81. QTextTableFormat tf;
  82. tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
  83. tf.setCellPadding(2);
  84. QVector<QTextLength> widths;
  85. widths << QTextLength(QTextLength::PercentageLength, 35);
  86. widths << QTextLength(QTextLength::PercentageLength, 65);
  87. tf.setColumnWidthConstraints(widths);
  88. QTextCharFormat bold;
  89. bold.setFontWeight(QFont::Bold);
  90. Q_FOREACH (const QString &line, coreOptions.split("\n")) {
  91. if (line.startsWith(" -"))
  92. {
  93. cursor.currentTable()->appendRows(1);
  94. cursor.movePosition(QTextCursor::PreviousCell);
  95. cursor.movePosition(QTextCursor::NextRow);
  96. cursor.insertText(line.trimmed());
  97. cursor.movePosition(QTextCursor::NextCell);
  98. } else if (line.startsWith(" ")) {
  99. cursor.insertText(line.trimmed()+' ');
  100. } else if (line.size() > 0) {
  101. //Title of a group
  102. if (cursor.currentTable())
  103. cursor.currentTable()->appendRows(1);
  104. cursor.movePosition(QTextCursor::Down);
  105. cursor.insertText(line.trimmed(), bold);
  106. cursor.insertTable(1, 2, tf);
  107. }
  108. }
  109. ui->helpMessage->moveCursor(QTextCursor::Start);
  110. ui->scrollArea->setVisible(false);
  111. ui->aboutLogo->setVisible(false);
  112. }
  113. }
  114. HelpMessageDialog::~HelpMessageDialog()
  115. {
  116. delete ui;
  117. }
  118. void HelpMessageDialog::printToConsole()
  119. {
  120. // On other operating systems, the expected action is to print the message to the console.
  121. fprintf(stdout, "%s\n", qPrintable(text));
  122. }
  123. void HelpMessageDialog::showOrPrint()
  124. {
  125. #if defined(WIN32)
  126. // On Windows, show a message box, as there is no stderr/stdout in windowed applications
  127. exec();
  128. #else
  129. // On other operating systems, print help text to console
  130. printToConsole();
  131. #endif
  132. }
  133. void HelpMessageDialog::on_okButton_accepted()
  134. {
  135. close();
  136. }
  137. /** "Shutdown" window */
  138. ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
  139. QWidget(parent, f)
  140. {
  141. QVBoxLayout *layout = new QVBoxLayout();
  142. layout->addWidget(new QLabel(
  143. tr("Bitcoin Core is shutting down...") + "<br /><br />" +
  144. tr("Do not shut down the computer until this window disappears.")));
  145. setLayout(layout);
  146. }
  147. void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
  148. {
  149. if (!window)
  150. return;
  151. // Show a simple window indicating shutdown status
  152. QWidget *shutdownWindow = new ShutdownWindow();
  153. // We don't hold a direct pointer to the shutdown window after creation, so use
  154. // Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
  155. shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
  156. shutdownWindow->setWindowTitle(window->windowTitle());
  157. // Center shutdown window at where main window was
  158. const QPoint global = window->mapToGlobal(window->rect().center());
  159. shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
  160. shutdownWindow->show();
  161. }
  162. void ShutdownWindow::closeEvent(QCloseEvent *event)
  163. {
  164. event->ignore();
  165. }