From 770f38f4aced1656fdee3c6d0dcf8ddfb9493c2b Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 20 Nov 2009 14:59:55 +0100 Subject: AdBlock, first file (and first UI. Probably not last :) --- src/adblock/kcmwebkitadblock.cpp | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/adblock/kcmwebkitadblock.cpp (limited to 'src/adblock/kcmwebkitadblock.cpp') diff --git a/src/adblock/kcmwebkitadblock.cpp b/src/adblock/kcmwebkitadblock.cpp new file mode 100644 index 00000000..28487b74 --- /dev/null +++ b/src/adblock/kcmwebkitadblock.cpp @@ -0,0 +1,67 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "kcmwebkitadblock.h" +#include "kcmwebkitadblock.moc" + +// KDE Includes +#include +#include + + +K_PLUGIN_FACTORY(RekonqPluginFactory, + registerPlugin("webkitAdblock"); + ) + +K_EXPORT_PLUGIN(RekonqPluginFactory("kcmrekonqfactory")) + + +KCMWebkitAdblock::KCMWebkitAdblock(QWidget *parent, const QVariantList &args) + : KCModule(KGlobal::mainComponent(), parent, args) +{ + setupUi(this); +} + + +KCMWebkitAdblock::~KCMWebkitAdblock() +{ +} + + +void KCMWebkitAdblock::defaults() +{ +} + + +void KCMWebkitAdblock::load() +{ +} + + +void KCMWebkitAdblock::save() +{ +} -- cgit v1.2.1 From 20a3df6c7d64d845009acc94ead1ddfbec4c413d Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 21 Nov 2009 01:58:23 +0100 Subject: A new kcmshell named "webkit adblock" to set... (guess what?!) First bits work, seems enough for this evening --- src/adblock/kcmwebkitadblock.cpp | 132 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) (limited to 'src/adblock/kcmwebkitadblock.cpp') diff --git a/src/adblock/kcmwebkitadblock.cpp b/src/adblock/kcmwebkitadblock.cpp index 28487b74..d114b30a 100644 --- a/src/adblock/kcmwebkitadblock.cpp +++ b/src/adblock/kcmwebkitadblock.cpp @@ -31,6 +31,15 @@ // KDE Includes #include #include +#include +#include +#include +#include + +// Qt Includes +#include +#include +#include K_PLUGIN_FACTORY(RekonqPluginFactory, @@ -42,8 +51,27 @@ K_EXPORT_PLUGIN(RekonqPluginFactory("kcmrekonqfactory")) KCMWebkitAdblock::KCMWebkitAdblock(QWidget *parent, const QVariantList &args) : KCModule(KGlobal::mainComponent(), parent, args) + , _isAdblockEnabled(false) + , _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 &)) ); + connect(groupBox,SIGNAL(clicked(bool)), this, SLOT(stateChanged(bool))); + 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); } @@ -54,14 +82,118 @@ KCMWebkitAdblock::~KCMWebkitAdblock() void KCMWebkitAdblock::defaults() { + searchLine->clear(); + lineEdit->clear(); + listWidget->clear(); + groupBox->setChecked(false); // set also _isAdblockEnabled } 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); + } +// updateButton(); } 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("

Enter an expression to filter. Filters can be defined as either:" + "

  • a shell-style wildcard, e.g. http://www.example.com/ads*, the wildcards *?[] may be used
  • " + "
  • a full regular expression by surrounding the string with '/', e.g. /\\/(ad|banner)\\./
" + "

