summaryrefslogtreecommitdiff
path: root/src/adblock/adblockmanager.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-11-30 10:26:43 +0100
committerAndrea Diamantini <adjam7@gmail.com>2009-11-30 10:26:43 +0100
commit88bde6fd1e73f30a9bdb1da5fd4bd24aeb84266b (patch)
treed002a585d5a889c5e5df8ea8ab83ec8a04e2e59a /src/adblock/adblockmanager.cpp
parentRestored QWebElementCollection (diff)
downloadrekonq-88bde6fd1e73f30a9bdb1da5fd4bd24aeb84266b.tar.xz
Porting rekonq to last Qt/KDE API
adblock (KDE one) fix #1
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r--src/adblock/adblockmanager.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index b25edcb1..987c793f 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -24,9 +24,12 @@
* ============================================================ */
+// Self Includes
#include "adblockmanager.h"
#include "adblockmanager.moc"
+// Local Includes
+#include "adblocknetworkreply.h"
// KDE Includes
#include <KSharedConfig>
@@ -53,10 +56,48 @@ AdBlockManager::~AdBlockManager()
void AdBlockManager::loadSettings()
{
+ KSharedConfig::Ptr config = KSharedConfig::openConfig("khtmlrc", KConfig::NoGlobals);
+ KConfigGroup cg( config, "Filter Settings" );
+
+ if ( cg.exists() )
+ {
+ _isAdblockEnabled = cg.readEntry("Enabled", false);
+ _isHideAdsEnabled = cg.readEntry("Shrink", false);
+
+ _adBlackList.clear();
+ _adWhiteList.clear();
+
+ QMap<QString,QString> entryMap = cg.entryMap();
+ QMap<QString,QString>::ConstIterator it;
+ for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
+ {
+ QString name = it.key();
+ QString url = it.value();
+
+ if (name.startsWith(QLatin1String("Filter")))
+ {
+ if (url.startsWith(QLatin1String("@@")))
+ _adWhiteList.addFilter(url);
+ else
+ _adBlackList.addFilter(url);
+ }
+ }
+ }
}
-bool AdBlockManager::isUrlAllowed(const QUrl &url)
+QNetworkReply *AdBlockManager::block(const QNetworkRequest &request)
{
- return true;
+ if (!_isAdblockEnabled)
+ return 0;
+
+ QString urlString = request.url().toString();
+
+ // Check the blacklist, and only if that matches, the whitelist
+ if(_adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString))
+ {
+ AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this);
+ return reply;
+ }
+ return 0;
}