~ubuntu-branches/debian/stretch/bitcoin/stretch

« back to all changes in this revision

Viewing changes to src/qt/rpcconsole.cpp

  • Committer: Package Import Robot
  • Author(s): Anthony Towns
  • Date: 2016-10-21 17:13:13 UTC
  • mfrom: (1.3.2)
  • Revision ID: package-import@ubuntu.com-20161021171313-7eu2ltpbk0xag3q1
Tags: 0.13.0-0.1
* Non-maintainer upload.
* New upstream release.
* Allow compilation with gcc/g++ 6. (Closes: Bug#835963)
* Additional fixes for openssl 1.1 compatibility. (See Bug#828248)
* Check if -latomic is needed (it is on mips*).
* Remove reproducible build patch, since leveldb build system is
  no longer used in 0.13. (See Bug#791834)
* Update description since the blockchain is much more than "several GB"
  now. (Closes: Bug#835809)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
 
 
5
#if defined(HAVE_CONFIG_H)
 
6
#include "config/bitcoin-config.h"
 
7
#endif
 
8
 
5
9
#include "rpcconsole.h"
6
10
#include "ui_debugwindow.h"
7
11
 
12
16
#include "bantablemodel.h"
13
17
 
14
18
#include "chainparams.h"
15
 
#include "rpcserver.h"
16
 
#include "rpcclient.h"
 
19
#include "rpc/server.h"
 
20
#include "rpc/client.h"
17
21
#include "util.h"
18
22
 
19
23
#include <openssl/crypto.h>
27
31
#include <QKeyEvent>
28
32
#include <QMenu>
29
33
#include <QScrollBar>
 
34
#include <QSettings>
30
35
#include <QSignalMapper>
31
36
#include <QThread>
32
37
#include <QTime>
33
38
#include <QTimer>
 
39
#include <QStringList>
34
40
 
35
41
#if QT_VERSION < 0x050000
36
42
#include <QUrl>
41
47
// TODO: receive errors and debug messages through ClientModel
42
48
 
43
49
const int CONSOLE_HISTORY = 50;
44
 
const QSize ICON_SIZE(24, 24);
45
 
 
46
50
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
 
51
const QSize FONT_RANGE(4, 40);
 
52
const char fontSizeSettingsKey[] = "consoleFontSize";
47
53
 
48
54
const struct {
49
55
    const char *url;
245
251
    cachedNodeid(-1),
246
252
    platformStyle(platformStyle),
247
253
    peersTableContextMenu(0),
248
 
    banTableContextMenu(0)
 
254
    banTableContextMenu(0),
 
255
    consoleFontSize(0)
249
256
{
250
257
    ui->setupUi(this);
251
258
    GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
252
259
 
 
260
    ui->openDebugLogfileButton->setToolTip(ui->openDebugLogfileButton->toolTip().arg(tr(PACKAGE_NAME)));
 
261
 
253
262
    if (platformStyle->getImagesOnButtons()) {
254
263
        ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
255
264
    }
256
265
    ui->clearButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
 
266
    ui->fontBiggerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontbigger"));
 
267
    ui->fontSmallerButton->setIcon(platformStyle->SingleColorIcon(":/icons/fontsmaller"));
257
268
 
258
269
    // Install event filter for up and down arrow
259
270
    ui->lineEdit->installEventFilter(this);
260
271
    ui->messagesWidget->installEventFilter(this);
261
272
 
262
273
    connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
 
274
    connect(ui->fontBiggerButton, SIGNAL(clicked()), this, SLOT(fontBigger()));
 
275
    connect(ui->fontSmallerButton, SIGNAL(clicked()), this, SLOT(fontSmaller()));
263
276
    connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, SLOT(clear()));
264
277
 
265
278
    // set library version labels
271
284
#endif
272
285
    // Register RPC timer interface
273
286
    rpcTimerInterface = new QtRPCTimerInterface();
274
 
    RPCRegisterTimerInterface(rpcTimerInterface);
 
287
    // avoid accidentally overwriting an existing, non QTThread
 
288
    // based timer interface
 
289
    RPCSetTimerInterfaceIfUnset(rpcTimerInterface);
275
290
 
276
291
    startExecutor();
277
292
    setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_MINS);
279
294
    ui->detailWidget->hide();
280
295
    ui->peerHeading->setText(tr("Select a peer to view detailed information."));
281
296
 
 
297
    QSettings settings;
 
298
    consoleFontSize = settings.value(fontSizeSettingsKey, QFontInfo(QFont()).pointSize()).toInt();
282
299
    clear();
283
300
}
284
301
 
286
303
{
287
304
    GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this);
288
305
    Q_EMIT stopExecutor();
289
 
    RPCUnregisterTimerInterface(rpcTimerInterface);
 
306
    RPCUnsetTimerInterface(rpcTimerInterface);
290
307
    delete rpcTimerInterface;
291
308
    delete ui;
292
309
}
310
327
                return true;
311
328
            }
312
329
            break;
 
330
        case Qt::Key_Return:
 
331
        case Qt::Key_Enter:
 
332
            // forward these events to lineEdit
 
333
            if(obj == autoCompleter->popup()) {
 
334
                QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
 
335
                return true;
 
336
            }
 
337
            break;
313
338
        default:
314
339
            // Typing in messages widget brings focus to line edit, and redirects key there
315
340
            // Exclude most combinations and keys that emit no text, except paste shortcuts
336
361
        setNumConnections(model->getNumConnections());
337
362
        connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
338
363
 
339
 
        setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL));
340
 
        connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double)), this, SLOT(setNumBlocks(int,QDateTime,double)));
 
364
        setNumBlocks(model->getNumBlocks(), model->getLastBlockDate(), model->getVerificationProgress(NULL), false);
 
365
        connect(model, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
341
366
 
342
367
        updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent());
343
368
        connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
426
451
        // Provide initial values
427
452
        ui->clientVersion->setText(model->formatFullVersion());
428
453
        ui->clientUserAgent->setText(model->formatSubVersion());
429
 
        ui->clientName->setText(model->clientName());
430
 
        ui->buildDate->setText(model->formatBuildDate());
 
454
        ui->dataDir->setText(model->dataDir());
431
455
        ui->startupTime->setText(model->formatClientStartupTime());
432
456
        ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
 
457
 
 
458
        //Setup autocomplete and attach it
 
459
        QStringList wordList;
 
460
        std::vector<std::string> commandList = tableRPC.listCommands();
 
461
        for (size_t i = 0; i < commandList.size(); ++i)
 
462
        {
 
463
            wordList << commandList[i].c_str();
 
464
        }
 
465
 
 
466
        autoCompleter = new QCompleter(wordList, this);
 
467
        ui->lineEdit->setCompleter(autoCompleter);
 
468
        autoCompleter->popup()->installEventFilter(this);
433
469
    }
434
470
}
435
471
 
444
480
    }
445
481
}
446
482
 
447
 
void RPCConsole::clear()
 
483
void RPCConsole::fontBigger()
 
484
{
 
485
    setFontSize(consoleFontSize+1);
 
486
}
 
487
 
 
488
void RPCConsole::fontSmaller()
 
489
{
 
490
    setFontSize(consoleFontSize-1);
 
491
}
 
492
 
 
493
void RPCConsole::setFontSize(int newSize)
 
494
{
 
495
    QSettings settings;
 
496
 
 
497
    //don't allow a insane font size
 
498
    if (newSize < FONT_RANGE.width() || newSize > FONT_RANGE.height())
 
499
        return;
 
500
 
 
501
    // temp. store the console content
 
502
    QString str = ui->messagesWidget->toHtml();
 
503
 
 
504
    // replace font tags size in current content
 
505
    str.replace(QString("font-size:%1pt").arg(consoleFontSize), QString("font-size:%1pt").arg(newSize));
 
506
 
 
507
    // store the new font size
 
508
    consoleFontSize = newSize;
 
509
    settings.setValue(fontSizeSettingsKey, consoleFontSize);
 
510
 
 
511
    // clear console (reset icon sizes, default stylesheet) and re-add the content
 
512
    float oldPosFactor = 1.0 / ui->messagesWidget->verticalScrollBar()->maximum() * ui->messagesWidget->verticalScrollBar()->value();
 
513
    clear(false);
 
514
    ui->messagesWidget->setHtml(str);
 
515
    ui->messagesWidget->verticalScrollBar()->setValue(oldPosFactor * ui->messagesWidget->verticalScrollBar()->maximum());
 
516
}
 
