diff --git a/src/librssguard/network-web/adblock/adblockmanager.cpp b/src/librssguard/network-web/adblock/adblockmanager.cpp index 17a282213..ada89197b 100644 --- a/src/librssguard/network-web/adblock/adblockmanager.cpp +++ b/src/librssguard/network-web/adblock/adblockmanager.cpp @@ -88,39 +88,6 @@ void AdBlockManager::removeDisabledRule(const QString& filter) { m_disabledRules.removeOne(filter); } -bool AdBlockManager::addSubscriptionFromUrl(const QUrl& url) { - const QList> queryItems = QUrlQuery(url).queryItems(QUrl::FullyDecoded); - QString subscriptionTitle; - QString subscriptionUrl; - - for (int i = 0; i < queryItems.count(); ++i) { - QPair pair = queryItems.at(i); - - if (pair.first == QL1S("location")) { - subscriptionUrl = pair.second; - } - else if (pair.first == QL1S("title")) { - subscriptionTitle = pair.second; - } - } - - if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty()) { - return false; - } - - const QString message = tr("Do you want to add %1 subscription?").arg(subscriptionTitle); - - QMessageBox::StandardButton result = QMessageBox::question(nullptr, tr("Add AdBlock subscription"), message, - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - - if (result == QMessageBox::StandardButton::Yes) { - qApp->web()->adBlock()->addSubscription(subscriptionTitle, subscriptionUrl); - qApp->web()->adBlock()->showDialog(); - } - - return true; -} - AdBlockSubscription* AdBlockManager::addSubscription(const QString& title, const QString& url) { if (title.isEmpty() || url.isEmpty()) { return nullptr; @@ -303,8 +270,7 @@ bool AdBlockManager::isEnabled() const { bool AdBlockManager::canRunOnScheme(const QString& scheme) const { return !(scheme == QSL("file") || scheme == QSL("qrc") || - scheme == QSL("data") || scheme == QSL("abp") || - scheme == QSL(APP_LOW_NAME)); + scheme == QSL("data") || scheme == QSL("abp")); } bool AdBlockManager::canBeBlocked(const QUrl& url) const { @@ -346,16 +312,6 @@ QString AdBlockManager::generateJsForElementHiding(const QString& css) const { return source.arg(style); } -AdBlockSubscription* AdBlockManager::subscriptionByName(const QString& name) const { - for (AdBlockSubscription* subscription : m_subscriptions) { - if (subscription->title() == name) { - return subscription; - } - } - - return nullptr; -} - void AdBlockManager::showDialog() { AdBlockDialog(qApp->mainFormWidget()).exec(); } diff --git a/src/librssguard/network-web/adblock/adblockmanager.h b/src/librssguard/network-web/adblock/adblockmanager.h index 9e8a7b5e8..5b802ef24 100644 --- a/src/librssguard/network-web/adblock/adblockmanager.h +++ b/src/librssguard/network-web/adblock/adblockmanager.h @@ -46,6 +46,8 @@ class AdBlockManager : public QObject { // if "initial_load" is true, then we want to forcefully perform // initial loading of Adblock. void load(bool initial_load); + + // Save all subscriptions to file(s). void save(); // General method for adblocking. Returns pointer to rule if request should @@ -57,17 +59,14 @@ class AdBlockManager : public QObject { QString elementHidingRules(const QUrl& url) const; QString elementHidingRulesForDomain(const QUrl& url) const; - QString generateJsForElementHiding(const QString& css) const; - AdBlockSubscription* subscriptionByName(const QString& name) const; QList subscriptions() const; QStringList disabledRules() const; void addDisabledRule(const QString& filter); void removeDisabledRule(const QString& filter); - bool addSubscriptionFromUrl(const QUrl& url); AdBlockSubscription* addSubscription(const QString& title, const QString& url); bool removeSubscription(AdBlockSubscription* subscription); diff --git a/src/librssguard/network-web/adblock/adblockrule.cpp b/src/librssguard/network-web/adblock/adblockrule.cpp index 561c7c5c5..7ebff7d51 100644 --- a/src/librssguard/network-web/adblock/adblockrule.cpp +++ b/src/librssguard/network-web/adblock/adblockrule.cpp @@ -738,21 +738,3 @@ QStringList AdBlockRule::parseRegExpFilter(const QString& filter) const { list.removeDuplicates(); return list; } - -bool AdBlockRule::hasOption(const AdBlockRule::RuleOption& opt) const { - return (m_options & opt) != 0; -} - -bool AdBlockRule::hasException(const AdBlockRule::RuleOption& opt) const { - return (m_exceptions & opt) != 0; -} - -void AdBlockRule::setOption(const AdBlockRule::RuleOption& opt) { - m_options |= opt; -} - -void AdBlockRule::setException(const AdBlockRule::RuleOption& opt, bool on) { - if (on) { - m_exceptions |= opt; - } -} diff --git a/src/librssguard/network-web/adblock/adblockrule.h b/src/librssguard/network-web/adblock/adblockrule.h index fb8c2ae44..8b38949f2 100644 --- a/src/librssguard/network-web/adblock/adblockrule.h +++ b/src/librssguard/network-web/adblock/adblockrule.h @@ -64,8 +64,8 @@ class AdBlockRule { virtual ~AdBlockRule() = default; AdBlockRule* copy() const; - AdBlockSubscription* subscription() const; + AdBlockSubscription* subscription() const; void setSubscription(AdBlockSubscription* subscription); QString filter() const; @@ -135,10 +135,10 @@ class AdBlockRule { Q_DECLARE_FLAGS(RuleOptions, RuleOption) - inline bool hasOption(const RuleOption& opt) const; - inline bool hasException(const RuleOption& opt) const; - inline void setOption(const RuleOption& opt); - inline void setException(const RuleOption& opt, bool on); + bool hasOption(const RuleOption& opt) const; + bool hasException(const RuleOption& opt) const; + void setOption(const RuleOption& opt); + void setException(const RuleOption& opt, bool on); void parseFilter(); void parseDomains(const QString& domains, const QChar& separator); @@ -174,4 +174,22 @@ class AdBlockRule { friend class AdBlockSubscription; }; +inline bool AdBlockRule::hasOption(const AdBlockRule::RuleOption& opt) const { + return (m_options & opt) != 0; +} + +inline bool AdBlockRule::hasException(const AdBlockRule::RuleOption& opt) const { + return (m_exceptions & opt) != 0; +} + +inline void AdBlockRule::setOption(const AdBlockRule::RuleOption& opt) { + m_options |= opt; +} + +inline void AdBlockRule::setException(const AdBlockRule::RuleOption& opt, bool on) { + if (on) { + m_exceptions |= opt; + } +} + #endif // ADBLOCKRULE_H diff --git a/src/librssguard/network-web/adblock/adblocksearchtree.h b/src/librssguard/network-web/adblock/adblocksearchtree.h index 9af9d6797..8ea1b3ecb 100644 --- a/src/librssguard/network-web/adblock/adblocksearchtree.h +++ b/src/librssguard/network-web/adblock/adblocksearchtree.h @@ -38,12 +38,11 @@ class AdBlockSearchTree { private: struct Node { + Node() : c(0), rule(0) {} + QChar c; const AdBlockRule* rule; QHash children; - - Node() : c(0), rule(0) { } - }; const AdBlockRule* prefixSearch(const AdblockRequestInfo& request, const QString& domain, diff --git a/src/librssguard/network-web/adblock/adblocksubscription.h b/src/librssguard/network-web/adblock/adblocksubscription.h index 645b8d7a8..863876dbf 100644 --- a/src/librssguard/network-web/adblock/adblocksubscription.h +++ b/src/librssguard/network-web/adblock/adblocksubscription.h @@ -61,7 +61,7 @@ class AdBlockSubscription : public QObject { Q_OBJECT public: - explicit AdBlockSubscription(QString title, QObject* parent = 0); + explicit AdBlockSubscription(QString title, QObject* parent = nullptr); virtual ~AdBlockSubscription(); QString title() const; @@ -72,14 +72,14 @@ class AdBlockSubscription : public QObject { QUrl url() const; void setUrl(const QUrl& url); - virtual void loadSubscription(const QStringList& disabledRules); - virtual void saveSubscription(); const AdBlockRule* rule(int offset) const; QVector allRules() const; const AdBlockRule* enableRule(int offset); const AdBlockRule* disableRule(int offset); + virtual void loadSubscription(const QStringList& disabledRules); + virtual void saveSubscription(); virtual bool canEditRules() const; virtual bool canBeRemoved() const; virtual int addRule(AdBlockRule* rule); @@ -99,8 +99,9 @@ class AdBlockSubscription : public QObject { protected: virtual bool saveDownloadedData(const QByteArray& data); - QNetworkReply* m_reply; + protected: + QNetworkReply* m_reply; QVector m_rules; private: diff --git a/src/librssguard/network-web/adblock/adblocktreewidget.h b/src/librssguard/network-web/adblock/adblocktreewidget.h index ccd3d4d45..12255977b 100644 --- a/src/librssguard/network-web/adblock/adblocktreewidget.h +++ b/src/librssguard/network-web/adblock/adblocktreewidget.h @@ -48,9 +48,11 @@ class AdBlockTreeWidget : public TreeWidget { void subscriptionUpdated(); void subscriptionError(const QString& message); + protected: + virtual void keyPressEvent(QKeyEvent* event); + private: void adjustItemFeatures(QTreeWidgetItem* item, const AdBlockRule* rule); - void keyPressEvent(QKeyEvent* event); AdBlockSubscription* m_subscription; QTreeWidgetItem* m_topItem;