summaryrefslogtreecommitdiff
path: root/src/adblock/adblockmanager.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-11-25 02:14:36 +0100
committerAndrea Diamantini <adjam7@gmail.com>2009-11-25 02:14:36 +0100
commit85a0f0d8f7cf37ba74182e0f9f94e69fe8c9bf61 (patch)
tree20a4546e0fd5e98612d7f1ac6ce3c34a4e7d2f13 /src/adblock/adblockmanager.cpp
parentLast history fixes (diff)
downloadrekonq-85a0f0d8f7cf37ba74182e0f9f94e69fe8c9bf61.tar.xz
Moving (back?) to konqueror adblock support.
This will be useful (if someone is interested) in pushing our patches directly on khtml filter engine.
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r--src/adblock/adblockmanager.cpp59
1 files changed, 25 insertions, 34 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index 70960b44..a0bc4e00 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -43,6 +43,7 @@
AdBlockManager::AdBlockManager(QObject *parent)
: QObject(parent)
, _isAdblockEnabled(false)
+ , _isHideAdsEnabled(false)
{
loadSettings();
}
@@ -55,24 +56,31 @@ AdBlockManager::~AdBlockManager()
void AdBlockManager::loadSettings()
{
- _blockList.clear();
-
- KSharedConfig::Ptr config = KSharedConfig::openConfig("webkitrc", KConfig::NoGlobals);
- KConfigGroup cg(config, "adblock");
-
- _isAdblockEnabled = cg.readEntry("Enabled", false);
+ KSharedConfig::Ptr config = KSharedConfig::openConfig("khtmlrc", KConfig::NoGlobals);
+ KConfigGroup cg( config, "Filter Settings" );
- int num = cg.readEntry("Count", 0);
- for (int i = 0; i < num; ++i)
+ if ( cg.exists() )
{
- QString key = "Filter-" + QString::number(i);
- QString filter = cg.readEntry( key, QString() );
- if(!filter.isEmpty())
+ _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 )
{
- if (filter.startsWith(QLatin1String("@@")))
- _whiteList << filter;
- else
- _blockList << filter;
+ QString name = it.key();
+ QString url = it.value();
+
+ if (name.startsWith(QLatin1String("Filter")))
+ {
+ if (url.startsWith(QLatin1String("@@")))
+ _adWhiteList.addFilter(url);
+ else
+ _adBlackList.addFilter(url);
+ }
}
}
}
@@ -80,28 +88,11 @@ void AdBlockManager::loadSettings()
bool AdBlockManager::isUrlAllowed(const QUrl &url)
{
- kDebug() << "matching rule...";
if (!_isAdblockEnabled)
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;
+ // Check the blacklist, and only if that matches, the whitelist
+ return _adBlackList.isUrlMatched(urlString) && !_adWhiteList.isUrlMatched(urlString);
}