summaryrefslogtreecommitdiff
path: root/src/adblock
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-11-23 03:11:26 +0100
committerAndrea Diamantini <adjam7@gmail.com>2009-11-23 03:11:26 +0100
commitdf7a2820a54d8b69e87b495269b88f9ae5ac156d (patch)
tree4124db211bddf2dbf784d0eddbf70bbb8c24ee0f /src/adblock
parentFixing urlbar size (diff)
parentSaving 4 bytes per tab :) (diff)
downloadrekonq-df7a2820a54d8b69e87b495269b88f9ae5ac156d.tar.xz
Merge branch 'devAdBlock'
Diffstat (limited to 'src/adblock')
-rw-r--r--src/adblock/CMakeLists.txt21
-rw-r--r--src/adblock/adblockmanager.cpp107
-rw-r--r--src/adblock/adblockmanager.h57
-rw-r--r--src/adblock/adblockrule.cpp173
-rw-r--r--src/adblock/adblockrule.h82
-rw-r--r--src/adblock/kcmwebkitadblock.cpp187
-rw-r--r--src/adblock/kcmwebkitadblock.h63
-rw-r--r--src/adblock/webkitAdblock.desktop14
-rw-r--r--src/adblock/webkitadblock.ui113
9 files changed, 817 insertions, 0 deletions
diff --git a/src/adblock/CMakeLists.txt b/src/adblock/CMakeLists.txt
new file mode 100644
index 00000000..f2785811
--- /dev/null
+++ b/src/adblock/CMakeLists.txt
@@ -0,0 +1,21 @@
+
+ADD_DEFINITIONS ( ${KDE4_DEFINITIONS} )
+
+SET(kcm_webkitadblock_SRCS
+ kcmwebkitadblock.cpp
+)
+
+kde4_add_ui_files(kcm_webkitadblock_SRCS
+ webkitadblock.ui
+)
+
+kde4_add_plugin(kcm_webkitadblock ${kcm_webkitadblock_SRCS})
+
+target_link_libraries(kcm_webkitadblock
+ ${KDE4_KDEUI_LIBS}
+ ${KDE4_KIO_LIBS}
+)
+
+install(TARGETS kcm_webkitadblock DESTINATION ${PLUGIN_INSTALL_DIR} )
+
+install( FILES webkitAdblock.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
new file mode 100644
index 00000000..70960b44
--- /dev/null
+++ b/src/adblock/adblockmanager.cpp
@@ -0,0 +1,107 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+#include "adblockmanager.h"
+#include "adblockmanager.moc"
+
+
+// Local Includes
+#include "adblockrule.h"
+
+// KDE Includes
+#include <KSharedConfig>
+#include <KConfigGroup>
+#include <KDebug>
+
+// Qt Includes
+#include <QUrl>
+
+
+AdBlockManager::AdBlockManager(QObject *parent)
+ : QObject(parent)
+ , _isAdblockEnabled(false)
+{
+ loadSettings();
+}
+
+
+AdBlockManager::~AdBlockManager()
+{
+}
+
+
+void AdBlockManager::loadSettings()
+{
+ _blockList.clear();
+
+ KSharedConfig::Ptr config = KSharedConfig::openConfig("webkitrc", KConfig::NoGlobals);
+ KConfigGroup cg(config, "adblock");
+
+ _isAdblockEnabled = cg.readEntry("Enabled", false);
+
+ int num = cg.readEntry("Count", 0);
+ for (int i = 0; i < num; ++i)
+ {
+ QString key = "Filter-" + QString::number(i);
+ QString filter = cg.readEntry( key, QString() );
+ if(!filter.isEmpty())
+ {
+ if (filter.startsWith(QLatin1String("@@")))
+ _whiteList << filter;
+ else
+ _blockList << filter;
+ }
+ }
+}
+
+
+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;
+}
diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h
new file mode 100644
index 00000000..a175fa2f
--- /dev/null
+++ b/src/adblock/adblockmanager.h
@@ -0,0 +1,57 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+
+#ifndef ADBLOCK_MANAGER_H
+#define ADBLOCK_MANAGER_H
+
+
+// Qt Includes
+#include <QObject>
+#include <QStringList>
+
+// Forward Includes
+class QUrl;
+
+
+class AdBlockManager : public QObject
+{
+Q_OBJECT
+
+public:
+ AdBlockManager(QObject *parent = 0);
+ ~AdBlockManager();
+
+ void loadSettings();
+ bool isUrlAllowed(const QUrl &url);
+
+private:
+ bool _isAdblockEnabled;
+ QStringList _blockList;
+ QStringList _whiteList;
+};
+
+#endif
diff --git a/src/adblock/adblockrule.cpp b/src/adblock/adblockrule.cpp
new file mode 100644
index 00000000..870ad825
--- /dev/null
+++ b/src/adblock/adblockrule.cpp
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2009, Zsombor Gegesy <gzsombor@gmail.com>
+ * Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Benjamin Meyer nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * ============================================================
+ *
+ * This file is a part of the rekonq project
+ *
+ * Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ============================================================ */
+
+
+#include "adblockrule.h"
+
+#include <QDebug>
+#include <QRegExp>
+#include <QUrl>
+
+
+AdBlockRule::AdBlockRule(const QString &filter)
+ : m_cssRule(false)
+ , m_exceptionRule(false)
+ , m_enabledRule(true)
+{
+ bool isRegExpRule = false;
+
+ if (filter.startsWith(QLatin1String("!")) || filter.trimmed().isEmpty())
+ m_enabledRule = false;
+
+ if (filter.contains(QLatin1String("##")))
+ m_cssRule = true;
+
+ QString parsedLine = filter;
+ if (parsedLine.startsWith(QLatin1String("@@")))
+ {
+ m_exceptionRule = true;
+ parsedLine = parsedLine.mid(2);
+ }
+
+ if (parsedLine.startsWith(QLatin1Char('/')))
+ {
+ if (parsedLine.endsWith(QLatin1Char('/')))
+ {
+ parsedLine = parsedLine.mid(1);
+ parsedLine = parsedLine.left(parsedLine.size() - 1);
+ isRegExpRule = true;
+ }
+ }
+
+ int options = parsedLine.indexOf(QLatin1String("$"), 0);
+ if (options >= 0)
+ {
+ m_options = parsedLine.mid(options + 1).split(QLatin1Char(','));
+ parsedLine = parsedLine.left(options);
+ }
+
+ if(!isRegExpRule)
+ parsedLine = convertPatternToRegExp(parsedLine);
+ m_regExp = QRegExp(parsedLine, Qt::CaseInsensitive, QRegExp::RegExp2);
+
+ if (m_options.contains(QLatin1String("match-case")))
+ {
+ m_regExp.setCaseSensitivity(Qt::CaseSensitive);
+ m_options.removeOne(QLatin1String("match-case"));
+ }
+}
+
+
+// here return false means that rule doesn't match,
+// so that url is allowed
+// return true means "matched rule", so stop url!
+bool AdBlockRule::match(const QString &encodedUrl) const
+{
+ if (m_cssRule)
+ return false;
+
+ if (!m_enabledRule)
+ return false;
+
+ bool matched = m_regExp.indexIn(encodedUrl) != -1;
+
+ if (matched && !m_options.isEmpty())
+ {
+ // we only support domain right now
+ if (m_options.count() == 1)
+ {
+ foreach (const QString &option, m_options)
+ {
+ if (option.startsWith(QLatin1String("domain=")))
+ {
+ QUrl url = QUrl::fromEncoded(encodedUrl.toUtf8());
+ QString host = url.host();
+ QStringList domainOptions = option.mid(7).split(QLatin1Char('|'));
+ foreach (QString domainOption, domainOptions)
+ {
+ bool negate = domainOption.at(0) == QLatin1Char('~');
+ if (negate)
+ domainOption = domainOption.mid(1);
+ bool hostMatched = domainOption == host;
+ if (hostMatched && !negate)
+ return true;
+ if (!hostMatched && negate)
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ return matched;
+}
+
+
+QString AdBlockRule::convertPatternToRegExp(const QString &wildcardPattern)
+{
+ QString pattern = wildcardPattern;
+ return pattern.replace(QRegExp(QLatin1String("\\*+")), QLatin1String("*")) // remove multiple wildcards
+ .replace(QRegExp(QLatin1String("\\^\\|$")), QLatin1String("^")) // remove anchors following separator placeholder
+ .replace(QRegExp(QLatin1String("^(\\*)")), QLatin1String("")) // remove leading wildcards
+ .replace(QRegExp(QLatin1String("(\\*)$")), QLatin1String("")) // remove trailing wildcards
+ .replace(QRegExp(QLatin1String("(\\W)")), QLatin1String("\\\\1")) // escape special symbols
+ .replace(QRegExp(QLatin1String("^\\\\\\|\\\\\\|")),
+ QLatin1String("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?")) // process extended anchor at expression start
+ .replace(QRegExp(QLatin1String("\\\\\\^")),
+ QLatin1String("(?:[^\\w\\d\\-.%]|$)")) // process separator placeholders
+ .replace(QRegExp(QLatin1String("^\\\\\\|")), QLatin1String("^")) // process anchor at expression start
+ .replace(QRegExp(QLatin1String("\\\\\\|$")), QLatin1String("$")) // process anchor at expression end
+ .replace(QRegExp(QLatin1String("\\\\\\*")), QLatin1String(".*")) // replace wildcards by .*
+ ;
+}
diff --git a/src/adblock/adblockrule.h b/src/adblock/adblockrule.h
new file mode 100644
index 00000000..3f1bd8bf
--- /dev/null
+++ b/src/adblock/adblockrule.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Benjamin Meyer nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * ============================================================
+ *
+ * This file is a part of the rekonq project
+ *
+ * Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ============================================================ */
+
+
+#ifndef ADBLOCKRULE_H
+#define ADBLOCKRULE_H
+
+// Qt Includes
+#include <QStringList>
+
+// Forward Includes
+class QUrl;
+class QRegExp;
+
+
+class AdBlockRule
+{
+public:
+ AdBlockRule(const QString &filter);
+
+ bool match(const QString &encodedUrl) const;
+
+private:
+ QString convertPatternToRegExp(const QString &wildcardPattern);
+
+ bool m_cssRule;
+ bool m_exceptionRule;
+ bool m_enabledRule;
+ QRegExp m_regExp;
+ QStringList m_options;
+};
+
+#endif // ADBLOCKRULE_H
diff --git a/src/adblock/kcmwebkitadblock.cpp b/src/adblock/kcmwebkitadblock.cpp
new file mode 100644
index 00000000..bbe44c0e
--- /dev/null
+++ b/src/adblock/kcmwebkitadblock.cpp
@@ -0,0 +1,187 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+// Self Includes
+#include "kcmwebkitadblock.h"
+#include "kcmwebkitadblock.moc"
+
+// KDE Includes
+#include <KDE/KPluginFactory>
+#include <KDE/KPluginLoader>
+#include <KDE/KAboutData>
+#include <KDE/KTemporaryFile>
+#include <KDE/KIO/NetAccess>
+#include <KDE/KDebug>
+
+// Qt Includes
+#include <QtCore/QTextStream>
+#include <QtGui/QWhatsThis>
+#include <QtGui/QListWidgetItem>
+
+
+K_PLUGIN_FACTORY(RekonqPluginFactory,
+ registerPlugin<KCMWebkitAdblock>("webkitAdblock");
+ )
+
+K_EXPORT_PLUGIN(RekonqPluginFactory("kcmrekonqfactory"))
+
+
+KCMWebkitAdblock::KCMWebkitAdblock(QWidget *parent, const QVariantList &args)
+ : KCModule(KGlobal::mainComponent(), parent, args)
+ , _group("adblock")
+{
+ KAboutData *about = new KAboutData( I18N_NOOP("kcmrekonqfactory"), 0,
+ ki18n( "rekonq Browsing Control Module" ), 0,
+ KLocalizedString(), KAboutData::License_GPL,
+ ki18n( "(c) 2009 Andrea Diamantini" ) );
+
+ about->addAuthor( ki18n("Andrea Diamantini"), KLocalizedString(), "adjam7@gmail.com" );
+ setAboutData( about );
+
+ setupUi(this);
+ connect(label, SIGNAL(linkActivated(const QString &)), SLOT(infoLinkActivated(const QString &)) );
+ searchLine->setListWidget(listWidget);
+
+ connect(addButton,SIGNAL(clicked()),this,SLOT(addExpr()));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeSelected()));
+ connect(importButton, SIGNAL(clicked()), this, SLOT(importExpr()));
+
+ _config = KSharedConfig::openConfig("webkitrc", KConfig::NoGlobals);
+}
+
+
+KCMWebkitAdblock::~KCMWebkitAdblock()
+{
+}
+
+
+void KCMWebkitAdblock::defaults()
+{
+ searchLine->clear();
+ lineEdit->clear();
+ listWidget->clear();
+ groupBox->setChecked(false);
+}
+
+
+void KCMWebkitAdblock::load()
+{
+ KConfigGroup cg(_config, _group);
+ groupBox->setChecked( cg.readEntry("Enabled", false) );
+
+ int num = cg.readEntry("Count", 0);
+ for (int i = 0; i < num; ++i)
+ {
+ QString key = "Filter-" + QString::number(i);
+ QString filter = cg.readEntry( key, QString() );
+ listWidget->addItem(filter);
+ }
+}
+
+
+void KCMWebkitAdblock::save()
+{
+ KConfigGroup cg(_config, _group);
+ cg.deleteGroup();
+ cg = KConfigGroup(_config, _group);
+
+ cg.writeEntry("Enabled", groupBox->isChecked());
+
+ for(int i = 0; i < listWidget->count(); ++i )
+ {
+ QString key = "Filter-" + QString::number(i);
+ cg.writeEntry(key, listWidget->item(i)->text());
+ }
+ cg.writeEntry("Count", listWidget->count());
+ cg.sync();
+}
+
+
+void KCMWebkitAdblock::infoLinkActivated(const QString &url)
+{
+ QString helpString = i18n("<qt><p>Enter an expression to filter. Filters can be defined as either:"
+ "<ul><li>a shell-style wildcard, e.g. <tt>http://www.example.com/ads*</tt>, the wildcards <tt>*?[]</tt> may be used</li>"
+ "<li>a full regular expression by surrounding the string with '<tt>/</tt>', e.g. <tt>/\\/(ad|banner)\\./</tt></li></ul>"
+ "<p>Any filter string can be preceded by '<tt>@@</tt>' to whitelist (allow) any matching URL, "
+ "which takes priority over any blacklist (blocking) filter.");
+
+
+ if ( url == "filterhelp" )
+ QWhatsThis::showText( QCursor::pos(), helpString );
+}
+
+
+void KCMWebkitAdblock::addExpr()
+{
+ listWidget->addItem( lineEdit->text() );
+ lineEdit->clear();
+ emit changed(true);
+}
+
+
+void KCMWebkitAdblock::removeSelected()
+{
+ listWidget->takeItem(listWidget->currentRow());
+ searchLine->clear();
+ emit changed(true);
+}
+
+
+void KCMWebkitAdblock::importExpr()
+{
+
+ QString target;
+ KUrl url("http://adblockplus.mozdev.org/easylist/easylist.txt");
+
+ kDebug() << "downloading list..";
+
+ bool success = KIO::NetAccess::download(url, target, 0);
+ if(!success)
+ {
+ kDebug() << "not success";
+ return;
+ }
+
+ QFile temp(target);
+ if (!temp.open(QIODevice::ReadOnly | QIODevice::Text))
+ {
+ kDebug() << "File not open";
+ return;
+ }
+
+ QTextStream stream(&temp);
+ QString line;
+ do
+ {
+ line = stream.readLine();
+ if(!line.startsWith('!') && !line.startsWith('['))
+ listWidget->addItem(line);
+ }
+ while (!line.isNull());
+
+ KIO::NetAccess::removeTempFile(target);
+ emit changed(true);
+}
diff --git a/src/adblock/kcmwebkitadblock.h b/src/adblock/kcmwebkitadblock.h
new file mode 100644
index 00000000..37130613
--- /dev/null
+++ b/src/adblock/kcmwebkitadblock.h
@@ -0,0 +1,63 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+#ifndef KCM_WEBKIT_ADBLOCK_H
+#define KCM_WEBKIT_ADBLOCK_H
+
+
+// UI Includes
+#include "ui_webkitadblock.h"
+
+// KDE Includes
+#include <kcmodule.h>
+#include <ksharedconfig.h>
+
+
+class KCMWebkitAdblock : public KCModule, private Ui::WebkitAdblock
+{
+Q_OBJECT
+
+public:
+ KCMWebkitAdblock(QWidget *parent, const QVariantList &args);
+ ~KCMWebkitAdblock();
+
+ void defaults();
+ void load();
+ void save();
+
+private slots:
+ void infoLinkActivated(const QString &url);
+
+ void addExpr();
+ void removeSelected();
+ void importExpr();
+
+private:
+ KSharedConfig::Ptr _config;
+ QString _group;
+};
+
+#endif
diff --git a/src/adblock/webkitAdblock.desktop b/src/adblock/webkitAdblock.desktop
new file mode 100644
index 00000000..61fa99c0
--- /dev/null
+++ b/src/adblock/webkitAdblock.desktop
@@ -0,0 +1,14 @@
+[Desktop Entry]
+Type=Service
+X-KDE-ServiceTypes=KCModule
+
+Icon=preferences-web-browser-adblock
+Exec=kcmshell4 webkitAdblock
+
+X-KDE-Library=kcm_webkitadblock
+X-KDE-PluginKeyword=webkitAdblock
+X-KDE-ParentApp=kcontrol
+
+Name=Webkit AdBlock
+
+Categories=Qt;KDE;X-KDE-settings-webbrowsing;
diff --git a/src/adblock/webkitadblock.ui b/src/adblock/webkitadblock.ui
new file mode 100644
index 00000000..c75c0f0f
--- /dev/null
+++ b/src/adblock/webkitadblock.ui
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>WebkitAdblock</class>
+ <widget class="QWidget" name="WebkitAdblock">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>543</width>
+ <height>491</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>enable adblock</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Search:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KListWidgetSearchLine" name="searchLine">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="KListWidget" name="listWidget"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>&lt;qt&gt;Filter expression (e.g. &lt;tt&gt;http://www.example.com/*&lt;/tt&gt;, &lt;a href=&quot;filterhelp&quot;&gt;more info&lt;/a&gt;):</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="KLineEdit" name="lineEdit"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="addButton">
+ <property name="text">
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="removeButton">
+ <property name="text">
+ <string>Remove Expr</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="importButton">
+ <property name="text">
+ <string>Import from...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>KListWidget</class>
+ <extends>QListWidget</extends>
+ <header>klistwidget.h</header>
+ </customwidget>
+ <customwidget>
+ <class>KLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>klineedit.h</header>
+ </customwidget>
+ <customwidget>
+ <class>KListWidgetSearchLine</class>
+ <extends>KLineEdit</extends>
+ <header>klistwidgetsearchline.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>