summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/adblock/adblockmanager.cpp29
-rw-r--r--src/adblock/adblockmanager.h4
-rw-r--r--src/webview.cpp19
-rw-r--r--src/webview.h3
4 files changed, 55 insertions, 0 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index b435d437..27fb4020 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -62,6 +62,12 @@ AdBlockManager::~AdBlockManager()
}
+bool AdBlockManager::isEnabled()
+{
+ return _isAdblockEnabled;
+}
+
+
void AdBlockManager::loadSettings()
{
// first, check this...
@@ -347,3 +353,26 @@ void AdBlockManager::showSettings()
dialog->deleteLater();
}
+
+
+void AdBlockManager::addCustomRule(const QString &stringRule)
+{
+ // save rule in local filters
+ QString localRulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_local"));
+
+ QFile ruleFile(localRulesFilePath);
+ if (!ruleFile.open(QFile::WriteOnly | QFile::Text))
+ {
+ kDebug() << "Unable to open rule file" << localRulesFilePath;
+ return;
+ }
+
+ QTextStream out(&ruleFile);
+ out << stringRule << '\n';
+
+ // load it
+ AdBlockRule rule(stringRule);
+ _blackList << rule;
+
+ // TODO: update page?
+}
diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h
index f853a8ed..2e7f7836 100644
--- a/src/adblock/adblockmanager.h
+++ b/src/adblock/adblockmanager.h
@@ -154,9 +154,13 @@ public:
AdBlockManager(QObject *parent = 0);
~AdBlockManager();
+ bool isEnabled();
+
QNetworkReply *block(const QNetworkRequest &request, WebPage *page);
void applyHidingRules(WebPage *page);
+ void addCustomRule(const QString &);
+
public Q_SLOTS:
void loadSettings();
void showSettings();
diff --git a/src/webview.cpp b/src/webview.cpp
index 80f021fc..3d4d7dcf 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -34,6 +34,7 @@
// Local Includes
#include "application.h"
+#include "adblockmanager.h"
#include "bookmarkmanager.h"
#include "iconmanager.h"
#include "mainview.h"
@@ -285,6 +286,14 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
a->setData(result.imageUrl());
connect(a, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(slotCopyImageLocation()));
menu.addAction(a);
+
+ if (rApp->adblockManager()->isEnabled())
+ {
+ a = new KAction(KIcon("preferences-web-browser-adblock"), i18n("Block image"), this);
+ a->setData(result.imageUrl());
+ connect(a, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(blockImage()));
+ menu.addAction(a);
+ }
}
// ACTIONS FOR TEXT SELECTION -----------------------------------------------------
@@ -1213,3 +1222,13 @@ void WebView::sendByMail()
KToolInvocation::invokeMailer("", "", "", "", url);
}
+
+void WebView::blockImage()
+{
+ QAction *action = qobject_cast<QAction*>(sender());
+ if (!action)
+ return;
+
+ QString imageUrl = action->data().toString();
+ rApp->adblockManager()->addCustomRule(imageUrl);
+}
diff --git a/src/webview.h b/src/webview.h
index 18977798..3ae9b7e9 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -108,6 +108,9 @@ private Q_SLOTS:
void loadStarted();
+ void blockImage();
+
+
Q_SIGNALS:
void loadUrl(const KUrl &, const Rekonq::OpenType &);
void zoomChanged(int);