Browse Source

- Removed IP filter list and buttons to add/remove ranges, I don't think

people handle this manually anyway.
- Prepare code for P2P/P2B filter files (soon to be coded)
adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
f6210d5857
  1. 350
      src/options.ui
  2. 156
      src/options_imp.cpp
  3. 2
      src/options_imp.h

350
src/options.ui

@ -22,16 +22,7 @@ @@ -22,16 +22,7 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>9</number>
</property>
<item>
@ -83,11 +74,20 @@ @@ -83,11 +74,20 @@
<enum>Qt::ElideLeft</enum>
</property>
<widget class="QWidget" name="tab" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>457</height>
</rect>
</property>
<attribute name="title" >
<string>General</string>
</attribute>
<attribute name="icon" >
<iconset resource="icons.qrc" >:/Icons/star.png</iconset>
<iconset resource="icons.qrc" >
<normaloff>:/Icons/star.png</normaloff>:/Icons/star.png</iconset>
</attribute>
<layout class="QVBoxLayout" >
<item>
@ -120,7 +120,7 @@ @@ -120,7 +120,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -189,7 +189,7 @@ @@ -189,7 +189,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -250,7 +250,7 @@ @@ -250,7 +250,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -318,7 +318,7 @@ @@ -318,7 +318,7 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>623</width>
<height>20</height>
@ -329,11 +329,20 @@ @@ -329,11 +329,20 @@
</layout>
</widget>
<widget class="QWidget" name="tab_5" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>457</height>
</rect>
</property>
<attribute name="title" >
<string>Downloads</string>
</attribute>
<attribute name="icon" >
<iconset resource="icons.qrc" >:/Icons/download.png</iconset>
<iconset resource="icons.qrc" >
<normaloff>:/Icons/download.png</normaloff>:/Icons/download.png</iconset>
</attribute>
<layout class="QVBoxLayout" >
<item>
@ -360,16 +369,7 @@ @@ -360,16 +369,7 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -377,16 +377,7 @@ @@ -377,16 +377,7 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -473,16 +464,7 @@ @@ -473,16 +464,7 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -490,16 +472,7 @@ @@ -490,16 +472,7 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -580,7 +553,7 @@ @@ -580,7 +553,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -623,7 +596,7 @@ @@ -623,7 +596,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -639,11 +612,20 @@ @@ -639,11 +612,20 @@
</layout>
</widget>
<widget class="QWidget" name="tab_3" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>457</height>
</rect>
</property>
<attribute name="title" >
<string>Connection</string>
</attribute>
<attribute name="icon" >
<iconset resource="icons.qrc" >:/Icons/connection.png</iconset>
<iconset resource="icons.qrc" >
<normaloff>:/Icons/connection.png</normaloff>:/Icons/connection.png</iconset>
</attribute>
<layout class="QVBoxLayout" >
<item>
@ -706,7 +688,7 @@ @@ -706,7 +688,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>20</height>
@ -954,7 +936,7 @@ @@ -954,7 +936,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>21</width>
<height>29</height>
@ -1043,7 +1025,7 @@ @@ -1043,7 +1025,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1145,11 +1127,20 @@ @@ -1145,11 +1127,20 @@
</layout>
</widget>
<widget class="QWidget" name="tab_6" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>457</height>
</rect>
</property>
<attribute name="title" >
<string>Bittorrent</string>
</attribute>
<attribute name="icon" >
<iconset resource="icons.qrc" >:/Icons/bt_settings.png</iconset>
<iconset resource="icons.qrc" >
<normaloff>:/Icons/bt_settings.png</normaloff>:/Icons/bt_settings.png</iconset>
</attribute>
<layout class="QVBoxLayout" >
<item>
@ -1196,7 +1187,7 @@ @@ -1196,7 +1187,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1241,7 +1232,7 @@ @@ -1241,7 +1232,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1283,7 +1274,7 @@ @@ -1283,7 +1274,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1365,7 +1356,7 @@ @@ -1365,7 +1356,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1428,7 +1419,7 @@ @@ -1428,7 +1419,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1482,7 +1473,7 @@ @@ -1482,7 +1473,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1500,7 +1491,7 @@ @@ -1500,7 +1491,7 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>40</height>
@ -1511,11 +1502,20 @@ @@ -1511,11 +1502,20 @@
</layout>
</widget>
<widget class="QWidget" name="tab_4" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>457</height>
</rect>
</property>
<attribute name="title" >
<string>Misc</string>
</attribute>
<attribute name="icon" >
<iconset resource="icons.qrc" >:/Icons/configure.png</iconset>
<iconset resource="icons.qrc" >
<normaloff>:/Icons/configure.png</normaloff>:/Icons/configure.png</iconset>
</attribute>
<layout class="QVBoxLayout" >
<item>
@ -1526,170 +1526,20 @@ @@ -1526,170 +1526,20 @@
<property name="title" >
<string>Filter Settings</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QCheckBox" name="checkIPFilter" >
<property name="text" >
<string>Activate IP Filtering</string>
</property>
<property name="icon" >
<iconset resource="icons.qrc" >:/Icons/filter.png</iconset>
<iconset resource="icons.qrc" >
<normaloff>:/Icons/filter.png</normaloff>:/Icons/filter.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="filtersList" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
<height>171</height>
</size>
</property>
<property name="font" >
<font>
<family>Sans Serif</family>
<pointsize>8</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
<underline>false</underline>
<strikeout>false</strikeout>
</font>
</property>
<property name="selectionMode" >
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="itemsExpandable" >
<bool>false</bool>
</property>
<column>
<property name="text" >
<string>Start IP</string>
</property>
</column>
<column>
<property name="text" >
<string>End IP</string>
</property>
</column>
<column>
<property name="text" >
<string>Origin</string>
</property>
</column>
<column>
<property name="text" >
<string>Comment</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="addFilterRangeButton" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string> Add Range</string>
</property>
<property name="icon" >
<iconset resource="icons.qrc" >:/Icons/skin/add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="delFilterRangeButton" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="text" >
<string> Remove Range</string>
</property>
<property name="icon" >
<iconset resource="icons.qrc" >:/Icons/skin/remove.png</iconset>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<widget class="QLabel" name="lblFilterPath" >
<property name="enabled" >
@ -1791,7 +1641,7 @@ @@ -1791,7 +1641,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1825,7 +1675,7 @@ @@ -1825,7 +1675,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@ -1842,14 +1692,36 @@ @@ -1842,14 +1692,36 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>457</height>
</rect>
</property>
<attribute name="title" >
<string>Web UI</string>
</attribute>
<attribute name="icon" >
<iconset resource="icons.qrc" >:/Icons/password.png</iconset>
<iconset resource="icons.qrc" >
<normaloff>:/Icons/password.png</normaloff>:/Icons/password.png</iconset>
</attribute>
<layout class="QVBoxLayout" >
<item>
@ -1902,7 +1774,7 @@ @@ -1902,7 +1774,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>21</width>
<height>29</height>
@ -1987,7 +1859,7 @@ @@ -1987,7 +1859,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>198</width>
<height>57</height>
@ -2003,7 +1875,7 @@ @@ -2003,7 +1875,7 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>623</width>
<height>41</height>
@ -2020,16 +1892,7 @@ @@ -2020,16 +1892,7 @@
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<property name="margin" >
<number>0</number>
</property>
<item>
@ -2038,7 +1901,7 @@ @@ -2038,7 +1901,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons" >
<bool>true</bool>
@ -2104,9 +1967,6 @@ @@ -2104,9 +1967,6 @@
<tabstop>checkRatioRemove</tabstop>
<tabstop>spinMaxRatio</tabstop>
<tabstop>checkIPFilter</tabstop>
<tabstop>filtersList</tabstop>
<tabstop>addFilterRangeButton</tabstop>
<tabstop>delFilterRangeButton</tabstop>
<tabstop>textFilterPath</tabstop>
<tabstop>browseFilterButton</tabstop>
<tabstop>spinRSSRefresh</tabstop>

