[Qt] add context menu with unban option to ban table
This commit is contained in:
parent
5f42132950
commit
770ca79aa0
2 changed files with 59 additions and 15 deletions
|
@ -241,8 +241,9 @@ RPCConsole::RPCConsole(const PlatformStyle *platformStyle, QWidget *parent) :
|
||||||
clientModel(0),
|
clientModel(0),
|
||||||
historyPtr(0),
|
historyPtr(0),
|
||||||
cachedNodeid(-1),
|
cachedNodeid(-1),
|
||||||
contextMenu(0),
|
|
||||||
platformStyle(platformStyle)
|
platformStyle(platformStyle)
|
||||||
|
peersTableContextMenu(0),
|
||||||
|
banTableContextMenu(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), 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::Address, ADDRESS_COLUMN_WIDTH);
|
||||||
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
|
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
|
||||||
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
|
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
|
||||||
|
ui->peerWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||||
// set up ban table
|
|
||||||
ui->banlistWidget->setModel(model->getBanTableModel());
|
|
||||||
|
|
||||||
// create context menu actions
|
// create context menu actions
|
||||||
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
|
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);
|
QAction* banAction365d = new QAction(tr("&Ban Node for 1 year"), this);
|
||||||
|
|
||||||
// create context menu
|
// create context menu
|
||||||
contextMenu = new QMenu();
|
peersTableContextMenu = new QMenu();
|
||||||
contextMenu->addAction(disconnectAction);
|
peersTableContextMenu->addAction(disconnectAction);
|
||||||
contextMenu->addAction(banAction1h);
|
peersTableContextMenu->addAction(banAction1h);
|
||||||
contextMenu->addAction(banAction24h);
|
peersTableContextMenu->addAction(banAction24h);
|
||||||
contextMenu->addAction(banAction7d);
|
peersTableContextMenu->addAction(banAction7d);
|
||||||
contextMenu->addAction(banAction365d);
|
peersTableContextMenu->addAction(banAction365d);
|
||||||
|
|
||||||
// context menu signals
|
// 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()));
|
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
|
//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 &)));
|
this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &)));
|
||||||
connect(model->getPeerTableModel(), SIGNAL(layoutChanged()), this, SLOT(peerLayoutChanged()));
|
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
|
// Provide initial values
|
||||||
ui->clientVersion->setText(model->formatFullVersion());
|
ui->clientVersion->setText(model->formatFullVersion());
|
||||||
ui->clientUserAgent->setText(model->formatSubVersion());
|
ui->clientUserAgent->setText(model->formatSubVersion());
|
||||||
|
@ -744,11 +763,18 @@ void RPCConsole::hideEvent(QHideEvent *event)
|
||||||
clientModel->getPeerTableModel()->stopAutoRefresh();
|
clientModel->getPeerTableModel()->stopAutoRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RPCConsole::showMenu(const QPoint& point)
|
void RPCConsole::showPeersTableContextMenu(const QPoint& point)
|
||||||
{
|
{
|
||||||
QModelIndex index = ui->peerWidget->indexAt(point);
|
QModelIndex index = ui->peerWidget->indexAt(point);
|
||||||
if (index.isValid())
|
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()
|
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()
|
void RPCConsole::clearSelectedNode()
|
||||||
{
|
{
|
||||||
ui->peerWidget->selectionModel()->clearSelection();
|
ui->peerWidget->selectionModel()->clearSelection();
|
||||||
|
|
|
@ -61,7 +61,9 @@ private Q_SLOTS:
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
void hideEvent(QHideEvent *event);
|
void hideEvent(QHideEvent *event);
|
||||||
/** Show custom context menu on Peers tab */
|
/** 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:
|
public Q_SLOTS:
|
||||||
void clear();
|
void clear();
|
||||||
|
@ -82,6 +84,8 @@ public Q_SLOTS:
|
||||||
void disconnectSelectedNode();
|
void disconnectSelectedNode();
|
||||||
/** Ban a selected node on the Peers tab */
|
/** Ban a selected node on the Peers tab */
|
||||||
void banSelectedNode(int bantime);
|
void banSelectedNode(int bantime);
|
||||||
|
/** Unban a selected node on the Bans tab */
|
||||||
|
void unbanSelectedNode();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
// For RPC command executor
|
// For RPC command executor
|
||||||
|
@ -109,9 +113,10 @@ private:
|
||||||
QStringList history;
|
QStringList history;
|
||||||
int historyPtr;
|
int historyPtr;
|
||||||
NodeId cachedNodeid;
|
NodeId cachedNodeid;
|
||||||
QMenu *contextMenu;
|
|
||||||
const PlatformStyle *platformStyle;
|
const PlatformStyle *platformStyle;
|
||||||
RPCTimerInterface *rpcTimerInterface;
|
RPCTimerInterface *rpcTimerInterface;
|
||||||
|
QMenu *peersTableContextMenu;
|
||||||
|
QMenu *banTableContextMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_QT_RPCCONSOLE_H
|
#endif // BITCOIN_QT_RPCCONSOLE_H
|
||||||
|
|
Loading…
Reference in a new issue