LCOV - code coverage report
Current view: top level - src/qt - utilitydialog.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 87 0.0 %
Date: 2015-10-12 22:39:14 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11