156
src/options_imp.cpp

@ -200,8 +200,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ @@ -200,8 +200,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
connect(spinMaxRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
// Misc tab
connect(checkIPFilter, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
connect(addFilterRangeButton, SIGNAL(clicked()), this, SLOT(enableApplyButton()));
connect(delFilterRangeButton, SIGNAL(clicked()), this, SLOT(enableApplyButton()));
connect(textFilterPath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinRSSRefresh, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinRSSMaxArticlesPerFeed, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
@ -845,17 +843,11 @@ void options_imp::enableMaxUploadsLimitPerTorrent(int checkBoxValue){ @@ -845,17 +843,11 @@ void options_imp::enableMaxUploadsLimitPerTorrent(int checkBoxValue){
void options_imp::enableFilter(int checkBoxValue){
if(checkBoxValue!=2){
//Disable
filtersList->setEnabled(false);
addFilterRangeButton->setEnabled(false);
delFilterRangeButton->setEnabled(false);
lblFilterPath->setEnabled(false);
textFilterPath->setEnabled(false);
browseFilterButton->setEnabled(false);
}else{
//enable
filtersList->setEnabled(true);
addFilterRangeButton->setEnabled(true);
delFilterRangeButton->setEnabled(true);
lblFilterPath->setEnabled(true);
textFilterPath->setEnabled(true);
browseFilterButton->setEnabled(true);
@ -1060,34 +1052,19 @@ void options_imp::on_browseSaveDirButton_clicked(){ @@ -1060,34 +1052,19 @@ void options_imp::on_browseSaveDirButton_clicked(){
}
}
// look for ipfilter.dat file
// reads emule ipfilter files.
// with the following format:
//
// <first-ip> - <last-ip> , <access> , <comment>
//
// first-ip is an ip address that defines the first
// address of the range
// last-ip is the last ip address in the range
// access is a number specifying the access control
// for this ip-range. Right now values > 127 = allowed
// and numbers <= 127 = blocked
// the rest of the line is ignored
//
// Lines may be commented using '#' or '//'
// Process ip filter file
// Supported formats:
// * eMule IP list (DAT): http://wiki.phoenixlabs.org/wiki/DAT_Format
// * PeerGuardian Text (P2P): http://wiki.phoenixlabs.org/wiki/P2P_Format (TODO)
// * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format (TODO)
void options_imp::processFilterFile(QString filePath){
qDebug("Processing filter files");
filtersList->clear();
QString manualFilters= misc::qBittorrentPath() + QString::fromUtf8("ipfilter.dat");
QStringList filterFiles(manualFilters);
filterFiles.append(filePath);
for(int i=0; i<2; ++i){
QFile file(filterFiles.at(i));
QFile file(filePath);
QStringList IP;
if (file.exists()){
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("Couldn't open %1 in read mode.").arg(filePath));
continue;
return;
}
unsigned int nbLine = 0;
while (!file.atEnd()) {
@ -1117,7 +1094,6 @@ void options_imp::processFilterFile(QString filePath){ @@ -1117,7 +1094,6 @@ void options_imp::processFilterFile(QString filePath){
strComment = QString();
}
// Split IP
QRegExp is_ipv6(QString::fromUtf8("^[0-9a-f]{4}(:[0-9a-f]{4}){7}$"), Qt::CaseInsensitive, QRegExp::RegExp);
QRegExp is_ipv4(QString::fromUtf8("^(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}$"), Qt::CaseInsensitive, QRegExp::RegExp);
@ -1127,17 +1103,6 @@ void options_imp::processFilterFile(QString filePath){ @@ -1127,17 +1103,6 @@ void options_imp::processFilterFile(QString filePath){
address_v4 start((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
IP = strEndIP.split('.');
address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
// add it to list
QStringList item(QString::fromUtf8(start.to_string().c_str()));
item.append(QString::fromUtf8(last.to_string().c_str()));
if(!i){
item.append(QString::fromUtf8("Manual"));
}else{
item.append(QString::fromUtf8("ipfilter.dat"));
}
item.append(strComment);
new QTreeWidgetItem(filtersList, item);
// Apply to bittorrent session
filter.add_rule(start, last, ip_filter::blocked);
} else if(strStartIP.contains(is_ipv6) && strEndIP.contains(is_ipv6)) {
@ -1146,29 +1111,16 @@ void options_imp::processFilterFile(QString filePath){ @@ -1146,29 +1111,16 @@ void options_imp::processFilterFile(QString filePath){
address_v6 start = address_v6::from_string(strStartIP.remove(':', 0).toUtf8().data());
IP = strEndIP.split(':');
address_v6 last = address_v6::from_string(strEndIP.remove(':', 0).toUtf8().data());
// add it to list
QStringList item(QString::fromUtf8(start.to_string().c_str()));
item.append(QString::fromUtf8(last.to_string().c_str()));
if(!i){
item.append(QString::fromUtf8("Manual"));
}else{
item.append(QString::fromUtf8("ipfilter.dat"));
}
item.append(strComment);
new QTreeWidgetItem(filtersList, item);
// Apply to bittorrent session
filter.add_rule(start, last, ip_filter::blocked);
} else {
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
continue;
}
}
}
file.close();
}
}
}
// Return Filter object to apply to BT session
@ -1176,100 +1128,6 @@ ip_filter options_imp::getFilter() const{ @@ -1176,100 +1128,6 @@ ip_filter options_imp::getFilter() const{
return filter;
}
// Add an IP Range to ipFilter
void options_imp::on_addFilterRangeButton_clicked(){
bool ok;
// Ask user for start ip
QString startIP = QInputDialog::getText(this, tr("Range Start IP"),
tr("Start IP:"), QLineEdit::Normal,
QString::fromUtf8("0.0.0.0"), &ok);
QStringList IP1 = startIP.split('.');
// Check IP
bool ipv4 = true;
QRegExp is_ipv6(QString::fromUtf8("^[0-9a-f]{4}(:[0-9a-f]{4}){7}$"), Qt::CaseInsensitive, QRegExp::RegExp);
QRegExp is_ipv4(QString::fromUtf8("^(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}$"), Qt::CaseInsensitive, QRegExp::RegExp);
if(!ok) {
return;
} else if(startIP.isEmpty()
|| (!startIP.contains(is_ipv4) && !startIP.contains(is_ipv6))){
QMessageBox::critical(0, tr("Invalid IP"), tr("This IP is invalid."));
return;
} else if(startIP.contains(is_ipv4)) {
ipv4 = true;
} else if(startIP.contains(is_ipv6)) {
ipv4 = false;
}
// Ask user for last ip
QString lastIP = QInputDialog::getText(this, tr("Range End IP"),
tr("End IP:"), QLineEdit::Normal,
startIP, &ok);
// check IP
if (!ok) {
return;
} else if(lastIP.isEmpty()
|| (!lastIP.contains(is_ipv4) && !lastIP.contains(is_ipv6))
|| (ipv4 == true && !lastIP.contains(is_ipv4))
|| (ipv4 == false && !lastIP.contains(is_ipv6))){
QMessageBox::critical(0, tr("Invalid IP"), tr("This IP is invalid."));
return;
}
// Ask user for Comment
QString comment = QInputDialog::getText(this, tr("IP Range Comment"),
tr("Comment:"), QLineEdit::Normal,
QString::fromUtf8(""), &ok);
if (!ok){
comment = QString::fromUtf8("");
return;
}
QFile ipfilter(misc::qBittorrentPath() + QString::fromUtf8("ipfilter.dat"));
if (!ipfilter.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text)){
std::cerr << "Error: Couldn't write in ipfilter.dat";
return;
}
QTextStream out(&ipfilter);
out << startIP << " - " << lastIP << ", 0, " << comment << "\n";
ipfilter.close();
processFilterFile(textFilterPath->text());
enableApplyButton();
}
// Delete selected IP range in list and ipfilter.dat file
// User can only delete IP added manually
void options_imp::on_delFilterRangeButton_clicked(){
bool changed = false;
QList<QTreeWidgetItem *> selectedItems = filtersList->selectedItems();
// Delete from list
for(int i=0; i<selectedItems.size(); ++i) {
QTreeWidgetItem *item = selectedItems.at(i);
if(item->text(2) == QString::fromUtf8("Manual")){
delete item;
changed = true;
}
if(changed){
enableApplyButton();
}
}
// Update ipfilter.dat
QFile ipfilter(misc::qBittorrentPath() + QString::fromUtf8("ipfilter.dat"));
if (!ipfilter.open(QIODevice::WriteOnly | QIODevice::Text)){
std::cerr << "Error: Couldn't write in ipfilter.dat";
return;
}
QTextStream out(&ipfilter);
for(int i=0; i<filtersList->topLevelItemCount();++i){
QTreeWidgetItem *item = filtersList->topLevelItem(i);
if(item->text(2) == QString::fromUtf8("Manual")){
out << item->text(0) << " - " << item->text(1) << ", 0, " << item->text(3) << "\n";
}
}
ipfilter.close();
}
// Web UI
void options_imp::enableWebUi(bool checkBoxValue){

2
src/options_imp.h

@ -133,8 +133,6 @@ class options_imp : public QDialog, private Ui::Dialog { @@ -133,8 +133,6 @@ class options_imp : public QDialog, private Ui::Dialog {
void closeEvent(QCloseEvent *e);
void on_buttonBox_rejected();
void applySettings(QAbstractButton* button);
void on_addFilterRangeButton_clicked();
void on_delFilterRangeButton_clicked();
void on_browseScanDirButton_clicked();
void on_browseFilterButton_clicked();
void on_browseSaveDirButton_clicked();

Loading…
Cancel
Save