summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Iacovitti <aiacovitti@libero.it>2012-04-11 20:38:35 (GMT)
committerAndrea Iacovitti <aiacovitti@libero.it>2012-04-11 20:38:35 (GMT)
commitabc933ccee0af644bc642dc7551651d1ce0ca29a (patch)
tree871e835133b5b8182b0e9e5e4e52ff9dfe60610a
parent6b33972259447ac4330c0c3df949eba6a9d906c0 (diff)
Load/Update filter lists only when AdBlock is enabled.
FIXED-IN: 4.8.3
-rw-r--r--khtml/khtml_settings.cpp98
1 files changed, 51 insertions, 47 deletions
diff --git a/khtml/khtml_settings.cpp b/khtml/khtml_settings.cpp
index 118f388..bbe1bb4 100644
--- a/khtml/khtml_settings.cpp
+++ b/khtml/khtml_settings.cpp
@@ -410,59 +410,63 @@ void KHTMLSettings::init( KConfig * config, bool reset )
d->adBlackList.clear();
d->adWhiteList.clear();
- /** read maximum age for filter list files, minimum is one day */
- int htmlFilterListMaxAgeDays = cgFilter.readEntry(QString("HTMLFilterListMaxAgeDays")).toInt();
- if (htmlFilterListMaxAgeDays < 1)
- htmlFilterListMaxAgeDays = 1;
-
- QMap<QString,QString> entryMap = cgFilter.entryMap();
- QMap<QString,QString>::ConstIterator it;
- for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
- {
- int id = -1;
- QString name = it.key();
- QString url = it.value();
+ if (d->m_adFilterEnabled) {
- if (name.startsWith("Filter"))
- {
- if (url.startsWith(QLatin1String("@@")))
- d->adWhiteList.addFilter(url);
- else
- d->adBlackList.addFilter(url);
- } else if (name.startsWith("HTMLFilterListName-") && (id = name.mid(19).toInt()) > 0)
+ /** read maximum age for filter list files, minimum is one day */
+ int htmlFilterListMaxAgeDays = cgFilter.readEntry(QString("HTMLFilterListMaxAgeDays")).toInt();
+ if (htmlFilterListMaxAgeDays < 1)
+ htmlFilterListMaxAgeDays = 1;
+
+ QMap<QString,QString> entryMap = cgFilter.entryMap();
+ QMap<QString,QString>::ConstIterator it;
+ for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
{
- /** check if entry is enabled */
- bool filterEnabled = cgFilter.readEntry(QString("HTMLFilterListEnabled-").append(QString::number(id))) != QLatin1String("false");
-
- /** get url for HTMLFilterList */
- KUrl url(cgFilter.readEntry(QString("HTMLFilterListURL-").append(QString::number(id))));
-
- if (filterEnabled && url.isValid()) {
- /** determine where to cache HTMLFilterList file */
- QString localFile = cgFilter.readEntry(QString("HTMLFilterListLocalFilename-").append(QString::number(id)));
- localFile = KStandardDirs::locateLocal("data", "khtml/" + localFile);
-
- /** determine existence and age of cache file */
- QFileInfo fileInfo(localFile);
-
- /** load cached file if it exists, irrespective of age */
- if (fileInfo.exists())
- d->adblockFilterLoadList( localFile );
-
- /** if no cache list file exists or if it is too old ... */
- if (!fileInfo.exists() || fileInfo.lastModified().daysTo(QDateTime::currentDateTime()) > htmlFilterListMaxAgeDays)
- {
- /** ... in this case, refetch list asynchronously */
- kDebug(6000) << "Asynchronously fetching filter list from" << url << "to" << localFile;
-
- KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::Reload, KIO::HideProgressInfo );
- QObject::connect( job, SIGNAL(result(KJob*)), d, SLOT(adblockFilterResult(KJob*)) );
- /** for later reference, store name of cache file */
- job->setProperty("khtmlsettings_adBlock_filename", localFile);
+ int id = -1;
+ QString name = it.key();
+ QString url = it.value();
+
+ if (name.startsWith("Filter"))
+ {
+ if (url.startsWith(QLatin1String("@@")))
+ d->adWhiteList.addFilter(url);
+ else
+ d->adBlackList.addFilter(url);
+ } else if (name.startsWith("HTMLFilterListName-") && (id = name.mid(19).toInt()) > 0)
+ {
+ /** check if entry is enabled */
+ bool filterEnabled = cgFilter.readEntry(QString("HTMLFilterListEnabled-").append(QString::number(id))) != QLatin1String("false");
+
+ /** get url for HTMLFilterList */
+ KUrl url(cgFilter.readEntry(QString("HTMLFilterListURL-").append(QString::number(id))));
+
+ if (filterEnabled && url.isValid()) {
+ /** determine where to cache HTMLFilterList file */
+ QString localFile = cgFilter.readEntry(QString("HTMLFilterListLocalFilename-").append(QString::number(id)));
+ localFile = KStandardDirs::locateLocal("data", "khtml/" + localFile);
+
+ /** determine existence and age of cache file */
+ QFileInfo fileInfo(localFile);
+
+ /** load cached file if it exists, irrespective of age */
+ if (fileInfo.exists())
+ d->adblockFilterLoadList( localFile );
+
+ /** if no cache list file exists or if it is too old ... */
+ if (!fileInfo.exists() || fileInfo.lastModified().daysTo(QDateTime::currentDateTime()) > htmlFilterListMaxAgeDays)
+ {
+ /** ... in this case, refetch list asynchronously */
+ kDebug(6000) << "Asynchronously fetching filter list from" << url << "to" << localFile;
+
+ KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::Reload, KIO::HideProgressInfo );
+ QObject::connect( job, SIGNAL(result(KJob*)), d, SLOT(adblockFilterResult(KJob*)) );
+ /** for later reference, store name of cache file */
+ job->setProperty("khtmlsettings_adBlock_filename", localFile);
+ }
}
}
}
}
+
}
KConfigGroup cgHtml( config, "HTML Settings" );