mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
adblock: port foreach -> range-based for
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
e34933b5d7
commit
018b8d1a28
|
@ -44,7 +44,7 @@ AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent)
|
|||
<< Subscription(QSL("Anti-Adblock Killer"), QSL("https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt"))
|
||||
<< Subscription(tr("Other..."), QString());
|
||||
|
||||
foreach (const Subscription &subscription, m_knownSubscriptions) {
|
||||
for (const Subscription &subscription : qAsConst(m_knownSubscriptions)) {
|
||||
ui->comboBox->addItem(subscription.title);
|
||||
}
|
||||
|
||||
|
|
|
@ -174,7 +174,8 @@ void AdBlockDialog::load()
|
|||
return;
|
||||
}
|
||||
|
||||
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
|
||||
const auto subscriptions = m_manager->subscriptions();
|
||||
for (AdBlockSubscription* subscription : subscriptions) {
|
||||
AdBlockTreeWidget* tree = new AdBlockTreeWidget(subscription, tabWidget);
|
||||
tabWidget->addTab(tree, subscription->title());
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ bool AdBlockManager::removeSubscription(AdBlockSubscription* subscription)
|
|||
|
||||
AdBlockCustomList* AdBlockManager::customList() const
|
||||
{
|
||||
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
||||
for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) {
|
||||
AdBlockCustomList* list = qobject_cast<AdBlockCustomList*>(subscription);
|
||||
|
||||
if (list) {
|
||||
|
@ -283,7 +283,8 @@ void AdBlockManager::load()
|
|||
QDir(DataPaths::currentProfilePath()).mkdir(QSL("adblock"));
|
||||
}
|
||||
|
||||
foreach (const QString &fileName, adblockDir.entryList(QStringList(QSL("*.txt")), QDir::Files)) {
|
||||
const auto fileNames = adblockDir.entryList(QStringList(QSL("*.txt")), QDir::Files);
|
||||
for (const QString &fileName : fileNames) {
|
||||
if (fileName == QLatin1String("customlist.txt")) {
|
||||
continue;
|
||||
}
|
||||
|
@ -329,7 +330,7 @@ void AdBlockManager::load()
|
|||
m_subscriptions.append(customList);
|
||||
|
||||
// Load all subscriptions
|
||||
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
||||
for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) {
|
||||
subscription->loadSubscription(m_disabledRules);
|
||||
|
||||
connect(subscription, &AdBlockSubscription::subscriptionUpdated, mApp, &MainApplication::reloadUserStyleSheet);
|
||||
|
@ -366,7 +367,7 @@ void AdBlockManager::updateMatcher()
|
|||
|
||||
void AdBlockManager::updateAllSubscriptions()
|
||||
{
|
||||
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
||||
for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) {
|
||||
subscription->updateSubscription();
|
||||
}
|
||||
|
||||
|
@ -382,7 +383,7 @@ void AdBlockManager::save()
|
|||
return;
|
||||
}
|
||||
|
||||
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
||||
for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) {
|
||||
subscription->saveSubscription();
|
||||
}
|
||||
|
||||
|
@ -427,7 +428,7 @@ QString AdBlockManager::elementHidingRulesForDomain(const QUrl &url) const
|
|||
|
||||
AdBlockSubscription* AdBlockManager::subscriptionByName(const QString &name) const
|
||||
{
|
||||
foreach (AdBlockSubscription* subscription, m_subscriptions) {
|
||||
for (AdBlockSubscription* subscription : qAsConst(m_subscriptions)) {
|
||||
if (subscription->title() == name) {
|
||||
return subscription;
|
||||
}
|
||||
|
|
|
@ -125,8 +125,10 @@ void AdBlockMatcher::update()
|
|||
QHash<QString, const AdBlockRule*> cssRulesHash;
|
||||
QVector<const AdBlockRule*> exceptionCssRules;
|
||||
|
||||
foreach (AdBlockSubscription* subscription, m_manager->subscriptions()) {
|
||||
foreach (const AdBlockRule* rule, subscription->allRules()) {
|
||||
const auto subscriptions = m_manager->subscriptions();
|
||||
for (AdBlockSubscription* subscription : subscriptions) {
|
||||
const auto rules = subscription->allRules();
|
||||
for (const AdBlockRule* rule : rules) {
|
||||
// Don't add internally disabled rules to cache
|
||||
if (rule->isInternalDisabled())
|
||||
continue;
|
||||
|
@ -159,7 +161,7 @@ void AdBlockMatcher::update()
|
|||
}
|
||||
}
|
||||
|
||||
foreach (const AdBlockRule* rule, exceptionCssRules) {
|
||||
for (const AdBlockRule* rule : qAsConst(exceptionCssRules)) {
|
||||
const AdBlockRule* originalRule = cssRulesHash.value(rule->cssSelector());
|
||||
|
||||
// If we don't have this selector, the exception does nothing
|
||||
|
|
|
@ -290,14 +290,14 @@ bool AdBlockRule::matchDomain(const QString &domain) const
|
|||
}
|
||||
|
||||
if (m_blockedDomains.isEmpty()) {
|
||||
foreach (const QString &d, m_allowedDomains) {
|
||||
for (const QString &d : qAsConst(m_allowedDomains)) {
|
||||
if (isMatchingDomain(domain, d)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_allowedDomains.isEmpty()) {
|
||||
foreach (const QString &d, m_blockedDomains) {
|
||||
for (const QString &d : qAsConst(m_blockedDomains)) {
|
||||
if (isMatchingDomain(domain, d)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -305,13 +305,13 @@ bool AdBlockRule::matchDomain(const QString &domain) const
|
|||
return true;
|
||||
}
|
||||
else {
|
||||
foreach (const QString &d, m_blockedDomains) {
|
||||
for (const QString &d : qAsConst(m_blockedDomains)) {
|
||||
if (isMatchingDomain(domain, d)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const QString &d, m_allowedDomains) {
|
||||
for (const QString &d : qAsConst(m_allowedDomains)) {
|
||||
if (isMatchingDomain(domain, d)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ void AdBlockRule::parseFilter()
|
|||
const QStringList options = parsedLine.mid(optionsIndex + 1).split(QL1C(','), QString::SkipEmptyParts);
|
||||
|
||||
int handledOptions = 0;
|
||||
foreach (const QString &option, options) {
|
||||
for (const QString &option : options) {
|
||||
if (option.startsWith(QL1S("domain="))) {
|
||||
parseDomains(option.mid(7), QL1C('|'));
|
||||
++handledOptions;
|
||||
|
@ -631,9 +631,9 @@ void AdBlockRule::parseFilter()
|
|||
|
||||
void AdBlockRule::parseDomains(const QString &domains, const QChar &separator)
|
||||
{
|
||||
QStringList domainsList = domains.split(separator, QString::SkipEmptyParts);
|
||||
const QStringList domainsList = domains.split(separator, QString::SkipEmptyParts);
|
||||
|
||||
foreach (const QString domain, domainsList) {
|
||||
for (const QString domain : domainsList) {
|
||||
if (domain.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -748,7 +748,7 @@ QList<QStringMatcher> AdBlockRule::createStringMatchers(const QStringList &filte
|
|||
QList<QStringMatcher> matchers;
|
||||
matchers.reserve(filters.size());
|
||||
|
||||
foreach (const QString &filter, filters) {
|
||||
for (const QString &filter : filters) {
|
||||
matchers.append(QStringMatcher(filter, m_caseSensitivity));
|
||||
}
|
||||
|
||||
|
@ -790,7 +790,8 @@ bool AdBlockRule::isMatchingRegExpStrings(const QString &url) const
|
|||
{
|
||||
Q_ASSERT(m_regExp);
|
||||
|
||||
foreach (const QStringMatcher &matcher, m_regExp->matchers) {
|
||||
const auto matchers = m_regExp->matchers;
|
||||
for (const QStringMatcher &matcher : matchers) {
|
||||
if (matcher.indexIn(url) == -1)
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -335,7 +335,7 @@ void AdBlockCustomList::saveSubscription()
|
|||
textStream << "Url: " << url().toString() << endl;
|
||||
textStream << "[Adblock Plus 1.1.1]" << endl;
|
||||
|
||||
foreach (const AdBlockRule* rule, m_rules) {
|
||||
for (const AdBlockRule* rule : qAsConst(m_rules)) {
|
||||
textStream << rule->filter() << endl;
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,7 @@ bool AdBlockCustomList::canBeRemoved() const
|
|||
|
||||
bool AdBlockCustomList::containsFilter(const QString &filter) const
|
||||
{
|
||||
foreach (const AdBlockRule* rule, m_rules) {
|
||||
for (const AdBlockRule* rule : qAsConst(m_rules)) {
|
||||
if (rule->filter() == filter) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -250,7 +250,7 @@ void AdBlockTreeWidget::refresh()
|
|||
const QVector<AdBlockRule*> &allRules = m_subscription->allRules();
|
||||
|
||||
int index = 0;
|
||||
foreach (const AdBlockRule* rule, allRules) {
|
||||
for (const AdBlockRule* rule : allRules) {
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem(m_topItem);
|
||||
item->setText(0, rule->filter());
|
||||
item->setData(0, Qt::UserRole + 10, index);
|
||||
|
|
Loading…
Reference in New Issue
Block a user