Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4ba1a3de authored by Laurent Montel's avatar Laurent Montel 😁

Add more code for loading list

parent e1f16819
......@@ -21,6 +21,8 @@
#include "adblockmatcher.h"
#include "adblocksubscription.h"
#include "globalsettings_webengineurlinterceptoradblock.h"
#include <QDir>
#include <QTextStream>
#include <QUrl>
using namespace AdBlock;
......@@ -40,6 +42,7 @@ AdblockManager::AdblockManager(QObject *parent)
AdblockManager::~AdblockManager()
{
qDeleteAll(mSubscriptions);
}
void AdblockManager::reloadConfig()
......@@ -52,7 +55,51 @@ void AdblockManager::reloadConfig()
void AdblockManager::loadSubscriptions()
{
//Clear subscription
qDeleteAll(mSubscriptions);
mSubscriptions.clear();
#if 0
QDir adblockDir(DataPaths::currentProfilePath() + "/adblock");
// Create if neccessary
if (!adblockDir.exists()) {
QDir(DataPaths::currentProfilePath()).mkdir("adblock");
}
foreach (const QString &fileName, adblockDir.entryList(QStringList("*.txt"), QDir::Files)) {
if (fileName == QLatin1String("customlist.txt")) {
continue;
}
const QString absolutePath = adblockDir.absoluteFilePath(fileName);
QFile file(absolutePath);
if (!file.open(QFile::ReadOnly)) {
continue;
}
QTextStream textStream(&file);
textStream.setCodec("UTF-8");
QString title = textStream.readLine(1024).remove(QLatin1String("Title: "));
QUrl url = QUrl(textStream.readLine(1024).remove(QLatin1String("Url: ")));
if (title.isEmpty() || !url.isValid()) {
qWarning() << "AdBlockManager: Invalid subscription file" << absolutePath;
continue;
}
AdBlockSubscription* subscription = new AdBlockSubscription(title, this);
subscription->setUrl(url);
subscription->setFilePath(absolutePath);
mSubscriptions.append(subscription);
}
#endif
// Prepend EasyList if subscriptions are empty
if (mSubscriptions.isEmpty()) {
// AdBlockSubscription* easyList = new AdBlockSubscription(tr("EasyList"), this);
// easyList->setUrl(QUrl(ADBLOCK_EASYLIST_URL));
// easyList->setFilePath(DataPaths::currentProfilePath() + QLatin1String("/adblock/easylist.txt"));
// mSubscriptions.prepend(easyList);
}
//TODO load it
// new AdBlockSubscription(...);
......
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