diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/adblock/adblockmanager.cpp | 43 | ||||
-rw-r--r-- | src/adblock/adblockmanager.h | 17 | ||||
-rw-r--r-- | src/adblock/blocked_elements.ui | 119 | ||||
-rw-r--r-- | src/adblock/blockedelementswidget.cpp | 106 | ||||
-rw-r--r-- | src/adblock/blockedelementswidget.h | 58 | ||||
-rw-r--r-- | src/mainwindow.cpp | 3 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 2 | ||||
-rw-r--r-- | src/webpage.cpp | 1 |
9 files changed, 344 insertions, 9 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82cf6066..10b57b1c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,6 +69,7 @@ SET( rekonq_KDEINIT_SRCS adblock/adblockrulenullimpl.cpp adblock/adblockruletextmatchimpl.cpp adblock/adblockwidget.cpp + adblock/blockedelementswidget.cpp #---------------------------------------- urlbar/stackedurlbar.cpp urlbar/urlbar.cpp @@ -112,7 +113,10 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS settings/settings_tabs.ui settings/settings_appearance.ui settings/settings_webkit.ui + # ---------------------------------------- adblock/settings_adblock.ui + adblock/blocked_elements.ui + # ---------------------------------------- cleardata.ui sslinfo.ui webappcreation.ui diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 27fb4020..8005c7e5 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -34,6 +34,8 @@ // Local Includes #include "adblocknetworkreply.h" #include "adblockwidget.h" +#include "blockedelementswidget.h" + #include "webpage.h" // KDE Includes @@ -68,6 +70,12 @@ bool AdBlockManager::isEnabled() } +bool AdBlockManager::isHidingElements() +{ + return _isHideAdsEnabled; +} + + void AdBlockManager::loadSettings() { // first, check this... @@ -88,10 +96,13 @@ void AdBlockManager::loadSettings() _hostWhiteList.clear(); _hostBlackList.clear(); + _whiteList.clear(); _blackList.clear(); _hideList.clear(); + clearElementsLists(); + KConfigGroup settingsGroup(_adblockConfig, "Settings"); _isAdblockEnabled = settingsGroup.readEntry("adBlockEnabled", false); kDebug() << "ADBLOCK ENABLED = " << _isAdblockEnabled; @@ -232,7 +243,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa { kDebug() << "ADBLOCK: BLACK RULE Matched by string: " << urlString; AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); - // TODO: add it to blocked list + _blockedElements << request.url().toString(); page->setHasAdBlockedElements(true); return reply; } @@ -261,7 +272,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *pa } AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); - // TODO: add it to blocked list + _blockedElements << request.url().toString(); page->setHasAdBlockedElements(true); return reply; } @@ -297,7 +308,7 @@ void AdBlockManager::applyHidingRules(WebPage *page) kDebug() << "Hide element: " << el.localName(); el.setStyleProperty(QL1S("visibility"), QL1S("hidden")); el.removeFromDocument(); - // TODO: add it to hided list + _hidedElements++; page->setHasAdBlockedElements(true); } } @@ -374,5 +385,29 @@ void AdBlockManager::addCustomRule(const QString &stringRule) AdBlockRule rule(stringRule); _blackList << rule; - // TODO: update page? + emit reloadCurrentPage(); +} + + +void AdBlockManager::showBlockedItemDialog() +{ + QPointer<KDialog> dialog = new KDialog(); + dialog->setCaption(i18nc("@title:window", "Blocked & hided elements")); + dialog->setButtons(KDialog::Ok); + + BlockedElementsWidget widget(this); + widget.setBlockedElements(_blockedElements); + widget.setHidedElements(_hidedElements); + + dialog->setMainWidget(&widget); + dialog->exec(); + + dialog->deleteLater(); +} + + +void AdBlockManager::clearElementsLists() +{ + _blockedElements.clear(); + _hidedElements = 0; } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 2e7f7836..30daa27e 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -155,20 +155,26 @@ public: ~AdBlockManager(); bool isEnabled(); + bool isHidingElements(); QNetworkReply *block(const QNetworkRequest &request, WebPage *page); void applyHidingRules(WebPage *page); void addCustomRule(const QString &); - -public Q_SLOTS: - void loadSettings(); - void showSettings(); + void clearElementsLists(); private: void updateSubscriptions(); void loadRules(const QString &); +private Q_SLOTS: + void loadSettings(); + void showSettings(); + void showBlockedItemDialog(); + +Q_SIGNALS: + void reloadCurrentPage(); + private: bool _isAdblockEnabled; bool _isHideAdsEnabled; @@ -179,6 +185,9 @@ private: AdBlockRuleList _whiteList; QStringList _hideList; + QStringList _blockedElements; + int _hidedElements; + KSharedConfig::Ptr _adblockConfig; }; diff --git a/src/adblock/blocked_elements.ui b/src/adblock/blocked_elements.ui new file mode 100644 index 00000000..884daee6 --- /dev/null +++ b/src/adblock/blocked_elements.ui @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BlockedElements</class> + <widget class="QWidget" name="BlockedElements"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>527</width> + <height>407</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="BlockedLabel"> + <property name="text"> + <string><html><head/><body><p><span style=" font-weight:600;">Blocked elements</span></p></body></html></string> + </property> + </widget> + </item> + <item> + <widget class="QFrame" name="frame"> + <property name="palette"> + <palette> + <active> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="autoFillBackground"> + <bool>true</bool> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="HidedLabel"> + <property name="text"> + <string><b>Hided elements</b></string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/adblock/blockedelementswidget.cpp b/src/adblock/blockedelementswidget.cpp new file mode 100644 index 00000000..cdb40c27 --- /dev/null +++ b/src/adblock/blockedelementswidget.cpp @@ -0,0 +1,106 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 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 "blockedelementswidget.h" +#include "blockedelementswidget.moc" + +// Local Includes +#include "adblockmanager.h" + +// Qt Includes +#include <QHBoxLayout> +#include <QVBoxLayout> +#include <QPushButton> + + +BlockedElementsWidget::BlockedElementsWidget(QObject *manager, QWidget *parent) + : QWidget(parent) + , _manager(manager) +{ + setupUi(this); +} + + +void BlockedElementsWidget::setBlockedElements(const QStringList &list) +{ + QVBoxLayout *frameLayout = new QVBoxLayout(frame); + + Q_FOREACH(const QString & block, list) + { + QString truncatedUrl = block; + const int maxTextSize = 73; + if (truncatedUrl.length() > maxTextSize) + { + const int truncateSize = 70; + truncatedUrl.truncate(truncateSize); + truncatedUrl += QL1S("..."); + } + QWidget *w = new QWidget(this); + QHBoxLayout *l = new QHBoxLayout(w); + l->addWidget(new QLabel(truncatedUrl, this)); + + QPushButton *button = new QPushButton(KIcon("dialog-ok-apply"), i18n("Unblock"), this); + button->setProperty("URLTOUNBLOCK", block); + button->setFixedWidth(100); + connect(button, SIGNAL(clicked()), this, SLOT(unblockElement())); + l->addWidget(button); + + w->setMinimumWidth(500); + frameLayout->addWidget(w); + } +} + + +void BlockedElementsWidget::setHidedElements(int n) +{ + AdBlockManager *m = qobject_cast<AdBlockManager *>(_manager); + if (m->isHidingElements()) + label->setText(i18n("In this page there are %1 hided elements.", QString::number(n))); + else + label->setText(i18n("Hiding elements is disabled.")); +} + + +void BlockedElementsWidget::unblockElement() +{ + QPushButton *buttonClicked = qobject_cast<QPushButton *>(sender()); + if (!buttonClicked) + return; + + QString newText = i18n("Unblocked"); + if (buttonClicked->text() == newText) + return; + + QString urlString = buttonClicked->property("URLTOUNBLOCK").toString(); + kDebug() << "urlString: " << urlString; + + buttonClicked->setText(newText); + buttonClicked->setIcon(KIcon("dialog-ok")); + + AdBlockManager *m = qobject_cast<AdBlockManager *>(_manager); + m->addCustomRule("@@" + urlString); +} diff --git a/src/adblock/blockedelementswidget.h b/src/adblock/blockedelementswidget.h new file mode 100644 index 00000000..6f5ceaf8 --- /dev/null +++ b/src/adblock/blockedelementswidget.h @@ -0,0 +1,58 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 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 BLOCKED_ELEMENTS_WIDGET_H +#define BLOCKED_ELEMENTS_WIDGET_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Ui Includes +#include "ui_blocked_elements.h" + +// Qt Includes +#include <QWidget> + + +class BlockedElementsWidget : public QWidget, private Ui::BlockedElements +{ + Q_OBJECT + +public: + explicit BlockedElementsWidget(QObject *manager, QWidget *parent = 0); + + void setBlockedElements(const QStringList &); + void setHidedElements(int); + +private Q_SLOTS: + void unblockElement(); + +private: + QObject *_manager; +}; + +#endif // BLOCKED_ELEMENTS_WIDGET_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e954e7d3..a14f11f0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -213,6 +213,9 @@ MainWindow::MainWindow() // Save session on window closing connect(this, SIGNAL(windowClosing()), rApp->sessionManager(), SLOT(saveSession())); + // Adblock Manager changed rules. Reload current page + connect(rApp->adblockManager(), SIGNAL(reloadCurrentPage()), m_view, SLOT(webReload())); + // setting up toolbars to NOT have context menu enabled setContextMenuPolicy(Qt::DefaultContextMenu); diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index 9ef51f47..8f5a10a3 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -405,7 +405,7 @@ void UrlBar::loadFinished() if (_tab->hasAdBlockedElements()) { IconButton *bt = addRightIcon(UrlBar::AdBlock); - connect(bt, SIGNAL(clicked(QPoint)), (QObject *) rApp->adblockManager(), SLOT(showBlockedItems())); + connect(bt, SIGNAL(clicked(QPoint)), (QObject *) rApp->adblockManager(), SLOT(showBlockedItemDialog())); } // we need to update urlbar after the right icon settings diff --git a/src/webpage.cpp b/src/webpage.cpp index 7ae7420d..2f4b5efc 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -445,6 +445,7 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) void WebPage::loadStarted() { _hasAdBlockedElements = false; + rApp->adblockManager()->clearElementsLists(); } |