LCOV - code coverage report
Current view: top level - src/qt - utilitydialog.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 97 0.0 %
Date: 2020-09-26 01:30:44 Functions: 0 12 0.0 %

          Line data    Source code
       1             : // Copyright (c) 2011-2020 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)
       6             : #include <config/bitcoin-config.h>
       7             : #endif
       8             : 
       9             : #include <qt/utilitydialog.h>
      10             : 
      11             : #include <qt/forms/ui_helpmessagedialog.h>
      12             : 
      13             : #include <qt/guiutil.h>
      14             : 
      15             : #include <clientversion.h>
      16             : #include <init.h>
      17             : #include <util/system.h>
      18             : #include <util/strencodings.h>
      19             : 
      20             : #include <stdio.h>
      21             : 
      22             : #include <QCloseEvent>
      23             : #include <QLabel>
      24             : #include <QMainWindow>
      25             : #include <QRegExp>
      26             : #include <QTextCursor>
      27             : #include <QTextTable>
      28             : #include <QVBoxLayout>
      29             : 
      30             : /** "Help message" or "About" dialog box */
      31           0 : HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) :
      32           0 :     QDialog(parent),
      33           0 :     ui(new Ui::HelpMessageDialog)
      34           0 : {
      35           0 :     ui->setupUi(this);
      36             : 
      37           0 :     QString version = QString{PACKAGE_NAME} + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
      38             : 
      39           0 :     if (about)
      40             :     {
      41           0 :         setWindowTitle(tr("About %1").arg(PACKAGE_NAME));
      42             : 
      43           0 :         std::string licenseInfo = LicenseInfo();
      44             :         /// HTML-format the license message from the core
      45           0 :         QString licenseInfoHTML = QString::fromStdString(LicenseInfo());
      46             :         // Make URLs clickable
      47           0 :         QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2);
      48           0 :         uri.setMinimal(true); // use non-greedy matching
      49           0 :         licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>");
      50             :         // Replace newlines with HTML breaks
      51           0 :         licenseInfoHTML.replace("\n", "<br>");
      52             : 
      53           0 :         ui->aboutMessage->setTextFormat(Qt::RichText);
      54           0 :         ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
      55           0 :         text = version + "\n" + QString::fromStdString(FormatParagraph(licenseInfo));
      56           0 :         ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML);
      57           0 :         ui->aboutMessage->setWordWrap(true);
      58           0 :         ui->helpMessage->setVisible(false);
      59           0 :     } else {
      60           0 :         setWindowTitle(tr("Command-line options"));
      61           0 :         QString header = "Usage:  bitcoin-qt [command-line options]                     \n";
      62           0 :         QTextCursor cursor(ui->helpMessage->document());
      63           0 :         cursor.insertText(version);
      64           0 :         cursor.insertBlock();
      65           0 :         cursor.insertText(header);
      66           0 :         cursor.insertBlock();
      67             : 
      68           0 :         std::string strUsage = gArgs.GetHelpMessage();
      69           0 :         QString coreOptions = QString::fromStdString(strUsage);
      70           0 :         text = version + "\n\n" + header + "\n" + coreOptions;
      71             : 
      72           0 :         QTextTableFormat tf;
      73           0 :         tf.setBorderStyle(QTextFrameFormat::BorderStyle_None);
      74           0 :         tf.setCellPadding(2);
      75           0 :         QVector<QTextLength> widths;
      76           0 :         widths << QTextLength(QTextLength::PercentageLength, 35);
      77           0 :         widths << QTextLength(QTextLength::PercentageLength, 65);
      78           0 :         tf.setColumnWidthConstraints(widths);
      79             : 
      80           0 :         QTextCharFormat bold;
      81           0 :         bold.setFontWeight(QFont::Bold);
      82             : 
      83           0 :         for (const QString &line : coreOptions.split("\n")) {
      84           0 :             if (line.startsWith("  -"))
      85             :             {
      86           0 :                 cursor.currentTable()->appendRows(1);
      87           0 :                 cursor.movePosition(QTextCursor::PreviousCell);
      88           0 :                 cursor.movePosition(QTextCursor::NextRow);
      89           0 :                 cursor.insertText(line.trimmed());
      90           0 :                 cursor.movePosition(QTextCursor::NextCell);
      91           0 :             } else if (line.startsWith("   ")) {
      92           0 :                 cursor.insertText(line.trimmed()+' ');
      93           0 :             } else if (line.size() > 0) {
      94             :                 //Title of a group
      95           0 :                 if (cursor.currentTable())
      96           0 :                     cursor.currentTable()->appendRows(1);
      97           0 :                 cursor.movePosition(QTextCursor::Down);
      98           0 :                 cursor.insertText(line.trimmed(), bold);
      99           0 :                 cursor.insertTable(1, 2, tf);
     100             :             }
     101           0 :         }
     102             : 
     103           0 :         ui->helpMessage->moveCursor(QTextCursor::Start);
     104           0 :         ui->scrollArea->setVisible(false);
     105           0 :         ui->aboutLogo->setVisible(false);
     106           0 :     }
     107             : 
     108           0 :     GUIUtil::handleCloseWindowShortcut(this);
     109           0 : }
     110             : 
     111           0 : HelpMessageDialog::~HelpMessageDialog()
     112           0 : {
     113           0 :     delete ui;
     114           0 : }
     115             : 
     116           0 : void HelpMessageDialog::printToConsole()
     117             : {
     118             :     // On other operating systems, the expected action is to print the message to the console.
     119           0 :     tfm::format(std::cout, "%s\n", qPrintable(text));
     120           0 : }
     121             : 
     122           0 : void HelpMessageDialog::showOrPrint()
     123             : {
     124             : #if defined(WIN32)
     125             :     // On Windows, show a message box, as there is no stderr/stdout in windowed applications
     126             :     exec();
     127             : #else
     128             :     // On other operating systems, print help text to console
     129           0 :     printToConsole();
     130             : #endif
     131           0 : }
     132             : 
     133           0 : void HelpMessageDialog::on_okButton_accepted()
     134             : {
     135           0 :     close();
     136           0 : }
     137             : 
     138             : 
     139             : /** "Shutdown" window */
     140           0 : ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
     141           0 :     QWidget(parent, f)
     142           0 : {
     143           0 :     QVBoxLayout *layout = new QVBoxLayout();
     144           0 :     layout->addWidget(new QLabel(
     145           0 :         tr("%1 is shutting down...").arg(PACKAGE_NAME) + "<br /><br />" +
     146           0 :         tr("Do not shut down the computer until this window disappears.")));
     147           0 :     setLayout(layout);
     148             : 
     149           0 :     GUIUtil::handleCloseWindowShortcut(this);
     150           0 : }
     151             : 
     152           0 : QWidget* ShutdownWindow::showShutdownWindow(QMainWindow* window)
     153             : {
     154           0 :     assert(window != nullptr);
     155             : 
     156             :     // Show a simple window indicating shutdown status
     157           0 :     QWidget *shutdownWindow = new ShutdownWindow();
     158           0 :     shutdownWindow->setWindowTitle(window->windowTitle());
     159             : 
     160             :     // Center shutdown window at where main window was
     161           0 :     const QPoint global = window->mapToGlobal(window->rect().center());
     162           0 :     shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
     163           0 :     shutdownWindow->show();
     164           0 :     return shutdownWindow;
     165           0 : }
     166             : 
     167           0 : void ShutdownWindow::closeEvent(QCloseEvent *event)
     168             : {
     169           0 :     event->ignore();
     170           0 : }

Generated by: LCOV version 1.15