Save work.
This commit is contained in:
		
							parent
							
								
									dcfa6fd97e
								
							
						
					
					
						commit
						570bc03c37
					
				
					 3 changed files with 156 additions and 114 deletions
				
			
		|  | @ -59,6 +59,10 @@ Application::Application(const QString &id, int &argc, char **argv) | ||||||
|   connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested, this, &Application::downloadRequested); |   connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested, this, &Application::downloadRequested); | ||||||
| 
 | 
 | ||||||
|   QWebEngineProfile::defaultProfile()->setRequestInterceptor(m_urlInterceptor); |   QWebEngineProfile::defaultProfile()->setRequestInterceptor(m_urlInterceptor); | ||||||
|  | 
 | ||||||
|  |   // TODO: Teď tam žádný nastavení není, ale jestli se DNT třeba
 | ||||||
|  |   // přidá do dialogu nastavení, tak toto volat při ukládání nastavení.
 | ||||||
|  |   m_urlInterceptor->loadSettings(); | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -17,43 +17,46 @@ | ||||||
| // along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
 | // along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
 | ||||||
| 
 | 
 | ||||||
| #include "network-web/adblock/adblockmanager.h" | #include "network-web/adblock/adblockmanager.h" | ||||||
| #include "network-web/adblock/adblockdialog.h" |  | ||||||
| #include "network-web/adblock/adblockmatcher.h" |  | ||||||
| #include "network-web/adblock/adblocksubscription.h" |  | ||||||
| #include "network-web/adblock/adblockurlinterceptor.h" |  | ||||||
| 
 | 
 | ||||||
| #include "miscellaneous/application.h" | #include "miscellaneous/application.h" | ||||||
| #include "miscellaneous/settings.h" | #include "miscellaneous/settings.h" | ||||||
|  | #include "network-web/adblock/adblockdialog.h" | ||||||
|  | #include "network-web/adblock/adblockmatcher.h" | ||||||
|  | 
 | ||||||
|  | #include "network-web/adblock/adblocksubscription.h" | ||||||
|  | #include "network-web/adblock/adblockurlinterceptor.h" | ||||||
| #include "network-web/networkurlinterceptor.h" | #include "network-web/networkurlinterceptor.h" | ||||||
| 
 | 
 | ||||||
| #include <QDateTime> | #include <QDateTime> | ||||||
| #include <QTextStream> |  | ||||||
| #include <QDir> | #include <QDir> | ||||||
| #include <QTimer> |  | ||||||
| #include <QMessageBox> | #include <QMessageBox> | ||||||
| #include <QUrlQuery> |  | ||||||
| #include <QMutexLocker> | #include <QMutexLocker> | ||||||
| #include <QSaveFile> | #include <QSaveFile> | ||||||
| #include <QWebEngineUrlRequestInfo> | #include <QTextStream> | ||||||
|  | #include <QTimer> | ||||||
|  | #include <QUrlQuery> | ||||||
| #include <QWebEngineProfile> | #include <QWebEngineProfile> | ||||||
|  | #include <QWebEngineUrlRequestInfo> | ||||||
| 
 | 
 | ||||||
