From 6f072c5dfcac294a12283d4ba93e22d50df9c660 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 6 Mar 2012 11:16:04 +0100 Subject: Let user change his mind enabling block/unblock --- src/adblock/adblockmanager.cpp | 5 +++++ src/adblock/blockedelementswidget.cpp | 25 ++++++++++++++++--------- src/adblock/blockedelementswidget.h | 4 ++++ 3 files changed, 25 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 39040767..b5739144 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -425,6 +425,11 @@ void AdBlockManager::showBlockedItemDialog() dialog->setMainWidget(&widget); dialog->exec(); + Q_FOREACH(const QString &r, widget.rulesToAdd()) + { + addCustomRule(r); + } + if (widget.pageNeedsReload()) emit reloadCurrentPage(); diff --git a/src/adblock/blockedelementswidget.cpp b/src/adblock/blockedelementswidget.cpp index 58b96299..8c02134f 100644 --- a/src/adblock/blockedelementswidget.cpp +++ b/src/adblock/blockedelementswidget.cpp @@ -92,18 +92,25 @@ void BlockedElementsWidget::unblockElement() if (!buttonClicked) return; - QString newText = i18n("Unblocked"); - if (buttonClicked->text() == newText) - return; - - QString urlString = buttonClicked->property("URLTOUNBLOCK").toString(); + QString urlString = QL1S("@@") + buttonClicked->property("URLTOUNBLOCK").toString(); kDebug() << "urlString: " << urlString; - buttonClicked->setText(newText); - buttonClicked->setIcon(KIcon("dialog-ok")); + QString newText = i18n("Unblocked"); + QString buttonText = buttonClicked->text().remove('&'); + if (buttonText == newText) + { + buttonClicked->setText(i18n("Unblock")); + buttonClicked->setIcon(KIcon("dialog-ok-apply")); - AdBlockManager *m = qobject_cast(_manager); - m->addCustomRule(QL1S("@@") + urlString, false); + _rulesToAdd.removeOne(urlString); + } + else + { + buttonClicked->setText(newText); + buttonClicked->setIcon(KIcon("dialog-ok")); + _rulesToAdd << urlString; + } + _reloadPage = true; } diff --git a/src/adblock/blockedelementswidget.h b/src/adblock/blockedelementswidget.h index d1b0b387..c796be87 100644 --- a/src/adblock/blockedelementswidget.h +++ b/src/adblock/blockedelementswidget.h @@ -49,13 +49,17 @@ public: void setHidedElements(int); bool pageNeedsReload() { return _reloadPage; }; + + QStringList rulesToAdd() { return _rulesToAdd; }; private Q_SLOTS: void unblockElement(); private: QObject *_manager; + bool _reloadPage; + QStringList _rulesToAdd; }; #endif // BLOCKED_ELEMENTS_WIDGET_H -- cgit v1.2.1