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/adblock/adblockhostmatcher.cpp | 37 +++++- src/adblock/adblockhostmatcher.h | 4 + src/adblock/adblockmanager.cpp | 64 +++++---- src/adblock/adblockmanager.h | 8 +- src/adblock/adblocksettingwidget.cpp | 242 ++++++++++++++++++++++++++++++++++ src/adblock/adblocksettingwidget.h | 73 ++++++++++ src/adblock/adblockwidget.cpp | 242 ---------------------------------- src/adblock/adblockwidget.h | 73 ---------- src/adblock/blockedelementswidget.cpp | 116 ---------------- src/adblock/blockedelementswidget.h | 71 ---------- 10 files changed, 397 insertions(+), 533 deletions(-) create mode 100644 src/adblock/adblocksettingwidget.cpp create mode 100644 src/adblock/adblocksettingwidget.h delete mode 100644 src/adblock/adblockwidget.cpp delete mode 100644 src/adblock/adblockwidget.h delete mode 100644 src/adblock/blockedelementswidget.cpp delete mode 100644 src/adblock/blockedelementswidget.h (limited to 'src/adblock') 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 #include +#include + class AdBlockHostMatcher { public: @@ -47,6 +49,8 @@ public: m_hostList.clear(); } + void remove(const QString &hostRule); + private: QSet 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 @@ -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 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 s_adBlockManager; diff --git a/src/adblock/adblocksettingwidget.cpp b/src/adblock/adblocksettingwidget.cpp new file mode 100644 index 00000000..55b48046 --- /dev/null +++ b/src/adblock/adblocksettingwidget.cpp @@ -0,0 +1,242 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010-2012 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 "adblocksettingwidget.h" +#include "adblocksettingwidget.moc" + +// Auto Includes +#include "rekonq.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include +#include +#include + + +AdBlockSettingWidget::AdBlockSettingWidget(KSharedConfig::Ptr config, QWidget *parent) + : QWidget(parent) + , _changed(false) + , _adblockConfig(config) +{ + setupUi(this); + + hintLabel->setText(i18n("Filter expression (e.g. http://www.example.com/ad/*, more information):")); + connect(hintLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotInfoLinkActivated(QString))); + + manualFiltersListWidget->setSortingEnabled(true); + manualFiltersListWidget->setSelectionMode(QAbstractItemView::SingleSelection); + + searchLine->setListWidget(manualFiltersListWidget); + + insertButton->setIcon(KIcon("list-add")); + connect(insertButton, SIGNAL(clicked()), this, SLOT(insertRule())); + + removeButton->setIcon(KIcon("list-remove")); + connect(removeButton, SIGNAL(clicked()), this, SLOT(removeRule())); + + load(); + + spinBox->setSuffix(ki18np(" day", " days")); + + // emit changed signal + connect(insertButton, SIGNAL(clicked()), this, SLOT(hasChanged())); + connect(removeButton, SIGNAL(clicked()), this, SLOT(hasChanged())); + connect(checkEnableAdblock, SIGNAL(stateChanged(int)), this, SLOT(hasChanged())); + connect(checkHideAds, SIGNAL(stateChanged(int)), this, SLOT(hasChanged())); + connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(hasChanged())); + + connect(automaticFiltersListWidget, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(hasChanged())); +} + + +void AdBlockSettingWidget::slotInfoLinkActivated(const QString &url) +{ + Q_UNUSED(url) + + QString hintHelpString = 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."); + + QWhatsThis::showText(QCursor::pos(), hintHelpString); +} + + +void AdBlockSettingWidget::insertRule() +{ + QString rule = addFilterLineEdit->text(); + if (rule.isEmpty()) + return; + + manualFiltersListWidget->addItem(rule); + addFilterLineEdit->clear(); +} + + +void AdBlockSettingWidget::removeRule() +{ + manualFiltersListWidget->takeItem(manualFiltersListWidget->currentRow()); +} + + +void AdBlockSettingWidget::load() +{ + // General settings + KConfigGroup settingsGroup(_adblockConfig, "Settings"); + + const bool isAdBlockEnabled = settingsGroup.readEntry("adBlockEnabled", false); + checkEnableAdblock->setChecked(isAdBlockEnabled); + + // update enabled status + checkHideAds->setEnabled(isAdBlockEnabled); + tabWidget->setEnabled(isAdBlockEnabled); + + const bool areImageFiltered = settingsGroup.readEntry("hideAdsEnabled", false); + checkHideAds->setChecked(areImageFiltered); + + const int days = settingsGroup.readEntry("updateInterval", 7); + spinBox->setValue(days); + + // ------------------------------------------------------------------------------ + + // automatic filters + KConfigGroup autoFiltersGroup(_adblockConfig, "FiltersList"); + + int i = 1; + QString n = QString::number(i); + + while (autoFiltersGroup.hasKey("FilterName-" + n)) + { + bool filterEnabled = autoFiltersGroup.readEntry("FilterEnabled-" + n, false); + QString filterName = autoFiltersGroup.readEntry("FilterName-" + n, QString()); + + QListWidgetItem *subItem = new QListWidgetItem(automaticFiltersListWidget); + subItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); + if (filterEnabled) + subItem->setCheckState(Qt::Checked); + else + subItem->setCheckState(Qt::Unchecked); + + subItem->setText(filterName); + + i++; + n = QString::number(i); + } + + // ------------------------------------------------------------------------------ + + // local filters + QString localRulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_local")); + + QFile ruleFile(localRulesFilePath); + if (!ruleFile.open(QFile::ReadOnly | QFile::Text)) + { + kDebug() << "Unable to open rule file" << localRulesFilePath; + return; + } + + QTextStream in(&ruleFile); + while (!in.atEnd()) + { + QString stringRule = in.readLine(); + QListWidgetItem *subItem = new QListWidgetItem(manualFiltersListWidget); + subItem->setText(stringRule); + } +} + + +void AdBlockSettingWidget::save() +{ + if (!_changed) + return; + + // General settings + KConfigGroup settingsGroup(_adblockConfig, "Settings"); + + settingsGroup.writeEntry("adBlockEnabled", checkEnableAdblock->isChecked()); + settingsGroup.writeEntry("hideAdsEnabled", checkHideAds->isChecked()); + settingsGroup.writeEntry("updateInterval", spinBox->value()); + + // automatic filters + KConfigGroup autoFiltersGroup(_adblockConfig, "FiltersList"); + for (int i = 0; i < automaticFiltersListWidget->count(); i++) + { + QListWidgetItem *subItem = automaticFiltersListWidget->item(i); + bool active = true; + if (subItem->checkState() == Qt::Unchecked) + active = false; + + QString n = QString::number(i + 1); + autoFiltersGroup.writeEntry("FilterEnabled-" + n, active); + } + + // local filters + QString localRulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_local")); + + QFile ruleFile(localRulesFilePath); + if (!ruleFile.open(QFile::WriteOnly | QFile::Text)) + { + kDebug() << "Unable to open rule file" << localRulesFilePath; + return; + } + + QTextStream out(&ruleFile); + for (int i = 0; i < manualFiltersListWidget->count(); i++) + { + QListWidgetItem *subItem = manualFiltersListWidget->item(i); + QString stringRule = subItem->text(); + out << stringRule << '\n'; + } + + // ------------------------------------------------------------------------------- + _changed = false; + emit changed(false); +} + + +void AdBlockSettingWidget::hasChanged() +{ + // update enabled status + checkHideAds->setEnabled(checkEnableAdblock->isChecked()); + tabWidget->setEnabled(checkEnableAdblock->isChecked()); + _changed = true; + emit changed(true); +} + + +bool AdBlockSettingWidget::changed() +{ + return _changed; +} diff --git a/src/adblock/adblocksettingwidget.h b/src/adblock/adblocksettingwidget.h new file mode 100644 index 00000000..c630d795 --- /dev/null +++ b/src/adblock/adblocksettingwidget.h @@ -0,0 +1,73 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2010-2012 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_SETTINGS_WIDGET_H +#define ADBLOCK_SETTINGS_WIDGET_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Ui Includes +#include "ui_settings_adblock.h" + +// KDE Includes +#include + +// Qt Includes +#include + + +class AdBlockSettingWidget : public QWidget, private Ui::adblock +{ + Q_OBJECT + +public: + explicit AdBlockSettingWidget(KSharedConfig::Ptr config, QWidget *parent = 0); + + bool changed(); + +Q_SIGNALS: + void changed(bool); + +public Q_SLOTS: + void save(); + +private Q_SLOTS: + void hasChanged(); + + void slotInfoLinkActivated(const QString &); + void insertRule(); + void removeRule(); + +private: + void load(); + + bool _changed; + KSharedConfig::Ptr _adblockConfig; +}; + +#endif // ADBLOCK_SETTINGS_WIDGET_H diff --git a/src/adblock/adblockwidget.cpp b/src/adblock/adblockwidget.cpp deleted file mode 100644 index 5ada506e..00000000 --- a/src/adblock/adblockwidget.cpp +++ /dev/null @@ -1,242 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010-2012 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 "adblockwidget.h" -#include "adblockwidget.moc" - -// Auto Includes -#include "rekonq.h" - -// KDE Includes -#include -#include -#include - -// Qt Includes -#include -#include -#include - - -AdBlockWidget::AdBlockWidget(KSharedConfig::Ptr config, QWidget *parent) - : QWidget(parent) - , _changed(false) - , _adblockConfig(config) -{ - setupUi(this); - - hintLabel->setText(i18n("Filter expression (e.g. http://www.example.com/ad/*, more information):")); - connect(hintLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotInfoLinkActivated(QString))); - - manualFiltersListWidget->setSortingEnabled(true); - manualFiltersListWidget->setSelectionMode(QAbstractItemView::SingleSelection); - - searchLine->setListWidget(manualFiltersListWidget); - - insertButton->setIcon(KIcon("list-add")); - connect(insertButton, SIGNAL(clicked()), this, SLOT(insertRule())); - - removeButton->setIcon(KIcon("list-remove")); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeRule())); - - load(); - - spinBox->setSuffix(ki18np(" day", " days")); - - // emit changed signal - connect(insertButton, SIGNAL(clicked()), this, SLOT(hasChanged())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(hasChanged())); - connect(checkEnableAdblock, SIGNAL(stateChanged(int)), this, SLOT(hasChanged())); - connect(checkHideAds, SIGNAL(stateChanged(int)), this, SLOT(hasChanged())); - connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(hasChanged())); - - connect(automaticFiltersListWidget, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(hasChanged())); -} - - -void AdBlockWidget::slotInfoLinkActivated(const QString &url) -{ - Q_UNUSED(url) - - QString hintHelpString = 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."); - - QWhatsThis::showText(QCursor::pos(), hintHelpString); -} - - -void AdBlockWidget::insertRule() -{ - QString rule = addFilterLineEdit->text(); - if (rule.isEmpty()) - return; - - manualFiltersListWidget->addItem(rule); - addFilterLineEdit->clear(); -} - - -void AdBlockWidget::removeRule() -{ - manualFiltersListWidget->takeItem(manualFiltersListWidget->currentRow()); -} - - -void AdBlockWidget::load() -{ - // General settings - KConfigGroup settingsGroup(_adblockConfig, "Settings"); - - const bool isAdBlockEnabled = settingsGroup.readEntry("adBlockEnabled", false); - checkEnableAdblock->setChecked(isAdBlockEnabled); - - // update enabled status - checkHideAds->setEnabled(isAdBlockEnabled); - tabWidget->setEnabled(isAdBlockEnabled); - - const bool areImageFiltered = settingsGroup.readEntry("hideAdsEnabled", false); - checkHideAds->setChecked(areImageFiltered); - - const int days = settingsGroup.readEntry("updateInterval", 7); - spinBox->setValue(days); - - // ------------------------------------------------------------------------------ - - // automatic filters - KConfigGroup autoFiltersGroup(_adblockConfig, "FiltersList"); - - int i = 1; - QString n = QString::number(i); - - while (autoFiltersGroup.hasKey("FilterName-" + n)) - { - bool filterEnabled = autoFiltersGroup.readEntry("FilterEnabled-" + n, false); - QString filterName = autoFiltersGroup.readEntry("FilterName-" + n, QString()); - - QListWidgetItem *subItem = new QListWidgetItem(automaticFiltersListWidget); - subItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); - if (filterEnabled) - subItem->setCheckState(Qt::Checked); - else - subItem->setCheckState(Qt::Unchecked); - - subItem->setText(filterName); - - i++; - n = QString::number(i); - } - - // ------------------------------------------------------------------------------ - - // local filters - QString localRulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_local")); - - QFile ruleFile(localRulesFilePath); - if (!ruleFile.open(QFile::ReadOnly | QFile::Text)) - { - kDebug() << "Unable to open rule file" << localRulesFilePath; - return; - } - - QTextStream in(&ruleFile); - while (!in.atEnd()) - { - QString stringRule = in.readLine(); - QListWidgetItem *subItem = new QListWidgetItem(manualFiltersListWidget); - subItem->setText(stringRule); - } -} - - -void AdBlockWidget::save() -{ - if (!_changed) - return; - - // General settings - KConfigGroup settingsGroup(_adblockConfig, "Settings"); - - settingsGroup.writeEntry("adBlockEnabled", checkEnableAdblock->isChecked()); - settingsGroup.writeEntry("hideAdsEnabled", checkHideAds->isChecked()); - settingsGroup.writeEntry("updateInterval", spinBox->value()); - - // automatic filters - KConfigGroup autoFiltersGroup(_adblockConfig, "FiltersList"); - for (int i = 0; i < automaticFiltersListWidget->count(); i++) - { - QListWidgetItem *subItem = automaticFiltersListWidget->item(i); - bool active = true; - if (subItem->checkState() == Qt::Unchecked) - active = false; - - QString n = QString::number(i + 1); - autoFiltersGroup.writeEntry("FilterEnabled-" + n, active); - } - - // local filters - QString localRulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_local")); - - QFile ruleFile(localRulesFilePath); - if (!ruleFile.open(QFile::WriteOnly | QFile::Text)) - { - kDebug() << "Unable to open rule file" << localRulesFilePath; - return; - } - - QTextStream out(&ruleFile); - for (int i = 0; i < manualFiltersListWidget->count(); i++) - { - QListWidgetItem *subItem = manualFiltersListWidget->item(i); - QString stringRule = subItem->text(); - out << stringRule << '\n'; - } - - // ------------------------------------------------------------------------------- - _changed = false; - emit changed(false); -} - - -void AdBlockWidget::hasChanged() -{ - // update enabled status - checkHideAds->setEnabled(checkEnableAdblock->isChecked()); - tabWidget->setEnabled(checkEnableAdblock->isChecked()); - _changed = true; - emit changed(true); -} - - -bool AdBlockWidget::changed() -{ - return _changed; -} diff --git a/src/adblock/adblockwidget.h b/src/adblock/adblockwidget.h deleted file mode 100644 index 37f29f93..00000000 --- a/src/adblock/adblockwidget.h +++ /dev/null @@ -1,73 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010-2012 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_WIDGET_H -#define ADBLOCK_WIDGET_H - - -// Rekonq Includes -#include "rekonq_defines.h" - -// Ui Includes -#include "ui_settings_adblock.h" - -// KDE Includes -#include - -// Qt Includes -#include - - -class AdBlockWidget : public QWidget, private Ui::adblock -{ - Q_OBJECT - -public: - explicit AdBlockWidget(KSharedConfig::Ptr config, QWidget *parent = 0); - - bool changed(); - -Q_SIGNALS: - void changed(bool); - -public Q_SLOTS: - void save(); - -private Q_SLOTS: - void hasChanged(); - - void slotInfoLinkActivated(const QString &); - void insertRule(); - void removeRule(); - -private: - void load(); - - bool _changed; - KSharedConfig::Ptr _adblockConfig; -}; - -#endif // ADBLOCK_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 -* -* -* 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 "blockedelementswidget.h" -#include "blockedelementswidget.moc" - -// Local Includes -#include "adblockmanager.h" - -// Qt Includes -#include -#include -#include - - -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(_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(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/adblock/blockedelementswidget.h b/src/adblock/blockedelementswidget.h deleted file mode 100644 index d26ee849..00000000 --- a/src/adblock/blockedelementswidget.h +++ /dev/null @@ -1,71 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2012 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 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 - - -class BlockedElementsWidget : public QWidget, private Ui::BlockedElements -{ - Q_OBJECT - -public: - explicit BlockedElementsWidget(QObject *manager, QWidget *parent = 0); - - void setBlockedElements(const QStringList &); - 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