diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index c6e70697fb2..5658cf87526 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -241,8 +241,9 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) : clientModel(0), historyPtr(0), cachedNodeid(-1), - contextMenu(0), platformStyle(platformStyle) + peersTableContextMenu(0), + banTableContextMenu(0) { ui->setupUi(this); GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this); @@ -351,9 +352,7 @@ void RPCConsole::setClientModel(ClientModel *model) ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH); ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH); ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH); - - // set up ban table - ui->banlistWidget->setModel(model->getBanTableModel()); + ui->peerWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); // create context menu actions QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this); @@ -363,15 +362,15 @@ void RPCConsole::setClientModel(ClientModel *model) QAction* banAction365d = new QAction(tr("&Ban Node for 1 year"), this); // create context menu - contextMenu = new QMenu(); - contextMenu->addAction(disconnectAction); - contextMenu->addAction(banAction1h); - contextMenu->addAction(banAction24h); - contextMenu->addAction(banAction7d); - contextMenu->addAction(banAction365d); + peersTableContextMenu = new QMenu(); + peersTableContextMenu->addAction(disconnectAction); + peersTableContextMenu->addAction(banAction1h); + peersTableContextMenu->addAction(banAction24h); + peersTableContextMenu->addAction(banAction7d); + peersTableContextMenu->addAction(banAction365d); // context menu signals - connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&))); + connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPeersTableContextMenu(const QPoint&))); connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode())); //add a signal mapping, use int instead of int64_t for bantime because signalmapper only supports int or objects @@ -392,6 +391,26 @@ void RPCConsole::setClientModel(ClientModel *model) this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &))); connect(model->getPeerTableModel(), SIGNAL(layoutChanged()), this, SLOT(peerLayoutChanged())); + // set up ban table + ui->banlistWidget->setModel(model->getBanTableModel()); + ui->banlistWidget->verticalHeader()->hide(); + ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui->banlistWidget->setColumnWidth(BanTableModel::Address, ADDRESS_COLUMN_WIDTH); + ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, PING_COLUMN_WIDTH); + ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection); + ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu); + ui->banlistWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + + // create context menu actions + QAction* unbanAction = new QAction(tr("&Unban Node"), this); + banTableContextMenu = new QMenu(); + banTableContextMenu->addAction(unbanAction); + + // context menu signals + connect(ui->banlistWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showBanTableContextMenu(const QPoint&))); + connect(unbanAction, SIGNAL(triggered()), this, SLOT(unbanSelectedNode())); + // Provide initial values ui->clientVersion->setText(model->formatFullVersion()); ui->clientUserAgent->setText(model->formatSubVersion()); @@ -744,11 +763,18 @@ void RPCConsole::hideEvent(QHideEvent *event) clientModel->getPeerTableModel()->stopAutoRefresh(); } -void RPCConsole::showMenu(const QPoint& point) +void RPCConsole::showPeersTableContextMenu(const QPoint& point) { QModelIndex index = ui->peerWidget->indexAt(point); if (index.isValid()) - contextMenu->exec(QCursor::pos()); + peersTableContextMenu->exec(QCursor::pos()); +} + +void RPCConsole::showBanTableContextMenu(const QPoint& point) +{ + QModelIndex index = ui->banlistWidget->indexAt(point); + if (index.isValid()) + banTableContextMenu->exec(QCursor::pos()); } void RPCConsole::disconnectSelectedNode() @@ -782,6 +808,19 @@ void RPCConsole::banSelectedNode(int bantime) } } +void RPCConsole::unbanSelectedNode() +{ + // Get currently selected peer address + QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address); + CSubNet possibleSubnet(strNode.toStdString()); + + if (possibleSubnet.IsValid()) + { + CNode::Unban(possibleSubnet); + clientModel->updateBanlist(); + } +} + void RPCConsole::clearSelectedNode() { ui->peerWidget->selectionModel()->clearSelection(); diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index 3218a635d7a..db1f3d433dd 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -61,7 +61,9 @@ private Q_SLOTS: void showEvent(QShowEvent *event); void hideEvent(QHideEvent *event); /** Show custom context menu on Peers tab */ - void showMenu(const QPoint& point); + void showPeersTableContextMenu(const QPoint& point); + /** Show custom context menu on Bans tab */ + void showBanTableContextMenu(const QPoint& point); public Q_SLOTS: void clear(); @@ -82,6 +84,8 @@ public Q_SLOTS: void disconnectSelectedNode(); /** Ban a selected node on the Peers tab */ void banSelectedNode(int bantime); + /** Unban a selected node on the Bans tab */ + void unbanSelectedNode(); Q_SIGNALS: // For RPC command executor @@ -109,9 +113,10 @@ private: QStringList history; int historyPtr; NodeId cachedNodeid; - QMenu *contextMenu; const PlatformStyle *platformStyle; RPCTimerInterface *rpcTimerInterface; + QMenu *peersTableContextMenu; + QMenu *banTableContextMenu; }; #endif // BITCOIN_QT_RPCCONSOLE_H