summaryrefslogtreecommitdiff
path: root/src/adblock/adblockmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r--src/adblock/adblockmanager.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index b25edcb1..209c2ab0 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,56 @@ 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);
+
+ filterList.clear();
+
+ // no need to load filters if adblock is not enabled :)
+ if(!_isAdblockEnabled)
+ return;
+
+ 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")))
+ {
+ AdBlockRule filter(url);
+ filterList << filter;
+ }
+ }
+ }
}
-bool AdBlockManager::isUrlAllowed(const QUrl &url)
+QNetworkReply *AdBlockManager::block(const QNetworkRequest &request)
{
- return true;
+ if (!_isAdblockEnabled)
+ return 0;
+
+ // we (ad)block just http traffic
+ if(request.url().scheme() != QLatin1String("http"))
+ return 0;
+
+ QString urlString = request.url().toString();
+
+ foreach(const AdBlockRule &filter, filterList)
+ {
+ if(filter.match(urlString))
+ {
+ kDebug() << "****ADBLOCK: Matched: ***********" << urlString;
+ AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this);
+ return reply;
+ }
+ }
+ return 0;
}