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. 262
      src/options_imp.cpp
  3. 2
      src/options_imp.h

350
src/options.ui

@ -22,16 +22,7 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" > <property name="margin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number> <number>9</number>
</property> </property>
<item> <item>
@ -83,11 +74,20 @@
<enum>Qt::ElideLeft</enum> <enum>Qt::ElideLeft</enum>
</property> </property>
<widget class="QWidget" name="tab" > <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" > <attribute name="title" >
<string>General</string> <string>General</string>
</attribute> </attribute>
<attribute name="icon" > <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> </attribute>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
@ -120,7 +120,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -189,7 +189,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -250,7 +250,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -318,7 +318,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>623</width> <width>623</width>
<height>20</height> <height>20</height>
@ -329,11 +329,20 @@
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_5" > <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" > <attribute name="title" >
<string>Downloads</string> <string>Downloads</string>
</attribute> </attribute>
<attribute name="icon" > <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> </attribute>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
@ -360,16 +369,7 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" > <property name="margin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -377,16 +377,7 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" > <property name="margin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -473,16 +464,7 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" > <property name="margin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -490,16 +472,7 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" > <property name="margin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -580,7 +553,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -623,7 +596,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -639,11 +612,20 @@
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_3" > <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" > <attribute name="title" >
<string>Connection</string> <string>Connection</string>
</attribute> </attribute>
<attribute name="icon" > <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> </attribute>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
@ -706,7 +688,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>20</width> <width>20</width>
<height>20</height> <height>20</height>
@ -954,7 +936,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>21</width> <width>21</width>
<height>29</height> <height>29</height>
@ -1043,7 +1025,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1145,11 +1127,20 @@
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_6" > <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" > <attribute name="title" >
<string>Bittorrent</string> <string>Bittorrent</string>
</attribute> </attribute>
<attribute name="icon" > <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> </attribute>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
@ -1196,7 +1187,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1241,7 +1232,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1283,7 +1274,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1365,7 +1356,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1428,7 +1419,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1482,7 +1473,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1500,7 +1491,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>20</width> <width>20</width>
<height>40</height> <height>40</height>
@ -1511,11 +1502,20 @@
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_4" > <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" > <attribute name="title" >
<string>Misc</string> <string>Misc</string>
</attribute> </attribute>
<attribute name="icon" > <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> </attribute>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
@ -1526,170 +1526,20 @@
<property name="title" > <property name="title" >
<string>Filter Settings</string> <string>Filter Settings</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" name="verticalLayout" >
<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>
<item> <item>
<widget class="QCheckBox" name="checkIPFilter" > <widget class="QCheckBox" name="checkIPFilter" >
<property name="text" > <property name="text" >
<string>Activate IP Filtering</string> <string>Activate IP Filtering</string>
</property> </property>
<property name="icon" > <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> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTreeWidget" name="filtersList" > <layout class="QHBoxLayout" name="horizontalLayout" >
<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>
<item> <item>
<widget class="QLabel" name="lblFilterPath" > <widget class="QLabel" name="lblFilterPath" >
<property name="enabled" > <property name="enabled" >
@ -1791,7 +1641,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1825,7 +1675,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
@ -1842,14 +1692,36 @@
</layout> </layout>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_2" > <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" > <attribute name="title" >
<string>Web UI</string> <string>Web UI</string>
</attribute> </attribute>
<attribute name="icon" > <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> </attribute>
<layout class="QVBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
@ -1902,7 +1774,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>21</width> <width>21</width>
<height>29</height> <height>29</height>
@ -1987,7 +1859,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>198</width> <width>198</width>
<height>57</height> <height>57</height>
@ -2003,7 +1875,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0" >
<size> <size>
<width>623</width> <width>623</width>
<height>41</height> <height>41</height>
@ -2020,16 +1892,7 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin" > <property name="margin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -2038,7 +1901,7 @@
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="standardButtons" > <property name="standardButtons" >
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
<property name="centerButtons" > <property name="centerButtons" >
<bool>true</bool> <bool>true</bool>
@ -2104,9 +1967,6 @@
<tabstop>checkRatioRemove</tabstop> <tabstop>checkRatioRemove</tabstop>
<tabstop>spinMaxRatio</tabstop> <tabstop>spinMaxRatio</tabstop>
<tabstop>checkIPFilter</tabstop> <tabstop>checkIPFilter</tabstop>
<tabstop>filtersList</tabstop>
<tabstop>addFilterRangeButton</tabstop>
<tabstop>delFilterRangeButton</tabstop>
<tabstop>textFilterPath</tabstop> <tabstop>textFilterPath</tabstop>
<tabstop>browseFilterButton</tabstop> <tabstop>browseFilterButton</tabstop>
<tabstop>spinRSSRefresh</tabstop> <tabstop>spinRSSRefresh</tabstop>

