adblock work
This commit is contained in:
parent
3a21265f0c
commit
f344ace62e
@ -30,7 +30,7 @@
|
||||
<url type="donation">https://martinrotter.github.io/donate/</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="3.9.0" date="2021-05-03"/>
|
||||
<release version="3.9.0" date="2021-05-04"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -33,9 +33,13 @@ const hostname = '127.0.0.1';
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
try {
|
||||
console.log(new Date());
|
||||
|
||||
const chunks = [];
|
||||
req.on('data', chunk => chunks.push(chunk));
|
||||
req.on('end', () => {
|
||||
console.log(new Date());
|
||||
|
||||
try {
|
||||
const jsonData = Buffer.concat(chunks);
|
||||
const jsonStruct = JSON.parse(jsonData.toString());
|
||||
@ -72,6 +76,8 @@ const server = http.createServer((req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(resultJson));
|
||||
|
||||
console.log(new Date());
|
||||
}
|
||||
catch (inner_error) {
|
||||
console.error(`adblocker: ${inner_error}.`);
|
||||
|
@ -441,7 +441,7 @@ equals(USE_WEBENGINE, true) {
|
||||
network-web/webpage.cpp
|
||||
|
||||
# Add AdBlock sources.
|
||||
HEADERS += network-web/adblock/adblockaddsubscriptiondialog.h \
|
||||
HEADERS += \
|
||||
network-web/adblock/adblockdialog.h \
|
||||
network-web/adblock/adblockicon.h \
|
||||
network-web/adblock/adblockmanager.h \
|
||||
@ -450,7 +450,7 @@ equals(USE_WEBENGINE, true) {
|
||||
network-web/urlinterceptor.h \
|
||||
network-web/networkurlinterceptor.h
|
||||
|
||||
SOURCES += network-web/adblock/adblockaddsubscriptiondialog.cpp \
|
||||
SOURCES += \
|
||||
network-web/adblock/adblockdialog.cpp \
|
||||
network-web/adblock/adblockicon.cpp \
|
||||
network-web/adblock/adblockmanager.cpp \
|
||||
@ -458,7 +458,7 @@ equals(USE_WEBENGINE, true) {
|
||||
network-web/adblock/adblockrequestinfo.cpp \
|
||||
network-web/networkurlinterceptor.cpp
|
||||
|
||||
FORMS += network-web/adblock/adblockaddsubscriptiondialog.ui \
|
||||
FORMS += \
|
||||
network-web/adblock/adblockdialog.ui
|
||||
}
|
||||
else {
|
||||
|
@ -25,7 +25,10 @@ DKEY AdBlock::AdBlockEnabled = "enabled";
|
||||
DVALUE(bool) AdBlock::AdBlockEnabledDef = false;
|
||||
|
||||
DKEY AdBlock::FilterLists = "filter_lists";
|
||||
DVALUE(QStringList) AdBlock::FilterListsDef = {};
|
||||
DVALUE(QStringList) AdBlock::FilterListsDef = {
|
||||
QSL("https://easylist.to/easylist/easylist.txt"),
|
||||
QSL("https://easylist.to/easylist/easyprivacy.txt")
|
||||
};
|
||||
|
||||
DKEY AdBlock::CustomFilters = "custom_filters";
|
||||
DVALUE(QStringList) AdBlock::CustomFiltersDef = {};
|
||||
|
@ -1,83 +0,0 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "network-web/adblock/adblockaddsubscriptiondialog.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "gui/guiutilities.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
|
||||
AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
||||
: QDialog(parent), m_ui(new Ui::AdBlockAddSubscriptionDialog) {
|
||||
m_ui->setupUi(this);
|
||||
m_knownSubscriptions
|
||||
<< Subscription(QSL("EasyList"), QSL(ADBLOCK_EASYLIST_URL))
|
||||
<< Subscription(QSL("EasyPrivacy"), QSL("https://easylist.to/easylist/easyprivacy.txt"))
|
||||
<< Subscription(QSL("EasyPrivacy Tracking Protection List"), QSL("https://easylist-downloads.adblockplus.org/easyprivacy.tpl"))
|
||||
<< Subscription(QSL("Adblock Warning Removal List"), QSL("https://easylist-downloads.adblockplus.org/antiadblockfilters.txt"));
|
||||
|
||||
for (const Subscription& subscription : qAsConst(m_knownSubscriptions)) {
|
||||
m_ui->m_cmbPresets->addItem(subscription.m_title);
|
||||
}
|
||||
|
||||
connect(m_ui->m_cmbPresets, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||
this, &AdBlockAddSubscriptionDialog::indexChanged);
|
||||
connect(m_ui->m_cbUsePredefined, &QCheckBox::toggled, this,
|
||||
&AdBlockAddSubscriptionDialog::presetsEnabledChanged);
|
||||
|
||||
m_ui->m_cbUsePredefined->setChecked(true);
|
||||
GuiUtilities::applyDialogProperties(*this,
|
||||
qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE),
|
||||
tr("Add subscription"));
|
||||
}
|
||||
|
||||
QString AdBlockAddSubscriptionDialog::url() const {
|
||||
return m_ui->m_txtUrl->text();
|
||||
}
|
||||
|
||||
void AdBlockAddSubscriptionDialog::indexChanged(int index) {
|
||||
const Subscription subscription = m_knownSubscriptions.at(index);
|
||||
|
||||
m_ui->m_txtUrl->setText(subscription.m_url);
|
||||
}
|
||||
|
||||
void AdBlockAddSubscriptionDialog::presetsEnabledChanged(bool enabled) {
|
||||
m_ui->m_txtUrl->setEnabled(!enabled);
|
||||
m_ui->m_cmbPresets->setEnabled(enabled);
|
||||
|
||||
if (!enabled) {
|
||||
m_ui->m_txtUrl->clear();
|
||||
m_ui->m_txtUrl->setFocus();
|
||||
}
|
||||
else {
|
||||
indexChanged(m_ui->m_cmbPresets->currentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog() {
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
AdBlockAddSubscriptionDialog::Subscription::Subscription() {}
|
||||
|
||||
AdBlockAddSubscriptionDialog::Subscription::Subscription(const QString& title, const QString& url) {
|
||||
m_title = title;
|
||||
m_url = url;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef ADBLOCKADDSUBSCRIPTIONDIALOG_H
|
||||
#define ADBLOCKADDSUBSCRIPTIONDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QVector>
|
||||
|
||||
#include "ui_adblockaddsubscriptiondialog.h"
|
||||
|
||||
namespace Ui {
|
||||
class AdBlockAddSubscriptionDialog;
|
||||
}
|
||||
|
||||
class AdBlockAddSubscriptionDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AdBlockAddSubscriptionDialog(QWidget* parent = nullptr);
|
||||
virtual ~AdBlockAddSubscriptionDialog();
|
||||
|
||||
QString url() const;
|
||||
|
||||
private slots:
|
||||
void indexChanged(int index);
|
||||
void presetsEnabledChanged(bool enabled);
|
||||
|
||||
private:
|
||||
struct Subscription {
|
||||
QString m_title;
|
||||
QString m_url;
|
||||
|
||||
explicit Subscription();
|
||||
explicit Subscription(const QString& title, const QString& url);
|
||||
};
|
||||
|
||||
Ui::AdBlockAddSubscriptionDialog* m_ui;
|
||||
QVector<Subscription> m_knownSubscriptions;
|
||||
};
|
||||
|
||||
#endif // ADBLOCKADDSUBSCRIPTIONDIALOG_H
|
@ -1,117 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AdBlockAddSubscriptionDialog</class>
|
||||
<widget class="QDialog" name="AdBlockAddSubscriptionDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>440</width>
|
||||
<height>145</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="m_cbUsePredefined">
|
||||
<property name="text">
|
||||
<string>Use predefined subscription</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="m_cmbPresets">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="m_lblUrl">
|
||||
<property name="text">
|
||||
<string>URL</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>m_txtUrl</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="m_txtUrl">
|
||||
<property name="placeholderText">
|
||||
<string>Absolute URL to online subscription file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="m_buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>m_cbUsePredefined</tabstop>
|
||||
<tabstop>m_cmbPresets</tabstop>
|
||||
<tabstop>m_txtUrl</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>m_buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AdBlockAddSubscriptionDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>283</x>
|
||||
<y>111</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>132</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>m_buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AdBlockAddSubscriptionDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>351</x>
|
||||
<y>111</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>132</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -1,25 +1,7 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "network-web/adblock/adblockdialog.h"
|
||||
|
||||
#include "network-web/adblock/adblockaddsubscriptiondialog.h"
|
||||
#include "network-web/adblock/adblockmanager.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
@ -34,60 +16,53 @@
|
||||
#include <QTimer>
|
||||
|
||||
AdBlockDialog::AdBlockDialog(QWidget* parent)
|
||||
: QDialog(parent), m_manager(qApp->web()->adBlock()), m_loaded(false), m_ui(new Ui::AdBlockDialog) {
|
||||
m_ui->setupUi(this);
|
||||
m_ui->m_cbEnable->setChecked(m_manager->isEnabled());
|
||||
: QDialog(parent), m_manager(qApp->web()->adBlock()), m_loaded(false) {
|
||||
m_ui.setupUi(this);
|
||||
m_ui.m_cbEnable->setChecked(m_manager->isEnabled());
|
||||
|
||||
GuiUtilities::applyDialogProperties(*this,
|
||||
qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE),
|
||||
tr("AdBlock configuration"));
|
||||
|
||||
QPushButton* btn_options = m_ui->m_buttonBox->addButton(QDialogButtonBox::FirstButton);
|
||||
|
||||
btn_options->setText(tr("Options"));
|
||||
QPushButton* btn_options = m_ui.m_buttonBox->addButton(tr("Options"),
|
||||
QDialogButtonBox::ButtonRole::HelpRole);
|
||||
auto* menu = new QMenu(btn_options);
|
||||
|
||||
m_actionAddSubscription = menu->addAction(tr("Add subscription"), this, &AdBlockDialog::addSubscription);
|
||||
menu->addSeparator();
|
||||
menu->addAction(tr("Learn about writing rules..."), this, &AdBlockDialog::learnAboutRules);
|
||||
|
||||
menu->addAction(tr("Learn about writing rules..."), this, &AdBlockDialog::learnAboutAdblock);
|
||||
btn_options->setMenu(menu);
|
||||
|
||||
connect(m_ui->m_cbEnable, &QCheckBox::toggled, this, &AdBlockDialog::enableAdBlock);
|
||||
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &AdBlockDialog::close);
|
||||
connect(m_ui.m_cbEnable, &QCheckBox::toggled, this, &AdBlockDialog::enableAdBlock);
|
||||
connect(m_ui.m_buttonBox, &QDialogButtonBox::rejected, this, &AdBlockDialog::saveAndClose);
|
||||
|
||||
load();
|
||||
m_ui->m_buttonBox->setFocus();
|
||||
m_ui.m_buttonBox->setFocus();
|
||||
}
|
||||
|
||||
void AdBlockDialog::addSubscription() {
|
||||
AdBlockAddSubscriptionDialog dialog(this);
|
||||
void AdBlockDialog::saveAndClose() {
|
||||
m_manager->setFilterLists(m_ui.m_txtPredefined->toPlainText().split(QSL("\n")));
|
||||
m_manager->setCustomFilters(m_ui.m_txtCustom->toPlainText().split(QSL("\n")));
|
||||
m_manager->updateUnifiedFiltersFile();
|
||||
|
||||
if (dialog.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString url = dialog.url();
|
||||
|
||||
// TODO: add filter list.
|
||||
close();
|
||||
}
|
||||
|
||||
void AdBlockDialog::enableAdBlock(bool state) {
|
||||
void AdBlockDialog::enableAdBlock(bool enable) {
|
||||
m_manager->load(false);
|
||||
|
||||
if (state) {
|
||||
if (enable) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::learnAboutRules() {
|
||||
void AdBlockDialog::learnAboutAdblock() {
|
||||
qApp->web()->openUrlInExternalBrowser(QSL(ADBLOCK_HOWTO));
|
||||
}
|
||||
|
||||
void AdBlockDialog::load() {
|
||||
if (m_loaded || !m_ui->m_cbEnable->isChecked()) {
|
||||
if (m_loaded || !m_ui.m_cbEnable->isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: load
|
||||
m_ui.m_txtCustom->setPlainText(m_manager->customFilters().join(QSL("\n")));
|
||||
m_ui.m_txtPredefined->setPlainText(m_manager->filterLists().join(QSL("\n")));
|
||||
}
|
||||
|
@ -1,22 +1,5 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef ADBLOCKDIALOG_H
|
||||
#define ADBLOCKDIALOG_H
|
||||
|
||||
@ -33,19 +16,18 @@ class AdBlockDialog : public QDialog {
|
||||
explicit AdBlockDialog(QWidget* parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void addSubscription();
|
||||
void enableAdBlock(bool state);
|
||||
void learnAboutRules();
|
||||
void saveAndClose();
|
||||
void enableAdBlock(bool enable);
|
||||
void learnAboutAdblock();
|
||||
|
||||
private:
|
||||
void load();
|
||||
|
||||
private:
|
||||
AdBlockManager* m_manager;
|
||||
QAction* m_actionAddSubscription;
|
||||
bool m_loaded;
|
||||
|
||||
Ui::AdBlockDialog* m_ui;
|
||||
Ui::AdBlockDialog m_ui;
|
||||
};
|
||||
|
||||
#endif // ADBLOCKDIALOG_H
|
||||
|
@ -27,13 +27,20 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="m_tcSubscriptions">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="m_tabPredefinedLists">
|
||||
<attribute name="title">
|
||||
<string>Filter lists (list per line)</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Add your direct links to filter lists here (one URL per line)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="m_txtPredefined"/>
|
||||
</item>
|
||||
@ -43,7 +50,14 @@
|
||||
<attribute name="title">
|
||||
<string>Custom filters</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Add your custom filters here (one filter per line)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="m_txtCustom"/>
|
||||
</item>
|
||||
|
@ -1,22 +1,5 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "network-web/adblock/adblockicon.h"
|
||||
|
||||
#include "gui/dialogs/formmain.h"
|
||||
|
@ -1,22 +1,5 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef ADBLOCKICON_H
|
||||
#define ADBLOCKICON_H
|
||||
|
||||
|
@ -1,39 +1,21 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "network-web/adblock/adblockmanager.h"
|
||||
|
||||
#include "exceptions/applicationexception.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/settings.h"
|
||||
#include "network-web/adblock/adblockdialog.h"
|
||||
#include "network-web/adblock/adblockicon.h"
|
||||
#include "network-web/adblock/adblockrequestinfo.h"
|
||||
#include "network-web/adblock/adblockurlinterceptor.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
#include "network-web/networkurlinterceptor.h"
|
||||
#include "network-web/webfactory.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QMutexLocker>
|
||||
#include <QSaveFile>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
#include <QUrlQuery>
|
||||
#include <QWebEngineProfile>
|
||||
@ -46,9 +28,7 @@ AdBlockManager::AdBlockManager(QObject* parent)
|
||||
m_unifiedFiltersFile = qApp->userDataFolder() + QDir::separator() + QSL("adblock-unified-filters.txt");
|
||||
}
|
||||
|
||||
bool AdBlockManager::block(const AdblockRequestInfo& request) {
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
bool AdBlockManager::block(const AdblockRequestInfo& request) const {
|
||||
if (!isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
@ -66,7 +46,6 @@ bool AdBlockManager::block(const AdblockRequestInfo& request) {
|
||||
}
|
||||
|
||||
void AdBlockManager::load(bool initial_load) {
|
||||
QMutexLocker locker(&m_mutex);
|
||||
auto new_enabled = qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::AdBlockEnabled)).toBool();
|
||||
|
||||
if (!initial_load) {
|
||||
@ -90,14 +69,7 @@ void AdBlockManager::load(bool initial_load) {
|
||||
}
|
||||
|
||||
if (m_enabled) {
|
||||
if (!QFile::exists(m_unifiedFiltersFile)) {
|
||||
updateUnifiedFiltersFile();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (QFile::exists(m_unifiedFiltersFile)) {
|
||||
QFile::remove(m_unifiedFiltersFile);
|
||||
}
|
||||
updateUnifiedFiltersFile();
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +86,23 @@ QString AdBlockManager::elementHidingRulesForDomain(const QUrl& url) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
QString AdBlockManager::generateJsForElementHiding(const QString& css) const {
|
||||
QStringList AdBlockManager::filterLists() const {
|
||||
return qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::FilterLists)).toStringList();
|
||||
}
|
||||
|
||||
void AdBlockManager::setFilterLists(const QStringList& filter_lists) {
|
||||
qApp->settings()->setValue(GROUP(AdBlock), AdBlock::FilterLists, filter_lists);
|
||||
}
|
||||
|
||||
QStringList AdBlockManager::customFilters() const {
|
||||
return qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::CustomFilters)).toStringList();
|
||||
}
|
||||
|
||||
void AdBlockManager::setCustomFilters(const QStringList& custom_filters) {
|
||||
qApp->settings()->setValue(GROUP(AdBlock), AdBlock::CustomFilters, custom_filters);
|
||||
}
|
||||
|
||||
QString AdBlockManager::generateJsForElementHiding(const QString& css) {
|
||||
QString source = QL1S("(function() {"
|
||||
"var head = document.getElementsByTagName('head')[0];"
|
||||
"if (!head) return;"
|
||||
@ -135,7 +123,57 @@ void AdBlockManager::showDialog() {
|
||||
AdBlockDialog(qApp->mainFormWidget()).exec();
|
||||
}
|
||||
|
||||
void AdBlockManager::updateUnifiedFiltersFile() {
|
||||
// TODO: download contents of all filter lists + append custom filters
|
||||
// and combine into single file.
|
||||
void AdBlockManager::restartServer() {
|
||||
// TODO:
|
||||
}
|
||||
|
||||
void AdBlockManager::updateUnifiedFiltersFile() {
|
||||
if (QFile::exists(m_unifiedFiltersFile)) {
|
||||
QFile::remove(m_unifiedFiltersFile);
|
||||
}
|
||||
|
||||
// TODO: generate file
|
||||
QByteArray unified_contents;
|
||||
auto filter_lists = filterLists();
|
||||
|
||||
// Download filters one by one and append.
|
||||
for (const QString& filter_list_url : qAsConst(filter_lists)) {
|
||||
QByteArray out;
|
||||
auto res = NetworkFactory::performNetworkOperation(filter_list_url,
|
||||
2000,
|
||||
{},
|
||||
out, QNetworkAccessManager::Operation::GetOperation);
|
||||
|
||||
if (res.first == QNetworkReply::NetworkError::NoError) {
|
||||
unified_contents += out;
|
||||
}
|
||||
else {
|
||||
qWarningNN << LOGSEC_ADBLOCK
|
||||
<< "Failed to download list of filters"
|
||||
<< QUOTE_W_SPACE(filter_list_url)
|
||||
<< "with error"
|
||||
<< QUOTE_W_SPACE_DOT(res.first);
|
||||
}
|
||||
}
|
||||
|
||||
unified_contents += customFilters().join(QSL("\n")).toUtf8();
|
||||
|
||||
// Save.
|
||||
m_unifiedFiltersFile = IOFactory::getSystemFolder(QStandardPaths::StandardLocation::TempLocation) +
|
||||
QDir::separator() +
|
||||
QSL("adblock.filters");
|
||||
|
||||
try {
|
||||
IOFactory::writeFile(m_unifiedFiltersFile, unified_contents);
|
||||
|
||||
if (m_enabled) {
|
||||
// TODO: re-start nodejs adblock server.
|
||||
restartServer();
|
||||
}
|
||||
}
|
||||
catch (const ApplicationException& ex) {
|
||||
qCriticalNN << LOGSEC_ADBLOCK
|
||||
<< "Failed to write unified filters to file, error:"
|
||||
<< QUOTE_W_SPACE_DOT(ex.message());
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,9 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard 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 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard 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 RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef ADBLOCKMANAGER_H
|
||||
#define ADBLOCKMANAGER_H
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QStringList>
|
||||
|
||||
class QUrl;
|
||||
class AdblockRequestInfo;
|
||||
@ -42,32 +22,38 @@ class AdBlockManager : public QObject {
|
||||
// initial loading of Adblock.
|
||||
void load(bool initial_load);
|
||||
|
||||
// General method for adblocking. Returns true if request should be blocked.
|
||||
bool block(const AdblockRequestInfo& request);
|
||||
|
||||
bool isEnabled() const;
|
||||
bool canRunOnScheme(const QString& scheme) const;
|
||||
|
||||
QString elementHidingRulesForDomain(const QUrl& url) const;
|
||||
QString generateJsForElementHiding(const QString& css) const;
|
||||
|
||||
AdBlockIcon* adBlockIcon() const;
|
||||
|
||||
// General methods for adblocking.
|
||||
bool block(const AdblockRequestInfo& request) const;
|
||||
QString elementHidingRulesForDomain(const QUrl& url) const;
|
||||
|
||||
QStringList filterLists() const;
|
||||
void setFilterLists(const QStringList& filter_lists);
|
||||
|
||||
QStringList customFilters() const;
|
||||
void setCustomFilters(const QStringList& custom_filters);
|
||||
|
||||
void updateUnifiedFiltersFile();
|
||||
|
||||
static QString generateJsForElementHiding(const QString& css);
|
||||
|
||||
public slots:
|
||||
void showDialog();
|
||||
|
||||
signals:
|
||||
void enabledChanged(bool enabled);
|
||||
|
||||
private slots:
|
||||
void updateUnifiedFiltersFile();
|
||||
private:
|
||||
void restartServer();
|
||||
|
||||
private:
|
||||
bool m_loaded;
|
||||
bool m_enabled;
|
||||
AdBlockIcon* m_adblockIcon;
|
||||
AdBlockUrlInterceptor* m_interceptor;
|
||||
QMutex m_mutex;
|
||||
QString m_unifiedFiltersFile;
|
||||
};
|
||||
|
||||
|
@ -16,40 +16,40 @@ QWebEngineUrlRequestInfo::ResourceType AdblockRequestInfo::resourceType() const
|
||||
return m_resourceType;
|
||||
}
|
||||
|
||||
void AdblockRequestInfo::setResourceType(const QWebEngineUrlRequestInfo::ResourceType& resourceType) {
|
||||
m_resourceType = resourceType;
|
||||
void AdblockRequestInfo::setResourceType(const QWebEngineUrlRequestInfo::ResourceType& resource_type) {
|
||||
m_resourceType = resource_type;
|
||||
}
|
||||
|
||||
QWebEngineUrlRequestInfo::NavigationType AdblockRequestInfo::navigationType() const {
|
||||
return m_navigationType;
|
||||
}
|
||||
|
||||
void AdblockRequestInfo::setNavigationType(const QWebEngineUrlRequestInfo::NavigationType& navigationType) {
|
||||
m_navigationType = navigationType;
|
||||
void AdblockRequestInfo::setNavigationType(const QWebEngineUrlRequestInfo::NavigationType& navigation_type) {
|
||||
m_navigationType = navigation_type;
|
||||
}
|
||||
|
||||
QUrl AdblockRequestInfo::requestUrl() const {
|
||||
return m_requestUrl;
|
||||
}
|
||||
|
||||
void AdblockRequestInfo::setRequestUrl(const QUrl& requestUrl) {
|
||||
m_requestUrl = requestUrl;
|
||||
void AdblockRequestInfo::setRequestUrl(const QUrl& request_url) {
|
||||
m_requestUrl = request_url;
|
||||
}
|
||||
|
||||
QUrl AdblockRequestInfo::firstPartyUrl() const {
|
||||
return m_firstPartyUrl;
|
||||
}
|
||||
|
||||
void AdblockRequestInfo::setFirstPartyUrl(const QUrl& firstPartyUrl) {
|
||||
m_firstPartyUrl = firstPartyUrl;
|
||||
void AdblockRequestInfo::setFirstPartyUrl(const QUrl& first_party_url) {
|
||||
m_firstPartyUrl = first_party_url;
|
||||
}
|
||||
|
||||
QByteArray AdblockRequestInfo::requestMethod() const {
|
||||
return m_requestMethod;
|
||||
}
|
||||
|
||||
void AdblockRequestInfo::setRequestMethod(const QByteArray& requestMethod) {
|
||||
m_requestMethod = requestMethod;
|
||||
void AdblockRequestInfo::setRequestMethod(const QByteArray& request_method) {
|
||||
m_requestMethod = request_method;
|
||||
}
|
||||
|
||||
void AdblockRequestInfo::initialize(const QWebEngineUrlRequestInfo& webengine_info) {
|
||||
|
@ -11,19 +11,19 @@ class AdblockRequestInfo {
|
||||
explicit AdblockRequestInfo(const QUrl& url);
|
||||
|
||||
QWebEngineUrlRequestInfo::ResourceType resourceType() const;
|
||||
void setResourceType(const QWebEngineUrlRequestInfo::ResourceType& resourceType);
|
||||
void setResourceType(const QWebEngineUrlRequestInfo::ResourceType& resource_type);
|
||||
|
||||
QWebEngineUrlRequestInfo::NavigationType navigationType() const;
|
||||
void setNavigationType(const QWebEngineUrlRequestInfo::NavigationType& navigationType);
|
||||
void setNavigationType(const QWebEngineUrlRequestInfo::NavigationType& navigation_type);
|
||||
|
||||
QUrl requestUrl() const;
|
||||
void setRequestUrl(const QUrl& requestUrl);
|
||||
void setRequestUrl(const QUrl& request_url);
|
||||
|
||||
QUrl firstPartyUrl() const;
|
||||
void setFirstPartyUrl(const QUrl& firstPartyUrl);
|
||||
void setFirstPartyUrl(const QUrl& first_party_url);
|
||||
|
||||
QByteArray requestMethod() const;
|
||||
void setRequestMethod(const QByteArray& requestMethod);
|
||||
void setRequestMethod(const QByteArray& request_method);
|
||||
|
||||
private:
|
||||
void initialize(const QWebEngineUrlRequestInfo& webengine_info);
|
||||
|
Loading…
x
Reference in New Issue
Block a user