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/CMakeLists.txt | 5 +- src/adblock/kcmwebkitadblock.cpp | 132 ++++++++++++++++++++++++++++++++++++++ src/adblock/kcmwebkitadblock.h | 17 +++++ src/adblock/webkitAdblock.desktop | 2 +- src/adblock/webkitadblock.ui | 59 ++++++++++------- src/settings/settingsdialog.cpp | 22 +++++-- 6 files changed, 204 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/adblock/CMakeLists.txt b/src/adblock/CMakeLists.txt index 8777bc50..f2785811 100644 --- a/src/adblock/CMakeLists.txt +++ b/src/adblock/CMakeLists.txt @@ -11,7 +11,10 @@ kde4_add_ui_files(kcm_webkitadblock_SRCS kde4_add_plugin(kcm_webkitadblock ${kcm_webkitadblock_SRCS}) -target_link_libraries(kcm_webkitadblock ${KDE4_KDEUI_LIBS} ) +target_link_libraries(kcm_webkitadblock + ${KDE4_KDEUI_LIBS} + ${KDE4_KIO_LIBS} +) install(TARGETS kcm_webkitadblock DESTINATION ${PLUGIN_INSTALL_DIR} ) 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); } diff --git a/src/adblock/kcmwebkitadblock.h b/src/adblock/kcmwebkitadblock.h index 01f0e653..15442ac7 100644 --- a/src/adblock/kcmwebkitadblock.h +++ b/src/adblock/kcmwebkitadblock.h @@ -33,6 +33,7 @@ // KDE Includes #include +#include class KCMWebkitAdblock : public KCModule, private Ui::WebkitAdblock @@ -47,6 +48,22 @@ public: void defaults(); void load(); void save(); + + bool isAdblockEnabled(); + +private slots: + void infoLinkActivated(const QString &url); + void stateChanged(bool state); + + void addExpr(); + void removeSelected(); + void importExpr(); + +private: + bool _isAdblockEnabled; + + KSharedConfig::Ptr _config; + QString _group; }; #endif diff --git a/src/adblock/webkitAdblock.desktop b/src/adblock/webkitAdblock.desktop index 22195b82..61fa99c0 100644 --- a/src/adblock/webkitAdblock.desktop +++ b/src/adblock/webkitAdblock.desktop @@ -9,6 +9,6 @@ X-KDE-Library=kcm_webkitadblock X-KDE-PluginKeyword=webkitAdblock X-KDE-ParentApp=kcontrol -Name=Webkit AdBlock Settings +Name=Webkit AdBlock Categories=Qt;KDE;X-KDE-settings-webbrowsing; diff --git a/src/adblock/webkitadblock.ui b/src/adblock/webkitadblock.ui index 8d7ac25f..c75c0f0f 100644 --- a/src/adblock/webkitadblock.ui +++ b/src/adblock/webkitadblock.ui @@ -15,23 +15,37 @@ - - - Enable adblock + + + enable adblock - + true - - - - - - adblock settings + + true - + + + + + Search: + + + + + + + + + + + + + + @@ -41,10 +55,10 @@ - - - - + + + + @@ -52,24 +66,21 @@ + + + + - Remove - - - - - - - Search + Remove Expr - Import + Import from... 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(); ; } -- cgit v1.2.1