diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 381f8e3..3611302 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1406,13 +1406,13 @@ QString peer2ip(QString peer) { void MainWindow::setupPeersTab() { qDebug() << __FUNCTION__; - // Set up context menu on transactions tab + // Set up context menu on peers tab ui->peersTable->setContextMenuPolicy(Qt::CustomContextMenu); ui->bannedPeersTable->setContextMenuPolicy(Qt::CustomContextMenu); // Table right click QObject::connect(ui->bannedPeersTable, &QTableView::customContextMenuRequested, [=] (QPoint pos) { - QModelIndex index = ui->peersTable->indexAt(pos); + QModelIndex index = ui->bannedPeersTable->indexAt(pos); if (index.row() < 0) return; QMenu menu(this); @@ -1440,6 +1440,16 @@ void MainWindow::setupPeersTab() { }); } + if(!ip.isEmpty()) { + menu.addAction(tr("Unban this peer"), [=] () { + rpc->setban(ip, "remove", [=] (QJsonValue response){ + qDebug() << "setban remove " << response; + ui->statusBar->showMessage(tr("Peer unbanned"), 3 * 1000); + rpc->refreshPeers(); + }); + }); + } + menu.exec(ui->bannedPeersTable->viewport()->mapToGlobal(pos)); }); @@ -1495,6 +1505,14 @@ void MainWindow::setupPeersTab() { }); } + menu.addAction(tr("Ban this peer"), [=] () { + rpc->setban(ip, "add", [=] (QJsonValue response){ + qDebug() << "setban add " << response; + ui->statusBar->showMessage(tr("Peer banned"), 3 * 1000); + rpc->refreshPeers(); + }); + }); + menu.exec(ui->peersTable->viewport()->mapToGlobal(pos)); }); diff --git a/src/rpc.h b/src/rpc.h index 952c3ac..80b9aa3 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -66,7 +66,8 @@ public: void refresh(bool force = false); void refreshAddresses(); - void refreshPeers(); + void refreshPeers(); + void setban(QString ip, QString command, const std::function& cb); void checkForUpdate(bool silent = true); void refreshPrice(); @@ -143,7 +144,6 @@ private: void z_sweepstatus (const std::function& cb); void z_consolidationstatus (const std::function& cb); void rescan (qint64 height, const std::function& cb); - void setban (QString ip, QString command, const std::function& cb); Connection* conn = nullptr; std::shared_ptr ehushd = nullptr;