Browse Source

Merge pull request #13390 from NotTsunami/ban

Prevent peers from being lost when banning
adaptive-webui-19844
Vladimir Golovnev 4 years ago committed by GitHub
parent
commit
e41ae1457e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/gui/properties/peerlistwidget.cpp

20
src/gui/properties/peerlistwidget.cpp

@ -41,6 +41,7 @@
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QTableView> #include <QTableView>
#include <QVector>
#include <QWheelEvent> #include <QWheelEvent>
#include "base/bittorrent/peeraddress.h" #include "base/bittorrent/peeraddress.h"
@ -291,15 +292,24 @@ void PeerListWidget::showPeerListMenu(const QPoint &)
void PeerListWidget::banSelectedPeers() void PeerListWidget::banSelectedPeers()
{ {
// Confirm first // Store selected rows first as selected peers may disconnect
const QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Ban peer permanently")
, tr("Are you sure you want to permanently ban the selected peers?"));
if (btn != QMessageBox::Yes) return;
const QModelIndexList selectedIndexes = selectionModel()->selectedRows(); const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QVector<QString> selectedIPs;
selectedIPs.reserve(selectedIndexes.size());
for (const QModelIndex &index : selectedIndexes) { for (const QModelIndex &index : selectedIndexes) {
const int row = m_proxyModel->mapToSource(index).row(); const int row = m_proxyModel->mapToSource(index).row();
const QString ip = m_listModel->item(row, PeerListColumns::IP_HIDDEN)->text(); const QString ip = m_listModel->item(row, PeerListColumns::IP_HIDDEN)->text();
selectedIPs += ip;
}
// Confirm before banning peer
const QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Ban peer permanently")
, tr("Are you sure you want to permanently ban the selected peers?"));
if (btn != QMessageBox::Yes) return;
for (const QString &ip : selectedIPs) {
BitTorrent::Session::instance()->banIP(ip); BitTorrent::Session::instance()->banIP(ip);
LogMsg(tr("Peer \"%1\" is manually banned").arg(ip)); LogMsg(tr("Peer \"%1\" is manually banned").arg(ip));
} }

Loading…
Cancel
Save