diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2009-11-23 01:25:17 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2009-11-23 01:25:17 +0100 |
commit | ae723ad13075808d687ad1b14f46f4a8cae87849 (patch) | |
tree | 0638fccb68de55749e33abf3f5512a35b61e096a /src/adblock | |
parent | Ok, same other bits on the adblock manager. (diff) | |
download | rekonq-ae723ad13075808d687ad1b14f46f4a8cae87849.tar.xz |
First adblock implementation. now rekonq seems... slower :(
But at least it's ads free!
Diffstat (limited to 'src/adblock')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 65 | ||||
-rw-r--r-- | src/adblock/adblockmanager.h | 3 |
2 files changed, 53 insertions, 15 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 6b2f9616..70960b44 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -27,6 +27,16 @@ #include "adblockmanager.h" #include "adblockmanager.moc" + +// Local Includes +#include "adblockrule.h" + +// KDE Includes +#include <KSharedConfig> +#include <KConfigGroup> +#include <KDebug> + +// Qt Includes #include <QUrl> @@ -45,26 +55,53 @@ AdBlockManager::~AdBlockManager() void AdBlockManager::loadSettings() { -// KConfigGroup cg(_config, _group); -// groupBox->setChecked( cg.readEntry("Enabled", false) ); -// -// int num = cg.readEntry("Count", 0); -// for (int i = 0; i < num; ++i) -// { -// QString key = "Filter-" + QString::number(i); -// QString filter = cg.readEntry( key, QString() ); -// listWidget->addItem(filter); -// } + _blockList.clear(); + + KSharedConfig::Ptr config = KSharedConfig::openConfig("webkitrc", KConfig::NoGlobals); + KConfigGroup cg(config, "adblock"); + + _isAdblockEnabled = cg.readEntry("Enabled", false); + + int num = cg.readEntry("Count", 0); + for (int i = 0; i < num; ++i) + { + QString key = "Filter-" + QString::number(i); + QString filter = cg.readEntry( key, QString() ); + if(!filter.isEmpty()) + { + if (filter.startsWith(QLatin1String("@@"))) + _whiteList << filter; + else + _blockList << filter; + } + } } bool AdBlockManager::isUrlAllowed(const QUrl &url) { - if (url.scheme() == QLatin1String("data")) - return false; - + kDebug() << "matching rule..."; if (!_isAdblockEnabled) - return false; + return true; + QString urlString = QString::fromUtf8(url.toEncoded()); + + foreach(const QString &str, _whiteList) + { + AdBlockRule rule(str); + kDebug() << "checking white list rule..."; + if(rule.match(urlString)) + return true; + } + + foreach(const QString &str, _blockList) + { + AdBlockRule rule(str); + kDebug() << "checking block list rule..."; + if(rule.match(urlString)) + return false; + } + + kDebug() << "done"; return true; } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index c782ee0d..a175fa2f 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -50,7 +50,8 @@ public: private: bool _isAdblockEnabled; - QStringList _blocks; + QStringList _blockList; + QStringList _whiteList; }; #endif |