Save work.
This commit is contained in:
parent
c2e1100ff6
commit
e3635f5394
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "definitions/definitions.h"
|
#include "definitions/definitions.h"
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
|
||||||
|
|
||||||
AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
||||||
: QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) {
|
: QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) {
|
||||||
@ -33,7 +35,7 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
|||||||
<< Subscription(QSL("IsraelList (Hebrew)"), QSL("http://secure.fanboy.co.nz/israelilist/IsraelList.txt"))
|
<< Subscription(QSL("IsraelList (Hebrew)"), QSL("http://secure.fanboy.co.nz/israelilist/IsraelList.txt"))
|
||||||
<< Subscription(QSL("NLBlock (Dutch)"), QSL("http://www.verzijlbergh.com/adblock/nlblock.txt"))
|
<< Subscription(QSL("NLBlock (Dutch)"), QSL("http://www.verzijlbergh.com/adblock/nlblock.txt"))
|
||||||
<< Subscription(QSL("Peter Lowe's list (English)"), QSL("http://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&mimetype=plaintext"))
|
<< Subscription(QSL("Peter Lowe's list (English)"), QSL("http://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&mimetype=plaintext"))
|
||||||
<< Subscription(QSL("PLgeneral (Polish))", QSL("http://www.niecko.pl/adblock/adblock.txt"))
|
<< Subscription(QSL("PLgeneral (Polish)"), QSL("http://www.niecko.pl/adblock/adblock.txt"))
|
||||||
<< Subscription(QSL("Schacks Adblock Plus liste (Danish)"), QSL("http://adblock.schack.dk/block.txt"))
|
<< Subscription(QSL("Schacks Adblock Plus liste (Danish)"), QSL("http://adblock.schack.dk/block.txt"))
|
||||||
<< Subscription(QSL("Xfiles (Italian)"), QSL("http://mozilla.gfsolone.com/filtri.txt"))
|
<< Subscription(QSL("Xfiles (Italian)"), QSL("http://mozilla.gfsolone.com/filtri.txt"))
|
||||||
<< Subscription(QSL("EasyPrivacy (English)"), QSL("http://easylist-downloads.adblockplus.org/easyprivacy.txt"))
|
<< Subscription(QSL("EasyPrivacy (English)"), QSL("http://easylist-downloads.adblockplus.org/easyprivacy.txt"))
|
||||||
@ -47,7 +49,8 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
|||||||
m_ui->comboBox->addItem(subscription.m_title);
|
m_ui->comboBox->addItem(subscription.m_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_ui->comboBox, &QComboBox::currentIndexChanged, this, &AdBlockAddSubscriptionDialog::indexChanged);
|
connect(m_ui->comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||||
|
this, &AdBlockAddSubscriptionDialog::indexChanged);
|
||||||
indexChanged(0);
|
indexChanged(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +65,7 @@ QString AdBlockAddSubscriptionDialog::url() const {
|
|||||||
void AdBlockAddSubscriptionDialog::indexChanged(int index) {
|
void AdBlockAddSubscriptionDialog::indexChanged(int index) {
|
||||||
const Subscription subscription = m_knownSubscriptions.at(index);
|
const Subscription subscription = m_knownSubscriptions.at(index);
|
||||||
|
|
||||||
// "Other..." entry
|
// "Other..." entry.
|
||||||
if (subscription.m_url.isEmpty()) {
|
if (subscription.m_url.isEmpty()) {
|
||||||
m_ui->title->clear();
|
m_ui->title->clear();
|
||||||
m_ui->url->clear();
|
m_ui->url->clear();
|
||||||
|
@ -43,7 +43,7 @@ class AdBlockAddSubscriptionDialog : public QDialog {
|
|||||||
void indexChanged(int index);
|
void indexChanged(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AdBlockAddSubscriptionDialog* m_ui;
|
Ui::AdBlockAddSubscriptionDialog *m_ui;
|
||||||
|
|
||||||
struct Subscription {
|
struct Subscription {
|
||||||
QString m_title;
|
QString m_title;
|
||||||
|
@ -41,7 +41,7 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
|
|||||||
|
|
||||||
m_ui->adblockCheckBox->setChecked(m_manager->isEnabled());
|
m_ui->adblockCheckBox->setChecked(m_manager->isEnabled());
|
||||||
|
|
||||||
QMenu* menu = new QMenu(buttonOptions);
|
QMenu* menu = new QMenu(m_ui->buttonOptions);
|
||||||
m_actionAddRule = menu->addAction(tr("Add Rule"), this, SLOT(addRule()));
|
m_actionAddRule = menu->addAction(tr("Add Rule"), this, SLOT(addRule()));
|
||||||
m_actionRemoveRule = menu->addAction(tr("Remove Rule"), this, SLOT(removeRule()));
|
m_actionRemoveRule = menu->addAction(tr("Remove Rule"), this, SLOT(removeRule()));
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
@ -54,10 +54,9 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
|
|||||||
m_ui->buttonOptions->setMenu(menu);
|
m_ui->buttonOptions->setMenu(menu);
|
||||||
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
|
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu()));
|
||||||
|
|
||||||
connect(adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
|
connect(m_ui->adblockCheckBox, SIGNAL(toggled(bool)), this, SLOT(enableAdBlock(bool)));
|
||||||
connect(search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString)));
|
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
|
||||||
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
|
connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(close()));
|
||||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(close()));
|
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
|
||||||
@ -71,12 +70,12 @@ void AdBlockDialog::showRule(const AdBlockRule* rule) const {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < tabWidget->count(); ++i) {
|
for (int i = 0; i < m_ui->tabWidget->count(); ++i) {
|
||||||
AdBlockTreeWidget *treeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(i));
|
AdBlockTreeWidget *treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(i));
|
||||||
|
|
||||||
if (subscription == treeWidget->subscription()) {
|
if (subscription == treeWidget->subscription()) {
|
||||||
treeWidget->showRule(rule);
|
treeWidget->showRule(rule);
|
||||||
tabWidget->setCurrentIndex(i);
|
m_ui->tabWidget->setCurrentIndex(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,10 +100,10 @@ void AdBlockDialog::addSubscription() {
|
|||||||
QString url = dialog.url();
|
QString url = dialog.url();
|
||||||
|
|
||||||
if (AdBlockSubscription *subscription = m_manager->addSubscription(title, url)) {
|
if (AdBlockSubscription *subscription = m_manager->addSubscription(title, url)) {
|
||||||
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, tabWidget);
|
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, m_ui->tabWidget);
|
||||||
int index = tabWidget->insertTab(tabWidget->count() - 1, tree, subscription->title());
|
int index = m_ui->tabWidget->insertTab(m_ui->tabWidget->count() - 1, tree, subscription->title());
|
||||||
|
|
||||||
tabWidget->setCurrentIndex(index);
|
m_ui->tabWidget->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,17 +115,11 @@ void AdBlockDialog::removeSubscription() {
|
|||||||
|
|
||||||
void AdBlockDialog::currentChanged(int index) {
|
void AdBlockDialog::currentChanged(int index) {
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(index));
|
m_currentTreeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(index));
|
||||||
m_currentSubscription = m_currentTreeWidget->subscription();
|
m_currentSubscription = m_currentTreeWidget->subscription();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::filterString(const QString &string) {
|
|
||||||
if (m_currentTreeWidget && adblockCheckBox->isChecked()) {
|
|
||||||
m_currentTreeWidget->filterString(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdBlockDialog::enableAdBlock(bool state) {
|
void AdBlockDialog::enableAdBlock(bool state) {
|
||||||
m_manager->setEnabled(state);
|
m_manager->setEnabled(state);
|
||||||
|
|
||||||
@ -149,20 +142,20 @@ void AdBlockDialog::learnAboutRules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::loadSubscriptions() {
|
void AdBlockDialog::loadSubscriptions() {
|
||||||
for (int i = 0; i < tabWidget->count(); ++i) {
|
for (int i = 0; i < m_ui->tabWidget->count(); ++i) {
|
||||||
AdBlockTreeWidget* treeWidget = qobject_cast<AdBlockTreeWidget*>(tabWidget->widget(i));
|
AdBlockTreeWidget *treeWidget = qobject_cast<AdBlockTreeWidget*>(m_ui->tabWidget->widget(i));
|
||||||
treeWidget->refresh();
|
treeWidget->refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockDialog::load() {
|
void AdBlockDialog::load() {
|
||||||
if (m_loaded || !adblockCheckBox->isChecked()) {
|
if (m_loaded || !m_ui->adblockCheckBox->isChecked()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
|
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
|
||||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, tabWidget);
|
AdBlockTreeWidget *tree = new AdBlockTreeWidget(subscription, m_ui->tabWidget);
|
||||||
tabWidget->addTab(tree, subscription->title());
|
m_ui->tabWidget->addTab(tree, subscription->title());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
|
@ -45,7 +45,6 @@ class AdBlockDialog : public QWidget {
|
|||||||
void removeSubscription();
|
void removeSubscription();
|
||||||
|
|
||||||
void currentChanged(int index);
|
void currentChanged(int index);
|
||||||
void filterString(const QString &string);
|
|
||||||
void enableAdBlock(bool state);
|
void enableAdBlock(bool state);
|
||||||
|
|
||||||
void aboutToShowMenu();
|
void aboutToShowMenu();
|
||||||
|
@ -24,33 +24,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="search">
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>Search...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Fixed</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>50</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="adblockWidget" native="true">
|
<widget class="QWidget" name="adblockWidget" native="true">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
@ -77,7 +50,7 @@
|
|||||||
<string>Options</string>
|
<string>Options</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../data/icons.qrc">
|
<iconset>
|
||||||
<normaloff>:/icons/other/adblock.png</normaloff>:/icons/other/adblock.png</iconset>
|
<normaloff>:/icons/other/adblock.png</normaloff>:/icons/other/adblock.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -139,9 +112,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources/>
|
||||||
<include location="../data/icons.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>adblockCheckBox</sender>
|
<sender>adblockCheckBox</sender>
|
||||||
|
@ -20,10 +20,13 @@
|
|||||||
#include "network-web/adblock/adblockrule.h"
|
#include "network-web/adblock/adblockrule.h"
|
||||||
#include "network-web/adblock/adblockmanager.h"
|
#include "network-web/adblock/adblockmanager.h"
|
||||||
#include "network-web/adblock/adblocksubscription.h"
|
#include "network-web/adblock/adblocksubscription.h"
|
||||||
|
#include "miscellaneous/application.h"
|
||||||
|
#include "network-web/webpage.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
AdBlockIcon::AdBlockIcon(BrowserWindow* window, QWidget* parent)
|
AdBlockIcon::AdBlockIcon(BrowserWindow* window, QWidget* parent)
|
||||||
: ClickableLabel(parent), m_window(window), m_menuAction(0), m_flashTimer(0), m_timerTicks(0), m_enabled(false) {
|
: ClickableLabel(parent), m_window(window), m_menuAction(0), m_flashTimer(0), m_timerTicks(0), m_enabled(false) {
|
||||||
setCursor(Qt::PointingHandCursor);
|
setCursor(Qt::PointingHandCursor);
|
||||||
@ -55,7 +58,8 @@ void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url) {
|
|||||||
pair.second = url;
|
pair.second = url;
|
||||||
m_blockedPopups.append(pair);
|
m_blockedPopups.append(pair);
|
||||||
|
|
||||||
mApp->desktopNotifications()->showNotification(QPixmap(":html/adblock_big.png"), tr("Blocked popup window"), tr("AdBlock blocked unwanted popup window."));
|
|
||||||
|
qApp->showGuiMessage(tr("Blocked popup window"), tr("AdBlock blocked unwanted popup window."), QSystemTrayIcon::Information);
|
||||||
|
|
||||||
if (!m_flashTimer) {
|
if (!m_flashTimer) {
|
||||||
m_flashTimer = new QTimer(this);
|
m_flashTimer = new QTimer(this);
|
||||||
@ -68,7 +72,7 @@ void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url) {
|
|||||||
m_flashTimer->setInterval(500);
|
m_flashTimer->setInterval(500);
|
||||||
m_flashTimer->start();
|
m_flashTimer->start();
|
||||||
|
|
||||||
connect(m_flashTimer, SIGNAL(timeout()), this, SLOT(animateIcon()));
|
connect(m_flashTimer, &QTimer::timeout, this, &AdBlockIcon::animateIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction *AdBlockIcon::menuAction() {
|
QAction *AdBlockIcon::menuAction() {
|
||||||
|
@ -16,29 +16,25 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "adblocksearchtree.h"
|
#include "network-web/adblock/adblocksearchtree.h"
|
||||||
#include "adblockrule.h"
|
#include "network-web/adblock/adblockrule.h"
|
||||||
|
|
||||||
#include <QWebEngineUrlRequestInfo>
|
#include <QWebEngineUrlRequestInfo>
|
||||||
|
|
||||||
AdBlockSearchTree::AdBlockSearchTree()
|
|
||||||
: m_root(new Node)
|
AdBlockSearchTree::AdBlockSearchTree() : m_root(new Node) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AdBlockSearchTree::~AdBlockSearchTree()
|
AdBlockSearchTree::~AdBlockSearchTree() {
|
||||||
{
|
|
||||||
deleteNode(m_root);
|
deleteNode(m_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSearchTree::clear()
|
void AdBlockSearchTree::clear() {
|
||||||
{
|
|
||||||
deleteNode(m_root);
|
deleteNode(m_root);
|
||||||
m_root = new Node;
|
m_root = new Node;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdBlockSearchTree::add(const AdBlockRule* rule)
|
bool AdBlockSearchTree::add(const AdBlockRule *rule) {
|
||||||
{
|
|
||||||
if (rule->m_type != AdBlockRule::StringContainsMatchRule) {
|
if (rule->m_type != AdBlockRule::StringContainsMatchRule) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -47,7 +43,7 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
|
|||||||
int len = filter.size();
|
int len = filter.size();
|
||||||
|
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
qDebug() << "AdBlockSearchTree: Inserting rule with filter len <= 0!";
|
qDebug("AdBlockSearchTree: Inserting rule with filter len <= 0!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,11 +52,13 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
|
|||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
const QChar c = filter.at(i);
|
const QChar c = filter.at(i);
|
||||||
Node *next = node->children.value(c);
|
Node *next = node->children.value(c);
|
||||||
|
|
||||||
if (!next) {
|
if (!next) {
|
||||||
next = new Node;
|
next = new Node;
|
||||||
next->c = c;
|
next->c = c;
|
||||||
node->children[c] = next;
|
node->children[c] = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = next;
|
node = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,18 +67,18 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdBlockRule* AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString) const
|
const AdBlockRule *AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString) const {
|
||||||
{
|
|
||||||
int len = urlString.size();
|
int len = urlString.size();
|
||||||
|
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QChar* string = urlString.constData();
|
const QChar *string = urlString.constData();
|
||||||
|
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
const AdBlockRule* rule = prefixSearch(request, domain, urlString, string++, len - i);
|
const AdBlockRule *rule = prefixSearch(request, domain, urlString, string++, len - i);
|
||||||
|
|
||||||
if (rule) {
|
if (rule) {
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
@ -89,15 +87,15 @@ const AdBlockRule* AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &reque
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdBlockRule* AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString, const QChar* string, int len) const
|
const AdBlockRule *AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString, const QChar *string, int len) const {
|
||||||
{
|
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QChar c = string[0];
|
QChar c = string[0];
|
||||||
|
|
||||||
Node* node = m_root->children.value(c);
|
Node *node = m_root->children.value(c);
|
||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -110,6 +108,7 @@ const AdBlockRule* AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
node = node->children.value(c);
|
node = node->children.value(c);
|
||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -122,13 +121,13 @@ const AdBlockRule* AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInf
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSearchTree::deleteNode(AdBlockSearchTree::Node* node)
|
void AdBlockSearchTree::deleteNode(AdBlockSearchTree::Node* node) {
|
||||||
{
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHashIterator<QChar, Node*> i(node->children);
|
QHashIterator<QChar, Node*> i(node->children);
|
||||||
|
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
deleteNode(i.value());
|
deleteNode(i.value());
|
||||||
|
@ -22,24 +22,21 @@
|
|||||||
#include <QChar>
|
#include <QChar>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
#include "qzcommon.h"
|
|
||||||
|
|
||||||
class QWebEngineUrlRequestInfo;
|
class QWebEngineUrlRequestInfo;
|
||||||
|
|
||||||
class AdBlockRule;
|
class AdBlockRule;
|
||||||
|
|
||||||
class QUPZILLA_EXPORT AdBlockSearchTree
|
class AdBlockSearchTree {
|
||||||
{
|
public:
|
||||||
public:
|
|
||||||
explicit AdBlockSearchTree();
|
explicit AdBlockSearchTree();
|
||||||
~AdBlockSearchTree();
|
virtual ~AdBlockSearchTree();
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
bool add(const AdBlockRule* rule);
|
bool add(const AdBlockRule *rule);
|
||||||
const AdBlockRule* find(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString) const;
|
const AdBlockRule *find(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Node {
|
struct Node {
|
||||||
QChar c;
|
QChar c;
|
||||||
const AdBlockRule* rule;
|
const AdBlockRule* rule;
|
||||||
@ -48,10 +45,10 @@ private:
|
|||||||
Node() : c(0) , rule(0) { }
|
Node() : c(0) , rule(0) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
const AdBlockRule* prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain,
|
const AdBlockRule *prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain,
|
||||||
const QString &urlString, const QChar* string, int len) const;
|
const QString &urlString, const QChar *string, int len) const;
|
||||||
|
|
||||||
void deleteNode(Node* node);
|
void deleteNode(Node *node);
|
||||||
|
|
||||||
Node* m_root;
|
Node* m_root;
|
||||||
};
|
};
|
||||||
|
@ -44,54 +44,44 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "adblocksubscription.h"
|
#include "network-web/adblock/adblocksubscription.h"
|
||||||
#include "adblockmanager.h"
|
|
||||||
#include "adblocksearchtree.h"
|
#include "network-web/adblock/adblockmanager.h"
|
||||||
#include "mainapplication.h"
|
#include "network-web/adblock/adblocksearchtree.h"
|
||||||
#include "networkmanager.h"
|
#include "definitions/definitions.h"
|
||||||
#include "datapaths.h"
|
#include "network-web/silentnetworkaccessmanager.h"
|
||||||
#include "qztools.h"
|
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QSaveFile>
|
#include <QSaveFile>
|
||||||
|
|
||||||
|
|
||||||
AdBlockSubscription::AdBlockSubscription(const QString &title, QObject* parent)
|
AdBlockSubscription::AdBlockSubscription(const QString &title, QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent), m_reply(0), m_title(title), m_updated(false) {
|
||||||
, m_reply(0)
|
|
||||||
, m_title(title)
|
|
||||||
, m_updated(false)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AdBlockSubscription::title() const
|
QString AdBlockSubscription::title() const {
|
||||||
{
|
|
||||||
return m_title;
|
return m_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AdBlockSubscription::filePath() const
|
QString AdBlockSubscription::filePath() const {
|
||||||
{
|
|
||||||
return m_filePath;
|
return m_filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::setFilePath(const QString &path)
|
void AdBlockSubscription::setFilePath(const QString &path) {
|
||||||
{
|
|
||||||
m_filePath = path;
|
m_filePath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl AdBlockSubscription::url() const
|
QUrl AdBlockSubscription::url() const {
|
||||||
{
|
|
||||||
return m_url;
|
return m_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::setUrl(const QUrl &url)
|
void AdBlockSubscription::setUrl(const QUrl &url) {
|
||||||
{
|
|
||||||
m_url = url;
|
m_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
|
void AdBlockSubscription::loadSubscription(const QStringList &disabledRules) {
|
||||||
{
|
|
||||||
QFile file(m_filePath);
|
QFile file(m_filePath);
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
@ -100,7 +90,7 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!file.open(QFile::ReadOnly)) {
|
if (!file.open(QFile::ReadOnly)) {
|
||||||
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for reading" << m_filePath;
|
qWarning("Unable to open adblock file '%s' for reading.", qPrintable(m_filePath));
|
||||||
QTimer::singleShot(0, this, SLOT(updateSubscription()));
|
QTimer::singleShot(0, this, SLOT(updateSubscription()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -112,8 +102,8 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
|
|||||||
textStream.readLine(1024);
|
textStream.readLine(1024);
|
||||||
QString header = textStream.readLine(1024);
|
QString header = textStream.readLine(1024);
|
||||||
|
|
||||||
if (!header.startsWith(QLatin1String("[Adblock")) || m_title.isEmpty()) {
|
if (!header.startsWith(QL1S("[Adblock")) || m_title.isEmpty()) {
|
||||||
qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "invalid format of adblock file" << m_filePath;
|
qWarning("Invalid format of AdBlock file '%s'.", qPrintable(m_filePath));
|
||||||
QTimer::singleShot(0, this, SLOT(updateSubscription()));
|
QTimer::singleShot(0, this, SLOT(updateSubscription()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -121,7 +111,7 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
|
|||||||
m_rules.clear();
|
m_rules.clear();
|
||||||
|
|
||||||
while (!textStream.atEnd()) {
|
while (!textStream.atEnd()) {
|
||||||
AdBlockRule* rule = new AdBlockRule(textStream.readLine(), this);
|
AdBlockRule *rule = new AdBlockRule(textStream.readLine(), this);
|
||||||
|
|
||||||
if (disabledRules.contains(rule->filter())) {
|
if (disabledRules.contains(rule->filter())) {
|
||||||
rule->setEnabled(false);
|
rule->setEnabled(false);
|
||||||
@ -130,23 +120,23 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules)
|
|||||||
m_rules.append(rule);
|
m_rules.append(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial update
|
// Initial update.
|
||||||
if (m_rules.isEmpty() && !m_updated) {
|
if (m_rules.isEmpty() && !m_updated) {
|
||||||
QTimer::singleShot(0, this, SLOT(updateSubscription()));
|
QTimer::singleShot(0, this, SLOT(updateSubscription()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::saveSubscription()
|
void AdBlockSubscription::saveSubscription() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdBlockSubscription::updateSubscription()
|
void AdBlockSubscription::updateSubscription() {
|
||||||
{
|
|
||||||
if (m_reply || !m_url.isValid()) {
|
if (m_reply || !m_url.isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_reply = mApp->networkManager()->get(QNetworkRequest(m_url));
|
SilentNetworkAccessManager *mgs = new SilentNetworkAccessManager(this);
|
||||||
|
|
||||||
|
m_reply = mgs->get(QNetworkRequest(m_url));
|
||||||
connect(m_reply, &QNetworkReply::finished, this, &AdBlockSubscription::subscriptionDownloaded);
|
connect(m_reply, &QNetworkReply::finished, this, &AdBlockSubscription::subscriptionDownloaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,13 +149,11 @@ void AdBlockSubscription::subscriptionDownloaded()
|
|||||||
bool error = false;
|
bool error = false;
|
||||||
const QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8();
|
const QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8();
|
||||||
|
|
||||||
if (m_reply->error() != QNetworkReply::NoError ||
|
if (m_reply->error() != QNetworkReply::NoError || !response.startsWith(QByteArray("[Adblock")) || !saveDownloadedData(response)) {
|
||||||
!response.startsWith(QByteArray("[Adblock")) ||
|
|
||||||
!saveDownloadedData(response)
|
|
||||||
) {
|
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_reply->manager()->deleteLater();
|
||||||
m_reply->deleteLater();
|
m_reply->deleteLater();
|
||||||
m_reply = 0;
|
m_reply = 0;
|
||||||
|
|
||||||
|
@ -50,19 +50,19 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "qzcommon.h"
|
#include "network-web/adblock/adblockrule.h"
|
||||||
#include "adblockrule.h"
|
#include "network-web/adblock/adblocksearchtree.h"
|
||||||
#include "adblocksearchtree.h"
|
|
||||||
|
|
||||||
class QUrl;
|
class QUrl;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
|
||||||
class QUPZILLA_EXPORT AdBlockSubscription : public QObject
|
class AdBlockSubscription : public QObject {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
|
||||||
explicit AdBlockSubscription(const QString &title, QObject* parent = 0);
|
public:
|
||||||
~AdBlockSubscription();
|
explicit AdBlockSubscription(const QString &title, QObject *parent = 0);
|
||||||
|
virtual ~AdBlockSubscription();
|
||||||
|
|
||||||
QString title() const;
|
QString title() const;
|
||||||
|
|
||||||
@ -75,11 +75,11 @@ public:
|
|||||||
virtual void loadSubscription(const QStringList &disabledRules);
|
virtual void loadSubscription(const QStringList &disabledRules);
|
||||||
virtual void saveSubscription();
|
virtual void saveSubscription();
|
||||||
|
|
||||||
const AdBlockRule* rule(int offset) const;
|
const AdBlockRule *rule(int offset) const;
|
||||||
QVector<AdBlockRule*> allRules() const;
|
QVector<AdBlockRule*> allRules() const;
|
||||||
|
|
||||||
const AdBlockRule* enableRule(int offset);
|
const AdBlockRule *enableRule(int offset);
|
||||||
const AdBlockRule* disableRule(int offset);
|
const AdBlockRule *disableRule(int offset);
|
||||||
|
|
||||||
virtual bool canEditRules() const;
|
virtual bool canEditRules() const;
|
||||||
virtual bool canBeRemoved() const;
|
virtual bool canBeRemoved() const;
|
||||||
@ -88,24 +88,24 @@ public:
|
|||||||
virtual bool removeRule(int offset);
|
virtual bool removeRule(int offset);
|
||||||
virtual const AdBlockRule* replaceRule(AdBlockRule* rule, int offset);
|
virtual const AdBlockRule* replaceRule(AdBlockRule* rule, int offset);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateSubscription();
|
void updateSubscription();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void subscriptionChanged();
|
void subscriptionChanged();
|
||||||
void subscriptionUpdated();
|
void subscriptionUpdated();
|
||||||
void subscriptionError(const QString &message);
|
void subscriptionError(const QString &message);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void subscriptionDownloaded();
|
void subscriptionDownloaded();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool saveDownloadedData(const QByteArray &data);
|
virtual bool saveDownloadedData(const QByteArray &data);
|
||||||
|
|
||||||
QNetworkReply *m_reply;
|
QNetworkReply *m_reply;
|
||||||
QVector<AdBlockRule*> m_rules;
|
QVector<AdBlockRule*> m_rules;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_title;
|
QString m_title;
|
||||||
QString m_filePath;
|
QString m_filePath;
|
||||||
|
|
||||||
@ -113,11 +113,11 @@ private:
|
|||||||
bool m_updated;
|
bool m_updated;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AdBlockCustomList : public AdBlockSubscription
|
class AdBlockCustomList : public AdBlockSubscription {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
|
||||||
explicit AdBlockCustomList(QObject* parent = 0);
|
public:
|
||||||
|
explicit AdBlockCustomList(QObject *parent = 0);
|
||||||
|
|
||||||
void loadSubscription(const QStringList &disabledRules);
|
void loadSubscription(const QStringList &disabledRules);
|
||||||
void saveSubscription();
|
void saveSubscription();
|
||||||
@ -128,9 +128,9 @@ public:
|
|||||||
bool containsFilter(const QString &filter) const;
|
bool containsFilter(const QString &filter) const;
|
||||||
bool removeFilter(const QString &filter);
|
bool removeFilter(const QString &filter);
|
||||||
|
|
||||||
int addRule(AdBlockRule* rule);
|
int addRule(AdBlockRule *rule);
|
||||||
bool removeRule(int offset);
|
bool removeRule(int offset);
|
||||||
const AdBlockRule* replaceRule(AdBlockRule* rule, int offset);
|
const AdBlockRule *replaceRule(AdBlockRule *rule, int offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADBLOCKSUBSCRIPTION_H
|
#endif // ADBLOCKSUBSCRIPTION_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user