mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
Use a QTreeView and a sort proxy in the manually banned IP list to have a consistent sort order with QStringList::sor().
This commit is contained in:
parent
431658bee6
commit
b90db12ba0
3 changed files with 47 additions and 15 deletions
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/utils/net.h"
|
#include "base/utils/net.h"
|
||||||
|
@ -41,7 +43,14 @@ BanListOptions::BanListOptions(QWidget *parent)
|
||||||
, m_modified(false)
|
, m_modified(false)
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
m_ui->bannedIPList->addItems(BitTorrent::Session::instance()->bannedIPs());
|
m_model = new QStringListModel(BitTorrent::Session::instance()->bannedIPs(), this);
|
||||||
|
|
||||||
|
m_sortFilter = new QSortFilterProxyModel(this);
|
||||||
|
m_sortFilter->setDynamicSortFilter(true);
|
||||||
|
m_sortFilter->setSourceModel(m_model);
|
||||||
|
|
||||||
|
m_ui->bannedIPList->setModel(m_sortFilter);
|
||||||
|
m_ui->bannedIPList->sortByColumn(0, Qt::AscendingOrder);
|
||||||
m_ui->buttonBanIP->setEnabled(false);
|
m_ui->buttonBanIP->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +64,11 @@ void BanListOptions::on_buttonBox_accepted()
|
||||||
if (m_modified) {
|
if (m_modified) {
|
||||||
// save to session
|
// save to session
|
||||||
QStringList IPList;
|
QStringList IPList;
|
||||||
for (int i = 0; i < m_ui->bannedIPList->count(); ++i)
|
// Operate on the m_sortFilter to grab the strings in sorted order
|
||||||
IPList << m_ui->bannedIPList->item(i)->text();
|
for (int i = 0; i < m_sortFilter->rowCount(); ++i) {
|
||||||
|
QModelIndex index = m_sortFilter->index(i, 0);
|
||||||
|
IPList << index.data().toString();
|
||||||
|
}
|
||||||
BitTorrent::Session::instance()->setBannedIPs(IPList);
|
BitTorrent::Session::instance()->setBannedIPs(IPList);
|
||||||
}
|
}
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
|
@ -64,7 +76,7 @@ void BanListOptions::on_buttonBox_accepted()
|
||||||
|
|
||||||
void BanListOptions::on_buttonBanIP_clicked()
|
void BanListOptions::on_buttonBanIP_clicked()
|
||||||
{
|
{
|
||||||
QString ip=m_ui->txtIP->text();
|
QString ip = m_ui->txtIP->text();
|
||||||
if (!Utils::Net::isValidIP(ip)) {
|
if (!Utils::Net::isValidIP(ip)) {
|
||||||
QMessageBox::warning(this, tr("Warning"), tr("The entered IP address is invalid."));
|
QMessageBox::warning(this, tr("Warning"), tr("The entered IP address is invalid."));
|
||||||
return;
|
return;
|
||||||
|
@ -73,23 +85,26 @@ void BanListOptions::on_buttonBanIP_clicked()
|
||||||
// QHostAddress::toString() result format follows RFC5952;
|
// QHostAddress::toString() result format follows RFC5952;
|
||||||
// thus we avoid duplicate entries pointing to the same address
|
// thus we avoid duplicate entries pointing to the same address
|
||||||
ip = QHostAddress(ip).toString();
|
ip = QHostAddress(ip).toString();
|
||||||
QList<QListWidgetItem *> findres = m_ui->bannedIPList->findItems(ip, Qt::MatchExactly);
|
for (int i = 0; i < m_sortFilter->rowCount(); ++i) {
|
||||||
if (!findres.isEmpty()) {
|
QModelIndex index = m_sortFilter->index(i, 0);
|
||||||
QMessageBox::warning(this, tr("Warning"), tr("The entered IP is already banned."));
|
if (ip == index.data().toString()) {
|
||||||
return;
|
QMessageBox::warning(this, tr("Warning"), tr("The entered IP is already banned."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_ui->bannedIPList->addItem(ip);
|
|
||||||
|
m_model->insertRow(m_model->rowCount());
|
||||||
|
m_model->setData(m_model->index(m_model->rowCount() - 1, 0), ip);
|
||||||
m_ui->txtIP->clear();
|
m_ui->txtIP->clear();
|
||||||
m_modified = true;
|
m_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BanListOptions::on_buttonDeleteIP_clicked()
|
void BanListOptions::on_buttonDeleteIP_clicked()
|
||||||
{
|
{
|
||||||
QList<QListWidgetItem *> selection = m_ui->bannedIPList->selectedItems();
|
QModelIndexList selection = m_ui->bannedIPList->selectionModel()->selectedIndexes();
|
||||||
for (auto &i : selection) {
|
for (auto &i : selection)
|
||||||
m_ui->bannedIPList->removeItemWidget(i);
|
m_sortFilter->removeRow(i.row());
|
||||||
delete i;
|
|
||||||
}
|
|
||||||
m_modified = true;
|
m_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
class QSortFilterProxyModel;
|
||||||
|
class QStringListModel;
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class BanListOptions;
|
class BanListOptions;
|
||||||
|
@ -52,6 +55,8 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::BanListOptions *m_ui;
|
Ui::BanListOptions *m_ui;
|
||||||
|
QStringListModel *m_model;
|
||||||
|
QSortFilterProxyModel *m_sortFilter;
|
||||||
bool m_modified;
|
bool m_modified;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,16 +42,28 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_21">
|
<layout class="QVBoxLayout" name="verticalLayout_21">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="bannedIPList">
|
<widget class="QTreeView" name="bannedIPList">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="rootIsDecorated">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="uniformRowHeights">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="itemsExpandable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="sortingEnabled">
|
<property name="sortingEnabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<attribute name="headerVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue