overhauled logic around adblock, now is much easier to use
This commit is contained in:
parent
fb7f91696c
commit
02e03e6d4a
@ -30,7 +30,7 @@
|
||||
<url type="donation">https://martinrotter.github.io/donate/</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="4.0.0" date="2021-08-23"/>
|
||||
<release version="4.0.0" date="2021-08-24"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -61,7 +61,9 @@ QMessageBox::StandardButton MessageBox::show(QWidget* parent,
|
||||
const QString& detailed_text,
|
||||
QMessageBox::StandardButtons buttons,
|
||||
QMessageBox::StandardButton default_button,
|
||||
bool* dont_show_again) {
|
||||
bool* dont_show_again,
|
||||
const QString& functor_heading,
|
||||
std::function<void ()> functor) {
|
||||
// Create and find needed components.
|
||||
MessageBox msg_box(parent);
|
||||
|
||||
@ -78,6 +80,13 @@ QMessageBox::StandardButton MessageBox::show(QWidget* parent,
|
||||
MessageBox::setCheckBox(&msg_box, tr("Do not show this dialog again."), dont_show_again);
|
||||
}
|
||||
|
||||
if (functor) {
|
||||
connect(msg_box.addButton(functor_heading, QMessageBox::ButtonRole::HelpRole),
|
||||
&QPushButton::clicked,
|
||||
&msg_box,
|
||||
functor);
|
||||
}
|
||||
|
||||
// Display it.
|
||||
if (msg_box.exec() == -1) {
|
||||
return QMessageBox::StandardButton::Cancel;
|
||||
|
@ -28,7 +28,9 @@ class MessageBox : public QMessageBox {
|
||||
const QString& detailed_text = QString(),
|
||||
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
|
||||
QMessageBox::StandardButton default_button = QMessageBox::Ok,
|
||||
bool* dont_show_again = nullptr);
|
||||
bool* dont_show_again = nullptr,
|
||||
const QString& functor_heading = {},
|
||||
std::function<void()> functor = nullptr);
|
||||
static QIcon iconForStatus(QMessageBox::Icon status);
|
||||
};
|
||||
|
||||
|
@ -80,19 +80,23 @@ Application::Application(const QString& id, int& argc, char** argv)
|
||||
connect(this, &Application::saveStateRequest, this, &Application::onSaveState);
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
m_webFactory->urlIinterceptor()->load();
|
||||
|
||||
connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested, this, &Application::downloadRequested);
|
||||
connect(m_webFactory->adBlock(), &AdBlockManager::processTerminated, this, &Application::onAdBlockFailure);
|
||||
|
||||
QTimer::singleShot(3000, this, [=]() {
|
||||
try {
|
||||
m_webFactory->adBlock()->setEnabled(qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::AdBlockEnabled)).toBool());
|
||||
}
|
||||
catch (...) {
|
||||
onAdBlockFailure();
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
m_webFactory->updateProxy();
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
m_webFactory->urlIinterceptor()->load();
|
||||
|
||||
QTimer::singleShot(3000, this, [=]() {
|
||||
m_webFactory->adBlock()->load(true);
|
||||
});
|
||||
#endif
|
||||
|
||||
if (isFirstRun()) {
|
||||
m_notifications->save({
|
||||
Notification(Notification::Event::GeneralEvent, true),
|
||||
@ -186,7 +190,7 @@ void Application::offerChanges() const {
|
||||
QSL(APP_NAME),
|
||||
QObject::tr("Welcome to %1.\n\nPlease, check NEW stuff included in this\n"
|
||||
"version by clicking this popup notification.").arg(APP_LONG_NAME),
|
||||
QSystemTrayIcon::MessageIcon::NoIcon, {}, {}, [] {
|
||||
QSystemTrayIcon::MessageIcon::NoIcon, {}, {}, "Go to changelog", [] {
|
||||
FormAbout(qApp->mainForm()).exec();
|
||||
});
|
||||
}
|
||||
@ -459,7 +463,7 @@ void Application::deleteTrayIcon() {
|
||||
|
||||
void Application::showGuiMessage(Notification::Event event, const QString& title,
|
||||
const QString& message, QSystemTrayIcon::MessageIcon message_type, bool show_at_least_msgbox,
|
||||
QWidget* parent, std::function<void()> functor) {
|
||||
QWidget* parent, const QString& functor_heading, std::function<void()> functor) {
|
||||
|
||||
if (SystemTrayIcon::areNotificationsEnabled()) {
|
||||
auto notification = m_notifications->notificationForEvent(event);
|
||||
@ -477,7 +481,8 @@ void Application::showGuiMessage(Notification::Event event, const QString& title
|
||||
|
||||
if (show_at_least_msgbox) {
|
||||
// Tray icon or OSD is not available, display simple text box.
|
||||
MessageBox::show(parent == nullptr ? mainFormWidget() : parent, QMessageBox::Icon(message_type), title, message);
|
||||
MessageBox::show(parent == nullptr ? mainFormWidget() : parent, QMessageBox::Icon(message_type), title, message,
|
||||
{}, {}, QMessageBox::StandardButton::Ok, QMessageBox::StandardButton::Ok, {}, functor_heading, functor);
|
||||
}
|
||||
else {
|
||||
qDebugNN << LOGSEC_CORE << "Silencing GUI message:" << QUOTE_W_SPACE_DOT(message);
|
||||
@ -581,12 +586,26 @@ void Application::restart() {
|
||||
}
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
|
||||
void Application::downloadRequested(QWebEngineDownloadItem* download_item) {
|
||||
downloadManager()->download(download_item->url());
|
||||
download_item->cancel();
|
||||
download_item->deleteLater();
|
||||
}
|
||||
|
||||
void Application::onAdBlockFailure() {
|
||||
qApp->showGuiMessage(Notification::Event::GeneralEvent,
|
||||
tr("AdBlock needs to be configured"),
|
||||
tr("AdBlock component is not configured properly."),
|
||||
QSystemTrayIcon::MessageIcon::Critical,
|
||||
true,
|
||||
{},
|
||||
tr("Configure now"),
|
||||
[=]() {
|
||||
m_webFactory->adBlock()->showDialog();
|
||||
});
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Application::onFeedUpdatesFinished(const FeedDownloadResults& results) {
|
||||
|
@ -115,7 +115,8 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
|
||||
// or in message box if tray icon is disabled.
|
||||
void showGuiMessage(Notification::Event event, const QString& title, const QString& message,
|
||||
QSystemTrayIcon::MessageIcon message_type, bool show_at_least_msgbox = false,
|
||||
QWidget* parent = nullptr, std::function<void()> functor = nullptr);
|
||||
QWidget* parent = nullptr, const QString& functor_heading = {},
|
||||
std::function<void()> functor = nullptr);
|
||||
|
||||
// Returns pointer to "GOD" application singleton.
|
||||
static Application* instance();
|
||||
@ -140,6 +141,7 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
void downloadRequested(QWebEngineDownloadItem* download_item);
|
||||
void onAdBlockFailure();
|
||||
#endif
|
||||
|
||||
void onFeedUpdatesFinished(const FeedDownloadResults& results);
|
||||
|
@ -231,6 +231,7 @@ void SystemFactory::checkForUpdatesOnStartup() {
|
||||
QObject::tr("New version available"),
|
||||
QObject::tr("Click the bubble for more information."),
|
||||
QSystemTrayIcon::Information, {}, {},
|
||||
tr("See new version info"),
|
||||
[] {
|
||||
FormUpdate(qApp->mainForm()).exec();
|
||||
});
|
||||
|
@ -29,31 +29,36 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
|
||||
connect(m_ui.m_btnHelp, &QPushButton::clicked, this, [=]() {
|
||||
qApp->web()->openUrlInExternalBrowser(QSL(ADBLOCK_HOWTO));
|
||||
});
|
||||
connect(m_ui.m_btnTest, &QPushButton::clicked, this, &AdBlockDialog::testConfiguration);
|
||||
connect(m_ui.m_cbEnable, &QCheckBox::toggled, this, &AdBlockDialog::enableAdBlock);
|
||||
connect(m_ui.m_buttonBox, &QDialogButtonBox::rejected, this, &AdBlockDialog::saveAndClose);
|
||||
connect(m_ui.m_cbEnable, &QCheckBox::clicked, this, &AdBlockDialog::enableAdBlock);
|
||||
connect(m_manager, &AdBlockManager::enabledChanged, this, &AdBlockDialog::onAdBlockEnabledChanged);
|
||||
connect(m_manager, &AdBlockManager::processTerminated, this, &AdBlockDialog::onAdBlockProcessTerminated);
|
||||
|
||||
m_ui.m_lblTestResult->label()->setWordWrap(true);
|
||||
m_ui.m_btnHelp->setIcon(qApp->icons()->fromTheme(QSL("help-about")));
|
||||
m_ui.m_btnTest->setIcon(qApp->icons()->fromTheme(QSL("media-playback-start")));
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information,
|
||||
tr("No test executed yet."),
|
||||
tr("No test executed yet."));
|
||||
tr("No additional info."),
|
||||
tr("No additional info."));
|
||||
|
||||
load();
|
||||
loadDialog();
|
||||
m_ui.m_buttonBox->setFocus();
|
||||
}
|
||||
|
||||
void AdBlockDialog::saveAndClose() {
|
||||
void AdBlockDialog::saveOnClose() {
|
||||
m_manager->setFilterLists(m_ui.m_txtPredefined->toPlainText().split(QSL("\n")));
|
||||
m_manager->setCustomFilters(m_ui.m_txtCustom->toPlainText().split(QSL("\n")));
|
||||
|
||||
try {
|
||||
m_manager->updateUnifiedFiltersFile();
|
||||
auto enabl = m_manager->isEnabled();
|
||||
|
||||
m_manager->setEnabled(false);
|
||||
|
||||
if (enabl) {
|
||||
m_manager->setEnabled(enabl);
|
||||
}
|
||||
}
|
||||
catch (const ApplicationException& ex) {
|
||||
qCriticalNN << LOGSEC_ADBLOCK
|
||||
<< "Failed to write unified filters to file or re-start server, error:"
|
||||
<< "Failed to enable AdBlock, error:"
|
||||
<< QUOTE_W_SPACE_DOT(ex.message());
|
||||
|
||||
MessageBox::show(this,
|
||||
@ -64,43 +69,61 @@ void AdBlockDialog::saveAndClose() {
|
||||
{},
|
||||
ex.message());
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
void AdBlockDialog::enableAdBlock(bool enable) {
|
||||
m_manager->load(false);
|
||||
qApp->settings()->setValue(GROUP(AdBlock), AdBlock::AdBlockEnabled, enable);
|
||||
|
||||
if (enable) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::testConfiguration() {
|
||||
try {
|
||||
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();
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok, tr("You are good to go."), tr("OK!"));
|
||||
|
||||
try {
|
||||
m_manager->setEnabled(enable);
|
||||
}
|
||||
catch (const ApplicationException& ex) {
|
||||
qCriticalNN << LOGSEC_ADBLOCK
|
||||
<< "Test of configuration failed:"
|
||||
<< QUOTE_W_SPACE_DOT(ex.message());
|
||||
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
|
||||
tr("There is error, check application log for more details and "
|
||||
"head to online documentation. Also make sure that Node.js is installed."
|
||||
"\n\nError: %1").arg(ex.message()),
|
||||
tr("ERROR!"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::load() {
|
||||
if (m_loaded) {
|
||||
return;
|
||||
void AdBlockDialog::onAdBlockEnabledChanged(bool enabled) {
|
||||
m_ui.m_cbEnable->setChecked(enabled);
|
||||
|
||||
if (enabled) {
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
|
||||
tr("It seems your AdBlock runs fine, but wait few seconds to be sure."),
|
||||
tr("OK!"));
|
||||
}
|
||||
else {
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information,
|
||||
tr("No additional info."),
|
||||
tr("No additional info."));
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockDialog::onAdBlockProcessTerminated() {
|
||||
m_ui.m_cbEnable->setChecked(false);
|
||||
|
||||
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
|
||||
tr("There is error, check application log for more details and "
|
||||
"head to online documentation. Also make sure that Node.js is installed."),
|
||||
tr("ERROR!"));
|
||||
}
|
||||
|
||||
void AdBlockDialog::loadDialog() {
|
||||
m_ui.m_txtCustom->setPlainText(m_manager->customFilters().join(QSL("\n")));
|
||||
m_ui.m_txtPredefined->setPlainText(m_manager->filterLists().join(QSL("\n")));
|
||||
}
|
||||
|
||||
void AdBlockDialog::hideEvent(QHideEvent* event) {
|
||||
QDialog::hideEvent(event);
|
||||
|
||||
saveOnClose();
|
||||
}
|
||||
|
@ -15,13 +15,17 @@ class AdBlockDialog : public QDialog {
|
||||
public:
|
||||
explicit AdBlockDialog(QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
virtual void hideEvent(QHideEvent* event);
|
||||
|
||||
private slots:
|
||||
void saveAndClose();
|
||||
void saveOnClose();
|
||||
void enableAdBlock(bool enable);
|
||||
void testConfiguration();
|
||||
void onAdBlockEnabledChanged(bool enabled);
|
||||
void onAdBlockProcessTerminated();
|
||||
|
||||
private:
|
||||
void load();
|
||||
void loadDialog();
|
||||
|
||||
private:
|
||||
AdBlockManager* m_manager;
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AdBlockDialog</class>
|
||||
<widget class="QWidget" name="AdBlockDialog">
|
||||
<widget class="QDialog" name="AdBlockDialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::NonModal</enum>
|
||||
</property>
|
||||
@ -33,13 +33,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_btnTest">
|
||||
<property name="text">
|
||||
<string>&Test configuration</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
@ -132,11 +125,43 @@
|
||||
<tabstops>
|
||||
<tabstop>m_cbEnable</tabstop>
|
||||
<tabstop>m_btnHelp</tabstop>
|
||||
<tabstop>m_btnTest</tabstop>
|
||||
<tabstop>m_tcSubscriptions</tabstop>
|
||||
<tabstop>m_txtPredefined</tabstop>
|
||||
<tabstop>m_txtCustom</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>m_buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AdBlockDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>226</x>
|
||||
<y>403</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>226</x>
|
||||
<y>211</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>m_buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AdBlockDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>226</x>
|
||||
<y>403</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>226</x>
|
||||
<y>211</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
@ -16,13 +16,17 @@ AdBlockIcon::AdBlockIcon(AdBlockManager* parent) : QAction(parent), m_manager(pa
|
||||
setText(QSL("AdBlock"));
|
||||
setMenu(new QMenu());
|
||||
|
||||
connect(m_manager, &AdBlockManager::enabledChanged, this, &AdBlockIcon::setEnabled);
|
||||
connect(m_manager, &AdBlockManager::enabledChanged, this, &AdBlockIcon::setIcon);
|
||||
connect(m_manager, &AdBlockManager::processTerminated, this, [this]() {
|
||||
setIcon(false);
|
||||
});
|
||||
|
||||
connect(menu(), &QMenu::aboutToShow, this, [this]() {
|
||||
createMenu();
|
||||
});
|
||||
connect(this, &QAction::triggered, m_manager, &AdBlockManager::showDialog);
|
||||
|
||||
setEnabled(m_manager->isEnabled());
|
||||
emit m_manager->enabledChanged(m_manager->isEnabled());
|
||||
}
|
||||
|
||||
AdBlockIcon::~AdBlockIcon() {
|
||||
@ -42,33 +46,6 @@ void AdBlockIcon::createMenu(QMenu* menu) {
|
||||
|
||||
menu->clear();
|
||||
menu->addAction(tr("Show AdBlock &settings"), m_manager, &AdBlockManager::showDialog);
|
||||
|
||||
/*
|
||||
WebPage* page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->viewer()->page();
|
||||
const QUrl page_url = page->url();
|
||||
AdBlockCustomList* custom_list = m_manager->customList();
|
||||
|
||||
menu->addSeparator();
|
||||
|
||||
if (!page_url.host().isEmpty() && m_manager->isEnabled() && m_manager->canRunOnScheme(page_url.scheme())) {
|
||||
const QString host = page->url().host().contains(QLatin1String("www.")) ? page_url.host().mid(4) : page_url.host();
|
||||
const QString host_filter = QString("@@||%1^$document").arg(host);
|
||||
const QString page_filter = QString("@@|%1|$document").arg(page_url.toString());
|
||||
QAction* act = menu->addAction(tr("Disable on %1").arg(host));
|
||||
|
||||
act->setCheckable(true);
|
||||
act->setChecked(custom_list->containsFilter(host_filter));
|
||||
act->setData(host_filter);
|
||||
connect(act, &QAction::triggered, this, &AdBlockIcon::toggleCustomFilter);
|
||||
|
||||
act = menu->addAction(tr("Disable only on this page"));
|
||||
act->setCheckable(true);
|
||||
act->setChecked(custom_list->containsFilter(page_filter));
|
||||
act->setData(page_filter);
|
||||
connect(act, &QAction::triggered, this, &AdBlockIcon::toggleCustomFilter);
|
||||
|
||||
menu->addSeparator();
|
||||
}*/
|
||||
}
|
||||
|
||||
void AdBlockIcon::showMenu(const QPoint& pos) {
|
||||
@ -78,11 +55,8 @@ void AdBlockIcon::showMenu(const QPoint& pos) {
|
||||
menu.exec(pos);
|
||||
}
|
||||
|
||||
void AdBlockIcon::setEnabled(bool enabled) {
|
||||
if (enabled) {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
}
|
||||
else {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
}
|
||||
void AdBlockIcon::setIcon(bool adblock_enabled) {
|
||||
QAction::setIcon(adblock_enabled
|
||||
? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE)
|
||||
: qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class AdBlockIcon : public QAction {
|
||||
virtual ~AdBlockIcon();
|
||||
|
||||
public slots:
|
||||
void setEnabled(bool enabled);
|
||||
void setIcon(bool adblock_enabled);
|
||||
|
||||
private slots:
|
||||
void showMenu(const QPoint& pos);
|
||||
|
@ -1,4 +1,4 @@
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
// For license of this file, see <project-root-folder>/LICENSE.md.
|
||||
|
||||
#include "network-web/adblock/adblockmanager.h"
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QUrlQuery>
|
||||
@ -34,9 +33,7 @@ AdBlockManager::AdBlockManager(QObject* parent)
|
||||
}
|
||||
|
||||
AdBlockManager::~AdBlockManager() {
|
||||
if (m_serverProcess != nullptr && m_serverProcess->state() == QProcess::ProcessState::Running) {
|
||||
m_serverProcess->kill();
|
||||
}
|
||||
killServer();
|
||||
}
|
||||
|
||||
BlockingResult AdBlockManager::block(const AdblockRequestInfo& request) {
|
||||
@ -54,7 +51,6 @@ BlockingResult AdBlockManager::block(const AdblockRequestInfo& request) {
|
||||
return { false };
|
||||
}
|
||||
else {
|
||||
if (m_serverProcess != nullptr && m_serverProcess->state() == QProcess::ProcessState::Running) {
|
||||
if (m_cacheBlocks.contains(url_pair)) {
|
||||
qDebugNN << LOGSEC_ADBLOCK
|
||||
<< "Found blocking data in cache, URL:"
|
||||
@ -63,6 +59,7 @@ BlockingResult AdBlockManager::block(const AdblockRequestInfo& request) {
|
||||
return m_cacheBlocks.value(url_pair);
|
||||
}
|
||||
|
||||
if (m_serverProcess != nullptr && m_serverProcess->state() == QProcess::ProcessState::Running) {
|
||||
try {
|
||||
auto result = askServerIfBlocked(firstparty_url_string, url_string, url_type);
|
||||
|
||||
@ -87,49 +84,35 @@ BlockingResult AdBlockManager::block(const AdblockRequestInfo& request) {
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockManager::load(bool initial_load) {
|
||||
auto new_enabled = qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::AdBlockEnabled)).toBool();
|
||||
|
||||
if (!initial_load) {
|
||||
new_enabled = !new_enabled;
|
||||
}
|
||||
|
||||
if (new_enabled != m_enabled) {
|
||||
emit enabledChanged(new_enabled);
|
||||
|
||||
qApp->settings()->setValue(GROUP(AdBlock), AdBlock::AdBlockEnabled, new_enabled);
|
||||
}
|
||||
else if (!initial_load) {
|
||||
void AdBlockManager::setEnabled(bool enabled) {
|
||||
if (enabled == m_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_enabled = new_enabled;
|
||||
|
||||
if (!m_loaded) {
|
||||
qApp->web()->urlIinterceptor()->installUrlInterceptor(m_interceptor);
|
||||
m_loaded = true;
|
||||
}
|
||||
|
||||
m_enabled = enabled;
|
||||
emit enabledChanged(m_enabled);
|
||||
|
||||
if (m_enabled) {
|
||||
try {
|
||||
updateUnifiedFiltersFile();
|
||||
updateUnifiedFiltersFileAndStartServer();
|
||||
}
|
||||
catch (const ApplicationException& ex) {
|
||||
qCriticalNN << LOGSEC_ADBLOCK
|
||||
<< "Failed to write unified filters to file or re-start server, error:"
|
||||
<< QUOTE_W_SPACE_DOT(ex.message());
|
||||
|
||||
qApp->showGuiMessage(Notification::Event::GeneralEvent,
|
||||
tr("AdBlock needs to be configured"),
|
||||
tr("AdBlock component is not configured properly."),
|
||||
QSystemTrayIcon::MessageIcon::Warning,
|
||||
true,
|
||||
{},
|
||||
[=]() {
|
||||
showDialog();
|
||||
});
|
||||
m_enabled = false;
|
||||
emit enabledChanged(m_enabled);
|
||||
}
|
||||
}
|
||||
else {
|
||||
killServer();
|
||||
}
|
||||
}
|
||||
|
||||
bool AdBlockManager::isEnabled() const {
|
||||
@ -196,6 +179,19 @@ void AdBlockManager::showDialog() {
|
||||
AdBlockDialog(qApp->mainFormWidget()).exec();
|
||||
}
|
||||
|
||||
void AdBlockManager::onServerProcessFinished(int exit_code, QProcess::ExitStatus exit_status) {
|
||||
Q_UNUSED(exit_status)
|
||||
killServer();
|
||||
|
||||
qCriticalNN << LOGSEC_ADBLOCK
|
||||
<< "Process exited with exit code"
|
||||
<< QUOTE_W_SPACE(exit_code)
|
||||
<< "so check application log for more details.";
|
||||
|
||||
m_enabled = false;
|
||||
emit processTerminated();
|
||||
}
|
||||
|
||||
BlockingResult AdBlockManager::askServerIfBlocked(const QString& fp_url, const QString& url, const QString& url_type) const {
|
||||
QJsonObject req_obj;
|
||||
QByteArray out;
|
||||
@ -274,7 +270,7 @@ QString AdBlockManager::askServerForCosmeticRules(const QString& url) const {
|
||||
}
|
||||
}
|
||||
|
||||
QProcess* AdBlockManager::restartServer(int port) {
|
||||
QProcess* AdBlockManager::startServer(int port) {
|
||||
QString temp_server = QDir::toNativeSeparators(IOFactory::getSystemFolder(QStandardPaths::StandardLocation::TempLocation)) +
|
||||
QDir::separator() +
|
||||
QSL("adblock-server.js");
|
||||
@ -317,25 +313,32 @@ QProcess* AdBlockManager::restartServer(int port) {
|
||||
|
||||
proc->setProcessEnvironment(pe);
|
||||
proc->setProcessChannelMode(QProcess::ProcessChannelMode::ForwardedErrorChannel);
|
||||
|
||||
connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &AdBlockManager::onServerProcessFinished);
|
||||
|
||||
proc->open();
|
||||
|
||||
proc->waitForFinished(1000);
|
||||
|
||||
if (proc->state() == QProcess::ProcessState::NotRunning ||
|
||||
proc->error() != QProcess::ProcessError::UnknownError) {
|
||||
auto ers = proc->errorString();
|
||||
proc->deleteLater();
|
||||
|
||||
throw ApplicationException(ers);
|
||||
}
|
||||
else {
|
||||
qDebugNN << LOGSEC_ADBLOCK << "Started server.";
|
||||
qDebugNN << LOGSEC_ADBLOCK << "Attempting to start AdBlock server.";
|
||||
return proc;
|
||||
}
|
||||
|
||||
void AdBlockManager::killServer() {
|
||||
if (m_serverProcess != nullptr) {
|
||||
disconnect(m_serverProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
this, &AdBlockManager::onServerProcessFinished);
|
||||
|
||||
if (m_serverProcess->state() == QProcess::ProcessState::Running) {
|
||||
m_serverProcess->kill();
|
||||
}
|
||||
|
||||
void AdBlockManager::updateUnifiedFiltersFile() {
|
||||
m_serverProcess->deleteLater();
|
||||
m_serverProcess = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockManager::updateUnifiedFiltersFileAndStartServer() {
|
||||
m_cacheBlocks.clear();
|
||||
killServer();
|
||||
|
||||
if (QFile::exists(m_unifiedFiltersFile)) {
|
||||
QFile::remove(m_unifiedFiltersFile);
|
||||
@ -380,13 +383,6 @@ void AdBlockManager::updateUnifiedFiltersFile() {
|
||||
IOFactory::writeFile(m_unifiedFiltersFile, unified_contents.toUtf8());
|
||||
|
||||
if (m_enabled) {
|
||||
if (m_serverProcess != nullptr && m_serverProcess->state() == QProcess::ProcessState::Running) {
|
||||
m_serverProcess->kill();
|
||||
m_serverProcess->waitForFinished(1000);
|
||||
m_serverProcess->deleteLater();
|
||||
m_serverProcess = nullptr;
|
||||
}
|
||||
|
||||
m_serverProcess = restartServer(ADBLOCK_SERVER_PORT);
|
||||
m_serverProcess = startServer(ADBLOCK_SERVER_PORT);
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@
|
||||
#include <QObject>
|
||||
|
||||
#include <QHash>
|
||||
#include <QProcess>
|
||||
|
||||
class QUrl;
|
||||
class QProcess;
|
||||
class AdblockRequestInfo;
|
||||
class AdBlockUrlInterceptor;
|
||||
class AdBlockIcon;
|
||||
@ -31,13 +31,18 @@ class AdBlockManager : public QObject {
|
||||
explicit AdBlockManager(QObject* parent = nullptr);
|
||||
virtual ~AdBlockManager();
|
||||
|
||||
// If "initial_load" is false, then we want to explicitly turn off
|
||||
// Adblock if it is running or turn on when not running.
|
||||
// if "initial_load" is true, then we want to forcefully perform
|
||||
// initial loading of Adblock.
|
||||
void load(bool initial_load);
|
||||
|
||||
// Enables (or disables) AdBlock feature asynchronously.
|
||||
// This method will start/stop AdBlock in separate process
|
||||
// and thus cannot run synchronously (when enabling) as process takes
|
||||
// some time to start.
|
||||
//
|
||||
// If the process fails then signal
|
||||
// processTerminated() is thrown.
|
||||
// If AdBlock is switched on/off peacefully then signal
|
||||
// enabledChanged(bool) is thrown.
|
||||
void setEnabled(bool enabled);
|
||||
bool isEnabled() const;
|
||||
|
||||
bool canRunOnScheme(const QString& scheme) const;
|
||||
AdBlockIcon* adBlockIcon() const;
|
||||
|
||||
@ -51,8 +56,6 @@ class AdBlockManager : public QObject {
|
||||
QStringList customFilters() const;
|
||||
void setCustomFilters(const QStringList& custom_filters);
|
||||
|
||||
void updateUnifiedFiltersFile();
|
||||
|
||||
static QString generateJsForElementHiding(const QString& css);
|
||||
|
||||
public slots:
|
||||
@ -60,11 +63,18 @@ class AdBlockManager : public QObject {
|
||||
|
||||
signals:
|
||||
void enabledChanged(bool enabled);
|
||||
void processTerminated();
|
||||
|
||||
private slots:
|
||||
void onServerProcessFinished(int exit_code, QProcess::ExitStatus exit_status);
|
||||
|
||||
private:
|
||||
void updateUnifiedFiltersFileAndStartServer();
|
||||
QProcess* startServer(int port);
|
||||
void killServer();
|
||||
|
||||
BlockingResult askServerIfBlocked(const QString& fp_url, const QString& url, const QString& url_type) const;
|
||||
QString askServerForCosmeticRules(const QString& url) const;
|
||||
QProcess* restartServer(int port);
|
||||
|
||||
private:
|
||||
bool m_loaded;
|
||||
|
@ -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/adblockurlinterceptor.h"
|
||||
|
||||
#include "definitions/definitions.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 ADBLOCKURLINTERCEPTOR_H
|
||||
#define ADBLOCKURLINTERCEPTOR_H
|
||||
|
||||
|
@ -422,6 +422,7 @@ void DownloadItem::finished() {
|
||||
QSystemTrayIcon::MessageIcon::Information,
|
||||
{},
|
||||
{},
|
||||
tr("Open folder"),
|
||||
[this] {
|
||||
openFolder();
|
||||
});
|
||||
|
@ -85,6 +85,7 @@ QString OAuth2Service::bearer() {
|
||||
tr("Click here to login."),
|
||||
QSystemTrayIcon::MessageIcon::Critical,
|
||||
{}, {},
|
||||
tr("Login"),
|
||||
[this]() {
|
||||
login();
|
||||
});
|
||||
|
@ -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 URLINTERCEPTOR_H
|
||||
#define URLINTERCEPTOR_H
|
||||
|
||||
@ -27,7 +10,7 @@ class UrlInterceptor : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UrlInterceptor(QObject* parent = Q_NULLPTR) : QObject(parent) { }
|
||||
explicit UrlInterceptor(QObject* parent = nullptr) : QObject(parent) { }
|
||||
|
||||
virtual void interceptRequest(QWebEngineUrlRequestInfo& info) = 0;
|
||||
};
|
||||
|
@ -511,6 +511,7 @@ void FeedlyNetwork::onTokensError(const QString& error, const QString& error_des
|
||||
tr("Click this to login again. Error is: '%1'").arg(error_description),
|
||||
QSystemTrayIcon::MessageIcon::Critical,
|
||||
{}, {},
|
||||
tr("Login"),
|
||||
[this]() {
|
||||
m_oauth->setAccessToken(QString());
|
||||
m_oauth->setRefreshToken(QString());
|
||||
@ -526,6 +527,7 @@ void FeedlyNetwork::onAuthFailed() {
|
||||
tr("Click this to login again."),
|
||||
QSystemTrayIcon::MessageIcon::Critical,
|
||||
{}, {},
|
||||
tr("Login"),
|
||||
[this]() {
|
||||
//m_oauth->logout(false);
|
||||
m_oauth->login();
|
||||
|
@ -425,6 +425,7 @@ void GmailNetworkFactory::onTokensError(const QString& error, const QString& err
|
||||
tr("Click this to login again. Error is: '%1'").arg(error_description),
|
||||
QSystemTrayIcon::MessageIcon::Critical,
|
||||
{}, {},
|
||||
tr("Login"),
|
||||
[this]() {
|
||||
m_oauth2->setAccessToken(QString());
|
||||
m_oauth2->setRefreshToken(QString());
|
||||
@ -438,6 +439,7 @@ void GmailNetworkFactory::onAuthFailed() {
|
||||
tr("Click this to login again."),
|
||||
QSystemTrayIcon::MessageIcon::Critical,
|
||||
{}, {},
|
||||
tr("Login"),
|
||||
[this]() {
|
||||
m_oauth2->login();
|
||||
});
|
||||
|
@ -1098,6 +1098,7 @@ void GreaderNetwork::onTokensError(const QString& error, const QString& error_de
|
||||
tr("Click this to login again. Error is: '%1'").arg(error_description),
|
||||
QSystemTrayIcon::MessageIcon::Critical,
|
||||
{}, {},
|
||||
tr("Login"),
|
||||
[this]() {
|
||||
m_oauth->setAccessToken(QString());
|
||||
m_oauth->setRefreshToken(QString());
|
||||
@ -1111,6 +1112,7 @@ void GreaderNetwork::onAuthFailed() {
|
||||
tr("Click this to login again."),
|
||||
QSystemTrayIcon::MessageIcon::Critical,
|
||||
{}, {},
|
||||
tr("Login"),
|
||||
[this]() {
|
||||
m_oauth->login();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user