summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-11-08 17:19:52 +0100
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:06 +0100
commit5d2d1c86ae51a7d17fb3e9906dbc6d5f563f19a9 (patch)
tree4388ca2cf2bb6a85a5a158acfe06a8f5c39724c9 /src
parentadblock work (diff)
downloadrekonq-5d2d1c86ae51a7d17fb3e9906dbc6d5f563f19a9.tar.xz
Clean up previous commit about adblock and fix enable/disable feature
Diffstat (limited to 'src')
-rw-r--r--src/adblock/adblockhostmatcher.cpp7
-rw-r--r--src/adblock/adblockhostmatcher.h2
-rw-r--r--src/adblock/adblockmanager.cpp53
-rw-r--r--src/adblock/adblockmanager.h1
-rw-r--r--src/rekonq.kcfg3
-rw-r--r--src/urlbar/adblockwidget.cpp36
-rw-r--r--src/urlbar/bookmarkwidget.cpp2
-rw-r--r--src/urlbar/urlbar.cpp5
8 files changed, 42 insertions, 67 deletions
diff --git a/src/adblock/adblockhostmatcher.cpp b/src/adblock/adblockhostmatcher.cpp
index 5033c6f7..60936ec0 100644
--- a/src/adblock/adblockhostmatcher.cpp
+++ b/src/adblock/adblockhostmatcher.cpp
@@ -80,10 +80,3 @@ bool AdBlockHostMatcher::tryAddFilter(const QString &filter)
return false;
}
-
-
-void AdBlockHostMatcher::remove(const QString &hostRule)
-{
- bool on = m_hostList.remove(hostRule);
- kDebug() << "REMOVED? " << on;
-}
diff --git a/src/adblock/adblockhostmatcher.h b/src/adblock/adblockhostmatcher.h
index 3ce6e284..79918239 100644
--- a/src/adblock/adblockhostmatcher.h
+++ b/src/adblock/adblockhostmatcher.h
@@ -48,8 +48,6 @@ public:
{
m_hostList.clear();
}
-
- void remove(const QString &hostRule);
private:
QSet<QString> m_hostList;
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index 49dfa4f4..d5a3e27c 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -241,6 +241,14 @@ bool AdBlockManager::blockRequest(const QNetworkRequest &request)
if (request.url().scheme() != QL1S("http"))
return false;
+ QStringList whiteRefererList = ReKonfig::whiteReferer();
+ const QString referer = request.rawHeader("referer");
+ Q_FOREACH(const QString &host, whiteRefererList)
+ {
+ if (referer.contains(host))
+ return false;
+ }
+
QString urlString = request.url().toString();
// We compute a lowercase version of the URL so each rule does not
// have to do it.
@@ -368,51 +376,6 @@ void AdBlockManager::addCustomRule(const QString &stringRule, bool reloadPage)
}
-void AdBlockManager::removeCustomHostRule(const QString &stringRule, bool reloadPage)
-{
- // save rule in local filters
- QString localRulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_local"));
-
- QFile ruleFile(localRulesFilePath);
- if (!ruleFile.open(QFile::ReadOnly))
- {
- kDebug() << "Unable to open rule file" << localRulesFilePath;
- return;
- }
-
- QTextStream in(&ruleFile);
- QStringList localRules;
- QString r;
- do
- {
- r = in.readLine();
- if (r != stringRule)
- localRules << r;
- }
- while (!r.isNull());
- ruleFile.close();
-
- if (!ruleFile.open(QFile::WriteOnly))
- {
- kDebug() << "Unable to open rule file" << localRulesFilePath;
- return;
- }
-
- QTextStream out(&ruleFile);
- Q_FOREACH(const QString &r, localRules)
- {
- out << r << '\n';
- }
-
- // (un)load it
- _hostWhiteList.remove(stringRule);
-
- // eventually reload page
- if (reloadPage)
- emit reloadCurrentPage();
-}
-
-
bool AdBlockManager::isAdblockEnabledForHost(const QString &host)
{
return ! _hostWhiteList.match(host);
diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h
index 7e93a379..993fa9a7 100644
--- a/src/adblock/adblockmanager.h
+++ b/src/adblock/adblockmanager.h
@@ -165,7 +165,6 @@ public:
bool blockRequest(const QNetworkRequest &request);
void addCustomRule(const QString &, bool reloadPage = true);
- void removeCustomHostRule(const QString &, bool reloadPage = true);
bool isAdblockEnabledForHost(const QString &host);
diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg
index cd1d37e0..40305a2f 100644
--- a/src/rekonq.kcfg
+++ b/src/rekonq.kcfg
@@ -54,6 +54,9 @@
<entry name="clearHomePageThumbs" type="Bool">
<default>true</default>
</entry>
+ <entry name="whiteReferer" type="StringList">
+ <default></default>
+ </entry>
</group>
diff --git a/src/urlbar/adblockwidget.cpp b/src/urlbar/adblockwidget.cpp
index 2d317667..136fd2f2 100644
--- a/src/urlbar/adblockwidget.cpp
+++ b/src/urlbar/adblockwidget.cpp
@@ -24,20 +24,21 @@
* ============================================================ */
-// Auto Includes
+// Self Includes
#include "adblockwidget.h"
#include "adblockwidget.moc"
-// Local includes
-#include "adblockmanager.h"
+// Auto Includes
+#include "rekonq.h"
// KDE Includes
+#include <KDialogButtonBox>
#include <KIcon>
#include <KLocalizedString>
+#include <KStandardGuiItem>
// Qt Includes
#include <QCheckBox>
-#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
@@ -47,7 +48,7 @@ AdBlockWidget::AdBlockWidget(const QUrl &url, QWidget *parent)
: QMenu(parent)
, _pageUrl(url)
, _chBox(new QCheckBox(this))
- , _isAdblockEnabledHere(AdBlockManager::self()->isAdblockEnabledForHost(_pageUrl.host()))
+ , _isAdblockEnabledHere(true)
{
setAttribute(Qt::WA_DeleteOnClose);
setFixedWidth(320);
@@ -62,6 +63,17 @@ AdBlockWidget::AdBlockWidget(const QUrl &url, QWidget *parent)
f.setBold(true);
title->setFont(f);
+ QStringList hList = ReKonfig::whiteReferer();
+ const QString urlHost = _pageUrl.host();
+ Q_FOREACH(const QString &host, hList)
+ {
+ if (host.contains(urlHost))
+ {
+ _isAdblockEnabledHere = false;
+ break;
+ }
+ }
+
// Checkbox
_chBox->setText(i18n("Enable adblock for this site"));
_chBox->setChecked(_isAdblockEnabledHere);
@@ -70,9 +82,9 @@ AdBlockWidget::AdBlockWidget(const QUrl &url, QWidget *parent)
layout->addWidget(_chBox);
// Ok & Cancel buttons
- QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
+ KDialogButtonBox *buttonBox = new KDialogButtonBox(this, Qt::Horizontal);
+ buttonBox->addButton(KStandardGuiItem::ok(), QDialogButtonBox::AcceptRole, this, SLOT(accept()));
+ buttonBox->addButton(KStandardGuiItem::cancel(), QDialogButtonBox::RejectRole, this, SLOT(close()));
layout->addWidget(buttonBox);
}
@@ -97,15 +109,19 @@ void AdBlockWidget::accept()
bool on = _chBox->isChecked();
if (on != _isAdblockEnabledHere)
{
+ QStringList hosts = ReKonfig::whiteReferer();
+
if (on)
{
kDebug() << "REMOVING IT...";
- AdBlockManager::self()->removeCustomHostRule(_pageUrl.host());
+ hosts.removeOne(_pageUrl.host());
}
else
{
- AdBlockManager::self()->addCustomRule(QL1S("@@") + _pageUrl.host());
+ hosts << _pageUrl.host();
}
+
+ ReKonfig::setWhiteReferer(hosts);
emit updateIcon();
}
diff --git a/src/urlbar/bookmarkwidget.cpp b/src/urlbar/bookmarkwidget.cpp
index 6c6763b0..6b39c2c8 100644
--- a/src/urlbar/bookmarkwidget.cpp
+++ b/src/urlbar/bookmarkwidget.cpp
@@ -26,7 +26,7 @@
* ============================================================ */
-// Auto Includes
+// Self Includes
#include "bookmarkwidget.h"
#include "bookmarkwidget.moc"
diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp
index 5bd126e2..9321d442 100644
--- a/src/urlbar/urlbar.cpp
+++ b/src/urlbar/urlbar.cpp
@@ -600,7 +600,9 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic)
}
break;
case UrlBar::AdBlock:
- if (AdBlockManager::self()->isAdblockEnabledForHost(_tab->url().host()))
+ {
+ QStringList hosts = ReKonfig::whiteReferer();
+ if (!hosts.contains(_tab->url().host()))
{
rightIcon->setIcon(KIcon("preferences-web-browser-adblock"));
rightIcon->setToolTip(i18n("AdBlock is enabled on this site"));
@@ -611,6 +613,7 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic)
rightIcon->setToolTip(i18n("AdBlock is NOT enabled on this site"));
}
break;
+ }
default:
ASSERT_NOT_REACHED("ERROR.. default non extant case!!");
break;