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

View file

@ -923,7 +923,7 @@ QGroupBox {
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-51</y>
<width>506</width> <width>506</width>
<height>457</height> <height>457</height>
</rect> </rect>
@ -1349,8 +1349,8 @@ QGroupBox {
<widget class="QToolButton" name="browseFilterButton"> <widget class="QToolButton" name="browseFilterButton">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>22</width> <width>28</width>
<height>22</height> <height>27</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
@ -1358,6 +1358,28 @@ QGroupBox {
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
</item> </item>
@ -1770,7 +1792,7 @@ QGroupBox {
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-7</y> <y>0</y>
<width>581</width> <width>581</width>
<height>422</height> <height>422</height>
</rect> </rect>
@ -2154,8 +2176,8 @@ QGroupBox {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>524</width> <width>377</width>
<height>414</height> <height>229</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_23"> <layout class="QVBoxLayout" name="verticalLayout_23">
@ -2317,8 +2339,8 @@ QGroupBox {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>524</width> <width>98</width>
<height>414</height> <height>28</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_36"/> <layout class="QVBoxLayout" name="verticalLayout_36"/>

View file

@ -49,11 +49,13 @@
#include "advancedsettings.h" #include "advancedsettings.h"
#include "scannedfoldersmodel.h" #include "scannedfoldersmodel.h"
#include "qinisettings.h" #include "qinisettings.h"
#include "qbtsession.h"
using namespace libtorrent; using namespace libtorrent;
// Constructor // Constructor
options_imp::options_imp(QWidget *parent):QDialog(parent){ options_imp::options_imp(QWidget *parent):
QDialog(parent), m_refreshingIpFilter(false) {
qDebug("-> Constructing Options"); qDebug("-> Constructing Options");
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); 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_SPEED)->setIcon(misc::getIcon("chronometer"));
tabSelection->item(TAB_WEBUI)->setIcon(misc::getIcon("network-server")); tabSelection->item(TAB_WEBUI)->setIcon(misc::getIcon("network-server"));
tabSelection->item(TAB_ADVANCED)->setIcon(misc::getIcon("preferences-other")); tabSelection->item(TAB_ADVANCED)->setIcon(misc::getIcon("preferences-other"));
IpFilterRefreshBtn->setIcon(misc::getIcon("view-refresh"));
hsplitter->setCollapsible(0, false); hsplitter->setCollapsible(0, false);
hsplitter->setCollapsible(1, false); hsplitter->setCollapsible(1, false);
@ -1146,3 +1149,27 @@ void options_imp::showConnectionTab()
tabSelection->setCurrentRow(2); 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_addScanFolderButton_clicked();
void on_removeScanFolderButton_clicked(); void on_removeScanFolderButton_clicked();
void handleScanFolderViewSelectionChanged(); void handleScanFolderViewSelectionChanged();
void on_IpFilterRefreshBtn_clicked();
void handleIPFilterParsed(bool error, int ruleCount);
public slots: public slots:
void setLocale(QString locale); void setLocale(QString locale);
@ -138,6 +140,7 @@ private:
// IP Filter // IP Filter
bool isFilteringEnabled() const; bool isFilteringEnabled() const;
QString getFilter() const; QString getFilter() const;
bool m_refreshingIpFilter;
// Queueing system // Queueing system
bool isQueueingSystemEnabled() const; bool isQueueingSystemEnabled() const;
int getMaxActiveDownloads() const; int getMaxActiveDownloads() const;

View file

@ -1745,16 +1745,16 @@ void QBtSession::setDHTPort(int dht_port) {
} }
// Enable IP Filtering // Enable IP Filtering
void QBtSession::enableIPFilter(QString filter) { void QBtSession::enableIPFilter(const QString &filter_path, bool force) {
qDebug("Enabling IPFiler"); qDebug("Enabling IPFiler");
if(!filterParser) { if(!filterParser) {
filterParser = new FilterParserThread(this, s); filterParser = new FilterParserThread(this, s);
connect(filterParser.data(), SIGNAL(IPFilterParsed(int)), SLOT(handleIPFilterParsed(int))); connect(filterParser.data(), SIGNAL(IPFilterParsed(int)), SLOT(handleIPFilterParsed(int)));
connect(filterParser.data(), SIGNAL(IPFilterError()), SLOT(handleIPFilterError())); connect(filterParser.data(), SIGNAL(IPFilterError()), SLOT(handleIPFilterError()));
} }
if(filterPath.isEmpty() || filterPath != filter) { if(filterPath.isEmpty() || filterPath != filter_path || force) {
filterPath = filter; filterPath = filter_path;
filterParser->processFilterFile(filter); filterParser->processFilterFile(filter_path);
} }
} }
@ -2554,9 +2554,11 @@ qlonglong QBtSession::getETA(const QString &hash) const
void QBtSession::handleIPFilterParsed(int ruleCount) void QBtSession::handleIPFilterParsed(int ruleCount)
{ {
addConsoleMessage(tr("Successfuly parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(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() void QBtSession::handleIPFilterError()
{ {
addConsoleMessage(tr("Error: Failed to parse the provided IP filter."), "red"); 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 */ /* End Web UI */
void preAllocateAllFiles(bool b); void preAllocateAllFiles(bool b);
void saveFastResumeData(); void saveFastResumeData();
void enableIPFilter(QString filter); void enableIPFilter(const QString &filter_path, bool force=false);
void disableIPFilter(); void disableIPFilter();
void setQueueingEnabled(bool enable); void setQueueingEnabled(bool enable);
void handleDownloadFailure(QString url, QString reason); void handleDownloadFailure(QString url, QString reason);
@ -203,6 +203,7 @@ signals:
void newBanMessage(const QString &msg); void newBanMessage(const QString &msg);
void alternativeSpeedsModeChanged(bool alternative); void alternativeSpeedsModeChanged(bool alternative);
void recursiveTorrentDownloadPossible(const QTorrentHandle &h); void recursiveTorrentDownloadPossible(const QTorrentHandle &h);
void ipFilterParsed(bool error, int ruleCount);
private: private:
#if LIBTORRENT_VERSION_MINOR < 15 #if LIBTORRENT_VERSION_MINOR < 15