1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

AdBlock: Remove option to use limited EasyList subscription

It is no longer need as AdBlock matching runs in separate thread
This commit is contained in:
David Rosca 2017-02-23 19:58:05 +01:00
parent 93b1104611
commit 8cbccbf71d
6 changed files with 16 additions and 71 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -34,7 +34,6 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
, m_currentTreeWidget(0) , m_currentTreeWidget(0)
, m_currentSubscription(0) , m_currentSubscription(0)
, m_loaded(false) , m_loaded(false)
, m_useLimitedEasyList(false)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setupUi(this); setupUi(this);
@ -127,9 +126,6 @@ void AdBlockDialog::currentChanged(int index)
if (index != -1) { if (index != -1) {
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index)); m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
m_currentSubscription = m_currentTreeWidget->subscription(); m_currentSubscription = m_currentTreeWidget->subscription();
bool isEasyList = m_currentSubscription->url() == QUrl(ADBLOCK_EASYLIST_URL);
useLimitedEasyList->setVisible(isEasyList);
} }
} }
@ -183,19 +179,7 @@ void AdBlockDialog::load()
tabWidget->addTab(tree, subscription->title()); tabWidget->addTab(tree, subscription->title());
} }
m_useLimitedEasyList = m_manager->useLimitedEasyList();
useLimitedEasyList->setChecked(m_useLimitedEasyList);
m_loaded = true; m_loaded = true;
QTimer::singleShot(50, this, SLOT(loadSubscriptions())); QTimer::singleShot(50, this, SLOT(loadSubscriptions()));
} }
void AdBlockDialog::closeEvent(QCloseEvent* ev)
{
if (useLimitedEasyList->isChecked() != m_useLimitedEasyList) {
m_manager->setUseLimitedEasyList(useLimitedEasyList->isChecked());
}
QWidget::closeEvent(ev);
}

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -55,8 +55,6 @@ private slots:
void load(); void load();
private: private:
void closeEvent(QCloseEvent* ev);
AdBlockManager* m_manager; AdBlockManager* m_manager;
AdBlockTreeWidget* m_currentTreeWidget; AdBlockTreeWidget* m_currentTreeWidget;
AdBlockSubscription* m_currentSubscription; AdBlockSubscription* m_currentSubscription;
@ -67,7 +65,6 @@ private:
QAction* m_actionRemoveSubscription; QAction* m_actionRemoveSubscription;
bool m_loaded; bool m_loaded;
bool m_useLimitedEasyList;
}; };
#endif // ADBLOCKDIALOG_H #endif // ADBLOCKDIALOG_H

View File

@ -57,7 +57,16 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item row="4" column="0" colspan="2"> <item row="4" column="0" colspan="2">
@ -116,13 +125,6 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="useLimitedEasyList">
<property name="text">
<string>Use only essential part of EasyList (for performance reasons)</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">

View File

@ -48,7 +48,6 @@ AdBlockManager::AdBlockManager(QObject* parent)
: QObject(parent) : QObject(parent)
, m_loaded(false) , m_loaded(false)
, m_enabled(true) , m_enabled(true)
, m_useLimitedEasyList(true)
, m_matcher(new AdBlockMatcher(this)) , m_matcher(new AdBlockMatcher(this))
, m_interceptor(new AdBlockUrlInterceptor(this)) , m_interceptor(new AdBlockUrlInterceptor(this))
{ {
@ -263,7 +262,6 @@ void AdBlockManager::load()
Settings settings; Settings settings;
settings.beginGroup("AdBlock"); settings.beginGroup("AdBlock");
m_enabled = settings.value("enabled", m_enabled).toBool(); m_enabled = settings.value("enabled", m_enabled).toBool();
m_useLimitedEasyList = settings.value("useLimitedEasyList", m_useLimitedEasyList).toBool();
m_disabledRules = settings.value("disabledRules", QStringList()).toStringList(); m_disabledRules = settings.value("disabledRules", QStringList()).toStringList();
QDateTime lastUpdate = settings.value("lastUpdate", QDateTime()).toDateTime(); QDateTime lastUpdate = settings.value("lastUpdate", QDateTime()).toDateTime();
settings.endGroup(); settings.endGroup();
@ -374,7 +372,6 @@ void AdBlockManager::save()
Settings settings; Settings settings;
settings.beginGroup("AdBlock"); settings.beginGroup("AdBlock");
settings.setValue("enabled", m_enabled); settings.setValue("enabled", m_enabled);
settings.setValue("useLimitedEasyList", m_useLimitedEasyList);
settings.setValue("disabledRules", m_disabledRules); settings.setValue("disabledRules", m_disabledRules);
settings.endGroup(); settings.endGroup();
} }
@ -391,22 +388,6 @@ bool AdBlockManager::canRunOnScheme(const QString &scheme) const
|| scheme == QLatin1String("abp")); || scheme == QLatin1String("abp"));
} }
bool AdBlockManager::useLimitedEasyList() const
{
return m_useLimitedEasyList;
}
void AdBlockManager::setUseLimitedEasyList(bool useLimited)
{
m_useLimitedEasyList = useLimited;
foreach (AdBlockSubscription* subscription, m_subscriptions) {
if (subscription->url() == QUrl(ADBLOCK_EASYLIST_URL)) {
subscription->updateSubscription();
}
}
}
bool AdBlockManager::canBeBlocked(const QUrl &url) const bool AdBlockManager::canBeBlocked(const QUrl &url) const
{ {
return !m_matcher->adBlockDisabledForUrl(url); return !m_matcher->adBlockDisabledForUrl(url);

View File

@ -49,9 +49,6 @@ public:
bool isEnabled() const; bool isEnabled() const;
bool canRunOnScheme(const QString &scheme) const; bool canRunOnScheme(const QString &scheme) const;
bool useLimitedEasyList() const;
void setUseLimitedEasyList(bool useLimited);
QString elementHidingRules(const QUrl &url) const; QString elementHidingRules(const QUrl &url) const;
QString elementHidingRulesForDomain(const QUrl &url) const; QString elementHidingRulesForDomain(const QUrl &url) const;
@ -90,7 +87,6 @@ private:
bool m_loaded; bool m_loaded;
bool m_enabled; bool m_enabled;
bool m_useLimitedEasyList;
QList<AdBlockSubscription*> m_subscriptions; QList<AdBlockSubscription*> m_subscriptions;
AdBlockMatcher* m_matcher; AdBlockMatcher* m_matcher;

View File

@ -1,6 +1,6 @@
/* ============================================================ /* ============================================================
* QupZilla - WebKit based browser * QupZilla - Qt web browser
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com> * Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -188,21 +188,6 @@ bool AdBlockSubscription::saveDownloadedData(const QByteArray &data)
// Write subscription header // Write subscription header
file.write(QString("Title: %1\nUrl: %2\n").arg(title(), url().toString()).toUtf8()); file.write(QString("Title: %1\nUrl: %2\n").arg(title(), url().toString()).toUtf8());
if (AdBlockManager::instance()->useLimitedEasyList() && m_url == QUrl(ADBLOCK_EASYLIST_URL)) {
// Third-party advertisers rules are with start domain (||) placeholder which needs regexps
// So we are ignoring it for keeping good performance
// But we will use whitelist rules at the end of list
QByteArray part1 = data.left(data.indexOf(QLatin1String("!-----------------------------Third-party adverts-----------------------------!")));
QByteArray part2 = data.mid(data.indexOf(QLatin1String("!---------------------------------Whitelists----------------------------------!")));
file.write(part1);
file.write(part2);
file.close();
return true;
}
file.write(data); file.write(data);
file.close(); file.close();
return true; return true;