517
 
 
518
void RPCConsole::clear(bool clearHistory)
448
519
{
449
520
    ui->messagesWidget->clear();
450
 
    history.clear();
451
 
    historyPtr = 0;
 
521
    if(clearHistory)
 
522
    {
 
523
        history.clear();
 
524
        historyPtr = 0;
 
525
    }
452
526
    ui->lineEdit->clear();
453
527
    ui->lineEdit->setFocus();
454
528
 
459
533
        ui->messagesWidget->document()->addResource(
460
534
                    QTextDocument::ImageResource,
461
535
                    QUrl(ICON_MAPPING[i].url),
462
 
                    platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(ICON_SIZE, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
 
536
                    platformStyle->SingleColorImage(ICON_MAPPING[i].source).scaled(QSize(consoleFontSize*2, consoleFontSize*2), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
463
537
    }
464
538
 
465
539
    // Set default style sheet
466
540
    QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont());
467
 
    // Try to make fixed font adequately large on different OS
468
 
#ifdef WIN32
469
 
    QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 10 / 8);
470
 
#else
471
 
    QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 8.5 / 9);
472
 
#endif
473
541
    ui->messagesWidget->document()->setDefaultStyleSheet(
474
542
        QString(
475
543
                "table { }"
476
 
                "td.time { color: #808080; padding-top: 3px; } "
 
544
                "td.time { color: #808080; font-size: %2; padding-top: 3px; } "
477
545
                "td.message { font-family: %1; font-size: %2; white-space:pre-wrap; } "
478
546
                "td.cmd-request { color: #006060; } "
479
547
                "td.cmd-error { color: red; } "
480
548
                "b { color: #006060; } "
481
 
            ).arg(fixedFontInfo.family(), ptSize)
 
549
            ).arg(fixedFontInfo.family(), QString("%1pt").arg(consoleFontSize))
482
550
        );
483
551
 
484
 
    message(CMD_REPLY, (tr("Welcome to the Bitcoin Core RPC console.") + "<br>" +
 
552
    message(CMD_REPLY, (tr("Welcome to the %1 RPC console.").arg(tr(PACKAGE_NAME)) + "<br>" +
485
553
                        tr("Use up and down arrows to navigate history, and <b>Ctrl-L</b> to clear screen.") + "<br>" +
486
554
                        tr("Type <b>help</b> for an overview of available commands.")), true);
487
555
}
522
590
    ui->numberOfConnections->setText(connections);
523
591
}
524
592
 
525
 
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress)
 
593
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers)
526
594
{
527
 
    ui->numberOfBlocks->setText(QString::number(count));
528
 
    ui->lastBlockTime->setText(blockDate.toString());
 
595
    if (!headers) {
 
596
        ui->numberOfBlocks->setText(QString::number(count));
 
597
        ui->lastBlockTime->setText(blockDate.toString());
 
598
    }
529
599
}
530
600
 
531
601
void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage)
822
892
    // Get currently selected peer address
823
893
    QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address);
824
894
    // Find possible nodes, ban it and clear the selected node
825
 
    if (CNode *bannedNode = FindNode(strNode.toStdString())) {
 
895
    if (FindNode(strNode.toStdString())) {
826
896
        std::string nStr = strNode.toStdString();
827
897
        std::string addr;
828
898
        int port = 0;
829
899
        SplitHostPort(nStr, port, addr);
830
900
 
831
901
        CNode::Ban(CNetAddr(addr), BanReasonManuallyAdded, bantime);
832
 
        bannedNode->fDisconnect = true;
833
 
        DumpBanlist();
834
902
 
835
903
        clearSelectedNode();
836
904
        clientModel->getBanTableModel()->refresh();
849
917
    if (possibleSubnet.IsValid())
850
918
    {
851
919
        CNode::Unban(possibleSubnet);
852
 
        DumpBanlist();
853
920
        clientModel->getBanTableModel()->refresh();
854
921
    }
855
922
}