Changeset View
Changeset View
Standalone View
Standalone View
src/qt/rpcconsole.cpp
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
/** Class for handling RPC timers | /** Class for handling RPC timers | ||||
* (used for e.g. re-locking the wallet after a timeout) | * (used for e.g. re-locking the wallet after a timeout) | ||||
*/ | */ | ||||
class QtRPCTimerBase : public QObject, public RPCTimerBase { | class QtRPCTimerBase : public QObject, public RPCTimerBase { | ||||
Q_OBJECT | Q_OBJECT | ||||
public: | public: | ||||
QtRPCTimerBase(std::function<void()> &_func, int64_t millis) : func(_func) { | QtRPCTimerBase(std::function<void()> &_func, int64_t millis) : func(_func) { | ||||
timer.setSingleShot(true); | timer.setSingleShot(true); | ||||
connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); | connect(&timer, &QTimer::timeout, [this] { func(); }); | ||||
timer.start(millis); | timer.start(millis); | ||||
} | } | ||||
~QtRPCTimerBase() {} | ~QtRPCTimerBase() {} | ||||
private Q_SLOTS: | |||||
void timeout() { func(); } | |||||
private: | private: | ||||
QTimer timer; | QTimer timer; | ||||
std::function<void()> func; | std::function<void()> func; | ||||
}; | }; | ||||
class QtRPCTimerInterface : public RPCTimerInterface { | class QtRPCTimerInterface : public RPCTimerInterface { | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 426 Lines • ▼ Show 20 Lines | ui->fontBiggerButton->setIcon( | ||||
platformStyle->SingleColorIcon(":/icons/fontbigger")); | platformStyle->SingleColorIcon(":/icons/fontbigger")); | ||||
ui->fontSmallerButton->setIcon( | ui->fontSmallerButton->setIcon( | ||||
platformStyle->SingleColorIcon(":/icons/fontsmaller")); | platformStyle->SingleColorIcon(":/icons/fontsmaller")); | ||||
// Install event filter for up and down arrow | // Install event filter for up and down arrow | ||||
ui->lineEdit->installEventFilter(this); | ui->lineEdit->installEventFilter(this); | ||||
ui->messagesWidget->installEventFilter(this); | ui->messagesWidget->installEventFilter(this); | ||||
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); | connect(ui->clearButton, &QPushButton::clicked, this, &RPCConsole::clear); | ||||
connect(ui->fontBiggerButton, SIGNAL(clicked()), this, SLOT(fontBigger())); | connect(ui->fontBiggerButton, &QPushButton::clicked, this, | ||||
connect(ui->fontSmallerButton, SIGNAL(clicked()), this, | &RPCConsole::fontBigger); | ||||
SLOT(fontSmaller())); | connect(ui->fontSmallerButton, &QPushButton::clicked, this, | ||||
connect(ui->btnClearTrafficGraph, SIGNAL(clicked()), ui->trafficGraph, | &RPCConsole::fontSmaller); | ||||
SLOT(clear())); | connect(ui->btnClearTrafficGraph, &QPushButton::clicked, ui->trafficGraph, | ||||
&TrafficGraphWidget::clear); | |||||
// disable the wallet selector by default | // disable the wallet selector by default | ||||
ui->WalletSelector->setVisible(false); | ui->WalletSelector->setVisible(false); | ||||
ui->WalletSelectorLabel->setVisible(false); | ui->WalletSelectorLabel->setVisible(false); | ||||
// set library version labels | // set library version labels | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
ui->berkeleyDBVersion->setText(DbEnv::version(0, 0, 0)); | ui->berkeleyDBVersion->setText(DbEnv::version(0, 0, 0)); | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
void RPCConsole::setClientModel(ClientModel *model) { | void RPCConsole::setClientModel(ClientModel *model) { | ||||
clientModel = model; | clientModel = model; | ||||
ui->trafficGraph->setClientModel(model); | ui->trafficGraph->setClientModel(model); | ||||
if (model && clientModel->getPeerTableModel() && | if (model && clientModel->getPeerTableModel() && | ||||
clientModel->getBanTableModel()) { | clientModel->getBanTableModel()) { | ||||
// Keep up to date with client | // Keep up to date with client | ||||
setNumConnections(model->getNumConnections()); | setNumConnections(model->getNumConnections()); | ||||
connect(model, SIGNAL(numConnectionsChanged(int)), this, | connect(model, &ClientModel::numConnectionsChanged, this, | ||||
SLOT(setNumConnections(int))); | &RPCConsole::setNumConnections); | ||||
interfaces::Node &node = clientModel->node(); | interfaces::Node &node = clientModel->node(); | ||||
setNumBlocks(node.getNumBlocks(), | setNumBlocks(node.getNumBlocks(), | ||||
QDateTime::fromTime_t(node.getLastBlockTime()), | QDateTime::fromTime_t(node.getLastBlockTime()), | ||||
node.getVerificationProgress(), false); | node.getVerificationProgress(), false); | ||||
connect(model, SIGNAL(numBlocksChanged(int, QDateTime, double, bool)), | connect(model, &ClientModel::numBlocksChanged, this, | ||||
this, SLOT(setNumBlocks(int, QDateTime, double, bool))); | &RPCConsole::setNumBlocks); | ||||
updateNetworkState(); | updateNetworkState(); | ||||
connect(model, SIGNAL(networkActiveChanged(bool)), this, | connect(model, &ClientModel::networkActiveChanged, this, | ||||
SLOT(setNetworkActive(bool))); | &RPCConsole::setNetworkActive); | ||||
updateTrafficStats(node.getTotalBytesRecv(), node.getTotalBytesSent()); | updateTrafficStats(node.getTotalBytesRecv(), node.getTotalBytesSent()); | ||||
connect(model, SIGNAL(bytesChanged(quint64, quint64)), this, | connect(model, &ClientModel::bytesChanged, this, | ||||
SLOT(updateTrafficStats(quint64, quint64))); | &RPCConsole::updateTrafficStats); | ||||
connect(model, SIGNAL(mempoolSizeChanged(long, size_t)), this, | connect(model, &ClientModel::mempoolSizeChanged, this, | ||||
SLOT(setMempoolSize(long, size_t))); | &RPCConsole::setMempoolSize); | ||||
// set up peer table | // set up peer table | ||||
ui->peerWidget->setModel(model->getPeerTableModel()); | ui->peerWidget->setModel(model->getPeerTableModel()); | ||||
ui->peerWidget->verticalHeader()->hide(); | ui->peerWidget->verticalHeader()->hide(); | ||||
ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); | ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); | ||||
ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows); | ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows); | ||||
ui->peerWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); | ui->peerWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); | ||||
ui->peerWidget->setContextMenuPolicy(Qt::CustomContextMenu); | ui->peerWidget->setContextMenuPolicy(Qt::CustomContextMenu); | ||||
Show All 27 Lines | if (model && clientModel->getPeerTableModel() && | ||||
// to use int (instead of int64_t), because signal mapper only supports | // to use int (instead of int64_t), because signal mapper only supports | ||||
// int or objects, which is okay because max bantime (1 year) is < | // int or objects, which is okay because max bantime (1 year) is < | ||||
// int_max. | // int_max. | ||||
QSignalMapper *signalMapper = new QSignalMapper(this); | QSignalMapper *signalMapper = new QSignalMapper(this); | ||||
signalMapper->setMapping(banAction1h, 60 * 60); | signalMapper->setMapping(banAction1h, 60 * 60); | ||||
signalMapper->setMapping(banAction24h, 60 * 60 * 24); | signalMapper->setMapping(banAction24h, 60 * 60 * 24); | ||||
signalMapper->setMapping(banAction7d, 60 * 60 * 24 * 7); | signalMapper->setMapping(banAction7d, 60 * 60 * 24 * 7); | ||||
signalMapper->setMapping(banAction365d, 60 * 60 * 24 * 365); | signalMapper->setMapping(banAction365d, 60 * 60 * 24 * 365); | ||||
connect(banAction1h, SIGNAL(triggered()), signalMapper, SLOT(map())); | connect(banAction1h, &QAction::triggered, signalMapper, | ||||
connect(banAction24h, SIGNAL(triggered()), signalMapper, SLOT(map())); | static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | ||||
connect(banAction7d, SIGNAL(triggered()), signalMapper, SLOT(map())); | connect(banAction24h, &QAction::triggered, signalMapper, | ||||
connect(banAction365d, SIGNAL(triggered()), signalMapper, SLOT(map())); | static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | ||||
connect(signalMapper, SIGNAL(mapped(int)), this, | connect(banAction7d, &QAction::triggered, signalMapper, | ||||
SLOT(banSelectedNode(int))); | static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | ||||
connect(banAction365d, &QAction::triggered, signalMapper, | |||||
static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | |||||
connect( | |||||
signalMapper, | |||||
static_cast<void (QSignalMapper::*)(int)>(&QSignalMapper::mapped), | |||||
this, &RPCConsole::banSelectedNode); | |||||
// peer table context menu signals | // peer table context menu signals | ||||
connect(ui->peerWidget, | connect(ui->peerWidget, &QTableView::customContextMenuRequested, this, | ||||
SIGNAL(customContextMenuRequested(const QPoint &)), this, | &RPCConsole::showPeersTableContextMenu); | ||||
SLOT(showPeersTableContextMenu(const QPoint &))); | connect(disconnectAction, &QAction::triggered, this, | ||||
connect(disconnectAction, SIGNAL(triggered()), this, | &RPCConsole::disconnectSelectedNode); | ||||
SLOT(disconnectSelectedNode())); | |||||
// peer table signal handling - update peer details when selecting new | // peer table signal handling - update peer details when selecting new | ||||
// node | // node | ||||
connect( | connect(ui->peerWidget->selectionModel(), | ||||
ui->peerWidget->selectionModel(), | &QItemSelectionModel::selectionChanged, this, | ||||
SIGNAL(selectionChanged(const QItemSelection &, | &RPCConsole::peerSelected); | ||||
const QItemSelection &)), | |||||
this, | |||||
SLOT(peerSelected(const QItemSelection &, const QItemSelection &))); | |||||
// peer table signal handling - update peer details when new nodes are | // peer table signal handling - update peer details when new nodes are | ||||
// added to the model | // added to the model | ||||
connect(model->getPeerTableModel(), SIGNAL(layoutChanged()), this, | connect(model->getPeerTableModel(), &PeerTableModel::layoutChanged, | ||||
SLOT(peerLayoutChanged())); | this, &RPCConsole::peerLayoutChanged); | ||||
// peer table signal handling - cache selected node ids | // peer table signal handling - cache selected node ids | ||||
connect(model->getPeerTableModel(), SIGNAL(layoutAboutToBeChanged()), | connect(model->getPeerTableModel(), | ||||
this, SLOT(peerLayoutAboutToChange())); | &PeerTableModel::layoutAboutToBeChanged, this, | ||||
&RPCConsole::peerLayoutAboutToChange); | |||||
// set up ban table | // set up ban table | ||||
ui->banlistWidget->setModel(model->getBanTableModel()); | ui->banlistWidget->setModel(model->getBanTableModel()); | ||||
ui->banlistWidget->verticalHeader()->hide(); | ui->banlistWidget->verticalHeader()->hide(); | ||||
ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); | ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); | ||||
ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows); | ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows); | ||||
ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection); | ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection); | ||||
ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu); | ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu); | ||||
ui->banlistWidget->setColumnWidth(BanTableModel::Address, | ui->banlistWidget->setColumnWidth(BanTableModel::Address, | ||||
BANSUBNET_COLUMN_WIDTH); | BANSUBNET_COLUMN_WIDTH); | ||||
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, | ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, | ||||
BANTIME_COLUMN_WIDTH); | BANTIME_COLUMN_WIDTH); | ||||
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true); | ui->banlistWidget->horizontalHeader()->setStretchLastSection(true); | ||||
// create ban table context menu action | // create ban table context menu action | ||||
QAction *unbanAction = new QAction(tr("&Unban"), this); | QAction *unbanAction = new QAction(tr("&Unban"), this); | ||||
// create ban table context menu | // create ban table context menu | ||||
banTableContextMenu = new QMenu(this); | banTableContextMenu = new QMenu(this); | ||||
banTableContextMenu->addAction(unbanAction); | banTableContextMenu->addAction(unbanAction); | ||||
// ban table context menu signals | // ban table context menu signals | ||||
connect(ui->banlistWidget, | connect(ui->banlistWidget, &QTableView::customContextMenuRequested, | ||||
SIGNAL(customContextMenuRequested(const QPoint &)), this, | this, &RPCConsole::showBanTableContextMenu); | ||||
SLOT(showBanTableContextMenu(const QPoint &))); | connect(unbanAction, &QAction::triggered, this, | ||||
connect(unbanAction, SIGNAL(triggered()), this, | &RPCConsole::unbanSelectedNode); | ||||
SLOT(unbanSelectedNode())); | |||||
// ban table signal handling - clear peer details when clicking a peer | // ban table signal handling - clear peer details when clicking a peer | ||||
// in the ban table | // in the ban table | ||||
connect(ui->banlistWidget, SIGNAL(clicked(const QModelIndex &)), this, | connect(ui->banlistWidget, &QTableView::clicked, this, | ||||
SLOT(clearSelectedNode())); | &RPCConsole::clearSelectedNode); | ||||
// ban table signal handling - ensure ban table is shown or hidden (if | // ban table signal handling - ensure ban table is shown or hidden (if | ||||
// empty) | // empty) | ||||
connect(model->getBanTableModel(), SIGNAL(layoutChanged()), this, | connect(model->getBanTableModel(), &BanTableModel::layoutChanged, this, | ||||
SLOT(showOrHideBanTableIfRequired())); | &RPCConsole::showOrHideBanTableIfRequired); | ||||
showOrHideBanTableIfRequired(); | showOrHideBanTableIfRequired(); | ||||
// Provide initial values | // Provide initial values | ||||
ui->clientVersion->setText(model->formatFullVersion()); | ui->clientVersion->setText(model->formatFullVersion()); | ||||
ui->clientUserAgent->setText(model->formatSubVersion()); | ui->clientUserAgent->setText(model->formatSubVersion()); | ||||
ui->dataDir->setText(model->dataDir()); | ui->dataDir->setText(model->dataDir()); | ||||
ui->blocksDir->setText(model->blocksDir()); | ui->blocksDir->setText(model->blocksDir()); | ||||
ui->startupTime->setText(model->formatClientStartupTime()); | ui->startupTime->setText(model->formatClientStartupTime()); | ||||
▲ Show 20 Lines • Show All 326 Lines • ▼ Show 20 Lines | void RPCConsole::browseHistory(int offset) { | ||||
ui->lineEdit->setText(cmd); | ui->lineEdit->setText(cmd); | ||||
} | } | ||||
void RPCConsole::startExecutor() { | void RPCConsole::startExecutor() { | ||||
RPCExecutor *executor = new RPCExecutor(m_node); | RPCExecutor *executor = new RPCExecutor(m_node); | ||||
executor->moveToThread(&thread); | executor->moveToThread(&thread); | ||||
// Replies from executor object must go to this object | // Replies from executor object must go to this object | ||||
connect(executor, SIGNAL(reply(int, QString)), this, | connect(executor, &RPCExecutor::reply, this, | ||||
SLOT(message(int, QString))); | static_cast<void (RPCConsole::*)(int, const QString &)>( | ||||
&RPCConsole::message)); | |||||
// Requests from this object must go to executor | // Requests from this object must go to executor | ||||
connect(this, SIGNAL(cmdRequest(QString, QString)), executor, | connect(this, &RPCConsole::cmdRequest, executor, &RPCExecutor::request); | ||||
SLOT(request(QString, QString))); | |||||
// On stopExecutor signal | // On stopExecutor signal | ||||
// - quit the Qt event loop in the execution thread | // - quit the Qt event loop in the execution thread | ||||
connect(this, SIGNAL(stopExecutor()), &thread, SLOT(quit())); | connect(this, &RPCConsole::stopExecutor, &thread, &QThread::quit); | ||||
// - queue executor for deletion (in execution thread) | // - queue executor for deletion (in execution thread) | ||||
connect(&thread, SIGNAL(finished()), executor, SLOT(deleteLater()), | connect(&thread, &QThread::finished, executor, &RPCExecutor::deleteLater, | ||||
Qt::DirectConnection); | Qt::DirectConnection); | ||||
// Default implementation of QThread::run() simply spins up an event loop in | // Default implementation of QThread::run() simply spins up an event loop in | ||||
// the thread, which is what we want. | // the thread, which is what we want. | ||||
thread.start(); | thread.start(); | ||||
} | } | ||||
void RPCConsole::on_tabWidget_currentChanged(int index) { | void RPCConsole::on_tabWidget_currentChanged(int index) { | ||||
▲ Show 20 Lines • Show All 309 Lines • Show Last 20 Lines |