Commit 7c73a7b9 authored by Laurent Montel's avatar Laurent Montel 😁

Merge duplicate files

parent 99385382
......@@ -12,7 +12,6 @@ set(adblocklibprivate_widget_SRCS
widgets/adblocklistwidget.cpp
widgets/adblocksettingwidget.cpp
widgets/adblockshowlistdialog.cpp
widgets/adblockutil.cpp
)
set(adblocklibprivate_job_SRCS
......
......@@ -63,6 +63,7 @@
#include "adblockutil.h"
#include "adblockinterceptor_debug.h"
#include <KLocalizedString>
#include <QFile>
#include <QTimer>
......@@ -291,7 +292,7 @@ AdBlockSubscription::~AdBlockSubscription()
AdBlockCustomList::AdBlockCustomList(QObject *parent)
: AdBlockSubscription(i18n("Custom Rules"), parent)
{
setFilePath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/adblock/customlist.txt"));
setFilePath(AdBlock::AdblockUtil::localFilterPath());
}
void AdBlockCustomList::loadSubscription(const QStringList &disabledRules)
......
......@@ -32,6 +32,9 @@
* ============================================================ */
#include "adblockutil.h"
#include <QMap>
#include <QStandardPaths>
using namespace AdBlock;
// Matches domain (assumes both pattern and domain not starting with dot)
// pattern = domain to be matched
......@@ -50,3 +53,40 @@ bool AdblockUtil::matchDomain(const QString &pattern, const QString &domain)
return index > 0 && domain[index - 1] == QLatin1Char('.');
}
QMap<QString, QString> AdBlock::AdblockUtil::listSubscriptions()
{
QMap<QString, QString> lst;
lst.insert(QStringLiteral("EasyList"), QStringLiteral("https://easylist-downloads.adblockplus.org/easylist.txt"));
lst.insert(QStringLiteral("EasyList without element hiding"), QStringLiteral("https://easylist-downloads.adblockplus.org/easylist_noelemhide.txt"));
lst.insert(QStringLiteral("Corset"), QStringLiteral("http://brianyi.com/corset.txt"));
lst.insert(QStringLiteral("EasyList Germany"), QStringLiteral("https://easylist-downloads.adblockplus.org/easylistgermany.txt"));
lst.insert(QStringLiteral("Liste FR+EasyList"), QStringLiteral("https://easylist-downloads.adblockplus.org/liste_fr+easylist.txt"));
lst.insert(QStringLiteral("ROList+EasyList"), QStringLiteral("https://easylist-downloads.adblockplus.org/rolist+easylist.txt"));
lst.insert(QStringLiteral("AdblockList.org"), QStringLiteral("http://adblocklist.org/adblock-pxf-polish.txt"));
lst.insert(QStringLiteral("Bulgarian list"), QStringLiteral("http://stanev.org/abp/adblock_bg.txt"));
lst.insert(QStringLiteral("EasyPrivacy+EasyList"), QStringLiteral("https://easylist-downloads.adblockplus.org/easyprivacy+easylist.txt"));
lst.insert(QStringLiteral("EasyPrivacy"), QStringLiteral("https://easylist-downloads.adblockplus.org/easyprivacy.txt"));
lst.insert(QStringLiteral("void.gr"), QStringLiteral("http://www.void.gr/kargig/void-gr-filters.txt"));
lst.insert(QStringLiteral("BSI Lista Polska"), QStringLiteral("http://www.bsi.info.pl/filtrABP.txt"));
lst.insert(QStringLiteral("Czech List"), QStringLiteral("http://dajbych.net/adblock.txt"));
lst.insert(QStringLiteral("Cédrics Liste"), QStringLiteral("http://chewey.de/mozilla/data/adblock.txt"));
lst.insert(QStringLiteral("Fanboy's List"), QStringLiteral("http://www.fanboy.co.nz/adblock/fanboy-adblocklist-current-expanded.txt"));
lst.insert(QStringLiteral("hufilter"), QStringLiteral("http://pete.teamlupus.hu/hufilter.txt"));
lst.insert(QStringLiteral("Japanese Site-Specific Filter"), QStringLiteral("http://adblock-plus-japanese-filter.googlecode.com/svn/trunk/abp_jp_site_specific.txt"));
lst.insert(QStringLiteral("NLBlock"), QStringLiteral("http://www.verzijlbergh.com/adblock/nlblock.txt"));
lst.insert(QStringLiteral("PLgeneral"), QStringLiteral("http://www.niecko.pl/adblock/adblock.txt"));
lst.insert(QStringLiteral("Schacks Adblock Plus liste"), QStringLiteral("http://adblock.schack.dk/block.txt"));
lst.insert(QStringLiteral("Xfiles"), QStringLiteral("http://mozilla.gfsolone.com/filtri.txt"));
lst.insert(QStringLiteral("adblock.free.fr"), QStringLiteral("http://adblock.free.fr/adblock.txt"));
lst.insert(QStringLiteral("adblock.free.fr basic (bloque les pubs uniquement)"), QStringLiteral("http://adblock.free.fr/adblock_basic.txt"));
lst.insert(QStringLiteral("Ajnasz's list"), QStringLiteral("http://ajnasz.hu/adblock/recent"));
lst.insert(QStringLiteral("Schuzak's Universal Filter"), QStringLiteral("http://www.schuzak.jp/other/abp.txt"));
lst.insert(QStringLiteral("Rickroll Blacklist"), QStringLiteral("http://rickrolldb.com/ricklist.txt"));
return lst;
}
QString AdBlock::AdblockUtil::localFilterPath()
{
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/adblock/customlist.txt");
}
......@@ -45,6 +45,9 @@ public:
{
return index >= 0 && container.count() > index;
}
static QMap<QString, QString> listSubscriptions();
static QString localFilterPath();
};
}
#endif
......@@ -77,7 +77,7 @@ AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog()
void AdBlockAddSubscriptionDialog::initializeList(const QStringList &excludeList)
{
QMapIterator<QString, QString> i(AdBlock::AdBlockUtil::listSubscriptions());
QMapIterator<QString, QString> i(AdBlock::AdblockUtil::listSubscriptions());
while (i.hasNext()) {
i.next();
if (!excludeList.contains(i.key())) {
......
......@@ -98,7 +98,7 @@ void AdBlockBlockableItemsWidget::saveFilters()
{
qCWarning(ADBLOCKINTERCEPTOR_LOG) << " void AdBlockBlockableItemsWidget::saveFilters() unimplemented yet";
// local filters
const QString localRulesFilePath = AdBlock::AdBlockUtil::localFilterPath();
const QString localRulesFilePath = AdBlock::AdblockUtil::localFilterPath();
QFile ruleFile(localRulesFilePath);
if (!ruleFile.open(QFile::WriteOnly | QFile::Text | QFile::Append)) {
......
......@@ -229,7 +229,6 @@ void AdBlockSettingWidget::doLoadFromGlobalSettings()
// ------------------------------------------------------------------------------
// automatic filters
KConfig config(QStringLiteral("AdBlockadblockrc"));
//TODO load customlist !
for (AdBlockSubscription* subscription : AdblockManager::self()->subscriptions()) {
......@@ -253,43 +252,17 @@ void AdBlockSettingWidget::doLoadFromGlobalSettings()
}
}
const QStringList itemList = config.groupList().filter(QRegularExpression(QStringLiteral("FilterList \\d+")));
for (const QString &item : itemList) {
KConfigGroup filtersGroup(&config, item);
const bool isFilterEnabled = filtersGroup.readEntry(QStringLiteral("FilterEnabled"), false);
const QString url = filtersGroup.readEntry(QStringLiteral("url"));
const QString path = filtersGroup.readEntry(QStringLiteral("path"));
const QString name = filtersGroup.readEntry(QStringLiteral("name"));
const QDateTime lastUpdate = filtersGroup.readEntry(QStringLiteral("lastUpdate"), QDateTime());
if (url.isEmpty() || path.isEmpty() || name.isEmpty()) {
continue;
}
QListWidgetItem *subItem = new QListWidgetItem(mUi->automaticFiltersListWidget);
subItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
if (isFilterEnabled) {
subItem->setCheckState(Qt::Checked);
} else {
subItem->setCheckState(Qt::Unchecked);
}
subItem->setData(UrlList, url);
subItem->setData(PathList, path);
subItem->setText(name);
}
// ------------------------------------------------------------------------------
// local filters
const QString localRulesFilePath = AdBlock::AdBlockUtil::localFilterPath();
const QString localRulesFilePath = AdBlock::AdblockUtil::localFilterPath();
QFile ruleFile(localRulesFilePath);
if (!ruleFile.open(QFile::ReadOnly | QFile::Text)) {
qCDebug(ADBLOCKINTERCEPTOR_LOG) << "Unable to open rule file" << localRulesFilePath;
return;
}
KConfig config(QStringLiteral("AdBlockadblockrc"));
KConfigGroup grp = config.group(QStringLiteral("DisableRules"));
const QStringList disableRules = grp.readEntry("DisableRules", QStringList());
......@@ -338,7 +311,7 @@ void AdBlockSettingWidget::save()
config.sync();
// local filters
const QString localRulesFilePath = AdBlock::AdBlockUtil::localFilterPath();
const QString localRulesFilePath = AdBlock::AdblockUtil::localFilterPath();
QFile ruleFile(localRulesFilePath);
if (!ruleFile.open(QFile::WriteOnly | QFile::Text)) {
......
/*
Copyright (C) 2013-2018 Montel Laurent <montel@kde.org>
This program 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 2 of the License, or (at your option) any later version.
This program 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 this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "adblockutil.h"
#include <QStandardPaths>
QMap<QString, QString> AdBlock::AdBlockUtil::listSubscriptions()
{
QMap<QString, QString> lst;
lst.insert(QStringLiteral("EasyList"), QStringLiteral("https://easylist-downloads.adblockplus.org/easylist.txt"));
lst.insert(QStringLiteral("EasyList without element hiding"), QStringLiteral("https://easylist-downloads.adblockplus.org/easylist_noelemhide.txt"));
lst.insert(QStringLiteral("Corset"), QStringLiteral("http://brianyi.com/corset.txt"));
lst.insert(QStringLiteral("EasyList Germany"), QStringLiteral("https://easylist-downloads.adblockplus.org/easylistgermany.txt"));
lst.insert(QStringLiteral("Liste FR+EasyList"), QStringLiteral("https://easylist-downloads.adblockplus.org/liste_fr+easylist.txt"));
lst.insert(QStringLiteral("ROList+EasyList"), QStringLiteral("https://easylist-downloads.adblockplus.org/rolist+easylist.txt"));
lst.insert(QStringLiteral("AdblockList.org"), QStringLiteral("http://adblocklist.org/adblock-pxf-polish.txt"));
lst.insert(QStringLiteral("Bulgarian list"), QStringLiteral("http://stanev.org/abp/adblock_bg.txt"));
lst.insert(QStringLiteral("EasyPrivacy+EasyList"), QStringLiteral("https://easylist-downloads.adblockplus.org/easyprivacy+easylist.txt"));
lst.insert(QStringLiteral("EasyPrivacy"), QStringLiteral("https://easylist-downloads.adblockplus.org/easyprivacy.txt"));
lst.insert(QStringLiteral("void.gr"), QStringLiteral("http://www.void.gr/kargig/void-gr-filters.txt"));
lst.insert(QStringLiteral("BSI Lista Polska"), QStringLiteral("http://www.bsi.info.pl/filtrABP.txt"));
lst.insert(QStringLiteral("Czech List"), QStringLiteral("http://dajbych.net/adblock.txt"));
lst.insert(QStringLiteral("Cédrics Liste"), QStringLiteral("http://chewey.de/mozilla/data/adblock.txt"));
lst.insert(QStringLiteral("Fanboy's List"), QStringLiteral("http://www.fanboy.co.nz/adblock/fanboy-adblocklist-current-expanded.txt"));
lst.insert(QStringLiteral("hufilter"), QStringLiteral("http://pete.teamlupus.hu/hufilter.txt"));
lst.insert(QStringLiteral("Japanese Site-Specific Filter"), QStringLiteral("http://adblock-plus-japanese-filter.googlecode.com/svn/trunk/abp_jp_site_specific.txt"));
lst.insert(QStringLiteral("NLBlock"), QStringLiteral("http://www.verzijlbergh.com/adblock/nlblock.txt"));
lst.insert(QStringLiteral("PLgeneral"), QStringLiteral("http://www.niecko.pl/adblock/adblock.txt"));
lst.insert(QStringLiteral("Schacks Adblock Plus liste"), QStringLiteral("http://adblock.schack.dk/block.txt"));
lst.insert(QStringLiteral("Xfiles"), QStringLiteral("http://mozilla.gfsolone.com/filtri.txt"));
lst.insert(QStringLiteral("adblock.free.fr"), QStringLiteral("http://adblock.free.fr/adblock.txt"));
lst.insert(QStringLiteral("adblock.free.fr basic (bloque les pubs uniquement)"), QStringLiteral("http://adblock.free.fr/adblock_basic.txt"));
lst.insert(QStringLiteral("Ajnasz's list"), QStringLiteral("http://ajnasz.hu/adblock/recent"));
lst.insert(QStringLiteral("Schuzak's Universal Filter"), QStringLiteral("http://www.schuzak.jp/other/abp.txt"));
lst.insert(QStringLiteral("Rickroll Blacklist"), QStringLiteral("http://rickrolldb.com/ricklist.txt"));
return lst;
}
QString AdBlock::AdBlockUtil::localFilterPath()
{
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/adblock/adblockrules_local");
}
/*
Copyright (C) 2013-2018 Montel Laurent <montel@kde.org>
This program 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 2 of the License, or (at your option) any later version.
This program 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 this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef ADBLOCKUTIL_H
#define ADBLOCKUTIL_H
#include <QString>
#include <QMap>
namespace AdBlock {
namespace AdBlockUtil {
QMap<QString, QString> listSubscriptions();
QString localFilterPath();
}
}
#endif // ADBLOCKUTIL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment