Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.1 KiB
121 lines
4.1 KiB
8 years ago
|
/*
|
||
|
* Bittorrent Client using Qt and libtorrent.
|
||
|
* Copyright (C) 2016 Alexandr Milovantsev <dzmat@yandex.ru>
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License
|
||
|
* as published by the Free Software Foundation; either version 2
|
||
|
* of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
* In addition, as a special exception, the copyright holders give permission to
|
||
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
||
|
* and distribute the linked executables. You must obey the GNU General Public
|
||
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
||
|
* modify file(s), you may extend this exception to your version of the file(s),
|
||
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||
|
* exception statement from your version.
|
||
|
*/
|
||
|
|
||
7 years ago
|
#include "banlistoptionsdialog.h"
|
||
8 years ago
|
|
||
|
#include <QHostAddress>
|
||
7 years ago
|
#include <QMessageBox>
|
||
8 years ago
|
#include <QSortFilterProxyModel>
|
||
|
#include <QStringListModel>
|
||
8 years ago
|
|
||
|
#include "base/bittorrent/session.h"
|
||
|
#include "base/utils/net.h"
|
||
7 years ago
|
#include "ui_banlistoptionsdialog.h"
|
||
7 years ago
|
#include "utils.h"
|
||
8 years ago
|
|
||
7 years ago
|
BanListOptionsDialog::BanListOptionsDialog(QWidget *parent)
|
||
8 years ago
|
: QDialog(parent)
|
||
7 years ago
|
, m_ui(new Ui::BanListOptionsDialog)
|
||
8 years ago
|
, m_modified(false)
|
||
|
{
|
||
|
m_ui->setupUi(this);
|
||
8 years ago
|
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);
|
||
8 years ago
|
m_ui->buttonBanIP->setEnabled(false);
|
||
7 years ago
|
|
||
|
Utils::Gui::resize(this);
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
BanListOptionsDialog::~BanListOptionsDialog()
|
||
8 years ago
|
{
|
||
|
delete m_ui;
|
||
|
}
|
||
|
|
||
7 years ago
|
void BanListOptionsDialog::on_buttonBox_accepted()
|
||
8 years ago
|
{
|
||
|
if (m_modified) {
|
||
|
// save to session
|
||
|
QStringList IPList;
|
||
8 years ago
|
// Operate on the m_sortFilter to grab the strings in sorted order
|
||
|
for (int i = 0; i < m_sortFilter->rowCount(); ++i) {
|
||
|
QModelIndex index = m_sortFilter->index(i, 0);
|
||
|
IPList << index.data().toString();
|
||
|
}
|
||
8 years ago
|
BitTorrent::Session::instance()->setBannedIPs(IPList);
|
||
7 years ago
|
QDialog::accept();
|
||
|
}
|
||
|
else {
|
||
|
QDialog::reject();
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
void BanListOptionsDialog::on_buttonBanIP_clicked()
|
||
8 years ago
|
{
|
||
8 years ago
|
QString ip = m_ui->txtIP->text();
|
||
8 years ago
|
if (!Utils::Net::isValidIP(ip)) {
|
||
|
QMessageBox::warning(this, tr("Warning"), tr("The entered IP address is invalid."));
|
||
|
return;
|
||
|
}
|
||
|
// the same IPv6 addresses could be written in different forms;
|
||
|
// QHostAddress::toString() result format follows RFC5952;
|
||
|
// thus we avoid duplicate entries pointing to the same address
|
||
|
ip = QHostAddress(ip).toString();
|
||
8 years ago
|
for (int i = 0; i < m_sortFilter->rowCount(); ++i) {
|
||
|
QModelIndex index = m_sortFilter->index(i, 0);
|
||
|
if (ip == index.data().toString()) {
|
||
|
QMessageBox::warning(this, tr("Warning"), tr("The entered IP is already banned."));
|
||
|
return;
|
||
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
m_model->insertRow(m_model->rowCount());
|
||
|
m_model->setData(m_model->index(m_model->rowCount() - 1, 0), ip);
|
||
8 years ago
|
m_ui->txtIP->clear();
|
||
|
m_modified = true;
|
||
|
}
|
||
|
|
||
7 years ago
|
void BanListOptionsDialog::on_buttonDeleteIP_clicked()
|
||
8 years ago
|
{
|
||
8 years ago
|
QModelIndexList selection = m_ui->bannedIPList->selectionModel()->selectedIndexes();
|
||
|
for (auto &i : selection)
|
||
|
m_sortFilter->removeRow(i.row());
|
||
|
|
||
8 years ago
|
m_modified = true;
|
||
|
}
|
||
|
|
||
7 years ago
|
void BanListOptionsDialog::on_txtIP_textChanged(const QString &ip)
|
||
8 years ago
|
{
|
||
|
m_ui->buttonBanIP->setEnabled(Utils::Net::isValidIP(ip));
|
||
|
}
|