diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 164 | ||||
-rw-r--r-- | src/adblock/adblockmanager.h | 13 | ||||
-rw-r--r-- | src/adblock/adblockwidget.cpp | 66 | ||||
-rw-r--r-- | src/data/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/data/adblockrc | 187 | ||||
-rw-r--r-- | src/rekonq.kcfg | 23 |
6 files changed, 302 insertions, 158 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index e48cc753..ff3aad6a 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -37,9 +37,8 @@ #include "webpage.h" // KDE Includes -#include <KSharedConfig> -#include <KConfigGroup> -#include <KIO/TransferJob> +#include <KIO/FileCopyJob> +#include <KStandardDirs> // Qt Includes #include <QUrl> @@ -50,7 +49,6 @@ AdBlockManager::AdBlockManager(QObject *parent) : QObject(parent) , _isAdblockEnabled(false) , _isHideAdsEnabled(false) - , _index(0) { loadSettings(); } @@ -66,8 +64,21 @@ AdBlockManager::~AdBlockManager() void AdBlockManager::loadSettings() { - _index = 0; - _buffer.clear(); + // first, check this... + QString adblockFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrc")); + if (!QFile::exists(adblockFilePath)) + { + QString generalAdblockFilePath = KStandardDirs::locate("appdata" , QL1S("adblockrc")); + QFile adblockFile(generalAdblockFilePath); + bool copied = adblockFile.copy(adblockFilePath); + if (!copied) + { + kDebug() << "oh oh... Problems copying default adblock file"; + return; + } + } + _adblockConfig = KSharedConfig::openConfig("adblockrc", KConfig::SimpleConfig, "appdata"); + // ---------------- _hostWhiteList.clear(); _hostBlackList.clear(); @@ -75,7 +86,8 @@ void AdBlockManager::loadSettings() _blackList.clear(); _hideList.clear(); - _isAdblockEnabled = ReKonfig::adBlockEnabled(); + KConfigGroup settingsGroup(_adblockConfig, "Settings"); + _isAdblockEnabled = settingsGroup.readEntry("adBlockEnabled", false); kDebug() << "ADBLOCK ENABLED = " << _isAdblockEnabled; // no need to load filters if adblock is not enabled :) @@ -83,43 +95,51 @@ void AdBlockManager::loadSettings() return; // just to be sure.. - _isHideAdsEnabled = ReKonfig::hideAdsEnabled(); - - // read settings - KSharedConfig::Ptr config = KSharedConfig::openConfig("adblock", KConfig::SimpleConfig, "appdata"); - KConfigGroup rulesGroup(config, "rules"); - QStringList rules; - rules = rulesGroup.readEntry("local-rules" , QStringList()); - loadRules(rules); + _isHideAdsEnabled = settingsGroup.readEntry("hideAdsEnabled", false); // ---------------------------------------------------------- QDateTime today = QDateTime::currentDateTime(); - QDateTime lastUpdate = ReKonfig::lastUpdate(); // the day of the implementation.. :) - int days = ReKonfig::updateInterval(); + QDateTime lastUpdate = QDateTime::fromString(settingsGroup.readEntry("lastUpdate", QString())); + int days = settingsGroup.readEntry("updateInterval", 7); if (today > lastUpdate.addDays(days)) { - ReKonfig::setLastUpdate(today); + settingsGroup.writeEntry("lastUpdate", today.toString()); - updateNextSubscription(); + updateSubscriptions(); return; } // else - QStringList titles = ReKonfig::subscriptionTitles(); - Q_FOREACH(const QString & title, titles) + KConfigGroup filtersGroup(_adblockConfig, "FiltersList"); + for (int i = 1; i <= 60; ++i) { - rules = rulesGroup.readEntry(title + "-rules" , QStringList()); - loadRules(rules); + QString n = QString::number(i); + bool filterActive = filtersGroup.readEntry("FilterEnabled-" + n, false); + if (filterActive) + { + QString rulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_") + n); + loadRules(rulesFilePath); + } } } -void AdBlockManager::loadRules(const QStringList &rules) +void AdBlockManager::loadRules(const QString &rulesFilePath) { - Q_FOREACH(const QString & stringRule, rules) + QFile ruleFile(rulesFilePath); + if (!ruleFile.open(QFile::ReadOnly | QFile::Text)) + { + kDebug() << "Unable to open rule file" << rulesFilePath; + return; + } + + QTextStream in(&ruleFile); + while (!in.atEnd()) { + QString stringRule = in.readLine(); + // ! rules are comments if (stringRule.startsWith('!')) continue; @@ -267,82 +287,38 @@ void AdBlockManager::applyHidingRules(WebPage *page) } -void AdBlockManager::updateNextSubscription() +void AdBlockManager::updateSubscriptions() { - QStringList locations = ReKonfig::subscriptionLocations(); - - if (_index < locations.size()) - { - QString urlString = locations.at(_index); - KUrl subUrl = KUrl(urlString); - - KIO::TransferJob* job = KIO::get(subUrl , KIO::Reload , KIO::HideProgressInfo); - job->metaData().insert("ssl_no_client_cert", "TRUE"); - job->metaData().insert("ssl_no_ui", "TRUE"); - job->metaData().insert("UseCache", "false"); - job->metaData().insert("cookies", "none"); - job->metaData().insert("no-auth", "true"); - - connect(job, SIGNAL(data(KIO::Job*,QByteArray)), this, SLOT(subscriptionData(KIO::Job*,QByteArray))); - connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); - - return; - } - - _index = 0; - _buffer.clear(); -} + KConfigGroup filtersGroup(_adblockConfig, "FiltersList"); + int i = 1; + QString n = QString::number(i); -void AdBlockManager::slotResult(KJob *job) -{ - if (job->error()) - return; - - QList<QByteArray> list = _buffer.split('\n'); - QStringList ruleList; - Q_FOREACH(const QByteArray & ba, list) + while (filtersGroup.hasKey("FilterName-" + n)) { - ruleList << QString(ba); - } - loadRules(ruleList); - saveRules(ruleList); - - _index++; - - // last.. - updateNextSubscription(); -} - - -void AdBlockManager::subscriptionData(KIO::Job* job, const QByteArray& data) -{ - Q_UNUSED(job) - - if (data.isEmpty()) - return; - - int oldSize = _buffer.size(); - _buffer.resize(_buffer.size() + data.size()); - memcpy(_buffer.data() + oldSize, data.data(), data.size()); -} - + bool isFilterEnabled = filtersGroup.readEntry("FilterEnabled-" + n, false); + if (isFilterEnabled) + { + QString fUrl = filtersGroup.readEntry("FilterURL-" + n, QString()); + KUrl subUrl = KUrl(fUrl); + + kDebug() << "Filter ENABLED: " << fUrl; + QString rulesFilePath = KStandardDirs::locateLocal("appdata" , QL1S("adblockrules_") + n); + KUrl destUrl = KUrl(rulesFilePath); + + KIO::FileCopyJob* job = KIO::file_copy(subUrl , destUrl, -1, KIO::HideProgressInfo); + job->metaData().insert("ssl_no_client_cert", "TRUE"); + job->metaData().insert("ssl_no_ui", "TRUE"); + job->metaData().insert("UseCache", "false"); + job->metaData().insert("cookies", "none"); + job->metaData().insert("no-auth", "true"); + } -void AdBlockManager::saveRules(const QStringList &rules) -{ - QStringList cleanedRules; - Q_FOREACH(const QString & r, rules) - { - if (!r.startsWith('!') && !r.startsWith('[') && !r.isEmpty()) - cleanedRules << r; + i++; + n = QString::number(i); } - QStringList titles = ReKonfig::subscriptionTitles(); - QString title = titles.at(_index) + "-rules"; - - KSharedConfig::Ptr config = KSharedConfig::openConfig("adblock", KConfig::SimpleConfig, "appdata"); - KConfigGroup cg(config , "rules"); - cg.writeEntry(title, cleanedRules); + loadSettings(); } diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index cce00877..6b7c225e 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -130,6 +130,7 @@ // KDE Includes #include <KIO/Job> +#include <KSharedConfig> // Qt Includes #include <QObject> @@ -161,13 +162,10 @@ public Q_SLOTS: void showSettings(); private: - void updateNextSubscription(); - void saveRules(const QStringList &); - void loadRules(const QStringList &); + void updateSubscriptions(); + void loadRules(const QString &); -private Q_SLOTS: - void slotResult(KJob *); - void subscriptionData(KIO::Job*, const QByteArray&); + KSharedConfig::Ptr config(); private: bool _isAdblockEnabled; @@ -179,8 +177,7 @@ private: AdBlockRuleList _whiteList; QStringList _hideList; - int _index; - QByteArray _buffer; + KSharedConfig::Ptr _adblockConfig; }; #endif diff --git a/src/adblock/adblockwidget.cpp b/src/adblock/adblockwidget.cpp index c26e31f4..8e6a81ae 100644 --- a/src/adblock/adblockwidget.cpp +++ b/src/adblock/adblockwidget.cpp @@ -108,36 +108,36 @@ void AdBlockWidget::removeRule() void AdBlockWidget::load() { - const bool isAdBlockEnabled = ReKonfig::adBlockEnabled(); - checkEnableAdblock->setChecked(isAdBlockEnabled); - // update enabled status - checkHideAds->setEnabled(checkEnableAdblock->isChecked()); - tabWidget->setEnabled(checkEnableAdblock->isChecked()); - - const bool areImageFiltered = ReKonfig::hideAdsEnabled(); - checkHideAds->setChecked(areImageFiltered); - - const int days = ReKonfig::updateInterval(); - spinBox->setValue(days); - - const QStringList subscriptions = ReKonfig::subscriptionTitles(); - - // load automatic rules - Q_FOREACH(const QString & sub, subscriptions) - { - QTreeWidgetItem *subItem = new QTreeWidgetItem(treeWidget); - subItem->setText(0, sub); - loadRules(subItem); - } - - // load local rules - KSharedConfig::Ptr config = KSharedConfig::openConfig("adblock", KConfig::SimpleConfig, "appdata"); - KConfigGroup localGroup(config, "rules"); - const QStringList rules = localGroup.readEntry("local-rules" , QStringList()); - Q_FOREACH(const QString & rule, rules) - { - listWidget->addItem(rule); - } +// const bool isAdBlockEnabled = ReKonfig::adBlockEnabled(); +// checkEnableAdblock->setChecked(isAdBlockEnabled); +// // update enabled status +// checkHideAds->setEnabled(checkEnableAdblock->isChecked()); +// tabWidget->setEnabled(checkEnableAdblock->isChecked()); +// +// const bool areImageFiltered = ReKonfig::hideAdsEnabled(); +// checkHideAds->setChecked(areImageFiltered); +// +// const int days = ReKonfig::updateInterval(); +// spinBox->setValue(days); +// +// const QStringList subscriptions = ReKonfig::subscriptionTitles(); +// +// // load automatic rules +// Q_FOREACH(const QString & sub, subscriptions) +// { +// QTreeWidgetItem *subItem = new QTreeWidgetItem(treeWidget); +// subItem->setText(0, sub); +// loadRules(subItem); +// } +// +// // load local rules +// KSharedConfig::Ptr config = KSharedConfig::openConfig("adblock", KConfig::SimpleConfig, "appdata"); +// KConfigGroup localGroup(config, "rules"); +// const QStringList rules = localGroup.readEntry("local-rules" , QStringList()); +// Q_FOREACH(const QString & rule, rules) +// { +// listWidget->addItem(rule); +// } } @@ -176,9 +176,9 @@ void AdBlockWidget::save() } localGroup.writeEntry("local-rules" , localRules); - ReKonfig::setAdBlockEnabled(checkEnableAdblock->isChecked()); - ReKonfig::setHideAdsEnabled(checkHideAds->isChecked()); - ReKonfig::setUpdateInterval(spinBox->value()); +// ReKonfig::setAdBlockEnabled(checkEnableAdblock->isChecked()); +// ReKonfig::setHideAdsEnabled(checkHideAds->isChecked()); +// ReKonfig::setUpdateInterval(spinBox->value()); _changed = false; emit changed(false); diff --git a/src/data/CMakeLists.txt b/src/data/CMakeLists.txt index 091650b9..5c3cfd80 100644 --- a/src/data/CMakeLists.txt +++ b/src/data/CMakeLists.txt @@ -28,6 +28,13 @@ INSTALL( DESTINATION ${DATA_INSTALL_DIR}/rekonq/htmls ) +# adblock default settings +INSTALL( + FILES + adblockrc + DESTINATION ${DATA_INSTALL_DIR}/rekonq +) + # opensearch engines INSTALL( FILES diff --git a/src/data/adblockrc b/src/data/adblockrc new file mode 100644 index 00000000..13843ba8 --- /dev/null +++ b/src/data/adblockrc @@ -0,0 +1,187 @@ +[Settings] +adBlockEnabled=false +hideAdsEnabled=false +updateInterval=7 +lastUpdate=Mon Feb 13 11:58:51 2012 + +[FiltersList] +FilterEnabled-1=true +FilterName-1=EasyList +FilterURL-1=https://easylist-downloads.adblockplus.org/easylist.txt +FilterEnabled-2=false +FilterName-2=Corset+EasyList +FilterURL-2=https://easylist-downloads.adblockplus.org/corset+easylist.txt +FilterEnabled-3=false +FilterName-3=Corset +FilterURL-3=http://brianyi.com/corset.txt +FilterEnabled-4=false +FilterName-4=EasyList Germany+EasyList +FilterURL-4=https://easylist-downloads.adblockplus.org/ares+easylist.txt +FilterEnabled-5=false +FilterName-5=EasyList Germany +FilterURL-5=https://easylist-downloads.adblockplus.org/easylistgermany.txt +FilterEnabled-6=false +FilterName-6=Liste FR+EasyList +FilterURL-6=https://easylist-downloads.adblockplus.org/liste_fr+easylist.txt +FilterEnabled-7=false +FilterName-7=Liste FR +FilterURL-7=http://lian.info.tm/liste_fr.txt +FilterEnabled-8=false +FilterName-8=ROList+EasyList +FilterURL-8=https://easylist-downloads.adblockplus.org/rolist+easylist.txt +FilterEnabled-9=false +FilterName-9=ROList +FilterURL-9=http://www.picpoc.ro/menetzrolist.txt +FilterEnabled-10=false +FilterName-10=Việt Nam List+EasyList +FilterURL-10=https://easylist-downloads.adblockplus.org/abpvn+easylist.txt +FilterEnabled-11=false +FilterName-11=Việt Nam List +FilterURL-11=http://adblockplus-vietnam.googlecode.com/svn/trunk/abpvn.txt +FilterEnabled-12=false +FilterName-12=AdblockList.org +FilterURL-12=http://adblocklist.org/adblock-pxf-polish.txt +FilterEnabled-13=false +FilterName-13=Bulgarian list +FilterURL-13=http://stanev.org/abp/adblock_bg.txt +FilterEnabled-14=false +FilterName-14=EasyPrivacy+EasyList +FilterURL-14=https://easylist-downloads.adblockplus.org/easyprivacy+easylist.txt +FilterEnabled-15=false +FilterName-15=EasyPrivacy+Cédrics Liste +FilterURL-15=https://easylist-downloads.adblockplus.org/easyprivacy+cedrics.txt +FilterEnabled-16=false +FilterName-16=EasyPrivacy +FilterURL-16=https://easylist-downloads.adblockplus.org/easyprivacy.txt +FilterEnabled-17=false +FilterName-17=IsraelList +FilterURL-17=http://israellist.googlecode.com/files/IsraelList.txt +FilterEnabled-18=false +FilterName-18=Morpeh Rus List+EasyList +FilterURL-18=https://easylist-downloads.adblockplus.org/morpeh+easylist.txt +FilterEnabled-19=false +FilterName-19=Morpeh Rus List +FilterURL-19=http://adblockplus.mihalkin.ru/Russia.txt +FilterEnabled-20=false +FilterName-20=Norsk adblockliste +FilterURL-20=http://home.online.no/~mlangsho/adblock.txt +FilterEnabled-21=false +FilterName-21=void.gr +FilterURL-21=http://www.void.gr/kargig/void-gr-filters.txt +FilterEnabled-22=false +FilterName-22=Wiltteri +FilterURL-22=http://www.wiltteri.net/wiltteri.txt +FilterEnabled-23=false +FilterName-23=ChinaList +FilterURL-23=http://adblock-chinalist.googlecode.com/svn/trunk/adblock.txt +FilterEnabled-24=false +FilterName-24=Filter von Dr.Evil +FilterURL-24=http://adblock.maltekraus.de/adblock.txt +FilterEnabled-25=false +FilterName-25=RuAdList +FilterURL-25=http://ruadlist.googlecode.com/svn/trunk/adblock.txt +FilterEnabled-26=false +FilterName-26=AdblockRules.org +FilterURL-26=http://adblockrules.org/download.php?type=all +FilterEnabled-27=false +FilterName-27=BSI Lista Polska +FilterURL-27=http://www.bsi.info.pl/filtrABP.txt +FilterEnabled-28=false +FilterName-28=Czech List +FilterURL-28=http://dajbych.net/adblock.txt +FilterEnabled-29=false +FilterName-29=Cédrics Liste +FilterURL-29=http://chewey.de/mozilla/data/adblock.txt +FilterEnabled-30=false +FilterName-30=dutchblock +FilterURL-30=http://dutchmega.nl/dutchblock/list.txt +FilterEnabled-31=false +FilterName-31=Fanboy's List +FilterURL-31=http://www.fanboy.co.nz/adblock/fanboy-adblocklist-current-expanded.txt +FilterEnabled-32=false +FilterName-32=Fanboy's Chinese +FilterURL-32=http://www.fanboy.co.nz/adblock/fanboy-adblocklist-chn.txt +FilterEnabled-33=false +FilterName-33=Fanboy's Czech +FilterURL-33=http://www.fanboy.co.nz/adblock/fanboy-adblocklist-cz.txt +FilterEnabled-34=false +FilterName-34=Fanboy's Espanol/Portuguese +FilterURL-34=http://www.fanboy.co.nz/adblock/fanboy-adblocklist-esp.txt +FilterEnabled-35=false +FilterName-35=Fanboy's Japanese +FilterURL-35=http://www.fanboy.co.nz/adblock/fanboy-adblocklist-jpn.txt +FilterEnabled-36=false +FilterName-36=Fanboy's Korean +FilterURL-36=http://www.fanboy.co.nz/adblock/fanboy-adblocklist-krn.txt +FilterEnabled-37=false +FilterName-37=Fanboy's Tracking/Stats Blocking +FilterURL-37=http://www.fanboy.co.nz/adblock/fanboy-adblocklist-stats.txt +FilterEnabled-38=false +FilterName-38=Fanboy's Turkish +FilterURL-38=http://www.fanboy.co.nz/adblock/fanboy-adblocklist-tky.txt +FilterEnabled-39=false +FilterName-39=Filter von MonztA +FilterURL-39=http://monzta.maltekraus.de/adblock.txt +FilterEnabled-40=false +FilterName-40=Filtros Nauscopicos +FilterURL-40=http://s3.amazonaws.com/lcp/maty/myfiles/AdBlock-Nauscopio-maty.txt +FilterEnabled-41=false +FilterName-41=Hackrus anti-advertisement +FilterURL-41=http://nsis.narod.ru/clean_internet/aag.txt +FilterEnabled-42=false +FilterName-42=Hackrus anti-advertisement supplemental +FilterURL-42=http://nsis.narod.ru/clean_internet/aas.txt +FilterEnabled-43=false +FilterName-43=Hackrus anti-counter +FilterURL-43=http://nsis.narod.ru/clean_internet/ac.txt +FilterEnabled-44=false +FilterName-44=hufilter +FilterURL-44=http://pete.teamlupus.hu/hufilter.txt +FilterEnabled-45=false +FilterName-45=Iceland List +FilterURL-45=http://adblock-iceland.googlecode.com/files/icelandic%20filter.txt +FilterEnabled-46=false +FilterName-46=Japanese General Filter +FilterURL-46=http://adblock-plus-japanese-filter.googlecode.com/svn/trunk/abp_jp_general.txt +FilterEnabled-47=false +FilterName-47=Japanese Site-Specific Filter +FilterURL-47=http://adblock-plus-japanese-filter.googlecode.com/svn/trunk/abp_jp_site_specific.txt +FilterEnabled-48=false +FilterName-48=Lista Basa +FilterURL-48=http://www.photographer.neostrada.pl/abp.txt +FilterEnabled-49=false +FilterName-49=NLBlock +FilterURL-49=http://www.verzijlbergh.com/adblock/nlblock.txt +FilterEnabled-50=false +FilterName-50=PLgeneral +FilterURL-50=http://www.niecko.pl/adblock/adblock.txt +FilterEnabled-51=false +FilterName-51=Schacks Adblock Plus liste +FilterURL-51=http://adblock.schack.dk/block.txt +FilterEnabled-52=false +FilterName-52=UA-IX Бан-лист +FilterURL-52=http://adblock.oasis.org.ua/banlist.txt +FilterEnabled-53=false +FilterName-53=Xfiles +FilterURL-53=http://mozilla.gfsolone.com/filtri.txt +FilterEnabled-54=false +FilterName-54=adblock.free.fr +FilterURL-54=http://adblock.free.fr/adblock.txt +FilterEnabled-55=false +FilterName-55=adblock.free.fr basic (bloque les pubs uniquement) +FilterURL-55=http://adblock.free.fr/adblock_basic.txt +FilterEnabled-56=false +FilterName-56=Ajnasz's list +FilterURL-56=http://ajnasz.hu/adblock/recent +FilterEnabled-57=false +FilterName-57=Schuzak's Universal Filter +FilterURL-57=http://www.schuzak.jp/other/abp.txt +FilterEnabled-58=false +FilterName-58=Malware Domains +FilterURL-58=http://malwaredomains.lanik.us/malwaredomains_full.txt +FilterEnabled-59=false +FilterName-59=Rickroll Blacklist +FilterURL-59=http://rickrolldb.com/ricklist.txt +FilterEnabled-60=false +FilterName-60=EasyList without element hiding +FilterURL-60=https://easylist-downloads.adblockplus.org/easylist_noelemhide.txt diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index 6de6d1f1..bdcbcb60 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -249,29 +249,6 @@ </group> -<!-- AdBlock Settings --> -<group name="AdBlock"> - <entry name="adBlockEnabled" type="Bool"> - <default>false</default> - </entry> - <entry name="hideAdsEnabled" type="Bool"> - <default>false</default> - </entry> - <entry name="subscriptionTitles" type="StringList"> - <default>EasyList</default> - </entry> - <entry name="subscriptionLocations" type="StringList"> - <default>https://easylist-downloads.adblockplus.org/easylist.txt</default> - </entry> - <entry name="lastUpdate" type="DateTime"> - <default code="true">QDateTime(QDate(2009,03,13))</default> - </entry> - <entry name="updateInterval" type="Int"> - <default>7</default> - </entry> -</group> - - <!-- Sync Settings --> <group name="Sync"> <entry name="syncEnabled" type="Bool"> |