mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-06 11:54:18 +00:00
Prevent peers from being lost when banning
The selected rows aren't queried until after a user confirms they would like to ban the selected peers. If a peer disconnects before the confirmation is pressed, they will not be included in the selection. This commit makes sure the selected rows are stored before a selection is made to prevent the loss of any peers. Closes #13385.
This commit is contained in:
parent
79bc4f40e8
commit
8d64d38914
@ -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 QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||||
|
|
||||||
|
QVector<QString> selectedIPs;
|
||||||
|
selectedIPs.reserve(selectedIndexes.size());
|
||||||
|
|
||||||
|
for (const QModelIndex &index : selectedIndexes) {
|
||||||
|
const int row = m_proxyModel->mapToSource(index).row();
|
||||||
|
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")
|
const QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Ban peer permanently")
|
||||||
, tr("Are you sure you want to permanently ban the selected peers?"));
|
, tr("Are you sure you want to permanently ban the selected peers?"));
|
||||||
if (btn != QMessageBox::Yes) return;
|
if (btn != QMessageBox::Yes) return;
|
||||||
|
|
||||||
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
for (const QString &ip : selectedIPs) {
|
||||||
for (const QModelIndex &index : selectedIndexes) {
|
|
||||||
const int row = m_proxyModel->mapToSource(index).row();
|
|
||||||
const QString ip = m_listModel->item(row, PeerListColumns::IP_HIDDEN)->text();
|
|
||||||
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…
x
Reference in New Issue
Block a user