From 85900021a041818ecf2415f5925fcc2a5aa5e7a4 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 20 Nov 2009 02:27:17 +0100 Subject: AdBlock. First blocks :D --- src/CMakeLists.txt | 12 ++++++++--- src/adblock/adblockmanager.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ src/adblock/adblockmanager.h | 48 ++++++++++++++++++++++++++++++++++++++++++ src/webpage.cpp | 5 ++--- src/webpage.h | 5 +++++ 5 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 src/adblock/adblockmanager.cpp create mode 100644 src/adblock/adblockmanager.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 296e91fd..a675573a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,11 +27,16 @@ 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 ) @@ -51,6 +56,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/adblockmanager.cpp b/src/adblock/adblockmanager.cpp new file mode 100644 index 00000000..2d3feff7 --- /dev/null +++ b/src/adblock/adblockmanager.cpp @@ -0,0 +1,47 @@ +/* ============================================================ +* +* 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 . +* +* ============================================================ */ + + +#include "adblockmanager.h" +#include "adblockmanager.moc" + +#include + + +AdBlockManager::AdBlockManager(QObject *parent) + : QObject(parent) +{ +} + + +AdBlockManager::~AdBlockManager() +{ +} + + +bool AdBlockManager::isUrlAllowed(const QUrl &url) +{ + return true; +} \ No newline at end of file diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h new file mode 100644 index 00000000..12e897c1 --- /dev/null +++ b/src/adblock/adblockmanager.h @@ -0,0 +1,48 @@ +/* ============================================================ +* +* 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 . +* +* ============================================================ */ + + + +#ifndef ADBLOCK_MANAGER_H +#define ADBLOCK_MANAGER_H + + +#include + +class QUrl; + + +class AdBlockManager : public QObject +{ +Q_OBJECT + +public: + AdBlockManager(QObject *parent = 0); + ~AdBlockManager(); + + bool isUrlAllowed(const QUrl &url); +}; + +#endif diff --git a/src/webpage.cpp b/src/webpage.cpp index 94ecbe09..9803d8a3 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -69,6 +69,7 @@ WebPage::WebPage(QObject *parent, qlonglong windowId) : KWebPage(parent, windowId) , m_keyboardModifiers(Qt::NoModifier) , m_pressedButtons(Qt::NoButton) + , m_adBlockMan(new AdBlockManager(this)) { setPluginFactory(new WebPluginFactory(this)); @@ -252,7 +253,5 @@ QString WebPage::errorPage(QNetworkReply *reply) bool WebPage::authorizedRequest(const QUrl &url) const { - Q_UNUSED(url) - // TODO implement ad-block here - return true; + return m_adBlockMan->isUrlAllowed(url); } diff --git a/src/webpage.h b/src/webpage.h index eb558220..acaaab25 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -32,6 +32,9 @@ #define WEBPAGE_H +// Local Includes +#include "adblockmanager.h" + // KDE Includes #include @@ -75,6 +78,8 @@ private: Qt::MouseButtons m_pressedButtons; QUrl m_requestedUrl; + + AdBlockManager *m_adBlockMan; }; #endif -- cgit v1.2.1 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/CMakeLists.txt | 1 + src/adblock/CMakeLists.txt | 18 +++++++ src/adblock/kcmwebkitadblock.cpp | 67 +++++++++++++++++++++++++ src/adblock/kcmwebkitadblock.h | 52 +++++++++++++++++++ src/adblock/webkitAdblock.desktop | 14 ++++++ src/adblock/webkitadblock.ui | 102 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 254 insertions(+) create mode 100644 src/adblock/CMakeLists.txt create mode 100644 src/adblock/kcmwebkitadblock.cpp create mode 100644 src/adblock/kcmwebkitadblock.h create mode 100644 src/adblock/webkitAdblock.desktop create mode 100644 src/adblock/webkitadblock.ui (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a675573a..4e12ccd7 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.. diff --git a/src/adblock/CMakeLists.txt b/src/adblock/CMakeLists.txt new file mode 100644 index 00000000..8777bc50 --- /dev/null +++ b/src/adblock/CMakeLists.txt @@ -0,0 +1,18 @@ + +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} ) + +install(TARGETS kcm_webkitadblock DESTINATION ${PLUGIN_INSTALL_DIR} ) + +install( FILES webkitAdblock.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) 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() +{ +} diff --git a/src/adblock/kcmwebkitadblock.h b/src/adblock/kcmwebkitadblock.h new file mode 100644 index 00000000..01f0e653 --- /dev/null +++ b/src/adblock/kcmwebkitadblock.h @@ -0,0 +1,52 @@ +/* ============================================================ +* +* 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 . +* +* ============================================================ */ + + +#ifndef KCM_WEBKIT_ADBLOCK_H +#define KCM_WEBKIT_ADBLOCK_H + + +// UI Includes +#include "ui_webkitadblock.h" + +// KDE Includes +#include + + +class KCMWebkitAdblock : public KCModule, private Ui::WebkitAdblock +{ +Q_OBJECT + +public: + KCMWebkitAdblock(QWidget *parent, const QVariantList &args); + + ~KCMWebkitAdblock(); + + void defaults(); + void load(); + void save(); +}; + +#endif diff --git a/src/adblock/webkitAdblock.desktop b/src/adblock/webkitAdblock.desktop new file mode 100644 index 00000000..22195b82 --- /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 Settings + +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..8d7ac25f --- /dev/null +++ b/src/adblock/webkitadblock.ui @@ -0,0 +1,102 @@ + + + WebkitAdblock + + + + 0 + 0 + 543 + 491 + + + + Form + + + + + + Enable adblock + + + true + + + + + + + adblock settings + + + + + + + + + <qt>Filter expression (e.g. <tt>http://www.example.com/*</tt>, <a href="filterhelp">more info</a>): + + + + + + + + + + + + Add + + + + + + + Remove + + + + + + + Search + + + + + + + Import + + + + + + + + + + + + + KListWidget + QListWidget +
klistwidget.h
+
+ + KLineEdit + QLineEdit +
klineedit.h
+
+ + KListWidgetSearchLine + KLineEdit +
klistwidgetsearchline.h
+
+
+ + +
-- 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/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 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/adblockmanager.cpp | 25 ++++++++++++++++++++++++- src/adblock/adblockmanager.h | 10 +++++++++- src/adblock/kcmwebkitadblock.cpp | 16 +--------------- src/adblock/kcmwebkitadblock.h | 6 ------ 4 files changed, 34 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 2d3feff7..6b2f9616 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -32,7 +32,9 @@ AdBlockManager::AdBlockManager(QObject *parent) : QObject(parent) + , _isAdblockEnabled(false) { + loadSettings(); } @@ -41,7 +43,28 @@ AdBlockManager::~AdBlockManager() } +void AdBlockManager::loadSettings() +{ +// 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); +// } +} + + bool AdBlockManager::isUrlAllowed(const QUrl &url) { + if (url.scheme() == QLatin1String("data")) + return false; + + if (!_isAdblockEnabled) + return false; + return true; -} \ No newline at end of file +} diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 12e897c1..c782ee0d 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -29,8 +29,11 @@ #define ADBLOCK_MANAGER_H +// Qt Includes #include +#include +// Forward Includes class QUrl; @@ -41,8 +44,13 @@ Q_OBJECT public: AdBlockManager(QObject *parent = 0); ~AdBlockManager(); - + + void loadSettings(); bool isUrlAllowed(const QUrl &url); + +private: + bool _isAdblockEnabled; + QStringList _blocks; }; #endif 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() ); diff --git a/src/adblock/kcmwebkitadblock.h b/src/adblock/kcmwebkitadblock.h index 15442ac7..37130613 100644 --- a/src/adblock/kcmwebkitadblock.h +++ b/src/adblock/kcmwebkitadblock.h @@ -42,26 +42,20 @@ Q_OBJECT public: KCMWebkitAdblock(QWidget *parent, const QVariantList &args); - ~KCMWebkitAdblock(); 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; }; -- cgit v1.2.1 From ae723ad13075808d687ad1b14f46f4a8cae87849 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 23 Nov 2009 01:25:17 +0100 Subject: First adblock implementation. now rekonq seems... slower :( But at least it's ads free! --- src/CMakeLists.txt | 1 + src/adblock/adblockmanager.cpp | 65 +++++++++++++++++++++++++++++++++--------- src/adblock/adblockmanager.h | 3 +- src/webpage.cpp | 4 +++ 4 files changed, 58 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e12ccd7..1061f3e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,6 +38,7 @@ SET( rekonq_KDEINIT_SRCS bookmarkspanel/bookmarksproxy.cpp #---------------------------------------- adblock/adblockmanager.cpp + adblock/adblockrule.cpp ) diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 6b2f9616..70960b44 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -27,6 +27,16 @@ #include "adblockmanager.h" #include "adblockmanager.moc" + +// Local Includes +#include "adblockrule.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes #include @@ -45,26 +55,53 @@ AdBlockManager::~AdBlockManager() void AdBlockManager::loadSettings() { -// 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); -// } + _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) { - if (url.scheme() == QLatin1String("data")) - return false; - + kDebug() << "matching rule..."; if (!_isAdblockEnabled) - return false; + 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 index c782ee0d..a175fa2f 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -50,7 +50,8 @@ public: private: bool _isAdblockEnabled; - QStringList _blocks; + QStringList _blockList; + QStringList _whiteList; }; #endif diff --git a/src/webpage.cpp b/src/webpage.cpp index 9803d8a3..e8c204f8 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -253,5 +253,9 @@ QString WebPage::errorPage(QNetworkReply *reply) bool WebPage::authorizedRequest(const QUrl &url) const { + // we filter just http sites + if(url.scheme() != QLatin1String("http")) + return true; + return m_adBlockMan->isUrlAllowed(url); } -- 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/adblockrule.cpp | 173 +++++++++++++++++++++++++++++++++++++++ src/adblock/adblockrule.h | 82 +++++++++++++++++++ src/adblock/kcmwebkitadblock.cpp | 4 +- 3 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 src/adblock/adblockrule.cpp create mode 100644 src/adblock/adblockrule.h (limited to 'src') 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 + * Copyright (c) 2009, Benjamin C. Meyer + * + * 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 + * + * + * 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 . + * + * ============================================================ */ + + +#include "adblockrule.h" + +#include +#include +#include + + +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 + * + * 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 + * + * + * 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 . + * + * ============================================================ */ + + +#ifndef ADBLOCKRULE_H +#define ADBLOCKRULE_H + +// Qt Includes +#include + +// 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 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 From 5d02d0ba7fc7dfff2776b1d6fe9bd3202a564c12 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 23 Nov 2009 02:38:07 +0100 Subject: Save memory. One ad-block is enough --- src/application.cpp | 14 +++++++++++++- src/application.h | 3 +++ src/mainwindow.cpp | 4 +++- src/webpage.cpp | 4 ++-- src/webpage.h | 5 ----- 5 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src') 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 @@ -61,7 +62,7 @@ QPointer Application::s_historyManager; QPointer Application::s_bookmarkProvider; QPointer Application::s_sessionManager; - +QPointer 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 > 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 s_historyManager; static QPointer s_bookmarkProvider; static QPointer s_sessionManager; + static QPointer s_adblockManager; MainWindowList m_mainWindows; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 137f0f2c..c7da7512 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" @@ -544,7 +545,8 @@ void MainWindow::updateConfiguration() // ====== load Settings on main classes Application::historyManager()->loadSettings(); - + Application::adblockManager()->loadSettings(); + defaultSettings = 0; } diff --git a/src/webpage.cpp b/src/webpage.cpp index e8c204f8..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 @@ -69,7 +70,6 @@ WebPage::WebPage(QObject *parent, qlonglong windowId) : KWebPage(parent, windowId) , m_keyboardModifiers(Qt::NoModifier) , m_pressedButtons(Qt::NoButton) - , m_adBlockMan(new AdBlockManager(this)) { setPluginFactory(new WebPluginFactory(this)); @@ -257,5 +257,5 @@ bool WebPage::authorizedRequest(const QUrl &url) const if(url.scheme() != QLatin1String("http")) return true; - return m_adBlockMan->isUrlAllowed(url); + return Application::adblockManager()->isUrlAllowed(url); } diff --git a/src/webpage.h b/src/webpage.h index acaaab25..eb558220 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -32,9 +32,6 @@ #define WEBPAGE_H -// Local Includes -#include "adblockmanager.h" - // KDE Includes #include @@ -78,8 +75,6 @@ private: Qt::MouseButtons m_pressedButtons; QUrl m_requestedUrl; - - AdBlockManager *m_adBlockMan; }; #endif -- cgit v1.2.1 From 27c78fdaae6e4deaf178da81a9c18806ed571327 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 23 Nov 2009 02:52:59 +0100 Subject: Removed dpi option. Doesn't work well with fixed font sites --- src/mainwindow.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c7da7512..a6857153 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -502,15 +502,15 @@ 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; +// // 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()); -- cgit v1.2.1 From ed1a5bac8bb6e03063df1f5c499a6fdcfc14d9a5 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 23 Nov 2009 03:10:56 +0100 Subject: Saving 4 bytes per tab :) --- src/mainwindow.cpp | 11 +++-------- src/tabbar.cpp | 20 ++++++++++++-------- src/tabbar.h | 5 +---- 3 files changed, 16 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a6857153..f2809beb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -212,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&))); @@ -239,9 +242,6 @@ void MainWindow::postLaunch() // accept d'n'd setAcceptDrops(true); - - // KActionCollection read settings - m_ac->readSettings(); } @@ -502,11 +502,6 @@ 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); 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 @@ -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(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()webView(tab); - WebView *currentView = m_parent->webView(currentIndex()); + MainView *mv = qobject_cast(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 @@ -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 */ -- cgit v1.2.1