FEATURE: Added a button to reload the IP filter

This commit is contained in:
Christophe Dumez 2010-12-25 14:47:52 +00:00
parent af63ba9a8d
commit b060f967d7
6 changed files with 70 additions and 14 deletions

View file

@ -6,6 +6,7 @@
- FEATURE: Display pieces size in torrent properties
- FEATURE: Added "Time Active/Seeded" column to transfer list
- FEATURE: Give feedback regarding the IP filter parsing
- FEATURE: Added a button to reload the IP filter
- COSMETIC: Same deletion confirmation dialog in the GUI and Web UI
- COSMETIC: Simplified the top toolbar
- COSMETIC: Display execution log as a tab instead of a modal window

View file

@ -923,7 +923,7 @@ QGroupBox {
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-51</y>
<width>506</width>
<height>457</height>
</rect>
@ -1349,8 +1349,8 @@ QGroupBox {
<widget class="QToolButton" name="browseFilterButton">
<property name="minimumSize">
<size>
<width>22</width>
<height>22</height>
<width>28</width>
<height>27</height>
</size>
</property>
<property name="text">
@ -1358,6 +1358,28 @@ QGroupBox {
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QToolButton" name="IpFilterRefreshBtn">
<property name="minimumSize">
<size>
<width>28</width>
<height>27</height>
</size>
</property>
<property name="toolTip">
<string>Reload the filter</string>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -1770,7 +1792,7 @@ QGroupBox {
<property name="geometry">
<rect>
<x>0</x>
<y>-7</y>
<y>0</y>
<width>581</width>
<height>422</height>
</rect>
@ -2154,8 +2176,8 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>414</height>
<width>377</width>
<height>229</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
@ -2317,8 +2339,8 @@ QGroupBox {
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>414</height>
<width>98</width>
<height>28</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_36"/>

View file

@ -49,11 +49,13 @@
#include "advancedsettings.h"
#include "scannedfoldersmodel.h"
#include "qinisettings.h"
#include "qbtsession.h"
using namespace libtorrent;
// Constructor
options_imp::options_imp(QWidget *parent):QDialog(parent){
options_imp::options_imp(QWidget *parent):
QDialog(parent), m_refreshingIpFilter(false) {
qDebug("-> Constructing Options");
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
@ -66,6 +68,7 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
tabSelection->item(TAB_SPEED)->setIcon(misc::getIcon("chronometer"));
tabSelection->item(TAB_WEBUI)->setIcon(misc::getIcon("network-server"));
tabSelection->item(TAB_ADVANCED)->setIcon(misc::getIcon("preferences-other"));
IpFilterRefreshBtn->setIcon(misc::getIcon("view-refresh"));
hsplitter->setCollapsible(0, false);
hsplitter->setCollapsible(1, false);
@ -1146,3 +1149,27 @@ void options_imp::showConnectionTab()
tabSelection->setCurrentRow(2);
}
void options_imp::on_IpFilterRefreshBtn_clicked() {
if(m_refreshingIpFilter) return;
m_refreshingIpFilter = true;
// Updating program preferences
Preferences pref;
pref.setFilteringEnabled(true);
pref.setFilter(getFilter());
// Force refresh
connect(QBtSession::instance(), SIGNAL(ipFilterParsed(bool, int)), SLOT(handleIPFilterParsed(bool, int)));
setCursor(QCursor(Qt::WaitCursor));
QBtSession::instance()->enableIPFilter(getFilter(), true);
}
void options_imp::handleIPFilterParsed(bool error, int ruleCount)
{
setCursor(QCursor(Qt::ArrowCursor));
if(error) {
QMessageBox::warning(this, tr("Parsing error"), tr("Failed to parse the provided IP filter"));
} else {
QMessageBox::information(this, tr("Succesfully refreshed"), tr("Successfuly parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount));
}
m_refreshingIpFilter = false;
disconnect(QBtSession::instance(), SIGNAL(ipFilterParsed(bool, int)), this, SLOT(handleIPFilterParsed(bool, int)));
}

View file

@ -80,6 +80,8 @@ protected slots:
void on_addScanFolderButton_clicked();
void on_removeScanFolderButton_clicked();
void handleScanFolderViewSelectionChanged();
void on_IpFilterRefreshBtn_clicked();
void handleIPFilterParsed(bool error, int ruleCount);
public slots:
void setLocale(QString locale);
@ -138,6 +140,7 @@ private:
// IP Filter
bool isFilteringEnabled() const;
QString getFilter() const;
bool m_refreshingIpFilter;
// Queueing system
bool isQueueingSystemEnabled() const;
int getMaxActiveDownloads() const;

View file

@ -1745,16 +1745,16 @@ void QBtSession::setDHTPort(int dht_port) {
}
// Enable IP Filtering
void QBtSession::enableIPFilter(QString filter) {
void QBtSession::enableIPFilter(const QString &filter_path, bool force) {
qDebug("Enabling IPFiler");
if(!filterParser) {
filterParser = new FilterParserThread(this, s);
connect(filterParser.data(), SIGNAL(IPFilterParsed(int)), SLOT(handleIPFilterParsed(int)));
connect(filterParser.data(), SIGNAL(IPFilterError()), SLOT(handleIPFilterError()));
}
if(filterPath.isEmpty() || filterPath != filter) {
filterPath = filter;
filterParser->processFilterFile(filter);
if(filterPath.isEmpty() || filterPath != filter_path || force) {
filterPath = filter_path;
filterParser->processFilterFile(filter_path);
}
}
@ -2554,9 +2554,11 @@ qlonglong QBtSession::getETA(const QString &hash) const
void QBtSession::handleIPFilterParsed(int ruleCount)
{
addConsoleMessage(tr("Successfuly parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount));
emit ipFilterParsed(false, ruleCount);
}
void QBtSession::handleIPFilterError()
{
addConsoleMessage(tr("Error: Failed to parse the provided IP filter."), "red");
emit ipFilterParsed(true, 0);
}

View file

@ -117,7 +117,7 @@ public slots:
/* End Web UI */
void preAllocateAllFiles(bool b);
void saveFastResumeData();
void enableIPFilter(QString filter);
void enableIPFilter(const QString &filter_path, bool force=false);
void disableIPFilter();
void setQueueingEnabled(bool enable);
void handleDownloadFailure(QString url, QString reason);
@ -203,6 +203,7 @@ signals:
void newBanMessage(const QString &msg);
void alternativeSpeedsModeChanged(bool alternative);
void recursiveTorrentDownloadPossible(const QTorrentHandle &h);
void ipFilterParsed(bool error, int ruleCount);
private:
#if LIBTORRENT_VERSION_MINOR < 15