summaryrefslogtreecommitdiff
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
parentFixing urlbar size (diff)
parentSaving 4 bytes per tab :) (diff)
downloadrekonq-df7a2820a54d8b69e87b495269b88f9ae5ac156d.tar.xz
Merge branch 'devAdBlock'
-rw-r--r--src/CMakeLists.txt14
-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
-rw-r--r--src/application.cpp14
-rw-r--r--src/application.h3
-rw-r--r--src/mainwindow.cpp19
-rw-r--r--src/settings/settingsdialog.cpp22
-rw-r--r--src/tabbar.cpp20
-rw-r--r--src/tabbar.h5
-rw-r--r--src/webpage.cpp9
17 files changed, 886 insertions, 37 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 296e91fd..1061f3e7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,6 +2,7 @@
ADD_SUBDIRECTORY( data )
ADD_SUBDIRECTORY( tests )
+ADD_SUBDIRECTORY( adblock )
### ------- SETTING REKONQ FILES..
@@ -27,11 +28,17 @@ SET( rekonq_KDEINIT_SRCS
webpluginfactory.cpp
websnap.cpp
webview.cpp
+#----------------------------------------
rekonqpage/newtabpage.cpp
+#----------------------------------------
settings/settingsdialog.cpp
- bookmarkspanel/bookmarkspanel.cpp
- bookmarkspanel/bookmarkstreemodel.cpp
- bookmarkspanel/bookmarksproxy.cpp
+#----------------------------------------
+ bookmarkspanel/bookmarkspanel.cpp
+ bookmarkspanel/bookmarkstreemodel.cpp
+ bookmarkspanel/bookmarksproxy.cpp
+#----------------------------------------
+ adblock/adblockmanager.cpp
+ adblock/adblockrule.cpp
)
@@ -51,6 +58,7 @@ KDE4_ADD_KCFG_FILES( rekonq_KDEINIT_SRCS rekonq.kcfgc )
INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/rekonqpage
${CMAKE_CURRENT_SOURCE_DIR}/settings
+ ${CMAKE_CURRENT_SOURCE_DIR}/adblock
${CMAKE_CURRENT_BINARY_DIR}
${KDE4_INCLUDES}
${QT4_INCLUDES}
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>
diff --git a/src/application.cpp b/src/application.cpp
index d02e44c9..766d56ed 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -40,6 +40,7 @@
#include "webview.h"
#include "urlbar.h"
#include "sessionmanager.h"
+#include "adblockmanager.h"
// KDE Includes
#include <KCmdLineArgs>
@@ -61,7 +62,7 @@
QPointer<HistoryManager> Application::s_historyManager;
QPointer<BookmarkProvider> Application::s_bookmarkProvider;
QPointer<SessionManager> Application::s_sessionManager;
-
+QPointer<AdBlockManager> Application::s_adblockManager;
Application::Application()
@@ -432,3 +433,14 @@ MainWindowList Application::mainWindowList()
{
return m_mainWindows;
}
+
+
+
+AdBlockManager *Application::adblockManager()
+{
+ if(!s_adblockManager)
+ {
+ s_adblockManager = new AdBlockManager(instance());
+ }
+ return s_adblockManager;
+} \ No newline at end of file
diff --git a/src/application.h b/src/application.h
index 786e5173..b15720f5 100644
--- a/src/application.h
+++ b/src/application.h
@@ -48,6 +48,7 @@ class BookmarkProvider;
class HistoryManager;
class MainWindow;
class SessionManager;
+class AdBlockManager;
typedef QList< QPointer<MainWindow> > MainWindowList;
@@ -105,6 +106,7 @@ public:
static HistoryManager *historyManager();
static BookmarkProvider *bookmarkProvider();
static SessionManager *sessionManager();
+ static AdBlockManager *adblockManager();
public slots:
/**
@@ -139,6 +141,7 @@ private:
static QPointer<HistoryManager> s_historyManager;
static QPointer<BookmarkProvider> s_bookmarkProvider;
static QPointer<SessionManager> s_sessionManager;
+ static QPointer<AdBlockManager> s_adblockManager;
MainWindowList m_mainWindows;
};
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 137f0f2c..f2809beb 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -46,6 +46,7 @@
#include "urlbar.h"
#include "tabbar.h"
#include "newtabpage.h"
+#include "adblockmanager.h"
// Ui Includes
#include "ui_cleardata.h"
@@ -211,6 +212,9 @@ void MainWindow::setupToolbars()
void MainWindow::postLaunch()
{
+ // KActionCollection read settings
+ m_ac->readSettings();
+
// notification system
connect(m_view, SIGNAL(showStatusBarMessage(const QString&, Rekonq::Notify)), this, SLOT(notifyMessage(const QString&, Rekonq::Notify)));
connect(m_view, SIGNAL(linkHovered(const QString&)), this, SLOT(notifyMessage(const QString&)));
@@ -238,9 +242,6 @@ void MainWindow::postLaunch()
// accept d'n'd
setAcceptDrops(true);
-
- // KActionCollection read settings
- m_ac->readSettings();
}
@@ -501,15 +502,10 @@ void MainWindow::updateConfiguration()
int fnSize = ReKonfig::fontSize();
int minFnSize = ReKonfig::minFontSize();
- // font size / dpi WARNING: is this right? why we need this?
- float toPix = m_view->logicalDpiY()/72.0;
- if (toPix < 96.0/72.0)
- toPix = 96.0/72.0;
-
QFont standardFont = ReKonfig::standardFont();
defaultSettings->setFontFamily(QWebSettings::StandardFont, standardFont.family());
- defaultSettings->setFontSize(QWebSettings::DefaultFontSize, fnSize*toPix);
- defaultSettings->setFontSize(QWebSettings::MinimumFontSize, minFnSize*toPix);
+ defaultSettings->setFontSize(QWebSettings::DefaultFontSize, fnSize);
+ defaultSettings->setFontSize(QWebSettings::MinimumFontSize, minFnSize);
QFont fixedFont = ReKonfig::fixedFont();
defaultSettings->setFontFamily(QWebSettings::FixedFont, fixedFont.family());
@@ -544,7 +540,8 @@ void MainWindow::updateConfiguration()
// ====== load Settings on main classes
Application::historyManager()->loadSettings();
-
+ Application::adblockManager()->loadSettings();
+
defaultSettings = 0;
}
diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp
index 1db38b96..1dde1196 100644
--- a/src/settings/settingsdialog.cpp
+++ b/src/settings/settingsdialog.cpp
@@ -70,6 +70,7 @@ private:
KCModuleProxy *ebrowsingModule;
KCModuleProxy *cookiesModule;
KCModuleProxy *cacheModule;
+ KCModuleProxy *adblockModule;
KShortcutsEditor *shortcutsEditor;
Private(SettingsDialog *parent);
@@ -124,6 +125,11 @@ Private::Private(SettingsDialog *parent)
KIcon webkitIcon = KIcon(QIcon(webkitIconPath));
pageItem->setIcon(webkitIcon);
+ KCModuleInfo adblockInfo("webkitAdblock.desktop");
+ adblockModule = new KCModuleProxy(adblockInfo,parent);
+ pageItem = parent->addPage(adblockModule, i18n(adblockInfo.moduleName().toLocal8Bit()));
+ pageItem->setIcon(KIcon(adblockInfo.icon()));
+
shortcutsEditor = new KShortcutsEditor(Application::instance()->mainWindow()->actionCollection(), parent);
pageItem = parent->addPage(shortcutsEditor , i18n("Shortcuts"));
pageItem->setIcon(KIcon("configure-shortcuts"));
@@ -133,7 +139,9 @@ Private::Private(SettingsDialog *parent)
pageItem = parent->addPage(ebrowsingModule, i18n(ebrowsingInfo.moduleName().toLocal8Bit()));
pageItem->setIcon(KIcon(ebrowsingInfo.icon()));
- parent->setMinimumSize(700,500);
+ // WARNING remember wheh changing here that the smaller netbooks
+ // have a 1024x576 resolution. So DONT bother that limits!!
+ parent->setMinimumSize(700,525);
}
@@ -144,22 +152,20 @@ SettingsDialog::SettingsDialog(QWidget *parent)
: KConfigDialog(parent, "rekonfig", ReKonfig::self())
, d(new Private(this))
{
- setFaceType(KPageDialog::Tree);
- showButtonSeparator(true);
-
- setWindowTitle(i18n("rekonfig..."));
+ showButtonSeparator(false);
+ setWindowTitle(i18n("Configure - rekonq"));
setModal(true);
readConfig();
-
connect(d->generalUi.setHomeToCurrentPageButton, SIGNAL(clicked()), this, SLOT(setHomeToCurrentPage()));
connect(d->ebrowsingModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
connect(d->cookiesModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
connect(d->proxyModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
connect(d->cacheModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
-
+ connect(d->adblockModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
+
connect(d->shortcutsEditor, SIGNAL(keyChange()), this, SLOT(updateButtons()));
connect(this, SIGNAL(applyClicked()), this, SLOT(saveSettings()));
@@ -209,6 +215,7 @@ void SettingsDialog::saveSettings()
d->proxyModule->save();
d->cacheModule->save();
d->shortcutsEditor->save();
+ d->adblockModule->save();
}
@@ -219,6 +226,7 @@ bool SettingsDialog::hasChanged()
|| d->cookiesModule->changed()
|| d->proxyModule->changed()
|| d->cacheModule->changed()
+ || d->adblockModule->changed()
|| d->shortcutsEditor->isModified();
;
}
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index 3eba53d7..6fdf4346 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -38,6 +38,7 @@
#include "urlbar.h"
#include "webview.h"
#include "websnap.h"
+#include "mainview.h"
// KDE Includes
#include <KShortcut>
@@ -59,9 +60,8 @@
#define MIN_WIDTH_DIVISOR 8
-TabBar::TabBar(MainView *parent)
+TabBar::TabBar(QWidget *parent)
: KTabBar(parent)
- , m_parent(parent)
, m_currentTabPreview(-1)
{
setElideMode(Qt::ElideRight);
@@ -84,10 +84,12 @@ TabBar::~TabBar()
QSize TabBar::tabSizeHint(int index) const
{
- int buttonSize = m_parent->addTabButton()->size().width();
- int tabBarWidth = m_parent->size().width() - buttonSize;
- int baseWidth = m_parent->sizeHint().width()/BASE_WIDTH_DIVISOR;
- int minWidth = m_parent->sizeHint().width()/MIN_WIDTH_DIVISOR;
+ MainView *view = qobject_cast<MainView *>(parent());
+
+ int buttonSize = view->addTabButton()->size().width();
+ int tabBarWidth = view->size().width() - buttonSize;
+ int baseWidth = view->sizeHint().width()/BASE_WIDTH_DIVISOR;
+ int minWidth = view->sizeHint().width()/MIN_WIDTH_DIVISOR;
int w;
if (baseWidth*count()<tabBarWidth)
@@ -139,8 +141,10 @@ void TabBar::reloadTab()
void TabBar::showTabPreview(int tab)
{
- WebView *view = m_parent->webView(tab);
- WebView *currentView = m_parent->webView(currentIndex());
+ MainView *mv = qobject_cast<MainView *>(parent());
+
+ WebView *view = mv->webView(tab);
+ WebView *currentView = mv->webView(currentIndex());
// should fix bug #212219
if(!currentView)
diff --git a/src/tabbar.h b/src/tabbar.h
index b78e9b24..76d70197 100644
--- a/src/tabbar.h
+++ b/src/tabbar.h
@@ -33,7 +33,6 @@
// Local Includes
#include "rekonqprivate_export.h"
-#include "mainview.h"
// Qt Includes
#include <QPointer>
@@ -59,7 +58,7 @@ class REKONQ_TESTS_EXPORT TabBar : public KTabBar
Q_OBJECT
public:
- TabBar(MainView *parent);
+ TabBar(QWidget *parent);
~TabBar();
void showTabPreview(int tab);
@@ -93,8 +92,6 @@ private slots:
private:
friend class MainView;
- MainView *m_parent;
-
/**
* the index in which we are seeing a Context menu
*/
diff --git a/src/webpage.cpp b/src/webpage.cpp
index 94ecbe09..941567a0 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -41,6 +41,7 @@
#include "mainview.h"
#include "webview.h"
#include "webpluginfactory.h"
+#include "adblockmanager.h"
// KDE Includes
#include <KStandardDirs>
@@ -252,7 +253,9 @@ QString WebPage::errorPage(QNetworkReply *reply)
bool WebPage::authorizedRequest(const QUrl &url) const
{
- Q_UNUSED(url)
- // TODO implement ad-block here
- return true;
+ // we filter just http sites
+ if(url.scheme() != QLatin1String("http"))
+ return true;
+
+ return Application::adblockManager()->isUrlAllowed(url);
}