2
2
// Distributed under the MIT software license, see the accompanying
3
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
#if defined(HAVE_CONFIG_H)
6
#include "config/bitcoin-config.h"
5
9
#include "rpcconsole.h"
6
10
#include "ui_debugwindow.h"
41
47
// TODO: receive errors and debug messages through ClientModel
43
49
const int CONSOLE_HISTORY = 50;
44
const QSize ICON_SIZE(24, 24);
46
50
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
51
const QSize FONT_RANGE(4, 40);
52
const char fontSizeSettingsKey[] = "consoleFontSize";
245
251
cachedNodeid(-1),
246
252
platformStyle(platformStyle),
247
253
peersTableContextMenu(0),
248
banTableContextMenu(0)
254
banTableContextMenu(0),
250
257
ui->setupUi(this);
251
258
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
260
ui->openDebugLogfileButton->setToolTip(ui->openDebugLogfileButton->toolTip().arg(tr(PACKAGE_NAME)));
253
262
if (platformStyle->getImagesOnButtons()) {
254
263
ui->openDebugLogfileButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));
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"));
258
269
// Install event filter for up and down arrow
259
270
ui->lineEdit->installEventFilter(this);
260
271
ui->messagesWidget->installEventFilter(this);
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()));
265
278
// set library version labels
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);
277
292
setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_MINS);
287
304
GUIUtil::saveWindowGeometry("nRPCConsoleWindow", this);
288
305
Q_EMIT stopExecutor();
289
RPCUnregisterTimerInterface(rpcTimerInterface);
306
RPCUnsetTimerInterface(rpcTimerInterface);
290
307
delete rpcTimerInterface;
332
// forward these events to lineEdit
333
if(obj == autoCompleter->popup()) {
334
QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
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)));
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)));
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()));
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)
463
wordList << commandList[i].c_str();
466
autoCompleter = new QCompleter(wordList, this);
467
ui->lineEdit->setCompleter(autoCompleter);
468
autoCompleter->popup()->installEventFilter(this);
447
void RPCConsole::clear()
483
void RPCConsole::fontBigger()
485
setFontSize(consoleFontSize+1);
488
void RPCConsole::fontSmaller()
490
setFontSize(consoleFontSize-1);
493
void RPCConsole::setFontSize(int newSize)
497
//don't allow a insane font size
498
if (newSize < FONT_RANGE.width() || newSize > FONT_RANGE.height())
501
// temp. store the console content
502
QString str = ui->messagesWidget->toHtml();
504
// replace font tags size in current content
505
str.replace(QString("font-size:%1pt").arg(consoleFontSize), QString("font-size:%1pt").arg(newSize));
507
// store the new font size
508
consoleFontSize = newSize;
509
settings.setValue(fontSizeSettingsKey, consoleFontSize);
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();
514
ui->messagesWidget->setHtml(str);
515
ui->messagesWidget->verticalScrollBar()->setValue(oldPosFactor * ui->messagesWidget->verticalScrollBar()->maximum());
518
void RPCConsole::clear(bool clearHistory)
449
520
ui->messagesWidget->clear();
452
526
ui->lineEdit->clear();
453
527
ui->lineEdit->setFocus();
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));
465
539
// Set default style sheet
466
540
QFontInfo fixedFontInfo(GUIUtil::fixedPitchFont());
467
// Try to make fixed font adequately large on different OS
469
QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 10 / 8);
471
QString ptSize = QString("%1pt").arg(QFontInfo(QFont()).pointSize() * 8.5 / 9);
473
541
ui->messagesWidget->document()->setDefaultStyleSheet(
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))
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);
522
590
ui->numberOfConnections->setText(connections);
525
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress)
593
void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers)
527
ui->numberOfBlocks->setText(QString::number(count));
528
ui->lastBlockTime->setText(blockDate.toString());
596
ui->numberOfBlocks->setText(QString::number(count));
597
ui->lastBlockTime->setText(blockDate.toString());
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;
829
899
SplitHostPort(nStr, port, addr);
831
901
CNode::Ban(CNetAddr(addr), BanReasonManuallyAdded, bantime);
832
bannedNode->fDisconnect = true;
835
903
clearSelectedNode();
836
904
clientModel->getBanTableModel()->refresh();