From 5cedad03ac7e4d03873fd3d626e83ec62851d49b Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 20 Jul 2017 08:05:21 +0200 Subject: [PATCH] Fix compilation, add interceptor to Application class. --- resources/binaries | 2 +- resources/graphics/misc/adblock-disabled.png | Bin 0 -> 3611 bytes resources/graphics/misc/adblock.png | Bin 0 -> 4267 bytes rssguard.pro | 6 +- src/definitions/definitions.h | 1 + src/gui/treewidget.cpp | 197 +++++++++ src/gui/treewidget.h | 70 ++++ src/miscellaneous/application.cpp | 5 + src/miscellaneous/application.h | 2 + src/miscellaneous/settings.cpp | 3 + src/miscellaneous/settings.h | 3 + src/network-web/adblock/adblockmanager.cpp | 14 +- src/network-web/adblock/adblockmatcher.cpp | 20 +- src/network-web/adblock/adblockmatcher.h | 4 +- src/network-web/adblock/adblockrule.cpp | 4 +- .../adblock/adblocksubscription.cpp | 113 +++-- src/network-web/adblock/adblocksubscription.h | 2 +- src/network-web/adblock/adblocktreewidget.cpp | 389 +++++++++--------- src/network-web/adblock/adblocktreewidget.h | 28 +- .../adblock/adblockurlinterceptor.cpp | 18 +- .../adblock/adblockurlinterceptor.h | 15 +- src/network-web/networkurlinterceptor.cpp | 54 ++- src/network-web/networkurlinterceptor.h | 12 +- src/network-web/urlinterceptor.h | 8 +- 24 files changed, 623 insertions(+), 347 deletions(-) create mode 100755 resources/graphics/misc/adblock-disabled.png create mode 100755 resources/graphics/misc/adblock.png create mode 100755 src/gui/treewidget.cpp create mode 100755 src/gui/treewidget.h diff --git a/resources/binaries b/resources/binaries index aea118796..1bb36a305 160000 --- a/resources/binaries +++ b/resources/binaries @@ -1 +1 @@ -Subproject commit aea11879635d0d6b029a7f6d49d1f31dd95b3c05 +Subproject commit 1bb36a305e8a23de1e4f3609d8fc4dfeb85ba6fe diff --git a/resources/graphics/misc/adblock-disabled.png b/resources/graphics/misc/adblock-disabled.png new file mode 100755 index 0000000000000000000000000000000000000000..a4f8f9c2e6f9f56458f2f157fec9c4145311d708 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6K64bL5GW}tL*Kja zBDHH5%9BYLJFv(C8KYbm?!*NC&vm){)mKGvW23%j<;s73Z~y)uDW$X|A~=qd-QL^# z)S6pw{cioLRbu9^eue#7v+#YuHk!CE2&GVe_%L?;>}N>W?ek}ffRtbW`<{OuEtw2L z`?^RJu#R*b$nkOPNhW#PYp;n!eSLW6iWUE||HBV|=s1ohB9_s1P{VPYT<@-3|8du< zRZrEmwPEh7ui`^yc5*q81t9?Bh%nFdF#P=U*uQr#ic=}DF?m}3)MJ~GS5$<~7hgo} z8*iW{nT#5vRRLgzFbJ5mW@hGXzxy5kp}wAj`g%^+*78_g9cSw5c%rtJ{e}k4RaEfqxpU3HfdhQJ zzdt)~?%YQKC~M;y!aRp&|16Kw6y&5=ANGKW)2-v`|iAx7vypR zsZ_pCDBB6&Vn%k&8Z7zhS24Gx1xckYdZjuvGJ+2}I&l1_KgHsG`_NQWgsdG)9m_Uu zA^}RLv3L4(p5NIihK-q6+1B>WzGKJ!$8j9KRN9D7iiFnMX<4%5n_GH%p7u|iaNfD& z4sOb11ecUVGpeP$Vx@34o5f+z!^FacNGw_eucijd^PopZ;U7K>@!or=`RF4obQ~lT z31qd7D3cjd2uQ~Pr_BTe&=B6MuQ!Xjy5#Axv9T3xZU1nhzyIY=GXApO6I&2+(ZYp~cK7!Frx+Sa?7r3IP>Uq}4l8Ddf(b!~1jRn&z%9d17#IWJO!s zqbEGjd%hZimgE*dYj=BgWR5c>`uJbT-!RbM|lIQZ)28h=Fq3P6a33l{wS z^FRLa<6c=Alik}~kqC{ayr^M`q5l5xk*|I2$&;r}y<*=QUH1Q0`F|9=$oD^Ao9X}n N002ovPDHLkV1hz$1qc8D literal 0 HcmV?d00001 diff --git a/rssguard.pro b/rssguard.pro index 03e0b50ce..961416ab1 100755 --- a/rssguard.pro +++ b/rssguard.pro @@ -518,7 +518,8 @@ equals(USE_WEBENGINE, true) { src/network-web/urlinterceptor.h \ src/network-web/networkurlinterceptor.h \ src/gui/clickablelabel.h \ - src/miscellaneous/simpleregexp.h + src/miscellaneous/simpleregexp.h \ + src/gui/treewidget.h SOURCES += src/network-web/adblock/adblockaddsubscriptiondialog.cpp \ src/network-web/adblock/adblockdialog.cpp \ @@ -532,7 +533,8 @@ equals(USE_WEBENGINE, true) { src/network-web/adblock/adblockurlinterceptor.cpp \ src/network-web/networkurlinterceptor.cpp \ src/gui/clickablelabel.cpp \ - src/miscellaneous/simpleregexp.cpp + src/miscellaneous/simpleregexp.cpp \ + src/gui/treewidget.cpp FORMS += src/network-web/adblock/adblockaddsubscriptiondialog.ui \ src/network-web/adblock/adblockdialog.ui diff --git a/src/definitions/definitions.h b/src/definitions/definitions.h index 182fe2518..f778db0a8 100755 --- a/src/definitions/definitions.h +++ b/src/definitions/definitions.h @@ -26,6 +26,7 @@ #define ARGUMENTS_LIST_SEPARATOR "\n" +#define IS_IN_ARRAY(offset, array) ((offset >= 0) && (offset < array.count())) #define ADBLOCK_CUSTOMLIST_NAME "customlist.txt" #define ADBLOCK_LISTS_SUBDIRECTORY "adblock" #define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt" diff --git a/src/gui/treewidget.cpp b/src/gui/treewidget.cpp new file mode 100755 index 000000000..9e40550d9 --- /dev/null +++ b/src/gui/treewidget.cpp @@ -0,0 +1,197 @@ +// This file is part of RSS Guard. +// +// 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 "gui/treewidget.h" + +#include + + +TreeWidget::TreeWidget(QWidget *parent) + : QTreeWidget(parent), m_refreshAllItemsNeeded(true), m_showMode(ItemsCollapsed) { + connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(sheduleRefresh())); +} + +void TreeWidget::clear() { + QTreeWidget::clear(); + m_allTreeItems.clear(); +} + +void TreeWidget::sheduleRefresh() { + m_refreshAllItemsNeeded = true; +} + +void TreeWidget::addTopLevelItem(QTreeWidgetItem *item) { + m_allTreeItems.append(item); + QTreeWidget::addTopLevelItem(item); +} + +void TreeWidget::addTopLevelItems(const QList &items) { + m_allTreeItems.append(items); + QTreeWidget::addTopLevelItems(items); +} + +void TreeWidget::insertTopLevelItem(int index, QTreeWidgetItem *item) { + m_allTreeItems.append(item); + QTreeWidget::insertTopLevelItem(index, item); +} + +void TreeWidget::insertTopLevelItems(int index, const QList &items) { + m_allTreeItems.append(items); + QTreeWidget::insertTopLevelItems(index, items); +} + +void TreeWidget::mousePressEvent(QMouseEvent *event) { + if (event->modifiers() == Qt::ControlModifier) { + emit itemControlClicked(itemAt(event->pos())); + } + + if (event->buttons() == Qt::MiddleButton) { + emit itemMiddleButtonClicked(itemAt(event->pos())); + } + + QTreeWidget::mousePressEvent(event); +} + +void TreeWidget::iterateAllItems(QTreeWidgetItem *parent) { + int count = parent ? parent->childCount() : topLevelItemCount(); + + for (int i = 0; i < count; i++) { + QTreeWidgetItem *item = parent ? parent->child(i) : topLevelItem(i); + + if (item->childCount() == 0) { + m_allTreeItems.append(item); + } + + iterateAllItems(item); + } +} + +QList TreeWidget::allItems() { + if (m_refreshAllItemsNeeded) { + m_allTreeItems.clear(); + iterateAllItems(0); + m_refreshAllItemsNeeded = false; + } + + return m_allTreeItems; +} + +void TreeWidget::filterString(const QString &string) { + QList _allItems = allItems(); + QList parents; + bool stringIsEmpty = string.isEmpty(); + foreach (QTreeWidgetItem *item, _allItems) { + bool containsString = stringIsEmpty || item->text(0).contains(string, Qt::CaseInsensitive); + + if (containsString) { + item->setHidden(false); + if (item->parent()) { + if (!parents.contains(item->parent())) { + parents << item->parent(); + } + } + } + else { + item->setHidden(true); + if (item->parent()) { + item->parent()->setHidden(true); + } + } + } + + for (int i = 0; i < parents.size(); ++i) { + QTreeWidgetItem *parentItem = parents.at(i); + parentItem->setHidden(false); + + if (stringIsEmpty) { + parentItem->setExpanded(m_showMode == ItemsExpanded); + } + else { + parentItem->setExpanded(true); + } + + if (parentItem->parent() && !parents.contains(parentItem->parent())) { + parents << parentItem->parent(); + } + } +} + +bool TreeWidget::appendToParentItem(const QString &parentText, QTreeWidgetItem *item) { + QList list = findItems(parentText, Qt::MatchExactly); + + if (list.count() == 0) { + return false; + } + + QTreeWidgetItem *parentItem = list.at(0); + + if (!parentItem) { + return false; + } + + m_allTreeItems.append(item); + parentItem->addChild(item); + return true; +} + +bool TreeWidget::appendToParentItem(QTreeWidgetItem *parent, QTreeWidgetItem *item) { + if (!parent || parent->treeWidget() != this) { + return false; + } + + m_allTreeItems.append(item); + parent->addChild(item); + return true; +} + +bool TreeWidget::prependToParentItem(const QString &parentText, QTreeWidgetItem *item) { + QList list = findItems(parentText, Qt::MatchExactly); + if (list.count() == 0) { + return false; + } + + QTreeWidgetItem *parentItem = list.at(0); + + if (!parentItem) { + return false; + } + + m_allTreeItems.append(item); + parentItem->insertChild(0, item); + return true; +} + +bool TreeWidget::prependToParentItem(QTreeWidgetItem *parent, QTreeWidgetItem *item) { + if (!parent || parent->treeWidget() != this) { + return false; + } + + m_allTreeItems.append(item); + parent->insertChild(0, item); + return true; +} + +void TreeWidget::deleteItem(QTreeWidgetItem* item) { + m_refreshAllItemsNeeded = true; + delete item; +} + +void TreeWidget::deleteItems(const QList &items) { + m_refreshAllItemsNeeded = true; + qDeleteAll(items); +} diff --git a/src/gui/treewidget.h b/src/gui/treewidget.h new file mode 100755 index 000000000..711bbccac --- /dev/null +++ b/src/gui/treewidget.h @@ -0,0 +1,70 @@ +// This file is part of RSS Guard. +// +// 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 BOOKMARKSTREEWIDGET_H +#define BOOKMARKSTREEWIDGET_H + +#include + + +class TreeWidget : public QTreeWidget { + Q_OBJECT + + public: + explicit TreeWidget(QWidget *parent = 0); + + enum ItemShowMode { ItemsCollapsed = 0, ItemsExpanded = 1 }; + + ItemShowMode defaultItemShowMode() { return m_showMode; } + void setDefaultItemShowMode(ItemShowMode mode) { m_showMode = mode; } + QList allItems(); + + bool appendToParentItem(const QString &parentText, QTreeWidgetItem *item); + bool appendToParentItem(QTreeWidgetItem* parent, QTreeWidgetItem *item); + bool prependToParentItem(const QString &parentText, QTreeWidgetItem *item); + bool prependToParentItem(QTreeWidgetItem* parent, QTreeWidgetItem *item); + + void addTopLevelItem(QTreeWidgetItem *item); + void addTopLevelItems(const QList &items); + void insertTopLevelItem(int index, QTreeWidgetItem *item); + void insertTopLevelItems(int index, const QList &items); + + void deleteItem(QTreeWidgetItem *item); + void deleteItems(const QList &items); + + signals: + void itemControlClicked(QTreeWidgetItem *item); + void itemMiddleButtonClicked(QTreeWidgetItem *item); + + public slots: + void filterString(const QString &string); + void clear(); + + private slots: + void sheduleRefresh(); + + private: + void mousePressEvent(QMouseEvent* event); + void iterateAllItems(QTreeWidgetItem* parent); + + bool m_refreshAllItemsNeeded; + QList m_allTreeItems; + ItemShowMode m_showMode; +}; + +#endif // BOOKMARKSTREEWIDGET_H diff --git a/src/miscellaneous/application.cpp b/src/miscellaneous/application.cpp index c94c7f13e..ad61c05aa 100755 --- a/src/miscellaneous/application.cpp +++ b/src/miscellaneous/application.cpp @@ -27,6 +27,8 @@ #include "gui/statusbar.h" #include "gui/dialogs/formmain.h" #include "exceptions/applicationexception.h" +#include "network-web/urlinterceptor.h" +#include "network-web/networkurlinterceptor.h" #include "services/abstract/serviceroot.h" #include "services/standard/standardserviceroot.h" @@ -44,6 +46,7 @@ Application::Application(const QString &id, int &argc, char **argv) : QtSingleApplication(id, argc, argv), + m_urlInterceptor(new NetworkUrlInterceptor(this)), m_feedReader(nullptr), m_updateFeedsLock(nullptr), m_userActions(QList()), m_mainForm(nullptr), m_trayIcon(nullptr), m_settings(nullptr), m_system(nullptr), m_skins(nullptr), @@ -54,6 +57,8 @@ Application::Application(const QString &id, int &argc, char **argv) #if defined(USE_WEBENGINE) connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested, this, &Application::downloadRequested); + + QWebEngineProfile::setRequestInterceptor(m_urlInterceptor); #endif } diff --git a/src/miscellaneous/application.h b/src/miscellaneous/application.h index 8edc9723e..29606bad8 100755 --- a/src/miscellaneous/application.h +++ b/src/miscellaneous/application.h @@ -47,6 +47,7 @@ class QAction; class Mutex; class QWebEngineDownloadItem; class FeedReader; +class NetworkUrlInterceptor; class Application : public QtSingleApplication { Q_OBJECT @@ -156,6 +157,7 @@ class Application : public QtSingleApplication { // action will be allowed to lock for reading. QScopedPointer m_updateFeedsLock; + NetworkUrlInterceptor *m_urlInterceptor; QList m_userActions; FormMain *m_mainForm; SystemTrayIcon *m_trayIcon; diff --git a/src/miscellaneous/settings.cpp b/src/miscellaneous/settings.cpp index f9bd589b1..9f05046a5 100755 --- a/src/miscellaneous/settings.cpp +++ b/src/miscellaneous/settings.cpp @@ -258,6 +258,9 @@ DKEY Keyboard::ID = "keyboard"; // Web browser. DKEY Browser::ID = "browser"; +KEY Browser::SendDNT = "send_dnt"; +VALUE(bool) Browser::SendDNTDef = false; + DKEY Browser::OpenLinksInExternalBrowserRightAway = "open_link_externally_wo_confirmation"; DVALUE(bool) Browser::OpenLinksInExternalBrowserRightAwayDef = false; diff --git a/src/miscellaneous/settings.h b/src/miscellaneous/settings.h index 34eda6474..72c863dad 100755 --- a/src/miscellaneous/settings.h +++ b/src/miscellaneous/settings.h @@ -291,6 +291,9 @@ namespace Keyboard { namespace Browser { KEY ID; + KEY SendDNT; + VALUE(bool) SendDNTDef; + KEY OpenLinksInExternalBrowserRightAway; VALUE(bool) OpenLinksInExternalBrowserRightAwayDef; diff --git a/src/network-web/adblock/adblockmanager.cpp b/src/network-web/adblock/adblockmanager.cpp index a42b2196a..322515f50 100755 --- a/src/network-web/adblock/adblockmanager.cpp +++ b/src/network-web/adblock/adblockmanager.cpp @@ -60,7 +60,7 @@ void AdBlockManager::setEnabled(bool enabled) { m_enabled = enabled; emit enabledChanged(enabled); - qApp->settings()->setValue(GROUP(Adblock), AdBlock::AdBlockEnabled, m_enabled); + qApp->settings()->setValue(GROUP(AdBlock), AdBlock::AdBlockEnabled, m_enabled); load(); // TODO: Reload user stylesheet. //mApp->reloadUserStyleSheet(); @@ -102,7 +102,8 @@ bool AdBlockManager::block(QWebEngineUrlRequestInfo &request) { if (request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) { // We are blocking main URL frame, we can display "AdBlock error page" or redirect to somewhere. - QMessageBox::warning(nullptr, "blocked website"); + // TODO: dodělat lepší + QMessageBox::warning(nullptr, "blocked website", "blocket"); // TODO request.redirect() přesměrovat na "chybovou stranku"; //QUrl url(QSL("rssguard:adblock")); @@ -190,7 +191,9 @@ AdBlockSubscription *AdBlockManager::addSubscription(const QString &title, const subscription->loadSubscription(m_disabledRules); m_subscriptions.insert(m_subscriptions.count() - 1, subscription); - connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet())); + + // TODO: po změně subskripce přehrat user css? + //connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet())); connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher())); return subscription; @@ -290,14 +293,15 @@ void AdBlockManager::load() { } // Append CustomList. - AdBlockCustomList* customList = new AdBlockCustomList(this); + AdBlockCustomList *customList = new AdBlockCustomList(this); m_subscriptions.append(customList); // Load all subscriptions foreach (AdBlockSubscription *subscription, m_subscriptions) { subscription->loadSubscription(m_disabledRules); - connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet())); + // TODO: po zmene subskripce prehrat user css? + //connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet())); connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher())); } diff --git a/src/network-web/adblock/adblockmatcher.cpp b/src/network-web/adblock/adblockmatcher.cpp index a2bf42846..ff41b47f1 100755 --- a/src/network-web/adblock/adblockmatcher.cpp +++ b/src/network-web/adblock/adblockmatcher.cpp @@ -32,7 +32,7 @@ AdBlockMatcher::~AdBlockMatcher() { clear(); } -const AdBlockRule* AdBlockMatcher::match(const QWebEngineUrlRequestInfo &request, const QString &urlDomain, const QString &urlString) const { +const AdBlockRule *AdBlockMatcher::match(const QWebEngineUrlRequestInfo &request, const QString &urlDomain, const QString &urlString) const { // Exception rules. if (m_networkExceptionTree.find(request, urlDomain, urlString)) { return 0; @@ -41,7 +41,7 @@ const AdBlockRule* AdBlockMatcher::match(const QWebEngineUrlRequestInfo &request int count = m_networkExceptionRules.count(); for (int i = 0; i < count; ++i) { - const AdBlockRule* rule = m_networkExceptionRules.at(i); + const AdBlockRule *rule = m_networkExceptionRules.at(i); if (rule->networkMatch(request, urlDomain, urlString)) { return 0; @@ -56,7 +56,7 @@ const AdBlockRule* AdBlockMatcher::match(const QWebEngineUrlRequestInfo &request count = m_networkBlockRules.count(); for (int i = 0; i < count; ++i) { - const AdBlockRule* rule = m_networkBlockRules.at(i); + const AdBlockRule *rule = m_networkBlockRules.at(i); if (rule->networkMatch(request, urlDomain, urlString)) { return rule; @@ -104,7 +104,7 @@ QString AdBlockMatcher::elementHidingRulesForDomain(const QString &domain) const int count = m_domainRestrictedCssRules.count(); for (int i = 0; i < count; ++i) { - const AdBlockRule* rule = m_domainRestrictedCssRules.at(i); + const AdBlockRule *rule = m_domainRestrictedCssRules.at(i); if (!rule->matchDomain(domain)) { continue; @@ -135,8 +135,8 @@ void AdBlockMatcher::update() { QHash cssRulesHash; QVector exceptionCssRules; - foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) { - foreach (const AdBlockRule* rule, subscription->allRules()) { + foreach (AdBlockSubscription *subscription, m_manager->subscriptions()) { + foreach (const AdBlockRule *rule, subscription->allRules()) { // Don't add internally disabled rules to cache. if (rule->isInternalDisabled()) { continue; @@ -178,7 +178,7 @@ void AdBlockMatcher::update() { foreach (const AdBlockRule *rule, exceptionCssRules) { const AdBlockRule *originalRule = cssRulesHash.value(rule->cssSelector()); - // If we don't have this selector, the exception does nothing + // If we don't have this selector, the exception does nothing. if (!originalRule) { continue; } @@ -192,11 +192,11 @@ void AdBlockMatcher::update() { } // Apparently, excessive amount of selectors for one CSS rule is not what WebKit likes. - // (In my testings, 4931 is the number that makes it crash) - // So let's split it by 1000 selectors... + // (In my testings, 4931 is the number that makes it crash). + // So let's split it by 1000 selectors. int hidingRulesCount = 0; - QHashIterator it(cssRulesHash); + while (it.hasNext()) { it.next(); const AdBlockRule *rule = it.value(); diff --git a/src/network-web/adblock/adblockmatcher.h b/src/network-web/adblock/adblockmatcher.h index 5583f6a9b..28862b8f6 100755 --- a/src/network-web/adblock/adblockmatcher.h +++ b/src/network-web/adblock/adblockmatcher.h @@ -20,10 +20,12 @@ #define ADBLOCKMATCHER_H #include -#include #include "network-web/adblock/adblocksearchtree.h" +#include +#include + class QWebEngineUrlRequestInfo; class AdBlockManager; diff --git a/src/network-web/adblock/adblockrule.cpp b/src/network-web/adblock/adblockrule.cpp index 9d017375f..3b2f0e4f5 100755 --- a/src/network-web/adblock/adblockrule.cpp +++ b/src/network-web/adblock/adblockrule.cpp @@ -454,7 +454,7 @@ void AdBlockRule::parseFilter() { parsedLine = parsedLine.left(optionsIndex); } - . + // Rule is classic regexp. if (parsedLine.startsWith(QL1C('/')) && parsedLine.endsWith(QL1C('/'))) { parsedLine = parsedLine.mid(1); @@ -659,7 +659,7 @@ bool AdBlockRule::stringMatch(const QString &domain, const QString &encodedUrl) return false; } -bool AdBlockRule::matchDomain(const QString &pattern, const QString &domain) { +bool AdBlockRule::matchDomain(const QString &pattern, const QString &domain) const { if (pattern == domain) { return true; } diff --git a/src/network-web/adblock/adblocksubscription.cpp b/src/network-web/adblock/adblocksubscription.cpp index 5fce6d84e..ce9c995a7 100755 --- a/src/network-web/adblock/adblocksubscription.cpp +++ b/src/network-web/adblock/adblocksubscription.cpp @@ -50,11 +50,14 @@ #include "network-web/adblock/adblocksearchtree.h" #include "definitions/definitions.h" #include "network-web/silentnetworkaccessmanager.h" +#include "miscellaneous/iofactory.h" +#include "miscellaneous/application.h" #include #include #include #include +#include AdBlockSubscription::AdBlockSubscription(const QString &title, QObject* parent) @@ -97,7 +100,8 @@ void AdBlockSubscription::loadSubscription(const QStringList &disabledRules) { QTextStream textStream(&file); textStream.setCodec("UTF-8"); - // Header is on 3rd line + + // Header is on 3rd line. textStream.readLine(1024); textStream.readLine(1024); QString header = textStream.readLine(1024); @@ -184,7 +188,7 @@ bool AdBlockSubscription::saveDownloadedData(const QByteArray &data) { } const AdBlockRule *AdBlockSubscription::rule(int offset) const { - if (offset >= 0 && offset < m_rules.size()) { + if (IS_IN_ARRAY(offset, m_rules)) { return m_rules[offset]; } else { @@ -197,7 +201,7 @@ QVector AdBlockSubscription::allRules() const { } const AdBlockRule *AdBlockSubscription::enableRule(int offset) { - if (offset >= 0 && offset < m_rules.size()) { + if (IS_IN_ARRAY(offset, m_rules)) { AdBlockRule *rule = m_rules[offset]; rule->setEnabled(true); AdBlockManager::instance()->removeDisabledRule(rule->filter()); @@ -216,9 +220,8 @@ const AdBlockRule *AdBlockSubscription::enableRule(int offset) { } } -const AdBlockRule* AdBlockSubscription::disableRule(int offset) -{ - if (!QzTools::containsIndex(m_rules, offset)) { +const AdBlockRule *AdBlockSubscription::disableRule(int offset) { + if (!IS_IN_ARRAY(offset, m_rules)) { return 0; } @@ -228,66 +231,60 @@ const AdBlockRule* AdBlockSubscription::disableRule(int offset) emit subscriptionChanged(); - if (rule->isCssRule()) - mApp->reloadUserStyleSheet(); + if (rule->isCssRule()) { + // TODO: opravdu? + //mApp->reloadUserStyleSheet(); + } return rule; } -bool AdBlockSubscription::canEditRules() const -{ +bool AdBlockSubscription::canEditRules() const { return false; } -bool AdBlockSubscription::canBeRemoved() const -{ +bool AdBlockSubscription::canBeRemoved() const { return true; } -int AdBlockSubscription::addRule(AdBlockRule* rule) -{ +int AdBlockSubscription::addRule(AdBlockRule* rule) { Q_UNUSED(rule) return -1; } -bool AdBlockSubscription::removeRule(int offset) -{ +bool AdBlockSubscription::removeRule(int offset) { Q_UNUSED(offset) return false; } -const AdBlockRule* AdBlockSubscription::replaceRule(AdBlockRule* rule, int offset) -{ +const AdBlockRule *AdBlockSubscription::replaceRule(AdBlockRule *rule, int offset) { Q_UNUSED(rule) Q_UNUSED(offset) return 0; } -AdBlockSubscription::~AdBlockSubscription() -{ +AdBlockSubscription::~AdBlockSubscription() { qDeleteAll(m_rules); } // AdBlockCustomList -AdBlockCustomList::AdBlockCustomList(QObject* parent) - : AdBlockSubscription(tr("Custom Rules"), parent) -{ - setFilePath(DataPaths::currentProfilePath() + QLatin1String("/adblock/customlist.txt")); +AdBlockCustomList::AdBlockCustomList(QObject *parent) + : AdBlockSubscription(tr("Custom rules"), parent) { + setFilePath(AdBlockManager::instance()->storedListsPath() + QDir::separator() + ADBLOCK_CUSTOMLIST_NAME); } -void AdBlockCustomList::loadSubscription(const QStringList &disabledRules) -{ +void AdBlockCustomList::loadSubscription(const QStringList &disabledRules) { // DuckDuckGo ad whitelist rules // They cannot be removed, but can be disabled. // Please consider not disabling them. Thanks! const QString ddg1 = QSL("@@||duckduckgo.com^$document"); const QString ddg2 = QSL("duckduckgo.com#@#.has-ad"); - - const QString rules = QzTools::readAllFileContents(filePath()); + const QString rules = QString::fromUtf8(IOFactory::readTextFile(filePath())); QFile file(filePath()); + if (!file.exists()) { saveSubscription(); } @@ -302,46 +299,44 @@ void AdBlockCustomList::loadSubscription(const QStringList &disabledRules) if (!rules.contains(QL1S("\n") + ddg2)) stream << ddg2 << endl; } + file.close(); AdBlockSubscription::loadSubscription(disabledRules); } -void AdBlockCustomList::saveSubscription() -{ +void AdBlockCustomList::saveSubscription() { QFile file(filePath()); if (!file.open(QFile::ReadWrite | QFile::Truncate)) { - qWarning() << "AdBlockSubscription::" << __FUNCTION__ << "Unable to open adblock file for writing:" << filePath(); + qWarning("Unable to open AdBlock file '%s' for writing.", qPrintable(filePath())); return; } QTextStream textStream(&file); + textStream.setCodec("UTF-8"); textStream << "Title: " << title() << endl; textStream << "Url: " << url().toString() << endl; textStream << "[Adblock Plus 1.1.1]" << endl; - foreach (const AdBlockRule* rule, m_rules) { + foreach (const AdBlockRule *rule, m_rules) { textStream << rule->filter() << endl; } file.close(); } -bool AdBlockCustomList::canEditRules() const -{ +bool AdBlockCustomList::canEditRules() const { return true; } -bool AdBlockCustomList::canBeRemoved() const -{ +bool AdBlockCustomList::canBeRemoved() const { return false; } -bool AdBlockCustomList::containsFilter(const QString &filter) const -{ - foreach (const AdBlockRule* rule, m_rules) { +bool AdBlockCustomList::containsFilter(const QString &filter) const { + foreach (const AdBlockRule *rule, m_rules) { if (rule->filter() == filter) { return true; } @@ -350,10 +345,9 @@ bool AdBlockCustomList::containsFilter(const QString &filter) const return false; } -bool AdBlockCustomList::removeFilter(const QString &filter) -{ +bool AdBlockCustomList::removeFilter(const QString &filter) { for (int i = 0; i < m_rules.count(); ++i) { - const AdBlockRule* rule = m_rules.at(i); + const AdBlockRule *rule = m_rules.at(i); if (rule->filter() == filter) { return removeRule(i); @@ -363,33 +357,35 @@ bool AdBlockCustomList::removeFilter(const QString &filter) return false; } -int AdBlockCustomList::addRule(AdBlockRule* rule) -{ +int AdBlockCustomList::addRule(AdBlockRule* rule) { m_rules.append(rule); emit subscriptionChanged(); - if (rule->isCssRule()) - mApp->reloadUserStyleSheet(); + if (rule->isCssRule()) { + // TODO: opravdu + //mApp->reloadUserStyleSheet(); + } return m_rules.count() - 1; } -bool AdBlockCustomList::removeRule(int offset) -{ - if (!QzTools::containsIndex(m_rules, offset)) { +bool AdBlockCustomList::removeRule(int offset) { + if (!IS_IN_ARRAY(offset, m_rules)) { return false; } - AdBlockRule* rule = m_rules.at(offset); + AdBlockRule *rule = m_rules.at(offset); const QString filter = rule->filter(); m_rules.remove(offset); emit subscriptionChanged(); - if (rule->isCssRule()) - mApp->reloadUserStyleSheet(); + if (rule->isCssRule()) { + // TODO: opravdu + //mApp->reloadUserStyleSheet(); + } AdBlockManager::instance()->removeDisabledRule(filter); @@ -397,19 +393,20 @@ bool AdBlockCustomList::removeRule(int offset) return true; } -const AdBlockRule* AdBlockCustomList::replaceRule(AdBlockRule* rule, int offset) -{ - if (!QzTools::containsIndex(m_rules, offset)) { +const AdBlockRule *AdBlockCustomList::replaceRule(AdBlockRule *rule, int offset) { + if (!IS_IN_ARRAY(offset, m_rules)) { return 0; } - AdBlockRule* oldRule = m_rules.at(offset); + AdBlockRule *oldRule = m_rules.at(offset); m_rules[offset] = rule; emit subscriptionChanged(); - if (rule->isCssRule() || oldRule->isCssRule()) - mApp->reloadUserStyleSheet(); + if (rule->isCssRule() || oldRule->isCssRule()) { + // TODO: opravdu + //mApp->reloadUserStyleSheet(); + } delete oldRule; return m_rules[offset]; diff --git a/src/network-web/adblock/adblocksubscription.h b/src/network-web/adblock/adblocksubscription.h index 75723a084..07fd296d5 100755 --- a/src/network-web/adblock/adblocksubscription.h +++ b/src/network-web/adblock/adblocksubscription.h @@ -86,7 +86,7 @@ class AdBlockSubscription : public QObject { virtual int addRule(AdBlockRule* rule); virtual bool removeRule(int offset); - virtual const AdBlockRule* replaceRule(AdBlockRule* rule, int offset); + virtual const AdBlockRule *replaceRule(AdBlockRule *rule, int offset); public slots: void updateSubscription(); diff --git a/src/network-web/adblock/adblocktreewidget.cpp b/src/network-web/adblock/adblocktreewidget.cpp index 61c6a97e5..db2970b37 100755 --- a/src/network-web/adblock/adblocktreewidget.cpp +++ b/src/network-web/adblock/adblocktreewidget.cpp @@ -16,8 +16,9 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "adblocktreewidget.h" -#include "adblocksubscription.h" +#include "network-web/adblock/adblocktreewidget.h" + +#include "network-web/adblock/adblocksubscription.h" #include #include @@ -25,243 +26,233 @@ #include #include -AdBlockTreeWidget::AdBlockTreeWidget(AdBlockSubscription* subscription, QWidget* parent) - : TreeWidget(parent) - , m_subscription(subscription) - , m_topItem(0) - , m_itemChangingBlock(false) -{ - setContextMenuPolicy(Qt::CustomContextMenu); - setDefaultItemShowMode(TreeWidget::ItemsExpanded); - setHeaderHidden(true); - setAlternatingRowColors(true); - setLayoutDirection(Qt::LeftToRight); - connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); - connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*))); - connect(m_subscription, SIGNAL(subscriptionUpdated()), this, SLOT(subscriptionUpdated())); - connect(m_subscription, SIGNAL(subscriptionError(QString)), this, SLOT(subscriptionError(QString))); +AdBlockTreeWidget::AdBlockTreeWidget(AdBlockSubscription *subscription, QWidget *parent) + : TreeWidget(parent), m_subscription(subscription), m_topItem(0), m_itemChangingBlock(false) { + setContextMenuPolicy(Qt::CustomContextMenu); + setDefaultItemShowMode(TreeWidget::ItemsExpanded); + setHeaderHidden(true); + setAlternatingRowColors(true); + setLayoutDirection(Qt::LeftToRight); + + connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); + connect(this, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*))); + connect(m_subscription, SIGNAL(subscriptionUpdated()), this, SLOT(subscriptionUpdated())); + connect(m_subscription, SIGNAL(subscriptionError(QString)), this, SLOT(subscriptionError(QString))); } -AdBlockSubscription* AdBlockTreeWidget::subscription() const -{ - return m_subscription; +AdBlockSubscription *AdBlockTreeWidget::subscription() const { + return m_subscription; } -void AdBlockTreeWidget::showRule(const AdBlockRule* rule) -{ - if (!m_topItem && rule) { - m_ruleToBeSelected = rule->filter(); - } - else if (!m_ruleToBeSelected.isEmpty()) { - QList items = findItems(m_ruleToBeSelected, Qt::MatchRecursive); - if (!items.isEmpty()) { - QTreeWidgetItem* item = items.at(0); +void AdBlockTreeWidget::showRule(const AdBlockRule *rule) { + if (!m_topItem && rule) { + m_ruleToBeSelected = rule->filter(); + } + else if (!m_ruleToBeSelected.isEmpty()) { + QList items = findItems(m_ruleToBeSelected, Qt::MatchRecursive); - setCurrentItem(item); - scrollToItem(item, QAbstractItemView::PositionAtCenter); - } + if (!items.isEmpty()) { + QTreeWidgetItem *item = items.at(0); - m_ruleToBeSelected.clear(); + setCurrentItem(item); + scrollToItem(item, QAbstractItemView::PositionAtCenter); } + + m_ruleToBeSelected.clear(); + } } -void AdBlockTreeWidget::contextMenuRequested(const QPoint &pos) -{ - if (!m_subscription->canEditRules()) { - return; - } +void AdBlockTreeWidget::contextMenuRequested(const QPoint &pos) { + if (!m_subscription->canEditRules()) { + return; + } - QTreeWidgetItem* item = itemAt(pos); - if (!item) { - return; - } + QTreeWidgetItem *item = itemAt(pos); - QMenu menu; - menu.addAction(tr("Add Rule"), this, SLOT(addRule())); - menu.addSeparator(); - QAction* deleteAction = menu.addAction(tr("Remove Rule"), this, SLOT(removeRule())); + if (!item) { + return; + } - if (!item->parent()) { - deleteAction->setDisabled(true); - } + QMenu menu; + menu.addAction(tr("Add rule"), this, SLOT(addRule())); + menu.addSeparator(); + QAction* deleteAction = menu.addAction(tr("Remove rule"), this, SLOT(removeRule())); - menu.exec(viewport()->mapToGlobal(pos)); + if (!item->parent()) { + deleteAction->setDisabled(true); + } + + menu.exec(viewport()->mapToGlobal(pos)); } -void AdBlockTreeWidget::itemChanged(QTreeWidgetItem* item) -{ - if (!item || m_itemChangingBlock) { - return; - } +void AdBlockTreeWidget::itemChanged(QTreeWidgetItem *item) { + if (!item || m_itemChangingBlock) { + return; + } - m_itemChangingBlock = true; + m_itemChangingBlock = true; - int offset = item->data(0, Qt::UserRole + 10).toInt(); - const AdBlockRule* oldRule = m_subscription->rule(offset); + int offset = item->data(0, Qt::UserRole + 10).toInt(); + const AdBlockRule *oldRule = m_subscription->rule(offset); - if (item->checkState(0) == Qt::Unchecked && oldRule->isEnabled()) { - // Disable rule - const AdBlockRule* rule = m_subscription->disableRule(offset); - - adjustItemFeatures(item, rule); - } - else if (item->checkState(0) == Qt::Checked && !oldRule->isEnabled()) { - // Enable rule - const AdBlockRule* rule = m_subscription->enableRule(offset); - - adjustItemFeatures(item, rule); - } - else if (m_subscription->canEditRules()) { - // Custom rule has been changed - AdBlockRule* newRule = new AdBlockRule(item->text(0), m_subscription); - const AdBlockRule* rule = m_subscription->replaceRule(newRule, offset); - - adjustItemFeatures(item, rule); - } - - m_itemChangingBlock = false; -} - -void AdBlockTreeWidget::copyFilter() -{ - QTreeWidgetItem* item = currentItem(); - if (!item) { - return; - } - - QApplication::clipboard()->setText(item->text(0)); -} - -void AdBlockTreeWidget::addRule() -{ - if (!m_subscription->canEditRules()) { - return; - } - - QString newRule = QInputDialog::getText(this, tr("Add Custom Rule"), tr("Please write your rule here:")); - if (newRule.isEmpty()) { - return; - } - - AdBlockRule* rule = new AdBlockRule(newRule, m_subscription); - int offset = m_subscription->addRule(rule); - - QTreeWidgetItem* item = new QTreeWidgetItem(); - item->setText(0, newRule); - item->setData(0, Qt::UserRole + 10, offset); - item->setFlags(item->flags() | Qt::ItemIsEditable); - - m_itemChangingBlock = true; - m_topItem->addChild(item); - m_itemChangingBlock = false; + if (item->checkState(0) == Qt::Unchecked && oldRule->isEnabled()) { + // Disable rule. + const AdBlockRule *rule = m_subscription->disableRule(offset); adjustItemFeatures(item, rule); + } + else if (item->checkState(0) == Qt::Checked && !oldRule->isEnabled()) { + // Enable rule. + const AdBlockRule *rule = m_subscription->enableRule(offset); + + adjustItemFeatures(item, rule); + } + else if (m_subscription->canEditRules()) { + // Custom rule has been changed. + AdBlockRule *newRule = new AdBlockRule(item->text(0), m_subscription); + const AdBlockRule *rule = m_subscription->replaceRule(newRule, offset); + + adjustItemFeatures(item, rule); + } + + m_itemChangingBlock = false; } -void AdBlockTreeWidget::removeRule() -{ - QTreeWidgetItem* item = currentItem(); - if (!item || !m_subscription->canEditRules() || item == m_topItem) { - return; - } +void AdBlockTreeWidget::copyFilter() { + QTreeWidgetItem *item = currentItem(); - int offset = item->data(0, Qt::UserRole + 10).toInt(); + if (!item) { + return; + } - m_subscription->removeRule(offset); - deleteItem(item); + QApplication::clipboard()->setText(item->text(0)); } -void AdBlockTreeWidget::subscriptionUpdated() -{ - refresh(); +void AdBlockTreeWidget::addRule() { + if (!m_subscription->canEditRules()) { + return; + } - m_itemChangingBlock = true; - m_topItem->setText(0, tr("%1 (recently updated)").arg(m_subscription->title())); - m_itemChangingBlock = false; + QString newRule = QInputDialog::getText(this, tr("Add custom rule"), tr("Please write your rule here:")); + + if (newRule.isEmpty()) { + return; + } + + AdBlockRule *rule = new AdBlockRule(newRule, m_subscription); + int offset = m_subscription->addRule(rule); + + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setText(0, newRule); + item->setData(0, Qt::UserRole + 10, offset); + item->setFlags(item->flags() | Qt::ItemIsEditable); + + m_itemChangingBlock = true; + m_topItem->addChild(item); + m_itemChangingBlock = false; + + adjustItemFeatures(item, rule); } -void AdBlockTreeWidget::subscriptionError(const QString &message) -{ - refresh(); +void AdBlockTreeWidget::removeRule() { + QTreeWidgetItem *item = currentItem(); - m_itemChangingBlock = true; - m_topItem->setText(0, tr("%1 (Error: %2)").arg(m_subscription->title(), message)); - m_itemChangingBlock = false; + if (!item || !m_subscription->canEditRules() || item == m_topItem) { + return; + } + + int offset = item->data(0, Qt::UserRole + 10).toInt(); + + m_subscription->removeRule(offset); + deleteItem(item); } -void AdBlockTreeWidget::adjustItemFeatures(QTreeWidgetItem* item, const AdBlockRule* rule) -{ - if (!rule->isEnabled()) { - QFont font; - font.setItalic(true); - item->setForeground(0, QColor(Qt::gray)); +void AdBlockTreeWidget::subscriptionUpdated() { + refresh(); - if (!rule->isComment()) { - item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState(0, Qt::Unchecked); - item->setFont(0, font); - } - - return; - } - - item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState(0, Qt::Checked); - - if (rule->isException()) { - item->setForeground(0, QColor(Qt::darkGreen)); - item->setFont(0, QFont()); - } - else if (rule->isCssRule()) { - item->setForeground(0, QColor(Qt::darkBlue)); - item->setFont(0, QFont()); - } + m_itemChangingBlock = true; + m_topItem->setText(0, tr("%1 (recently updated)").arg(m_subscription->title())); + m_itemChangingBlock = false; } -void AdBlockTreeWidget::keyPressEvent(QKeyEvent* event) -{ - if (event->key() == Qt::Key_C && event->modifiers() & Qt::ControlModifier) { - copyFilter(); - } +void AdBlockTreeWidget::subscriptionError(const QString &message) { + refresh(); - if (event->key() == Qt::Key_Delete) { - removeRule(); - } - - TreeWidget::keyPressEvent(event); + m_itemChangingBlock = true; + m_topItem->setText(0, tr("%1 (Error: %2)").arg(m_subscription->title(), message)); + m_itemChangingBlock = false; } -void AdBlockTreeWidget::refresh() -{ - m_itemChangingBlock = true; - clear(); +void AdBlockTreeWidget::adjustItemFeatures(QTreeWidgetItem* item, const AdBlockRule* rule) { + if (!rule->isEnabled()) { + QFont font; + font.setItalic(true); + item->setForeground(0, QColor(Qt::gray)); - QFont boldFont; - boldFont.setBold(true); - - m_topItem = new QTreeWidgetItem(this); - m_topItem->setText(0, m_subscription->title()); - m_topItem->setFont(0, boldFont); - m_topItem->setExpanded(true); - addTopLevelItem(m_topItem); - - const QVector &allRules = m_subscription->allRules(); - - int index = 0; - foreach (const AdBlockRule* rule, allRules) { - QTreeWidgetItem* item = new QTreeWidgetItem(m_topItem); - item->setText(0, rule->filter()); - item->setData(0, Qt::UserRole + 10, index); - - if (m_subscription->canEditRules()) { - item->setFlags(item->flags() | Qt::ItemIsEditable); - } - - adjustItemFeatures(item, rule); - ++index; + if (!rule->isComment()) { + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + item->setCheckState(0, Qt::Unchecked); + item->setFont(0, font); } - showRule(0); - m_itemChangingBlock = false; + return; + } + + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + item->setCheckState(0, Qt::Checked); + + if (rule->isException()) { + item->setForeground(0, QColor(Qt::darkGreen)); + item->setFont(0, QFont()); + } + else if (rule->isCssRule()) { + item->setForeground(0, QColor(Qt::darkBlue)); + item->setFont(0, QFont()); + } +} + +void AdBlockTreeWidget::keyPressEvent(QKeyEvent* event) { + if (event->key() == Qt::Key_C && event->modifiers() & Qt::ControlModifier) { + copyFilter(); + } + + if (event->key() == Qt::Key_Delete) { + removeRule(); + } + + TreeWidget::keyPressEvent(event); +} + +void AdBlockTreeWidget::refresh() { + m_itemChangingBlock = true; + clear(); + + QFont boldFont; + boldFont.setBold(true); + + m_topItem = new QTreeWidgetItem(this); + m_topItem->setText(0, m_subscription->title()); + m_topItem->setFont(0, boldFont); + m_topItem->setExpanded(true); + addTopLevelItem(m_topItem); + + const QVector &allRules = m_subscription->allRules(); + + int index = 0; + foreach (const AdBlockRule *rule, allRules) { + QTreeWidgetItem *item = new QTreeWidgetItem(m_topItem); + item->setText(0, rule->filter()); + item->setData(0, Qt::UserRole + 10, index); + + if (m_subscription->canEditRules()) { + item->setFlags(item->flags() | Qt::ItemIsEditable); + } + + adjustItemFeatures(item, rule); + ++index; + } + + showRule(0); + m_itemChangingBlock = false; } diff --git a/src/network-web/adblock/adblocktreewidget.h b/src/network-web/adblock/adblocktreewidget.h index 6c10e4b6c..3407345f0 100755 --- a/src/network-web/adblock/adblocktreewidget.h +++ b/src/network-web/adblock/adblocktreewidget.h @@ -19,41 +19,41 @@ #ifndef ADBLOCKTREEWIDGET_H #define ADBLOCKTREEWIDGET_H -#include +#include "gui/treewidget.h" class AdBlockSubscription; class AdBlockRule; -class AdBlockTreeWidget : public QTreeWidget -{ +class AdBlockTreeWidget : public TreeWidget { Q_OBJECT -public: - explicit AdBlockTreeWidget(AdBlockSubscription* subscription, QWidget* parent = 0); - AdBlockSubscription* subscription() const; + public: + explicit AdBlockTreeWidget(AdBlockSubscription *subscription, QWidget *parent = 0); - void showRule(const AdBlockRule* rule); + AdBlockSubscription *subscription() const; + + void showRule(const AdBlockRule *rule); void refresh(); -public slots: + public slots: void addRule(); void removeRule(); -private slots: + private slots: void contextMenuRequested(const QPoint &pos); - void itemChanged(QTreeWidgetItem* item); + void itemChanged(QTreeWidgetItem *item); void copyFilter(); void subscriptionUpdated(); void subscriptionError(const QString &message); -private: - void adjustItemFeatures(QTreeWidgetItem* item, const AdBlockRule* rule); + private: + void adjustItemFeatures(QTreeWidgetItem *item, const AdBlockRule *rule); void keyPressEvent(QKeyEvent* event); - AdBlockSubscription* m_subscription; - QTreeWidgetItem* m_topItem; + AdBlockSubscription *m_subscription; + QTreeWidgetItem *m_topItem; QString m_ruleToBeSelected; bool m_itemChangingBlock; diff --git a/src/network-web/adblock/adblockurlinterceptor.cpp b/src/network-web/adblock/adblockurlinterceptor.cpp index cc2812aba..63d07c705 100755 --- a/src/network-web/adblock/adblockurlinterceptor.cpp +++ b/src/network-web/adblock/adblockurlinterceptor.cpp @@ -16,17 +16,17 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "adblockurlinterceptor.h" -#include "adblockmanager.h" +#include "network-web/adblock/adblockurlinterceptor.h" + +#include "network-web/adblock/adblockmanager.h" + AdBlockUrlInterceptor::AdBlockUrlInterceptor(AdBlockManager *manager) - : UrlInterceptor(manager) - , m_manager(manager) -{ + : UrlInterceptor(manager), m_manager(manager) { } -void AdBlockUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) -{ - if (m_manager->block(info)) - info.block(true); +void AdBlockUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { + if (m_manager->block(info)) { + info.block(true); + } } diff --git a/src/network-web/adblock/adblockurlinterceptor.h b/src/network-web/adblock/adblockurlinterceptor.h index 2646f6746..76e627572 100755 --- a/src/network-web/adblock/adblockurlinterceptor.h +++ b/src/network-web/adblock/adblockurlinterceptor.h @@ -19,19 +19,20 @@ #ifndef ADBLOCKURLINTERCEPTOR_H #define ADBLOCKURLINTERCEPTOR_H -#include "urlinterceptor.h" -#include "qzcommon.h" +#include "network-web/urlinterceptor.h" + class AdBlockManager; -class QUPZILLA_EXPORT AdBlockUrlInterceptor : public UrlInterceptor -{ -public: - explicit AdBlockUrlInterceptor(AdBlockManager* manager); +class AdBlockUrlInterceptor : public UrlInterceptor { + Q_OBJECT + + public: + explicit AdBlockUrlInterceptor(AdBlockManager *manager); void interceptRequest(QWebEngineUrlRequestInfo &info); -private: + private: AdBlockManager *m_manager; }; diff --git a/src/network-web/networkurlinterceptor.cpp b/src/network-web/networkurlinterceptor.cpp index 9b6d8e29e..27b0344ac 100755 --- a/src/network-web/networkurlinterceptor.cpp +++ b/src/network-web/networkurlinterceptor.cpp @@ -16,45 +16,41 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "networkurlinterceptor.h" -#include "urlinterceptor.h" -#include "settings.h" -#include "mainapplication.h" -#include "useragentmanager.h" +#include "network-web/networkurlinterceptor.h" + +#include "network-web/urlinterceptor.h" +#include "miscellaneous/application.h" +#include "miscellaneous/settings.h" + NetworkUrlInterceptor::NetworkUrlInterceptor(QObject *parent) - : QWebEngineUrlRequestInterceptor(parent) - , m_sendDNT(false) -{ + : QWebEngineUrlRequestInterceptor(parent), m_sendDNT(false) { } -void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) -{ - if (m_sendDNT) - info.setHttpHeader(QByteArrayLiteral("DNT"), QByteArrayLiteral("1")); +void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { + if (m_sendDNT) { + info.setHttpHeader(QByteArrayLiteral("DNT"), QByteArrayLiteral("1")); + } - info.setHttpHeader(QByteArrayLiteral("User-Agent"), mApp->userAgentManager()->userAgentForUrl(info.firstPartyUrl()).toUtf8()); + // TODO: mužeme zde nastavovat custom věci pro každej webengine sitovej pozadavek + // treba user agenta + //info.setHttpHeader(QByteArrayLiteral("User-Agent"), mApp->userAgentManager()->userAgentForUrl(info.firstPartyUrl()).toUtf8()); - foreach (UrlInterceptor *interceptor, m_interceptors) { - interceptor->interceptRequest(info); - } + foreach (UrlInterceptor *interceptor, m_interceptors) { + interceptor->interceptRequest(info); + } } -void NetworkUrlInterceptor::installUrlInterceptor(UrlInterceptor *interceptor) -{ - if (!m_interceptors.contains(interceptor)) - m_interceptors.append(interceptor); +void NetworkUrlInterceptor::installUrlInterceptor(UrlInterceptor *interceptor) { + if (!m_interceptors.contains(interceptor)) { + m_interceptors.append(interceptor); + } } -void NetworkUrlInterceptor::removeUrlInterceptor(UrlInterceptor *interceptor) -{ - m_interceptors.removeOne(interceptor); +void NetworkUrlInterceptor::removeUrlInterceptor(UrlInterceptor *interceptor) { + m_interceptors.removeOne(interceptor); } -void NetworkUrlInterceptor::loadSettings() -{ - Settings settings; - settings.beginGroup("Web-Browser-Settings"); - m_sendDNT = settings.value("DoNotTrack", false).toBool(); - settings.endGroup(); +void NetworkUrlInterceptor::loadSettings() { + m_sendDNT = qApp->settings()->value(GROUP(Browser), SETTING(Browser::SendDNT)).toBool(); } diff --git a/src/network-web/networkurlinterceptor.h b/src/network-web/networkurlinterceptor.h index 85441c8dd..2ab533577 100755 --- a/src/network-web/networkurlinterceptor.h +++ b/src/network-web/networkurlinterceptor.h @@ -21,14 +21,14 @@ #include -#include "qzcommon.h" class UrlInterceptor; -class QUPZILLA_EXPORT NetworkUrlInterceptor : public QWebEngineUrlRequestInterceptor -{ -public: - explicit NetworkUrlInterceptor(QObject* parent = Q_NULLPTR); +class NetworkUrlInterceptor : public QWebEngineUrlRequestInterceptor { + Q_OBJECT + + public: + explicit NetworkUrlInterceptor(QObject *parent = nullptr); void interceptRequest(QWebEngineUrlRequestInfo &info) Q_DECL_OVERRIDE; @@ -37,7 +37,7 @@ public: void loadSettings(); -private: + private: QList m_interceptors; bool m_sendDNT; }; diff --git a/src/network-web/urlinterceptor.h b/src/network-web/urlinterceptor.h index da0242595..50ba1435c 100755 --- a/src/network-web/urlinterceptor.h +++ b/src/network-web/urlinterceptor.h @@ -23,9 +23,11 @@ #include #include -class UrlInterceptor : public QObject -{ -public: + +class UrlInterceptor : public QObject { + Q_OBJECT + + public: explicit UrlInterceptor(QObject *parent = Q_NULLPTR) : QObject(parent) { } virtual void interceptRequest(QWebEngineUrlRequestInfo &info) = 0; };