From fb57031a8d81a19e426765b1ceaa325ce51411b4 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 5 Nov 2012 18:51:31 +0100 Subject: adblock work readded an icon in the urlbar when adblock is active, BUT with different features: you can now disable adblock "per-site", in a similar way chromium does. cleaned up adblock manager code, removing some old no more used code fragments --- src/urlbar/urlbar.cpp | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'src/urlbar/urlbar.cpp') diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index ab7bfb89..5bd126e2 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -38,15 +38,17 @@ #include "application.h" // Local Includes +#include "adblockmanager.h" #include "bookmarkmanager.h" #include "bookmarkowner.h" // FIXME: Why is this needed? Why everything interesting in BookmarkManager is in its owner? #include "iconmanager.h" -#include "completionwidget.h" +#include "adblockwidget.h" #include "bookmarkwidget.h" #include "favoritewidget.h" #include "rsswidget.h" +#include "completionwidget.h" #include "urlresolver.h" #include "webtab.h" @@ -408,11 +410,12 @@ void UrlBar::loadFinished() connect(bt, SIGNAL(clicked(QPoint)), _tab->page(), SLOT(showSSLInfo(QPoint))); } -// FIXME Reimplement if (_tab->hasAdBlockedElements()) -// { -// IconButton *bt = addRightIcon(UrlBar::AdBlock); -// connect(bt, SIGNAL(clicked(QPoint)), (QObject *) AdBlockManager::self(), SLOT(showBlockedItemDialog())); -// } + // Show adblock + if (AdBlockManager::self()->isEnabled()) + { + IconButton *bt = addRightIcon(UrlBar::AdBlock); + connect(bt, SIGNAL(clicked(QPoint)), this, SLOT(manageAdBlock(QPoint))); + } // we need to update urlbar after the right icon settings // removing this code (where setStyleSheet automatically calls update) needs adding again @@ -597,8 +600,16 @@ IconButton *UrlBar::addRightIcon(UrlBar::icon ic) } break; case UrlBar::AdBlock: - rightIcon->setIcon(KIcon("preferences-web-browser-adblock")); - rightIcon->setToolTip(i18n("There are elements blocked by AdBlock")); + if (AdBlockManager::self()->isAdblockEnabledForHost(_tab->url().host())) + { + rightIcon->setIcon(KIcon("preferences-web-browser-adblock")); + rightIcon->setToolTip(i18n("AdBlock is enabled on this site")); + } + else + { + rightIcon->setIcon(KIcon("preferences-web-browser-adblock").pixmap(32, 32, QIcon::Disabled)); + rightIcon->setToolTip(i18n("AdBlock is NOT enabled on this site")); + } break; default: ASSERT_NOT_REACHED("ERROR.. default non extant case!!"); @@ -766,6 +777,21 @@ void UrlBar::manageFavorites(QPoint pos) } +void UrlBar::manageAdBlock(QPoint pos) +{ + IconButton *bt = qobject_cast(this->sender()); + if (!bt) + return; + + if (_tab->url().scheme() == QL1S("about")) + return; + + AdBlockWidget *widget = new AdBlockWidget(_tab->url(), this); + connect(widget, SIGNAL(updateIcon()), this, SLOT(updateRightIcons())); + widget->showAt(pos); +} + + void UrlBar::updateRightIconPosition(IconButton *icon, int iconsCount) { // NOTE: cannot show a (let's say) 16x16 icon in a 16x16 square. -- cgit v1.2.1