diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml
index 368acb3a9..652be1387 100644
--- a/resources/desktop/com.github.rssguard.appdata.xml
+++ b/resources/desktop/com.github.rssguard.appdata.xml
@@ -30,7 +30,7 @@
https://martinrotter.github.io/donate/
-
+
none
diff --git a/resources/scripts/adblock/adblock-server.js b/resources/scripts/adblock/adblock-server.js
index c542aed6a..98eaa3852 100755
--- a/resources/scripts/adblock/adblock-server.js
+++ b/resources/scripts/adblock/adblock-server.js
@@ -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}.`);
diff --git a/src/librssguard/librssguard.pro b/src/librssguard/librssguard.pro
index 9bcc16c4d..b20edd096 100644
--- a/src/librssguard/librssguard.pro
+++ b/src/librssguard/librssguard.pro
@@ -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 {
diff --git a/src/librssguard/miscellaneous/settings.cpp b/src/librssguard/miscellaneous/settings.cpp
index 0347f19bf..b3c390ee1 100755
--- a/src/librssguard/miscellaneous/settings.cpp
+++ b/src/librssguard/miscellaneous/settings.cpp
@@ -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 = {};
diff --git a/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.cpp b/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.cpp
deleted file mode 100644
index f02923429..000000000
--- a/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-// For license of this file, see /LICENSE.md.
-
-//
-// Copyright (C) 2011-2017 by Martin Rotter
-// Copyright (C) 2010-2014 by David Rosca
-//
-// 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 .
-
-#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(&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;
-}
diff --git a/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.h b/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.h
deleted file mode 100644
index 058590ee2..000000000
--- a/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.h
+++ /dev/null
@@ -1,58 +0,0 @@
-// For license of this file, see /LICENSE.md.
-
-//
-// Copyright (C) 2011-2017 by Martin Rotter
-// Copyright (C) 2010-2014 by David Rosca
-//
-// 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 .
-
-#ifndef ADBLOCKADDSUBSCRIPTIONDIALOG_H
-#define ADBLOCKADDSUBSCRIPTIONDIALOG_H
-
-#include
-#include
-
-#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 m_knownSubscriptions;
-};
-
-#endif // ADBLOCKADDSUBSCRIPTIONDIALOG_H
diff --git a/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.ui b/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.ui
deleted file mode 100644
index cca22a22c..000000000
--- a/src/librssguard/network-web/adblock/adblockaddsubscriptiondialog.ui
+++ /dev/null
@@ -1,117 +0,0 @@
-
-
- AdBlockAddSubscriptionDialog
-
-
-
- 0
- 0
- 440
- 145
-
-
-
- -
-
-
-
-
-
- Use predefined subscription
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
-
-
- -
-
-
- URL
-
-
- m_txtUrl
-
-
-
- -
-
-
- Absolute URL to online subscription file
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Ok
-
-
-
-
-
-
- m_cbUsePredefined
- m_cmbPresets
- m_txtUrl
-
-
-
-
- m_buttonBox
- accepted()
- AdBlockAddSubscriptionDialog
- accept()
-
-
- 283
- 111
-
-
- 157
- 132
-
-
-
-
- m_buttonBox
- rejected()
- AdBlockAddSubscriptionDialog
- reject()
-
-
- 351
- 111
-
-
- 286
- 132
-
-
-
-
-
diff --git a/src/librssguard/network-web/adblock/adblockdialog.cpp b/src/librssguard/network-web/adblock/adblockdialog.cpp
index cbff41400..ee5d3df5c 100644
--- a/src/librssguard/network-web/adblock/adblockdialog.cpp
+++ b/src/librssguard/network-web/adblock/adblockdialog.cpp
@@ -1,25 +1,7 @@
// For license of this file, see /LICENSE.md.
-//
-// Copyright (C) 2011-2017 by Martin Rotter
-// Copyright (C) 2010-2014 by David Rosca
-//
-// 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 .
-
#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
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")));
}
diff --git a/src/librssguard/network-web/adblock/adblockdialog.h b/src/librssguard/network-web/adblock/adblockdialog.h
index e0bcba891..6688a4b43 100644
--- a/src/librssguard/network-web/adblock/adblockdialog.h
+++ b/src/librssguard/network-web/adblock/adblockdialog.h
@@ -1,22 +1,5 @@
// For license of this file, see /LICENSE.md.
-//
-// Copyright (C) 2011-2017 by Martin Rotter
-// Copyright (C) 2010-2014 by David Rosca
-//
-// 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 .
-
#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
diff --git a/src/librssguard/network-web/adblock/adblockdialog.ui b/src/librssguard/network-web/adblock/adblockdialog.ui
index da1672fc1..c49a8b20d 100644
--- a/src/librssguard/network-web/adblock/adblockdialog.ui
+++ b/src/librssguard/network-web/adblock/adblockdialog.ui
@@ -27,13 +27,20 @@
-
- 1
+ 0
Filter lists (list per line)
-
+
+
-
+
+
+ Add your direct links to filter lists here (one URL per line)
+
+
+
-
@@ -43,7 +50,14 @@
Custom filters
-
+
+ -
+
+
+ Add your custom filters here (one filter per line)
+
+
+
-
diff --git a/src/librssguard/network-web/adblock/adblockicon.cpp b/src/librssguard/network-web/adblock/adblockicon.cpp
index 3461cffe2..225efbea5 100644
--- a/src/librssguard/network-web/adblock/adblockicon.cpp
+++ b/src/librssguard/network-web/adblock/adblockicon.cpp
@@ -1,22 +1,5 @@
// For license of this file, see /LICENSE.md.
-//
-// Copyright (C) 2011-2017 by Martin Rotter
-// Copyright (C) 2010-2014 by David Rosca
-//
-// 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 .
-
#include "network-web/adblock/adblockicon.h"
#include "gui/dialogs/formmain.h"
diff --git a/src/librssguard/network-web/adblock/adblockicon.h b/src/librssguard/network-web/adblock/adblockicon.h
index 594bf8443..4b305aaaf 100644
--- a/src/librssguard/network-web/adblock/adblockicon.h
+++ b/src/librssguard/network-web/adblock/adblockicon.h
@@ -1,22 +1,5 @@
// For license of this file, see /LICENSE.md.
-//
-// Copyright (C) 2011-2017 by Martin Rotter
-// Copyright (C) 2010-2014 by David Rosca
-//
-// 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 .
-
#ifndef ADBLOCKICON_H
#define ADBLOCKICON_H
diff --git a/src/librssguard/network-web/adblock/adblockmanager.cpp b/src/librssguard/network-web/adblock/adblockmanager.cpp
index 9a05fb645..8fbf1ab3b 100644
--- a/src/librssguard/network-web/adblock/adblockmanager.cpp
+++ b/src/librssguard/network-web/adblock/adblockmanager.cpp
@@ -1,39 +1,21 @@
// For license of this file, see /LICENSE.md.
-//
-// Copyright (C) 2011-2017 by Martin Rotter
-// Copyright (C) 2010-2014 by David Rosca
-//
-// 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 .
-
#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
#include
#include
-#include
-#include
-#include
#include
#include
#include
@@ -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());
+ }
}
diff --git a/src/librssguard/network-web/adblock/adblockmanager.h b/src/librssguard/network-web/adblock/adblockmanager.h
index 6c0e35e80..2e856642c 100644
--- a/src/librssguard/network-web/adblock/adblockmanager.h
+++ b/src/librssguard/network-web/adblock/adblockmanager.h
@@ -1,29 +1,9 @@
// For license of this file, see /LICENSE.md.
-//
-// Copyright (C) 2011-2017 by Martin Rotter
-// Copyright (C) 2010-2014 by David Rosca
-//
-// 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 .
-
#ifndef ADBLOCKMANAGER_H
#define ADBLOCKMANAGER_H
-#include
#include
-#include
-#include
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;
};
diff --git a/src/librssguard/network-web/adblock/adblockrequestinfo.cpp b/src/librssguard/network-web/adblock/adblockrequestinfo.cpp
index 1cca4a4ac..ee25df99d 100755
--- a/src/librssguard/network-web/adblock/adblockrequestinfo.cpp
+++ b/src/librssguard/network-web/adblock/adblockrequestinfo.cpp
@@ -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) {
diff --git a/src/librssguard/network-web/adblock/adblockrequestinfo.h b/src/librssguard/network-web/adblock/adblockrequestinfo.h
index fa22197a2..75142b914 100755
--- a/src/librssguard/network-web/adblock/adblockrequestinfo.h
+++ b/src/librssguard/network-web/adblock/adblockrequestinfo.h
@@ -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);