| Q_GLOBAL_STATIC(AdBlockManager, qz_adblock_manager) | Q_GLOBAL_STATIC(AdBlockManager, qz_adblock_manager) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| AdBlockManager::AdBlockManager(QObject* parent) | AdBlockManager::AdBlockManager(QObject* parent) | ||||||
|   : QObject(parent), m_loaded(false), m_enabled(true), m_matcher(new AdBlockMatcher(this)), m_interceptor(new AdBlockUrlInterceptor(this)) { |   : QObject(parent) | ||||||
|  |   , m_loaded(false) | ||||||
|  |   , m_enabled(true) | ||||||
|  |   , m_matcher(new AdBlockMatcher(this)) | ||||||
|  |   , m_interceptor(new AdBlockUrlInterceptor(this)) | ||||||
|  | { | ||||||
|   load(); |   load(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| AdBlockManager::~AdBlockManager() { | AdBlockManager::~AdBlockManager() { qDeleteAll(m_subscriptions); } | ||||||
|   qDeleteAll(m_subscriptions); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| AdBlockManager *AdBlockManager::instance() { | AdBlockManager* AdBlockManager::instance() { return qz_adblock_manager(); } | ||||||
|   return qz_adblock_manager(); |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| void AdBlockManager::setEnabled(bool enabled) { | void AdBlockManager::setEnabled(bool enabled) | ||||||
|  | { | ||||||
|   if (m_enabled == enabled) { |   if (m_enabled == enabled) { | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  | @ -61,7 +64,8 @@ void AdBlockManager::setEnabled(bool enabled) { | ||||||
|   m_enabled = enabled; |   m_enabled = enabled; | ||||||
|   emit enabledChanged(enabled); |   emit enabledChanged(enabled); | ||||||
| 
 | 
 | ||||||
|   qApp->settings()->setValue(GROUP(AdBlock), AdBlock::AdBlockEnabled, m_enabled); |   qApp->settings()->setValue(GROUP(AdBlock), AdBlock::AdBlockEnabled, | ||||||
|  |                              m_enabled); | ||||||
|   load(); |   load(); | ||||||
|   // TODO: Reload user stylesheet.
 |   // TODO: Reload user stylesheet.
 | ||||||
|   // mApp->reloadUserStyleSheet();
 |   // mApp->reloadUserStyleSheet();
 | ||||||
|  | @ -70,17 +74,18 @@ void AdBlockManager::setEnabled(bool enabled) { | ||||||
| 
 | 
 | ||||||
|   if (m_enabled) { |   if (m_enabled) { | ||||||
|     m_matcher->update(); |     m_matcher->update(); | ||||||
|   } |   } else { | ||||||
|   else { |  | ||||||
|     m_matcher->clear(); |     m_matcher->clear(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QList<AdBlockSubscription*> AdBlockManager::subscriptions() const { | QList<AdBlockSubscription*> AdBlockManager::subscriptions() const | ||||||
|  | { | ||||||
|   return m_subscriptions; |   return m_subscriptions; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool AdBlockManager::block(QWebEngineUrlRequestInfo &request) { | bool AdBlockManager::block(QWebEngineUrlRequestInfo& request) | ||||||
|  | { | ||||||
|   QMutexLocker locker(&m_mutex); |   QMutexLocker locker(&m_mutex); | ||||||
| 
 | 
 | ||||||
|   if (!isEnabled()) { |   if (!isEnabled()) { | ||||||
|  | @ -102,7 +107,8 @@ bool AdBlockManager::block(QWebEngineUrlRequestInfo &request) { | ||||||
|     res = true; |     res = true; | ||||||
| 
 | 
 | ||||||
|     if (request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) { |     if (request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) { | ||||||
|       // We are blocking main URL frame, we can display "AdBlock error page" or redirect to somewhere.
 |       // We are blocking main URL frame, we can display "AdBlock error page" or
 | ||||||
|  |       // redirect to somewhere.
 | ||||||
|       // TODO: dodělat lepší
 |       // TODO: dodělat lepší
 | ||||||
|       QMessageBox::warning(nullptr, "blocked website", "blocket"); |       QMessageBox::warning(nullptr, "blocked website", "blocket"); | ||||||
| 
 | 
 | ||||||
|  | @ -110,32 +116,33 @@ bool AdBlockManager::block(QWebEngineUrlRequestInfo &request) { | ||||||
|       // QUrl url(QSL("rssguard:adblock"));
 |       // QUrl url(QSL("rssguard:adblock"));
 | ||||||
|       // QUrlQuery query;
 |       // QUrlQuery query;
 | ||||||
|       // query.addQueryItem(QSL("rule"), blockedRule->filter());
 |       // query.addQueryItem(QSL("rule"), blockedRule->filter());
 | ||||||
|       //query.addQueryItem(QSL("subscription"), blockedRule->subscription()->title());
 |       // query.addQueryItem(QSL("subscription"),
 | ||||||
|  |       // blockedRule->subscription()->title());
 | ||||||
|       // url.setQuery(query);
 |       // url.setQuery(query);
 | ||||||
|       // request.redirect(url);
 |       // request.redirect(url);
 | ||||||
| 
 | 
 | ||||||
|       request.block(true); |       request.block(true); | ||||||
|     } |     } else { | ||||||
|     else { |  | ||||||
|       request.block(true); |       request.block(true); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   return res; |   return res; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QStringList AdBlockManager::disabledRules() const { | QStringList AdBlockManager::disabledRules() const { return m_disabledRules; } | ||||||
|   return m_disabledRules; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| void AdBlockManager::addDisabledRule(const QString &filter) { | void AdBlockManager::addDisabledRule(const QString& filter) | ||||||
|  | { | ||||||
|   m_disabledRules.append(filter); |   m_disabledRules.append(filter); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AdBlockManager::removeDisabledRule(const QString &filter) { | void AdBlockManager::removeDisabledRule(const QString& filter) | ||||||
|  | { | ||||||
|   m_disabledRules.removeOne(filter); |   m_disabledRules.removeOne(filter); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool AdBlockManager::addSubscriptionFromUrl(const QUrl &url) { | bool AdBlockManager::addSubscriptionFromUrl(const QUrl& url) | ||||||
|  | { | ||||||
|   const QList<QPair<QString, QString>> queryItems = QUrlQuery(url).queryItems(QUrl::FullyDecoded); |   const QList<QPair<QString, QString>> queryItems = QUrlQuery(url).queryItems(QUrl::FullyDecoded); | ||||||
| 
 | 
 | ||||||
|   QString subscriptionTitle; |   QString subscriptionTitle; | ||||||
|  | @ -146,8 +153,7 @@ bool AdBlockManager::addSubscriptionFromUrl(const QUrl &url) { | ||||||
| 
 | 
 | ||||||
|     if (pair.first == QL1S("location")) { |     if (pair.first == QL1S("location")) { | ||||||
|       subscriptionUrl = pair.second; |       subscriptionUrl = pair.second; | ||||||
|     } |     } else if (pair.first == QL1S("title")) { | ||||||
|     else if (pair.first == QL1S("title")) { |  | ||||||
|       subscriptionTitle = pair.second; |       subscriptionTitle = pair.second; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | @ -158,28 +164,36 @@ bool AdBlockManager::addSubscriptionFromUrl(const QUrl &url) { | ||||||
| 
 | 
 | ||||||
|   const QString message = tr("Do you want to add <b>%1</b> subscription?").arg(subscriptionTitle); |   const QString message = tr("Do you want to add <b>%1</b> subscription?").arg(subscriptionTitle); | ||||||
| 
 | 
 | ||||||
|   QMessageBox::StandardButton result = QMessageBox::question(nullptr, tr("Add AdBlock subscription"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); |   QMessageBox::StandardButton result = QMessageBox::question( | ||||||
|  |                                          nullptr, tr("Add AdBlock subscription"), message, | ||||||
|  |                                          QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); | ||||||
| 
 | 
 | ||||||
|   if (result == QMessageBox::Yes) { |   if (result == QMessageBox::Yes) { | ||||||
|     AdBlockManager::instance()->addSubscription(subscriptionTitle, subscriptionUrl); |     AdBlockManager::instance()->addSubscription(subscriptionTitle, | ||||||
|  |                                                 subscriptionUrl); | ||||||
|     AdBlockManager::instance()->showDialog(); |     AdBlockManager::instance()->showDialog(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return true; |   return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| AdBlockSubscription *AdBlockManager::addSubscription(const QString &title, const QString &url) { | AdBlockSubscription* AdBlockManager::addSubscription(const QString& title, | ||||||
|  |                                                      const QString& url) | ||||||
|  | { | ||||||
|   if (title.isEmpty() || url.isEmpty()) { |   if (title.isEmpty() || url.isEmpty()) { | ||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   QString fileName = title + QSL(".txt"); |   QString fileName = title + QSL(".txt"); | ||||||
|   QString filePath = storedListsPath() + QDir::separator() + fileName; |   QString filePath = storedListsPath() + QDir::separator() + fileName; | ||||||
|   QByteArray data = QString("Title: %1\nUrl: %2\n[Adblock Plus 1.1.1]").arg(title, url).toLatin1(); |   QByteArray data = QString("Title: %1\nUrl: %2\n[Adblock Plus 1.1.1]") | ||||||
|  |                     .arg(title, url) | ||||||
|  |                     .toLatin1(); | ||||||
| 
 | 
 | ||||||
|   QSaveFile file(filePath); |   QSaveFile file(filePath); | ||||||
|   if (!file.open(QFile::WriteOnly)) { |   if (!file.open(QFile::WriteOnly)) { | ||||||
|     qWarning("Cannot save AdBlock subscription to file '%s'.", qPrintable(filePath)); |     qWarning("Cannot save AdBlock subscription to file '%s'.", | ||||||
|  |              qPrintable(filePath)); | ||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -194,13 +208,16 @@ AdBlockSubscription *AdBlockManager::addSubscription(const QString &title, const | ||||||
|   m_subscriptions.insert(m_subscriptions.count() - 1, subscription); |   m_subscriptions.insert(m_subscriptions.count() - 1, subscription); | ||||||
| 
 | 
 | ||||||
|   // TODO: po změně subskripce přehrat user css?
 |   // TODO: po změně subskripce přehrat user css?
 | ||||||
|   //connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
 |   // connect(subscription, SIGNAL(subscriptionUpdated()), mApp,
 | ||||||
|   connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher())); |   // SLOT(reloadUserStyleSheet()));
 | ||||||
|  |   connect(subscription, SIGNAL(subscriptionChanged()), this, | ||||||
|  |           SLOT(updateMatcher())); | ||||||
| 
 | 
 | ||||||
|   return subscription; |   return subscription; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool AdBlockManager::removeSubscription(AdBlockSubscription* subscription) { | bool AdBlockManager::removeSubscription(AdBlockSubscription* subscription) | ||||||
|  | { | ||||||
|   QMutexLocker locker(&m_mutex); |   QMutexLocker locker(&m_mutex); | ||||||
| 
 | 
 | ||||||
|   if (!m_subscriptions.contains(subscription) || !subscription->canBeRemoved()) { |   if (!m_subscriptions.contains(subscription) || !subscription->canBeRemoved()) { | ||||||
|  | @ -216,7 +233,8 @@ bool AdBlockManager::removeSubscription(AdBlockSubscription* subscription) { | ||||||
|   return true; |   return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| AdBlockCustomList *AdBlockManager::customList() const { | AdBlockCustomList* AdBlockManager::customList() const | ||||||
|  | { | ||||||
|   foreach (AdBlockSubscription* subscription, m_subscriptions) { |   foreach (AdBlockSubscription* subscription, m_subscriptions) { | ||||||
|     AdBlockCustomList* list = qobject_cast<AdBlockCustomList*>(subscription); |     AdBlockCustomList* list = qobject_cast<AdBlockCustomList*>(subscription); | ||||||
| 
 | 
 | ||||||
|  | @ -228,20 +246,28 @@ AdBlockCustomList *AdBlockManager::customList() const { | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QString AdBlockManager::storedListsPath() const { | QString AdBlockManager::storedListsPath() const | ||||||
|  | { | ||||||
|   return qApp->getUserDataPath() + QDir::separator() + ADBLOCK_LISTS_SUBDIRECTORY; |   return qApp->getUserDataPath() + QDir::separator() + ADBLOCK_LISTS_SUBDIRECTORY; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AdBlockManager::load() { | void AdBlockManager::load() | ||||||
|  | { | ||||||
|   QMutexLocker locker(&m_mutex); |   QMutexLocker locker(&m_mutex); | ||||||
| 
 | 
 | ||||||
|   if (m_loaded) { |   if (m_loaded) { | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   m_enabled = qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::AdBlockEnabled)).toBool(); |   m_enabled = qApp->settings() | ||||||
|   m_disabledRules = qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::DisabledRules)).toStringList(); |               ->value(GROUP(AdBlock), SETTING(AdBlock::AdBlockEnabled)) | ||||||
|   QDateTime lastUpdate = qApp->settings()->value(GROUP(AdBlock), SETTING(AdBlock::LastUpdatedOn)).toDateTime(); |               .toBool(); | ||||||
|  |   m_disabledRules = qApp->settings() | ||||||
|  |                     ->value(GROUP(AdBlock), SETTING(AdBlock::DisabledRules)) | ||||||
|  |                     .toStringList(); | ||||||
|  |   QDateTime lastUpdate = qApp->settings() | ||||||
|  |                          ->value(GROUP(AdBlock), SETTING(AdBlock::LastUpdatedOn)) | ||||||
|  |                          .toDateTime(); | ||||||
| 
 | 
 | ||||||
|   if (!m_enabled) { |   if (!m_enabled) { | ||||||
|     return; |     return; | ||||||
|  | @ -254,7 +280,8 @@ void AdBlockManager::load() { | ||||||
|     QDir().mkpath(storedListsPath()); |     QDir().mkpath(storedListsPath()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   foreach (const QString &fileName, adblockDir.entryList(QStringList("*.txt"), QDir::Files)) { |   foreach (const QString& fileName, | ||||||
|  |            adblockDir.entryList(QStringList("*.txt"), QDir::Files)) { | ||||||
|     if (fileName == ADBLOCK_CUSTOMLIST_NAME) { |     if (fileName == ADBLOCK_CUSTOMLIST_NAME) { | ||||||
|       continue; |       continue; | ||||||
|     } |     } | ||||||
|  | @ -272,7 +299,8 @@ void AdBlockManager::load() { | ||||||
|     QUrl url = QUrl(textStream.readLine(1024).remove(QLatin1String("Url: "))); |     QUrl url = QUrl(textStream.readLine(1024).remove(QLatin1String("Url: "))); | ||||||
| 
 | 
 | ||||||
|     if (title.isEmpty() || !url.isValid()) { |     if (title.isEmpty() || !url.isValid()) { | ||||||
|       qWarning("Invalid AdBlock subscription file '%s'.", qPrintable(absolutePath)); |       qWarning("Invalid AdBlock subscription file '%s'.", | ||||||
|  |                qPrintable(absolutePath)); | ||||||
|       continue; |       continue; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -302,8 +330,10 @@ void AdBlockManager::load() { | ||||||
|     subscription->loadSubscription(m_disabledRules); |     subscription->loadSubscription(m_disabledRules); | ||||||
| 
 | 
 | ||||||
|     // TODO: po zmene subskripce prehrat user css?
 |     // TODO: po zmene subskripce prehrat user css?
 | ||||||
|     //connect(subscription, SIGNAL(subscriptionUpdated()), mApp, SLOT(reloadUserStyleSheet()));
 |     // connect(subscription, SIGNAL(subscriptionUpdated()), mApp,
 | ||||||
|     connect(subscription, SIGNAL(subscriptionChanged()), this, SLOT(updateMatcher())); |     // SLOT(reloadUserStyleSheet()));
 | ||||||
|  |     connect(subscription, SIGNAL(subscriptionChanged()), this, | ||||||
|  |             SLOT(updateMatcher())); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   if (lastUpdate.addDays(5) < QDateTime::currentDateTime()) { |   if (lastUpdate.addDays(5) < QDateTime::currentDateTime()) { | ||||||
|  | @ -316,21 +346,25 @@ void AdBlockManager::load() { | ||||||
|   qApp->urlIinterceptor()->installUrlInterceptor(m_interceptor); |   qApp->urlIinterceptor()->installUrlInterceptor(m_interceptor); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AdBlockManager::updateMatcher() { | void AdBlockManager::updateMatcher() | ||||||
|  | { | ||||||
|   QMutexLocker locker(&m_mutex); |   QMutexLocker locker(&m_mutex); | ||||||
| 
 | 
 | ||||||
|   m_matcher->update(); |   m_matcher->update(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AdBlockManager::updateAllSubscriptions() { | void AdBlockManager::updateAllSubscriptions() | ||||||
|  | { | ||||||
|   foreach (AdBlockSubscription* subscription, m_subscriptions) { |   foreach (AdBlockSubscription* subscription, m_subscriptions) { | ||||||
|     subscription->updateSubscription(); |     subscription->updateSubscription(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   qApp->settings()->setValue(GROUP(AdBlock), AdBlock::LastUpdatedOn, QDateTime::currentDateTime()); |   qApp->settings()->setValue(GROUP(AdBlock), AdBlock::LastUpdatedOn, | ||||||
|  |                              QDateTime::currentDateTime()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AdBlockManager::save() { | void AdBlockManager::save() | ||||||
|  | { | ||||||
|   if (!m_loaded) { |   if (!m_loaded) { | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  | @ -339,41 +373,45 @@ void AdBlockManager::save() { | ||||||
|     subscription->saveSubscription(); |     subscription->saveSubscription(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   qApp->settings()->setValue(GROUP(AdBlock), AdBlock::AdBlockEnabled, m_enabled); |   qApp->settings()->setValue(GROUP(AdBlock), AdBlock::AdBlockEnabled, | ||||||
|   qApp->settings()->setValue(GROUP(AdBlock), AdBlock::DisabledRules, m_disabledRules); |                              m_enabled); | ||||||
|  |   qApp->settings()->setValue(GROUP(AdBlock), AdBlock::DisabledRules, | ||||||
|  |                              m_disabledRules); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool AdBlockManager::isEnabled() const { | bool AdBlockManager::isEnabled() const { return m_enabled; } | ||||||
|   return m_enabled; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| bool AdBlockManager::canRunOnScheme(const QString &scheme) const { | bool AdBlockManager::canRunOnScheme(const QString& scheme) const | ||||||
|  | { | ||||||
|   return !(scheme == QSL("file") || scheme == QSL("qrc") || scheme == QSL("data") || scheme == QSL("abp")); |   return !(scheme == QSL("file") || scheme == QSL("qrc") || scheme == QSL("data") || scheme == QSL("abp")); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool AdBlockManager::canBeBlocked(const QUrl &url) const { | bool AdBlockManager::canBeBlocked(const QUrl& url) const | ||||||
|  | { | ||||||
|   return !m_matcher->adBlockDisabledForUrl(url); |   return !m_matcher->adBlockDisabledForUrl(url); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QString AdBlockManager::elementHidingRules(const QUrl &url) const { | QString AdBlockManager::elementHidingRules(const QUrl& url) const | ||||||
|  | { | ||||||
|   if (!isEnabled() || !canRunOnScheme(url.scheme()) || !canBeBlocked(url)) { |   if (!isEnabled() || !canRunOnScheme(url.scheme()) || !canBeBlocked(url)) { | ||||||
|     return QString(); |     return QString(); | ||||||
|   } |   } else { | ||||||
|   else { |  | ||||||
|     return m_matcher->elementHidingRules(); |     return m_matcher->elementHidingRules(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QString AdBlockManager::elementHidingRulesForDomain(const QUrl &url) const { | QString AdBlockManager::elementHidingRulesForDomain(const QUrl& url) const | ||||||
|  | { | ||||||
|   if (!isEnabled() || !canRunOnScheme(url.scheme()) || !canBeBlocked(url)) { |   if (!isEnabled() || !canRunOnScheme(url.scheme()) || !canBeBlocked(url)) { | ||||||
|     return QString(); |     return QString(); | ||||||
|   } |   } else { | ||||||
|   else { |  | ||||||
|     return m_matcher->elementHidingRulesForDomain(url.host()); |     return m_matcher->elementHidingRulesForDomain(url.host()); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| AdBlockSubscription* AdBlockManager::subscriptionByName(const QString &name) const { | AdBlockSubscription* AdBlockManager::subscriptionByName( | ||||||
|  |     const QString& name) const | ||||||
|  | { | ||||||
|   foreach (AdBlockSubscription* subscription, m_subscriptions) { |   foreach (AdBlockSubscription* subscription, m_subscriptions) { | ||||||
|     if (subscription->title() == name) { |     if (subscription->title() == name) { | ||||||
|       return subscription; |       return subscription; | ||||||
|  | @ -383,7 +421,8 @@ AdBlockSubscription* AdBlockManager::subscriptionByName(const QString &name) con | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| AdBlockDialog *AdBlockManager::showDialog() { | AdBlockDialog* AdBlockManager::showDialog() | ||||||
|  | { | ||||||
|   if (!m_adBlockDialog) { |   if (!m_adBlockDialog) { | ||||||
|     m_adBlockDialog = new AdBlockDialog; |     m_adBlockDialog = new AdBlockDialog; | ||||||
|   } |   } | ||||||
|  | @ -395,7 +434,8 @@ AdBlockDialog *AdBlockManager::showDialog() { | ||||||
|   return m_adBlockDialog.data(); |   return m_adBlockDialog.data(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AdBlockManager::showRule() { | void AdBlockManager::showRule() | ||||||
|  | { | ||||||
|   if (QAction* action = qobject_cast<QAction*>(sender())) { |   if (QAction* action = qobject_cast<QAction*>(sender())) { | ||||||
|     const AdBlockRule* rule = static_cast<const AdBlockRule*>(action->data().value<void*>()); |     const AdBlockRule* rule = static_cast<const AdBlockRule*>(action->data().value<void*>()); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -19,20 +19,18 @@ | ||||||
| #ifndef ADBLOCKMANAGER_H | #ifndef ADBLOCKMANAGER_H | ||||||
| #define ADBLOCKMANAGER_H | #define ADBLOCKMANAGER_H | ||||||
| 
 | 
 | ||||||
| #include <QObject> |  | ||||||
| #include <QStringList> |  | ||||||
| #include <QPointer> |  | ||||||
| #include <QMutex> | #include <QMutex> | ||||||
| 
 | #include <QObject> | ||||||
|  | #include <QPointer> | ||||||
|  | #include <QStringList> | ||||||
| 
 | 
 | ||||||
| class QUrl; | class QUrl; | ||||||
| class QWebEngineUrlRequestInfo; | class QWebEngineUrlRequestInfo; | ||||||
| 
 |  | ||||||
| class AdBlockRule; |  | ||||||
| class AdBlockDialog; |  | ||||||
| class AdBlockMatcher; | class AdBlockMatcher; | ||||||
| class AdBlockCustomList; | class AdBlockCustomList; | ||||||
| class AdBlockSubscription; | class AdBlockSubscription; | ||||||
|  | class AdBlockRule; | ||||||
|  | class AdBlockDialog; | ||||||
| class AdBlockUrlInterceptor; | class AdBlockUrlInterceptor; | ||||||
| 
 | 
 | ||||||
| class AdBlockManager : public QObject { | class AdBlockManager : public QObject { | ||||||
|  | @ -62,7 +60,8 @@ class AdBlockManager : public QObject { | ||||||
| 
 | 
 | ||||||
|     bool addSubscriptionFromUrl(const QUrl& url); |     bool addSubscriptionFromUrl(const QUrl& url); | ||||||
| 
 | 
 | ||||||
|     AdBlockSubscription *addSubscription(const QString &title, const QString &url); |     AdBlockSubscription* addSubscription(const QString& title, | ||||||
|  |         const QString& url); | ||||||
|     bool removeSubscription(AdBlockSubscription* subscription); |     bool removeSubscription(AdBlockSubscription* subscription); | ||||||
| 
 | 
 | ||||||
|     AdBlockCustomList* customList() const; |     AdBlockCustomList* customList() const; | ||||||
|  | @ -99,4 +98,3 @@ class AdBlockManager : public QObject { | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| #endif // ADBLOCKMANAGER_H
 | #endif // ADBLOCKMANAGER_H
 | ||||||
| 
 |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue