From b17c8b84d1b491bbd84d7f9b827b94fa00ead011 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 17 May 2008 17:11:01 +0000 Subject: [PATCH] - Prepare code for p2p ip filter support --- src/options_imp.cpp | 35 +++++++++++++++++++++++++++-------- src/options_imp.h | 2 ++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/options_imp.cpp b/src/options_imp.cpp index 84d43cd88..0fc75d59b 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -1037,7 +1037,7 @@ void options_imp::on_browseScanDirButton_clicked() { } void options_imp::on_browseFilterButton_clicked() { - QString ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ipfilter.dat file"), QDir::homePath()); + QString ipfilter = QFileDialog::getOpenFileName(this, tr("Choose an ip filter file"), QDir::homePath(), tr("Filters (*.dat *.p2p *.p2b)")); if(!ipfilter.isNull()){ textFilterPath->setText(ipfilter); processFilterFile(ipfilter); @@ -1052,13 +1052,8 @@ void options_imp::on_browseSaveDirButton_clicked(){ } } -// 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"); +// Parser for eMule ip filter in DAT format +void options_imp::parseDATFilterFile(QString filePath) { QFile file(filePath); QStringList IP; if (file.exists()){ @@ -1123,6 +1118,30 @@ void options_imp::processFilterFile(QString filePath){ } } +// Parser for PeerGuardian ip filter in p2p format +void options_imp::parseP2PFilterFile(QString filePath) { + std::cerr << "p2p file support was not implemented yet\n"; +} + +// 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"); + if(filePath.endsWith(".dat", Qt::CaseInsensitive)) { + // eMule DAT file + parseDATFilterFile(filePath); + } else { + if(filePath.endsWith(".p2p", Qt::CaseInsensitive)) { + // PeerGuardian p2p file + parseP2PFilterFile(filePath); + } + // TODO: Add p2b support + } +} + // Return Filter object to apply to BT session ip_filter options_imp::getFilter() const{ return filter; diff --git a/src/options_imp.h b/src/options_imp.h index 31046805f..6be471c40 100644 --- a/src/options_imp.h +++ b/src/options_imp.h @@ -143,6 +143,8 @@ class options_imp : public QDialog, private Ui::Dialog { void disableSystrayOptions(); void setSystrayOptionsState(int checkBoxValue); void enableWebUi(bool checkBoxValue); + void parseDATFilterFile(QString filePath); + void parseP2PFilterFile(QString filePath); public slots: void setLocale(QString locale);