summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-11-05 18:51:31 +0100
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:06 +0100
commitfb57031a8d81a19e426765b1ceaa325ce51411b4 (patch)
tree465eaf0c619e9c84ac15c4002cd668c977e9f752
parentFix tools menu position (diff)
downloadrekonq-fb57031a8d81a19e426765b1ceaa325ce51411b4.tar.xz
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
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/adblock/adblockhostmatcher.cpp37
-rw-r--r--src/adblock/adblockhostmatcher.h4
-rw-r--r--src/adblock/adblockmanager.cpp64
-rw-r--r--src/adblock/adblockmanager.h8
-rw-r--r--src/adblock/adblocksettingwidget.cpp (renamed from src/adblock/adblockwidget.cpp)20
-rw-r--r--src/adblock/adblocksettingwidget.h (renamed from src/adblock/adblockwidget.h)10
-rw-r--r--src/adblock/blockedelementswidget.cpp116
-rw-r--r--src/urlbar/adblockwidget.cpp113
-rw-r--r--src/urlbar/adblockwidget.h (renamed from src/adblock/blockedelementswidget.h)44
-rw-r--r--src/urlbar/urlbar.cpp42
-rw-r--r--src/urlbar/urlbar.h1
-rw-r--r--src/webtab/networkaccessmanager.cpp2
13 files changed, 264 insertions, 201 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 91764c2d..143f9dc1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -23,8 +23,7 @@ set(rekonq_KDEINIT_SRCS
adblock/adblockrulefallbackimpl.cpp
adblock/adblockrulenullimpl.cpp
adblock/adblockruletextmatchimpl.cpp
- adblock/adblockwidget.cpp
- adblock/blockedelementswidget.cpp
+ adblock/adblocksettingwidget.cpp
#----------------------------------------
bookmarks/bookmarkmanager.cpp
bookmarks/bookmarkscontextmenu.cpp
@@ -75,6 +74,7 @@ set(rekonq_KDEINIT_SRCS
urlbar/urlbar.cpp
urlbar/completionwidget.cpp
urlbar/listitem.cpp
+ urlbar/adblockwidget.cpp
urlbar/bookmarkwidget.cpp
urlbar/favoritewidget.cpp
urlbar/rsswidget.cpp
diff --git a/src/adblock/adblockhostmatcher.cpp b/src/adblock/adblockhostmatcher.cpp
index 021fe12d..5033c6f7 100644
--- a/src/adblock/adblockhostmatcher.cpp
+++ b/src/adblock/adblockhostmatcher.cpp
@@ -29,11 +29,11 @@
// Rekonq Includes
#include "rekonq_defines.h"
+
bool AdBlockHostMatcher::tryAddFilter(const QString &filter)
{
if (filter.startsWith(QL1S("||")))
{
-
QString domain = filter.mid(2);
if (!domain.endsWith(QL1C('^')))
@@ -49,8 +49,41 @@ bool AdBlockHostMatcher::tryAddFilter(const QString &filter)
domain = domain.toLower();
m_hostList.insert(domain);
- m_hostList.insert(QL1S("www.") + domain);
return true;
}
+
+ if (filter.startsWith(QL1S("@@")))
+ {
+ QString domain = filter.mid(2);
+
+ if (domain.contains(QL1C('^')))
+ return false;
+
+ if (domain.contains(QL1C('$')))
+ return false;
+
+ if (domain.contains(QL1C('*')))
+ return false;
+
+ if (domain.contains(QL1C('|')))
+ return false;
+
+ if (domain.contains(QL1C('/')))
+ {
+ if (!domain.endsWith(QL1C('/')))
+ return false;
+ }
+ domain = domain.toLower();
+ m_hostList.insert(domain);
+ return true;
+ }
+
return false;
}
+
+
+void AdBlockHostMatcher::remove(const QString &hostRule)
+{
+ bool on = m_hostList.remove(hostRule);
+ kDebug() << "REMOVED? " << on;
+}
diff --git a/src/adblock/adblockhostmatcher.h b/src/adblock/adblockhostmatcher.h
index bdad883c..3ce6e284 100644
--- a/src/adblock/adblockhostmatcher.h
+++ b/src/adblock/adblockhostmatcher.h
@@ -29,6 +29,8 @@
#include <QSet>
#include <QString>
+#include <KDebug>
+
class AdBlockHostMatcher
{
public:
@@ -47,6 +49,8 @@ public:
m_hostList.clear();
}
+ void remove(const QString &hostRule);
+
private:
QSet<QString> m_hostList;
};
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp
index feee243e..49dfa4f4 100644
--- a/src/adblock/adblockmanager.cpp
+++ b/src/adblock/adblockmanager.cpp
@@ -32,10 +32,7 @@
#include "rekonq.h"
// Local Includes
-#include "adblockwidget.h"
-#include "blockedelementswidget.h"
-
-#include "webpage.h"
+#include "adblocksettingwidget.h"
// KDE Includes
#include <KIO/FileCopyJob>
@@ -207,10 +204,10 @@ void AdBlockManager::loadRuleString(const QString &stringRule)
// white rules
if (stringRule.startsWith(QL1S("@@")))
{
- const QString filter = stringRule.mid(2);
- if (_hostWhiteList.tryAddFilter(filter))
+ if (_hostWhiteList.tryAddFilter(stringRule))
return;
+ const QString filter = stringRule.mid(2);
AdBlockRule rule(filter);
_whiteList << rule;
return;
@@ -335,7 +332,7 @@ void AdBlockManager::showSettings()
dialog->setCaption(i18nc("@title:window", "Ad Block Settings"));
dialog->setButtons(KDialog::Ok | KDialog::Cancel);
- AdBlockWidget widget(_adblockConfig);
+ AdBlockSettingWidget widget(_adblockConfig);
dialog->setMainWidget(&widget);
connect(dialog, SIGNAL(okClicked()), &widget, SLOT(save()));
connect(dialog, SIGNAL(okClicked()), this, SLOT(loadSettings()));
@@ -371,33 +368,52 @@ void AdBlockManager::addCustomRule(const QString &stringRule, bool reloadPage)
}
-void AdBlockManager::showBlockedItemDialog()
+void AdBlockManager::removeCustomHostRule(const QString &stringRule, bool reloadPage)
{
- QPointer<KDialog> dialog = new KDialog();
- dialog->setCaption(i18nc("@title:window", "Blocked elements"));
- dialog->setButtons(KDialog::Ok);
+ // save rule in local filters
+ QString localRulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_local"));
- BlockedElementsWidget widget(this);
- widget.setBlockedElements(_blockedElements);
- widget.setHidedElements(_hidedElements);
+ QFile ruleFile(localRulesFilePath);
+ if (!ruleFile.open(QFile::ReadOnly))
+ {
+ kDebug() << "Unable to open rule file" << localRulesFilePath;
+ return;
+ }
- dialog->setMainWidget(&widget);
- dialog->exec();
+ QTextStream in(&ruleFile);
+ QStringList localRules;
+ QString r;
+ do
+ {
+ r = in.readLine();
+ if (r != stringRule)
+ localRules << r;
+ }
+ while (!r.isNull());
+ ruleFile.close();
- Q_FOREACH(const QString & r, widget.rulesToAdd())
+ if (!ruleFile.open(QFile::WriteOnly))
{
- addCustomRule(r);
+ kDebug() << "Unable to open rule file" << localRulesFilePath;
+ return;
}
- if (widget.pageNeedsReload())
- emit reloadCurrentPage();
+ QTextStream out(&ruleFile);
+ Q_FOREACH(const QString &r, localRules)
+ {
+ out << r << '\n';
+ }
+
+ // (un)load it
+ _hostWhiteList.remove(stringRule);
- dialog->deleteLater();
+ // eventually reload page
+ if (reloadPage)
+ emit reloadCurrentPage();
}
-void AdBlockManager::clearElementsLists()
+bool AdBlockManager::isAdblockEnabledForHost(const QString &host)
{
- _blockedElements.clear();
- _hidedElements = 0;
+ return ! _hostWhiteList.match(host);
}
diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h
index 1946d4ad..7e93a379 100644
--- a/src/adblock/adblockmanager.h
+++ b/src/adblock/adblockmanager.h
@@ -165,8 +165,10 @@ public:
bool blockRequest(const QNetworkRequest &request);
void addCustomRule(const QString &, bool reloadPage = true);
- void clearElementsLists();
+ void removeCustomHostRule(const QString &, bool reloadPage = true);
+ bool isAdblockEnabledForHost(const QString &host);
+
private:
AdBlockManager(QObject *parent = 0);
@@ -182,7 +184,6 @@ private:
private Q_SLOTS:
void loadSettings();
void showSettings();
- void showBlockedItemDialog();
void slotFinished(KJob *);
@@ -199,9 +200,6 @@ private:
AdBlockRuleList _whiteList;
QStringList _hideList;
- QStringList _blockedElements;
- int _hidedElements;
-
KSharedConfig::Ptr _adblockConfig;
static QWeakPointer<AdBlockManager> s_adBlockManager;
diff --git a/src/adblock/adblockwidget.cpp b/src/adblock/adblocksettingwidget.cpp
index 5ada506e..55b48046 100644
--- a/src/adblock/adblockwidget.cpp
+++ b/src/adblock/adblocksettingwidget.cpp
@@ -25,8 +25,8 @@
// Self Includes
-#include "adblockwidget.h"
-#include "adblockwidget.moc"
+#include "adblocksettingwidget.h"
+#include "adblocksettingwidget.moc"
// Auto Includes
#include "rekonq.h"
@@ -42,7 +42,7 @@
#include <QListWidgetItem>
-AdBlockWidget::AdBlockWidget(KSharedConfig::Ptr config, QWidget *parent)
+AdBlockSettingWidget::AdBlockSettingWidget(KSharedConfig::Ptr config, QWidget *parent)
: QWidget(parent)
, _changed(false)
, _adblockConfig(config)
@@ -78,7 +78,7 @@ AdBlockWidget::AdBlockWidget(KSharedConfig::Ptr config, QWidget *parent)
}
-void AdBlockWidget::slotInfoLinkActivated(const QString &url)
+void AdBlockSettingWidget::slotInfoLinkActivated(const QString &url)
{
Q_UNUSED(url)
@@ -94,7 +94,7 @@ void AdBlockWidget::slotInfoLinkActivated(const QString &url)
}
-void AdBlockWidget::insertRule()
+void AdBlockSettingWidget::insertRule()
{
QString rule = addFilterLineEdit->text();
if (rule.isEmpty())
@@ -105,13 +105,13 @@ void AdBlockWidget::insertRule()
}
-void AdBlockWidget::removeRule()
+void AdBlockSettingWidget::removeRule()
{
manualFiltersListWidget->takeItem(manualFiltersListWidget->currentRow());
}
-void AdBlockWidget::load()
+void AdBlockSettingWidget::load()
{
// General settings
KConfigGroup settingsGroup(_adblockConfig, "Settings");
@@ -177,7 +177,7 @@ void AdBlockWidget::load()
}
-void AdBlockWidget::save()
+void AdBlockSettingWidget::save()
{
if (!_changed)
return;
@@ -226,7 +226,7 @@ void AdBlockWidget::save()
}
-void AdBlockWidget::hasChanged()
+void AdBlockSettingWidget::hasChanged()
{
// update enabled status
checkHideAds->setEnabled(checkEnableAdblock->isChecked());
@@ -236,7 +236,7 @@ void AdBlockWidget::hasChanged()
}
-bool AdBlockWidget::changed()
+bool AdBlockSettingWidget::changed()
{
return _changed;
}
diff --git a/src/adblock/adblockwidget.h b/src/adblock/adblocksettingwidget.h
index 37f29f93..c630d795 100644
--- a/src/adblock/adblockwidget.h
+++ b/src/adblock/adblocksettingwidget.h
@@ -24,8 +24,8 @@
* ============================================================ */
-#ifndef ADBLOCK_WIDGET_H
-#define ADBLOCK_WIDGET_H
+#ifndef ADBLOCK_SETTINGS_WIDGET_H
+#define ADBLOCK_SETTINGS_WIDGET_H
// Rekonq Includes
@@ -41,12 +41,12 @@
#include <QWidget>
-class AdBlockWidget : public QWidget, private Ui::adblock
+class AdBlockSettingWidget : public QWidget, private Ui::adblock
{
Q_OBJECT
public:
- explicit AdBlockWidget(KSharedConfig::Ptr config, QWidget *parent = 0);
+ explicit AdBlockSettingWidget(KSharedConfig::Ptr config, QWidget *parent = 0);
bool changed();
@@ -70,4 +70,4 @@ private:
KSharedConfig::Ptr _adblockConfig;
};
-#endif // ADBLOCK_WIDGET_H
+#endif // ADBLOCK_SETTINGS_WIDGET_H
diff --git a/src/adblock/blockedelementswidget.cpp b/src/adblock/blockedelementswidget.cpp
deleted file mode 100644
index 141dd203..00000000
--- a/src/adblock/blockedelementswidget.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/* ============================================================
-*
-* 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)
- , _reloadPage(false)
-{
- 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(i18np("There is %1 hidden element in this page.", "There are %1 hidden elements in this page.", QString::number(n)));
- else
- label->setText(i18n("Hiding elements is disabled."));
-}
-
-
-void BlockedElementsWidget::unblockElement()
-{
- QPushButton *buttonClicked = qobject_cast<QPushButton *>(sender());
- if (!buttonClicked)
- return;
-
- QString urlString = QL1S("@@") + buttonClicked->property("URLTOUNBLOCK").toString();
- kDebug() << "urlString: " << urlString;
-
- QString newText = i18n("Unblocked");
- QString buttonText = buttonClicked->text().remove('&');
- if (buttonText == newText)
- {
- buttonClicked->setText(i18n("Unblock"));
- buttonClicked->setIcon(KIcon("dialog-ok-apply"));
-
- _rulesToAdd.removeOne(urlString);
- }
- else
- {
- buttonClicked->setText(newText);
- buttonClicked->setIcon(KIcon("dialog-ok"));
-
- _rulesToAdd << urlString;
- }
-
- _reloadPage = true;
-}
diff --git a/src/urlbar/adblockwidget.cpp b/src/urlbar/adblockwidget.cpp
new file mode 100644
index 00000000..2d317667
--- /dev/null
+++ b/src/urlbar/adblockwidget.cpp
@@ -0,0 +1,113 @@
+/* ============================================================
+*
+* 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/>.
+*
+* ============================================================ */
+
+
+// Auto Includes
+#include "adblockwidget.h"
+#include "adblockwidget.moc"
+
+// Local includes
+#include "adblockmanager.h"
+
+// KDE Includes
+#include <KIcon>
+#include <KLocalizedString>
+
+// Qt Includes
+#include <QCheckBox>
+#include <QDialogButtonBox>
+#include <QVBoxLayout>
+#include <QLabel>
+#include <QPushButton>
+
+
+AdBlockWidget::AdBlockWidget(const QUrl &url, QWidget *parent)
+ : QMenu(parent)
+ , _pageUrl(url)
+ , _chBox(new QCheckBox(this))
+ , _isAdblockEnabledHere(AdBlockManager::self()->isAdblockEnabledForHost(_pageUrl.host()))
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+ setFixedWidth(320);
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->setSpacing(10);
+
+ // Title
+ QLabel *title = new QLabel(this);
+ title->setText(i18n(" AdBlock"));
+ QFont f = title->font();
+ f.setBold(true);
+ title->setFont(f);
+
+ // Checkbox
+ _chBox->setText(i18n("Enable adblock for this site"));
+ _chBox->setChecked(_isAdblockEnabledHere);
+
+ layout->addWidget(title);
+ layout->addWidget(_chBox);
+
+ // Ok & Cancel buttons
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
+ layout->addWidget(buttonBox);
+}
+
+
+AdBlockWidget::~AdBlockWidget()
+{
+}
+
+
+void AdBlockWidget::showAt(const QPoint &pos)
+{
+ adjustSize();
+
+ QPoint p(pos.x() - width(), pos.y() + 10);
+ move(p);
+ show();
+}
+
+
+void AdBlockWidget::accept()
+{
+ bool on = _chBox->isChecked();
+ if (on != _isAdblockEnabledHere)
+ {
+ if (on)
+ {
+ kDebug() << "REMOVING IT...";
+ AdBlockManager::self()->removeCustomHostRule(_pageUrl.host());
+ }
+ else
+ {
+ AdBlockManager::self()->addCustomRule(QL1S("@@") + _pageUrl.host());
+ }
+
+ emit updateIcon();
+ }
+ close();
+}
diff --git a/src/adblock/blockedelementswidget.h b/src/urlbar/adblockwidget.h
index d26ee849..32458067 100644
--- a/src/adblock/blockedelementswidget.h
+++ b/src/urlbar/adblockwidget.h
@@ -24,48 +24,36 @@
* ============================================================ */
-#ifndef BLOCKED_ELEMENTS_WIDGET_H
-#define BLOCKED_ELEMENTS_WIDGET_H
-
-
-// Rekonq Includes
-#include "rekonq_defines.h"
-
-// Ui Includes
-#include "ui_blocked_elements.h"
+#ifndef ADBLOCK_WIDGET_H
+#define ADBLOCK_WIDGET_H
// Qt Includes
-#include <QWidget>
+#include <QCheckBox>
+#include <QMenu>
+#include <QUrl>
-class BlockedElementsWidget : public QWidget, private Ui::BlockedElements
+class AdBlockWidget : public QMenu
{
Q_OBJECT
public:
- explicit BlockedElementsWidget(QObject *manager, QWidget *parent = 0);
-
- void setBlockedElements(const QStringList &);
- void setHidedElements(int);
+ explicit AdBlockWidget(const QUrl &url, QWidget *parent = 0);
+ virtual ~AdBlockWidget();
- bool pageNeedsReload()
- {
- return _reloadPage;
- };
+ void showAt(const QPoint &pos);
- QStringList rulesToAdd()
- {
- return _rulesToAdd;
- };
+Q_SIGNALS:
+ void updateIcon();
private Q_SLOTS:
- void unblockElement();
+ void accept();
private:
- QObject *_manager;
+ QUrl _pageUrl;
- bool _reloadPage;
- QStringList _rulesToAdd;
+ QCheckBox *_chBox;
+ bool _isAdblockEnabledHere;
};
-#endif // BLOCKED_ELEMENTS_WIDGET_H
+#endif
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<IconButton *>(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.
diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h
index d115d34a..b0edc80e 100644
--- a/src/urlbar/urlbar.h
+++ b/src/urlbar/urlbar.h
@@ -112,6 +112,7 @@ private Q_SLOTS:
void detectTypedString(const QString &);
void suggest();
+ void manageAdBlock(QPoint);
void manageFavorites(QPoint);
void refreshFavicon();
diff --git a/src/webtab/networkaccessmanager.cpp b/src/webtab/networkaccessmanager.cpp
index 95bfa47d..ce10e10d 100644
--- a/src/webtab/networkaccessmanager.cpp
+++ b/src/webtab/networkaccessmanager.cpp
@@ -181,5 +181,5 @@ void NetworkAccessManager::slotFinished(bool ok)
collection += frame->parentFrame()->findAllElements(HIDABLE_ELEMENTS);
Q_FOREACH(const QUrl & url, urls)
- hideBlockedElements(url, collection);
+ hideBlockedElements(url, collection);
}