mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
parent
71f0737511
commit
93b1104611
@ -34,6 +34,7 @@
|
||||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include <QUrlQuery>
|
||||
#include <QMutexLocker>
|
||||
|
||||
//#define ADBLOCK_DEBUG
|
||||
|
||||
@ -80,6 +81,14 @@ void AdBlockManager::setEnabled(bool enabled)
|
||||
|
||||
load();
|
||||
mApp->reloadUserStyleSheet();
|
||||
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
if (m_enabled) {
|
||||
m_matcher->update();
|
||||
} else {
|
||||
m_matcher->clear();
|
||||
}
|
||||
}
|
||||
|
||||
QList<AdBlockSubscription*> AdBlockManager::subscriptions() const
|
||||
@ -89,6 +98,8 @@ QList<AdBlockSubscription*> AdBlockManager::subscriptions() const
|
||||
|
||||
bool AdBlockManager::block(QWebEngineUrlRequestInfo &request)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
#ifdef ADBLOCK_DEBUG
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
@ -201,13 +212,15 @@ AdBlockSubscription* AdBlockManager::addSubscription(const QString &title, const
|
||||
|
||||
m_subscriptions.insert(m_subscriptions.count() - 1, subscription);
|
||||
connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
|
||||
connect(subscription, SIGNAL(subscriptionChanged()), m_matcher, SLOT(update()));
|
||||
connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher()));
|
||||
|
||||
return subscription;
|
||||
}
|
||||
|
||||
bool AdBlockManager::removeSubscription(AdBlockSubscription* subscription)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
if (!m_subscriptions.contains(subscription) || !subscription->canBeRemoved()) {
|
||||
return false;
|
||||
}
|
||||
@ -236,6 +249,8 @@ AdBlockCustomList* AdBlockManager::customList() const
|
||||
|
||||
void AdBlockManager::load()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
if (m_loaded) {
|
||||
return;
|
||||
}
|
||||
@ -310,7 +325,7 @@ void AdBlockManager::load()
|
||||
subscription->loadSubscription(m_disabledRules);
|
||||
|
||||
connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
|
||||
connect(subscription, SIGNAL(subscriptionChanged()), m_matcher, SLOT(update()));
|
||||
connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher()));
|
||||
}
|
||||
|
||||
if (lastUpdate.addDays(5) < QDateTime::currentDateTime()) {
|
||||
@ -327,6 +342,13 @@ void AdBlockManager::load()
|
||||
mApp->networkManager()->installUrlInterceptor(m_interceptor);
|
||||
}
|
||||
|
||||
void AdBlockManager::updateMatcher()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
m_matcher->update();
|
||||
}
|
||||
|
||||
void AdBlockManager::updateAllSubscriptions()
|
||||
{
|
||||
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
|
||||
* QupZilla - Qt web browser
|
||||
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.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
|
||||
@ -21,6 +21,7 @@
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QPointer>
|
||||
#include <QMutex>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
@ -79,6 +80,7 @@ public slots:
|
||||
void setEnabled(bool enabled);
|
||||
void showRule();
|
||||
|
||||
void updateMatcher();
|
||||
void updateAllSubscriptions();
|
||||
|
||||
AdBlockDialog* showDialog();
|
||||
@ -96,6 +98,7 @@ private:
|
||||
|
||||
AdBlockUrlInterceptor *m_interceptor;
|
||||
QPointer<AdBlockDialog> m_adBlockDialog;
|
||||
QMutex m_mutex;
|
||||
};
|
||||
|
||||
#endif // ADBLOCKMANAGER_H
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
||||
* QupZilla - Qt web browser
|
||||
* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.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
|
||||
@ -24,7 +24,6 @@ AdBlockMatcher::AdBlockMatcher(AdBlockManager* manager)
|
||||
: QObject(manager)
|
||||
, m_manager(manager)
|
||||
{
|
||||
connect(manager, SIGNAL(enabledChanged(bool)), this, SLOT(enabledChanged(bool)));
|
||||
}
|
||||
|
||||
AdBlockMatcher::~AdBlockMatcher()
|
||||
@ -218,11 +217,3 @@ void AdBlockMatcher::clear()
|
||||
qDeleteAll(m_createdRules);
|
||||
m_createdRules.clear();
|
||||
}
|
||||
|
||||
void AdBlockMatcher::enabledChanged(bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
update();
|
||||
else
|
||||
clear();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
||||
* QupZilla - Qt web browser
|
||||
* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.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
|
||||
@ -48,9 +48,6 @@ public slots:
|
||||
void update();
|
||||
void clear();
|
||||
|
||||
private slots:
|
||||
void enabledChanged(bool enabled);
|
||||
|
||||
private:
|
||||
AdBlockManager* m_manager;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user