Any filter string can be preceded by '@@' to whitelist (allow) any matching URL, " + "which takes priority over any blacklist (blocking) filter."); + + + if ( url == "filterhelp" ) + QWhatsThis::showText( QCursor::pos(), helpString ); +} + + +void KCMWebkitAdblock::stateChanged(bool state) +{ + _isAdblockEnabled = state; +} + + +bool KCMWebkitAdblock::isAdblockEnabled() +{ + return _isAdblockEnabled; +} + + +void KCMWebkitAdblock::addExpr() +{ + listWidget->addItem( lineEdit->text() ); + lineEdit->clear(); +} + + +void KCMWebkitAdblock::removeSelected() +{ + listWidget->takeItem(listWidget->currentRow()); + searchLine->clear(); +} + + +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); } -- cgit v1.2.1 From 4f5ac89ad5afdc6aa57e655b33ebed8ef87c1f23 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 21 Nov 2009 02:12:25 +0100 Subject: Ok, same other bits on the adblock manager. Now it's really time to go to bed :) --- src/adblock/kcmwebkitadblock.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'src/adblock/kcmwebkitadblock.cpp') diff --git a/src/adblock/kcmwebkitadblock.cpp b/src/adblock/kcmwebkitadblock.cpp index d114b30a..f6383788 100644 --- a/src/adblock/kcmwebkitadblock.cpp +++ b/src/adblock/kcmwebkitadblock.cpp @@ -51,7 +51,6 @@ K_EXPORT_PLUGIN(RekonqPluginFactory("kcmrekonqfactory")) KCMWebkitAdblock::KCMWebkitAdblock(QWidget *parent, const QVariantList &args) : KCModule(KGlobal::mainComponent(), parent, args) - , _isAdblockEnabled(false) , _group("adblock") { KAboutData *about = new KAboutData( I18N_NOOP("kcmrekonqfactory"), 0, @@ -64,7 +63,6 @@ KCMWebkitAdblock::KCMWebkitAdblock(QWidget *parent, const QVariantList &args) setupUi(this); connect(label, SIGNAL(linkActivated(const QString &)), SLOT(infoLinkActivated(const QString &)) ); - connect(groupBox,SIGNAL(clicked(bool)), this, SLOT(stateChanged(bool))); searchLine->setListWidget(listWidget); connect(addButton,SIGNAL(clicked()),this,SLOT(addExpr())); @@ -85,7 +83,7 @@ void KCMWebkitAdblock::defaults() searchLine->clear(); lineEdit->clear(); listWidget->clear(); - groupBox->setChecked(false); // set also _isAdblockEnabled + groupBox->setChecked(false); } @@ -137,18 +135,6 @@ void KCMWebkitAdblock::infoLinkActivated(const QString &url) } -void KCMWebkitAdblock::stateChanged(bool state) -{ - _isAdblockEnabled = state; -} - - -bool KCMWebkitAdblock::isAdblockEnabled() -{ - return _isAdblockEnabled; -} - - void KCMWebkitAdblock::addExpr() { listWidget->addItem( lineEdit->text() ); -- cgit v1.2.1 From fd4886d7500e6b56b7e9a5f9128e535d0520c66a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 23 Nov 2009 01:41:31 +0100 Subject: Forgot some files :) --- src/adblock/kcmwebkitadblock.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/adblock/kcmwebkitadblock.cpp') diff --git a/src/adblock/kcmwebkitadblock.cpp b/src/adblock/kcmwebkitadblock.cpp index f6383788..bbe44c0e 100644 --- a/src/adblock/kcmwebkitadblock.cpp +++ b/src/adblock/kcmwebkitadblock.cpp @@ -99,7 +99,6 @@ void KCMWebkitAdblock::load() QString filter = cg.readEntry( key, QString() ); listWidget->addItem(filter); } -// updateButton(); } @@ -139,6 +138,7 @@ void KCMWebkitAdblock::addExpr() { listWidget->addItem( lineEdit->text() ); lineEdit->clear(); + emit changed(true); } @@ -146,6 +146,7 @@ void KCMWebkitAdblock::removeSelected() { listWidget->takeItem(listWidget->currentRow()); searchLine->clear(); + emit changed(true); } @@ -182,4 +183,5 @@ void KCMWebkitAdblock::importExpr() while (!line.isNull()); KIO::NetAccess::removeTempFile(target); + emit changed(true); } -- cgit v1.2.1