262
src/options_imp.cpp

@ -200,8 +200,6 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){
connect(spinMaxRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinMaxRatio, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
// Misc tab // Misc tab
connect(checkIPFilter, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); 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(textFilterPath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinRSSRefresh, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinRSSRefresh, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
connect(spinRSSMaxArticlesPerFeed, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton())); connect(spinRSSMaxArticlesPerFeed, SIGNAL(valueChanged(QString)), this, SLOT(enableApplyButton()));
@ -845,17 +843,11 @@ void options_imp::enableMaxUploadsLimitPerTorrent(int checkBoxValue){
void options_imp::enableFilter(int checkBoxValue){ void options_imp::enableFilter(int checkBoxValue){
if(checkBoxValue!=2){ if(checkBoxValue!=2){
//Disable //Disable
filtersList->setEnabled(false);
addFilterRangeButton->setEnabled(false);
delFilterRangeButton->setEnabled(false);
lblFilterPath->setEnabled(false); lblFilterPath->setEnabled(false);
textFilterPath->setEnabled(false); textFilterPath->setEnabled(false);
browseFilterButton->setEnabled(false); browseFilterButton->setEnabled(false);
}else{ }else{
//enable //enable
filtersList->setEnabled(true);
addFilterRangeButton->setEnabled(true);
delFilterRangeButton->setEnabled(true);
lblFilterPath->setEnabled(true); lblFilterPath->setEnabled(true);
textFilterPath->setEnabled(true); textFilterPath->setEnabled(true);
browseFilterButton->setEnabled(true); browseFilterButton->setEnabled(true);
@ -1060,114 +1052,74 @@ void options_imp::on_browseSaveDirButton_clicked(){
} }
} }
// look for ipfilter.dat file // Process ip filter file
// reads emule ipfilter files. // Supported formats:
// with the following format: // * eMule IP list (DAT): http://wiki.phoenixlabs.org/wiki/DAT_Format
// // * PeerGuardian Text (P2P): http://wiki.phoenixlabs.org/wiki/P2P_Format (TODO)
// <first-ip> - <last-ip> , <access> , <comment> // * PeerGuardian Binary (P2B): http://wiki.phoenixlabs.org/wiki/P2B_Format (TODO)
//
// 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 '//'
void options_imp::processFilterFile(QString filePath){ void options_imp::processFilterFile(QString filePath){
qDebug("Processing filter files"); qDebug("Processing filter files");
filtersList->clear(); QFile file(filePath);
QString manualFilters= misc::qBittorrentPath() + QString::fromUtf8("ipfilter.dat"); QStringList IP;
QStringList filterFiles(manualFilters); if (file.exists()){
filterFiles.append(filePath); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
for(int i=0; i<2; ++i){ QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("Couldn't open %1 in read mode.").arg(filePath));
QFile file(filterFiles.at(i)); return;
QStringList IP; }
if (file.exists()){ unsigned int nbLine = 0;
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ while (!file.atEnd()) {
QMessageBox::critical(0, tr("I/O Error", "Input/Output Error"), tr("Couldn't open %1 in read mode.").arg(filePath)); ++nbLine;
QByteArray line = file.readLine();
if(line.startsWith('#') || line.startsWith("//")) continue;
// Line is not commented
QList<QByteArray> partsList = line.split(',');
unsigned int nbElem = partsList.size();
if(nbElem < 2){
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
continue; continue;
} }
unsigned int nbLine = 0; bool ok;
while (!file.atEnd()) { int nbAccess = partsList.at(1).trimmed().toInt(&ok);
++nbLine; if(!ok){
QByteArray line = file.readLine(); qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
if(line.startsWith('#') || line.startsWith("//")) continue; continue;
// Line is not commented }
QList<QByteArray> partsList = line.split(','); if(nbAccess <= 127){
unsigned int nbElem = partsList.size(); QString strComment;
if(nbElem < 2){ QString strStartIP = partsList.at(0).split('-').at(0).trimmed();
qDebug("Ipfilter.dat: line %d is malformed.", nbLine); QString strEndIP = partsList.at(0).split('-').at(1).trimmed();
continue; if(nbElem > 2){
} strComment = partsList.at(2).trimmed();
bool ok; }else{
int nbAccess = partsList.at(1).trimmed().toInt(&ok); strComment = QString();
if(!ok){
qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
continue;
} }
if(nbAccess <= 127){ // Split IP
QString strComment; QRegExp is_ipv6(QString::fromUtf8("^[0-9a-f]{4}(:[0-9a-f]{4}){7}$"), Qt::CaseInsensitive, QRegExp::RegExp);
QString strStartIP = partsList.at(0).split('-').at(0).trimmed(); 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);
QString strEndIP = partsList.at(0).split('-').at(1).trimmed();
if(nbElem > 2){ if(strStartIP.contains(is_ipv4) && strEndIP.contains(is_ipv4)) {
strComment = partsList.at(2).trimmed(); // IPv4
}else{ IP = strStartIP.split('.');
strComment = QString(); 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('.');
// Split IP address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt());
// Apply to bittorrent session
QRegExp is_ipv6(QString::fromUtf8("^[0-9a-f]{4}(:[0-9a-f]{4}){7}$"), Qt::CaseInsensitive, QRegExp::RegExp); filter.add_rule(start, last, ip_filter::blocked);
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); } else if(strStartIP.contains(is_ipv6) && strEndIP.contains(is_ipv6)) {
// IPv6, ex : 1fff:0000:0a88:85a3:0000:0000:ac1f:8001
if(strStartIP.contains(is_ipv4) && strEndIP.contains(is_ipv4)) { IP = strStartIP.split(':');
// IPv4 address_v6 start = address_v6::from_string(strStartIP.remove(':', 0).toUtf8().data());
IP = strStartIP.split('.'); IP = strEndIP.split(':');
address_v4 start((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt()); address_v6 last = address_v6::from_string(strEndIP.remove(':', 0).toUtf8().data());
IP = strEndIP.split('.'); // Apply to bittorrent session
address_v4 last((IP.at(0).toInt() << 24) + (IP.at(1).toInt() << 16) + (IP.at(2).toInt() << 8) + IP.at(3).toInt()); filter.add_rule(start, last, ip_filter::blocked);
} else {
// add it to list qDebug("Ipfilter.dat: line %d is malformed.", nbLine);
QStringList item(QString::fromUtf8(start.to_string().c_str())); continue;
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)) {
// IPv6, ex : 1fff:0000:0a88:85a3:0000:0000:ac1f:8001
IP = strStartIP.split(':');
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();
} }
file.close();
} }
} }
@ -1176,100 +1128,6 @@ ip_filter options_imp::getFilter() const{
return filter; 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 // Web UI
void options_imp::enableWebUi(bool checkBoxValue){ void options_imp::enableWebUi(bool checkBoxValue){

2
src/options_imp.h

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

Loading…
Cancel
Save