aboutsummaryrefslogtreecommitdiff
path: root/src/qt/rpcconsole.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <jonas.schnelli@include7.ch>2015-06-20 20:55:21 +0200
committerJonas Schnelli <jonas.schnelli@include7.ch>2015-09-16 16:50:19 +0200
commit770ca79aa02964f56610ffaf15b16297634fa065 (patch)
tree27b549b178f6499bf2e0e45b6fa8e7111f039b86 /src/qt/rpcconsole.cpp
parent5f421329508d6e86c410282c7de39d7e80b0b289 (diff)
[Qt] add context menu with unban option to ban table
Diffstat (limited to 'src/qt/rpcconsole.cpp')
-rw-r--r--src/qt/rpcconsole.cpp65
1 files changed, 52 insertions, 13 deletions
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index c6e70697fb..5658cf8752 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();