mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
AdBlock: Added option to use full EasyList subscription
Instead of downloading only the essential half of EasyList, user can now choose to download and use the full list. This restriction is still here because the other half of EasyList is full of domain restricted rules that are using RegExps in our implementation, and thus being slow.
This commit is contained in:
parent
9ad5563d36
commit
2abefeaf79
@ -24,7 +24,7 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
m_knownSubscriptions << Subscription("EasyList (English)", "https://easylist-downloads.adblockplus.org/easylist.txt")
|
m_knownSubscriptions << Subscription("EasyList (English)", ADBLOCK_EASYLIST_URL)
|
||||||
<< Subscription("Fanboy's List (English)", "http://www.fanboy.co.nz/adblock/fanboy-adblock.txt")
|
<< Subscription("Fanboy's List (English)", "http://www.fanboy.co.nz/adblock/fanboy-adblock.txt")
|
||||||
<< Subscription("Adversity (English)", "http://adversity.googlecode.com/hg/Adversity.txt")
|
<< Subscription("Adversity (English)", "http://adversity.googlecode.com/hg/Adversity.txt")
|
||||||
<< Subscription("BSI Lista Polska (Polish)", "http://www.bsi.info.pl/filtrABP.txt")
|
<< Subscription("BSI Lista Polska (Polish)", "http://www.bsi.info.pl/filtrABP.txt")
|
||||||
|
@ -33,6 +33,7 @@ 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);
|
||||||
@ -57,6 +58,7 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
|
|||||||
connect(adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
|
connect(adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
|
||||||
connect(search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
|
connect(search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
|
||||||
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
|
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
|
||||||
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
|
||||||
@ -121,6 +123,9 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +179,19 @@ 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialog::closeEvent(ev);
|
||||||
|
}
|
||||||
|
@ -55,6 +55,8 @@ 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;
|
||||||
@ -65,6 +67,7 @@ private:
|
|||||||
QAction* m_actionRemoveSubscription;
|
QAction* m_actionRemoveSubscription;
|
||||||
|
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
|
bool m_useLimitedEasyList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKDIALOG_H
|
#endif // ADBLOCKDIALOG_H
|
||||||
|
@ -120,6 +120,15 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<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">
|
||||||
@ -131,6 +140,8 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../data/icons.qrc"/>
|
<include location="../data/icons.qrc"/>
|
||||||
|
@ -44,6 +44,7 @@ AdBlockManager::AdBlockManager(QObject* parent)
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_loaded(false)
|
, m_loaded(false)
|
||||||
, m_enabled(true)
|
, m_enabled(true)
|
||||||
|
, m_useLimitedEasyList(true)
|
||||||
{
|
{
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
@ -210,6 +211,7 @@ 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();
|
||||||
@ -256,7 +258,7 @@ void AdBlockManager::load()
|
|||||||
// Prepend EasyList if subscriptions are empty
|
// Prepend EasyList if subscriptions are empty
|
||||||
if (m_subscriptions.isEmpty()) {
|
if (m_subscriptions.isEmpty()) {
|
||||||
AdBlockSubscription* easyList = new AdBlockSubscription(tr("EasyList"), this);
|
AdBlockSubscription* easyList = new AdBlockSubscription(tr("EasyList"), this);
|
||||||
easyList->setUrl(QUrl("https://easylist-downloads.adblockplus.org/easylist.txt"));
|
easyList->setUrl(QUrl(ADBLOCK_EASYLIST_URL));
|
||||||
easyList->setFilePath(mApp->currentProfilePath() + "adblock/easylist.txt");
|
easyList->setFilePath(mApp->currentProfilePath() + "adblock/easylist.txt");
|
||||||
connect(easyList, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
|
connect(easyList, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
|
||||||
|
|
||||||
@ -309,6 +311,7 @@ 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();
|
||||||
}
|
}
|
||||||
@ -325,6 +328,22 @@ 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
|
||||||
{
|
{
|
||||||
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
||||||
|
@ -48,6 +48,9 @@ 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;
|
QString elementHidingRules() const;
|
||||||
QString elementHidingRulesForDomain(const QUrl &url) const;
|
QString elementHidingRulesForDomain(const QUrl &url) const;
|
||||||
|
|
||||||
@ -79,6 +82,7 @@ private:
|
|||||||
|
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
|
bool m_useLimitedEasyList;
|
||||||
|
|
||||||
QList<AdBlockSubscription*> m_subscriptions;
|
QList<AdBlockSubscription*> m_subscriptions;
|
||||||
QStringList m_disabledRules;
|
QStringList m_disabledRules;
|
||||||
|
@ -182,7 +182,7 @@ void AdBlockSubscription::saveDownloadedData(const QByteArray &data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_url == QUrl("https://easylist-downloads.adblockplus.org/easylist.txt")) {
|
if (AdBlockManager::instance()->useLimitedEasyList() && m_url == QUrl(ADBLOCK_EASYLIST_URL)) {
|
||||||
// Third-party advertisers rules are with start domain (||) placeholder which needs regexps
|
// Third-party advertisers rules are with start domain (||) placeholder which needs regexps
|
||||||
// So we are ignoring it for keeping good performance
|
// So we are ignoring it for keeping good performance
|
||||||
// But we will use whitelist rules at the end of list
|
// But we will use whitelist rules at the end of list
|
||||||
|
@ -99,6 +99,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qz::NewTabPositionFlags)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#define DEFAULT_THEME_NAME "windows"
|
#define DEFAULT_THEME_NAME "windows"
|
||||||
#elif defined(QZ_WS_X11)
|
#elif defined(QZ_WS_X11)
|
||||||
|
Loading…
Reference in New Issue
Block a user