diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index 953ed2327..3fd67b1fe 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/src/librssguard/gui/messagebox.cpp b/src/librssguard/gui/messagebox.cpp index 74f4161ed..b2b2ed690 100755 --- a/src/librssguard/gui/messagebox.cpp +++ b/src/librssguard/gui/messagebox.cpp @@ -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 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; diff --git a/src/librssguard/gui/messagebox.h b/src/librssguard/gui/messagebox.h index f1c5b9b50..aa98dbf72 100755 --- a/src/librssguard/gui/messagebox.h +++ b/src/librssguard/gui/messagebox.h @@ -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 functor = nullptr); static QIcon iconForStatus(QMessageBox::Icon status); }; diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index e5c144351..a772c333e 100755 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -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 functor) { + QWidget* parent, const QString& functor_heading, std::function 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) { diff --git a/src/librssguard/miscellaneous/application.h b/src/librssguard/miscellaneous/application.h index b73bd8632..fc22a7162 100755 --- a/src/librssguard/miscellaneous/application.h +++ b/src/librssguard/miscellaneous/application.h @@ -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 functor = nullptr); + QWidget* parent = nullptr, const QString& functor_heading = {}, + std::function 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); diff --git a/src/librssguard/miscellaneous/systemfactory.cpp b/src/librssguard/miscellaneous/systemfactory.cpp index 1548b7b86..0e0680bcb 100644 --- a/src/librssguard/miscellaneous/systemfactory.cpp +++ b/src/librssguard/miscellaneous/systemfactory.cpp @@ -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(); }); diff --git a/src/librssguard/network-web/adblock/adblockdialog.cpp b/src/librssguard/network-web/adblock/adblockdialog.cpp index cf92067fe..a41f63ad1 100644 --- a/src/librssguard/network-web/adblock/adblockdialog.cpp +++ b/src/librssguard/network-web/adblock/adblockdialog.cpp @@ -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(); - } -} + m_manager->setFilterLists(m_ui.m_txtPredefined->toPlainText().split(QSL("\n"))); + m_manager->setCustomFilters(m_ui.m_txtCustom->toPlainText().split(QSL("\n"))); -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!")); + 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(); +} diff --git a/src/librssguard/network-web/adblock/adblockdialog.h b/src/librssguard/network-web/adblock/adblockdialog.h index f4510e0ca..80c1ec08e 100644 --- a/src/librssguard/network-web/adblock/adblockdialog.h +++ b/src/librssguard/network-web/adblock/adblockdialog.h @@ -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; diff --git a/src/librssguard/network-web/adblock/adblockdialog.ui b/src/librssguard/network-web/adblock/adblockdialog.ui index c6e08e9f3..67db7d2bc 100644 --- a/src/librssguard/network-web/adblock/adblockdialog.ui +++ b/src/librssguard/network-web/adblock/adblockdialog.ui @@ -1,7 +1,7 @@ AdBlockDialog - + Qt::NonModal @@ -33,13 +33,6 @@ - - - - &Test configuration - - - @@ -132,11 +125,43 @@ m_cbEnable m_btnHelp - m_btnTest m_tcSubscriptions m_txtPredefined m_txtCustom - + + + m_buttonBox + accepted() + AdBlockDialog + accept() + + + 226 + 403 + + + 226 + 211 + + + + + m_buttonBox + rejected() + AdBlockDialog + reject() + + + 226 + 403 + + + 226 + 211 + + + + diff --git a/src/librssguard/network-web/adblock/adblockicon.cpp b/src/librssguard/network-web/adblock/adblockicon.cpp index 225efbea5..3dcd5b3bb 100644 --- a/src/librssguard/network-web/adblock/adblockicon.cpp +++ b/src/librssguard/network-web/adblock/adblockicon.cpp @@ -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)); } diff --git a/src/librssguard/network-web/adblock/adblockicon.h b/src/librssguard/network-web/adblock/adblockicon.h index 4b305aaaf..a0c6da573 100644 --- a/src/librssguard/network-web/adblock/adblockicon.h +++ b/src/librssguard/network-web/adblock/adblockicon.h @@ -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); diff --git a/src/librssguard/network-web/adblock/adblockmanager.cpp b/src/librssguard/network-web/adblock/adblockmanager.cpp index 2038ed709..50ea01ee8 100644 --- a/src/librssguard/network-web/adblock/adblockmanager.cpp +++ b/src/librssguard/network-web/adblock/adblockmanager.cpp @@ -1,4 +1,4 @@ -// For license of this file, see /LICENSE.md. +// For license of this file, see /LICENSE.md. #include "network-web/adblock/adblockmanager.h" @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -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,15 +51,15 @@ BlockingResult AdBlockManager::block(const AdblockRequestInfo& request) { return { false }; } else { + if (m_cacheBlocks.contains(url_pair)) { + qDebugNN << LOGSEC_ADBLOCK + << "Found blocking data in cache, URL:" + << QUOTE_W_SPACE_DOT(url_pair); + + return m_cacheBlocks.value(url_pair); + } + 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:" - << QUOTE_W_SPACE_DOT(url_pair); - - return m_cacheBlocks.value(url_pair); - } - 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::of(&QProcess::finished), this, &AdBlockManager::onServerProcessFinished); + proc->open(); - proc->waitForFinished(1000); + qDebugNN << LOGSEC_ADBLOCK << "Attempting to start AdBlock server."; + return proc; +} - if (proc->state() == QProcess::ProcessState::NotRunning || - proc->error() != QProcess::ProcessError::UnknownError) { - auto ers = proc->errorString(); - proc->deleteLater(); +void AdBlockManager::killServer() { + if (m_serverProcess != nullptr) { + disconnect(m_serverProcess, QOverload::of(&QProcess::finished), + this, &AdBlockManager::onServerProcessFinished); - throw ApplicationException(ers); - } - else { - qDebugNN << LOGSEC_ADBLOCK << "Started server."; - return proc; + if (m_serverProcess->state() == QProcess::ProcessState::Running) { + m_serverProcess->kill(); + } + + m_serverProcess->deleteLater(); + m_serverProcess = nullptr; } } -void AdBlockManager::updateUnifiedFiltersFile() { +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); } } diff --git a/src/librssguard/network-web/adblock/adblockmanager.h b/src/librssguard/network-web/adblock/adblockmanager.h index 832ffb2e9..11600aca9 100644 --- a/src/librssguard/network-web/adblock/adblockmanager.h +++ b/src/librssguard/network-web/adblock/adblockmanager.h @@ -6,9 +6,9 @@ #include #include +#include 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; diff --git a/src/librssguard/network-web/adblock/adblockurlinterceptor.cpp b/src/librssguard/network-web/adblock/adblockurlinterceptor.cpp index a33df98ba..6cf2b7dcc 100644 --- a/src/librssguard/network-web/adblock/adblockurlinterceptor.cpp +++ b/src/librssguard/network-web/adblock/adblockurlinterceptor.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/adblockurlinterceptor.h" #include "definitions/definitions.h" diff --git a/src/librssguard/network-web/adblock/adblockurlinterceptor.h b/src/librssguard/network-web/adblock/adblockurlinterceptor.h index 2d6fec8fe..b0f558b7c 100644 --- a/src/librssguard/network-web/adblock/adblockurlinterceptor.h +++ b/src/librssguard/network-web/adblock/adblockurlinterceptor.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 ADBLOCKURLINTERCEPTOR_H #define ADBLOCKURLINTERCEPTOR_H diff --git a/src/librssguard/network-web/downloadmanager.cpp b/src/librssguard/network-web/downloadmanager.cpp index c6db9cee2..16a9f0f10 100644 --- a/src/librssguard/network-web/downloadmanager.cpp +++ b/src/librssguard/network-web/downloadmanager.cpp @@ -422,6 +422,7 @@ void DownloadItem::finished() { QSystemTrayIcon::MessageIcon::Information, {}, {}, + tr("Open folder"), [this] { openFolder(); }); diff --git a/src/librssguard/network-web/oauth2service.cpp b/src/librssguard/network-web/oauth2service.cpp index 63efd7d2b..7c8ce3cdc 100644 --- a/src/librssguard/network-web/oauth2service.cpp +++ b/src/librssguard/network-web/oauth2service.cpp @@ -85,6 +85,7 @@ QString OAuth2Service::bearer() { tr("Click here to login."), QSystemTrayIcon::MessageIcon::Critical, {}, {}, + tr("Login"), [this]() { login(); }); diff --git a/src/librssguard/network-web/urlinterceptor.h b/src/librssguard/network-web/urlinterceptor.h index cc3ca9083..a8a509bc1 100644 --- a/src/librssguard/network-web/urlinterceptor.h +++ b/src/librssguard/network-web/urlinterceptor.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 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; }; diff --git a/src/librssguard/services/feedly/feedlynetwork.cpp b/src/librssguard/services/feedly/feedlynetwork.cpp index 49598f269..36ebd299d 100755 --- a/src/librssguard/services/feedly/feedlynetwork.cpp +++ b/src/librssguard/services/feedly/feedlynetwork.cpp @@ -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(); diff --git a/src/librssguard/services/gmail/gmailnetworkfactory.cpp b/src/librssguard/services/gmail/gmailnetworkfactory.cpp index 94bdadadd..a7d25eb94 100755 --- a/src/librssguard/services/gmail/gmailnetworkfactory.cpp +++ b/src/librssguard/services/gmail/gmailnetworkfactory.cpp @@ -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(); }); diff --git a/src/librssguard/services/greader/greadernetwork.cpp b/src/librssguard/services/greader/greadernetwork.cpp index c3e2d1d74..511ef0cf9 100755 --- a/src/librssguard/services/greader/greadernetwork.cpp +++ b/src/librssguard/services/greader/greadernetwork.cpp @@ -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(); });