aboutsummaryrefslogtreecommitdiff
path: root/src/blocker
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-05-25 20:59:43 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2017-05-25 20:59:43 +0200
commit1143429887f61d8b3c74a4c3a1fafca632eb4b87 (patch)
tree87e03b38241afb33c1e7dc70c299bfb824533429 /src/blocker
parentMerged FilterRule into FilterNode (diff)
downloadsmolbote-1143429887f61d8b3c74a4c3a1fafca632eb4b87.tar.xz
Filter code refactoring
Diffstat (limited to 'src/blocker')
-rw-r--r--src/blocker/blockermanager.cpp53
-rw-r--r--src/blocker/blockermanager.h46
-rw-r--r--src/blocker/filtercollection.cpp163
-rw-r--r--src/blocker/filtercollection.h61
-rw-r--r--src/blocker/filternode.cpp168
-rw-r--r--src/blocker/filternode.h103
-rw-r--r--src/blocker/filtertree.cpp160
-rw-r--r--src/blocker/filtertree.h51
-rw-r--r--src/blocker/regexp.cpp72
-rw-r--r--src/blocker/regexp.h38
-rw-r--r--src/blocker/subscriptiondialog.ui67
-rw-r--r--src/blocker/subscriptionform.ui125
12 files changed, 0 insertions, 1107 deletions
diff --git a/src/blocker/blockermanager.cpp b/src/blocker/blockermanager.cpp
deleted file mode 100644
index ee30b65..0000000
--- a/src/blocker/blockermanager.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#include "blockermanager.h"
-#include "ui_subscriptiondialog.h"
-
-#include "browser.h"
-#include <QLabel>
-#include <QListWidget>
-
-#include "blocker/filtercollection.h"
-
-BlockerManager::BlockerManager(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::UrlInterceptorDialog)
-{
- ui->setupUi(this);
-
- const QStringList subscriptions = sSettings->value("blocker.subscriptions").toStringList();
- QStringList::const_iterator i;
- for(i = subscriptions.constBegin(); i != subscriptions.constEnd(); ++i) {
- FilterCollection *sub = new FilterCollection(QString(*i), this);
- m_subscriptions.append(sub);
- ui->tabWidget->addTab(sub, sub->name());
- }
-}
-
-BlockerManager::~BlockerManager()
-{
- delete ui;
-}
-
-QVector<FilterCollection *> BlockerManager::subscriptions() const
-{
- return m_subscriptions;
-}
diff --git a/src/blocker/blockermanager.h b/src/blocker/blockermanager.h
deleted file mode 100644
index cfa2110..0000000
--- a/src/blocker/blockermanager.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#ifndef URLINTERCEPTORDIALOG_H
-#define URLINTERCEPTORDIALOG_H
-
-#include <QDialog>
-
-namespace Ui {
-class UrlInterceptorDialog;
-}
-
-class FilterCollection;
-class BlockerManager : public QDialog
-{
- Q_OBJECT
-
-public:
- explicit BlockerManager(QWidget *parent = 0);
- ~BlockerManager();
-
- QVector<FilterCollection* > subscriptions() const;
-
-private:
- Ui::UrlInterceptorDialog *ui;
- QVector<FilterCollection *> m_subscriptions;
-};
-
-#endif // URLINTERCEPTORDIALOG_H
diff --git a/src/blocker/filtercollection.cpp b/src/blocker/filtercollection.cpp
deleted file mode 100644
index 935776c..0000000
--- a/src/blocker/filtercollection.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#include "filtercollection.h"
-#include "ui_subscriptionform.h"
-
-#include "browser.h"
-#include <QNetworkRequest>
-#include <QNetworkReply>
-
-#include <QJsonDocument>
-#include <QJsonObject>
-#include <QJsonArray>
-
-#include <QListWidget>
-#include <QLabel>
-
-#include <QTreeView>
-#include "filtertree.h"
-#include "filternode.h"
-
-FilterCollection::FilterCollection(const QString path, QWidget *parent) :
- QWidget(parent),
- ui(new Ui::SubscriptionForm)
-{
- ui->setupUi(this);
-
- ui->homepage->setText(path);
-
- qDebug("Adding subscription [%s]", qUtf8Printable(path));
-
- m_filters = new FilterTree(this);
- ui->treeView->setModel(m_filters);
-
- QFile filterFile(path);
- if(!filterFile.open(QIODevice::ReadOnly)) {
- qWarning("Could not open filter!");
- return;
- }
-
- QJsonDocument filters(QJsonDocument::fromJson(filterFile.readAll()));
- load(filters.object());
-
- qDebug("Added %i rules", m_filters->columnCount());
-}
-
-FilterCollection::~FilterCollection()
-{
- delete ui;
-}
-
-QString FilterCollection::name() const
-{
- return ui->title->text();
-}
-
-/**
- * Check if a URL request should be blocked or not
- * @param info
- * @return true if it should be blocked; false otherwise
- */
-FilterCollection::MatchResult FilterCollection::match(QWebEngineUrlRequestInfo &info)
-{
- MatchResult result;
-
- for(FilterNode *rule : m_filters->filters(info.firstPartyUrl().toString())) {
- if(rule->isValid()) {
- result.match = rule->hasMatch(info);
- if(result.match) {
- result.block = rule->shouldBlock(info);
- } else {
- result.block = false;
- }
- result.pattern = rule->domain() + " | " + rule->request();
- return result;
- }
- }
-
- // request matches neither whitelist nor blacklist
- result.match = false;
- result.block = false;
- return result;
-}
-
-void FilterCollection::load(const QJsonObject &json)
-{
- ui->title->setText(json["name"].toString());
- ui->homepage->setText(json["url"].toString());
-
- for(QJsonValue v : json["rules"].toArray()) {
- QJsonObject obj = v.toObject();
-
- FilterNode::ResourceRules r;
- r.allowed = parseJsonRules(obj["allowTypes"]);
- r.blocked = parseJsonRules(obj["blockTypes"]);
-
- m_filters->addFilter(obj["firstPartyUrl"].toString(), obj["requestUrl"].toString(), r, obj["shouldBlock"].toBool());
- }
-}
-
-FilterNode::Resources FilterCollection::parseJsonRules(const QJsonValue &obj)
-{
- FilterNode::Resources res;
- for(QJsonValue v : obj.toArray()) {
- QString t = v.toString();
- if(t == "MainFrame") {
- res.setFlag(FilterNode::ResourceType::MainFrame);
- } else if(t == "SubFrame") {
- res.setFlag(FilterNode::ResourceType::SubFrame);
- } else if(t == "Stylesheet") {
- res.setFlag(FilterNode::ResourceType::Stylesheet);
- } else if(t == "Script") {
- res.setFlag(FilterNode::ResourceType::Script);
- } else if(t == "Image") {
- res.setFlag(FilterNode::ResourceType::Image);
- } else if(t == "FontResource") {
- res.setFlag(FilterNode::ResourceType::FontResource);
- } else if(t == "SubResource") {
- res.setFlag(FilterNode::ResourceType::SubResource);
- } else if(t == "Object") {
- res.setFlag(FilterNode::ResourceType::Object);
- } else if(t == "Media") {
- res.setFlag(FilterNode::ResourceType::Media);
- } else if(t == "Worker") {
- res.setFlag(FilterNode::ResourceType::Worker);
- } else if(t == "SharedWorker") {
- res.setFlag(FilterNode::ResourceType::SharedWorker);
- } else if(t == "Prefetch") {
- res.setFlag(FilterNode::ResourceType::Prefetch);
- } else if(t == "Favicon") {
- res.setFlag(FilterNode::ResourceType::Favicon);
- } else if(t == "Xhr") {
- res.setFlag(FilterNode::ResourceType::Xhr);
- } else if(t == "Ping") {
- res.setFlag(FilterNode::ResourceType::Ping);
- } else if(t == "ServiceWorker") {
- res.setFlag(FilterNode::ResourceType::ServiceWorker);
- } else if(t == "CspWorker") {
- res.setFlag(FilterNode::ResourceType::CspReport);
- } else if(t == "PluginResource") {
- res.setFlag(FilterNode::ResourceType::PluginResource);
- }
- }
-
- return res;
-}
diff --git a/src/blocker/filtercollection.h b/src/blocker/filtercollection.h
deleted file mode 100644
index 4059ff1..0000000
--- a/src/blocker/filtercollection.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#ifndef SUBSCRIPTIONFORM_H
-#define SUBSCRIPTIONFORM_H
-
-#include <QWidget>
-#include <QFile>
-#include "filtertree.h"
-
-namespace Ui {
-class SubscriptionForm;
-}
-
-class FilterCollection : public QWidget
-{
- Q_OBJECT
-
-public:
- struct MatchResult {
- bool match;
- bool block;
- QString pattern;
- };
-
- explicit FilterCollection(const QString path, QWidget *parent = 0);
- ~FilterCollection();
-
- QString name() const;
- MatchResult match(QWebEngineUrlRequestInfo &info);
-
-private slots:
- void load(const QJsonObject &json);
-
-private:
- FilterNode::Resources parseJsonRules(const QJsonValue &obj);
-
- Ui::SubscriptionForm *ui;
-
- FilterTree *m_filters;
-
-};
-
-#endif // SUBSCRIPTIONFORM_H
diff --git a/src/blocker/filternode.cpp b/src/blocker/filternode.cpp
deleted file mode 100644
index 67614ce..0000000
--- a/src/blocker/filternode.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#include "filternode.h"
-
-FilterNode::FilterNode(const QString &domain, const QString &request, ResourceRules rules, bool shouldBlock, FilterNode *parentItem)
-{
- m_parentItem = parentItem;
-
- m_domainUrl.setPattern(domain);
- m_requestUrl.setPattern(request);
- m_rules = rules;
- m_shouldBlock = shouldBlock;
-
- m_valid = false;
-
-#ifdef DEBUG_VERBOSE
- qDebug("Created rule [%s] [%s]", qUtf8Printable(domain), qUtf8Printable(request));
-#endif
-}
-
-FilterNode::~FilterNode()
-{
- qDeleteAll(m_children);
-}
-
-void FilterNode::enable()
-{
- m_valid = true;
-}
-
-FilterNode *FilterNode::parentItem()
-{
- return m_parentItem;
-}
-
-void FilterNode::appendChild(FilterNode *child)
-{
- m_children.append(child);
-}
-
-FilterNode *FilterNode::child(int row)
-{
- return m_children.value(row);
-}
-
-int FilterNode::childCount() const
-{
- return m_children.count();
-}
-
-QString FilterNode::domain() const
-{
- return m_domainUrl.pattern();
-}
-
-QString FilterNode::request() const
-{
- return m_requestUrl.pattern();
-}
-
-bool FilterNode::isBlocking()
-{
- return m_shouldBlock;
-}
-
-int FilterNode::row() const
-{
- if(m_parentItem) {
- return m_parentItem->m_children.indexOf(const_cast<FilterNode*>(this));
- }
-
- return 0;
-}
-
-bool FilterNode::hasMatch(const QWebEngineUrlRequestInfo &info)
-{
- if(m_domainUrl.hasMatch(info.firstPartyUrl().toString()) && m_requestUrl.hasMatch(info.requestUrl().toString())) {
- return true;
- } else {
- return false;
- }
-}
-
-bool FilterNode::shouldBlock(const QWebEngineUrlRequestInfo &info)
-{
- if(!m_valid) {
- return false;
- }
-
- // Check options
- switch (info.resourceType()) {
- case QWebEngineUrlRequestInfo::ResourceTypeMainFrame:
- return testFlag(MainFrame);
- case QWebEngineUrlRequestInfo::ResourceTypeSubFrame:
- return testFlag(SubFrame);
- case QWebEngineUrlRequestInfo::ResourceTypeStylesheet:
- return testFlag(Stylesheet);
- case QWebEngineUrlRequestInfo::ResourceTypeScript:
- return testFlag(Script);
- case QWebEngineUrlRequestInfo::ResourceTypeImage:
- return testFlag(Image);
- case QWebEngineUrlRequestInfo::ResourceTypeFontResource:
- return testFlag(FontResource);
- case QWebEngineUrlRequestInfo::ResourceTypeSubResource:
- return testFlag(SubResource);
- case QWebEngineUrlRequestInfo::ResourceTypeObject:
- return testFlag(Object);
- case QWebEngineUrlRequestInfo::ResourceTypeMedia:
- return testFlag(Media);
- case QWebEngineUrlRequestInfo::ResourceTypeWorker:
- return testFlag(Worker);
- case QWebEngineUrlRequestInfo::ResourceTypeSharedWorker:
- return testFlag(SharedWorker);
- case QWebEngineUrlRequestInfo::ResourceTypePrefetch:
- return testFlag(Prefetch);
- case QWebEngineUrlRequestInfo::ResourceTypeFavicon:
- return testFlag(Favicon);
- case QWebEngineUrlRequestInfo::ResourceTypeXhr:
- return testFlag(Xhr);
- case QWebEngineUrlRequestInfo::ResourceTypePing:
- return testFlag(Ping);
- case QWebEngineUrlRequestInfo::ResourceTypeServiceWorker:
- return testFlag(ServiceWorker);
- case QWebEngineUrlRequestInfo::ResourceTypeCspReport:
- return testFlag(CspReport);
- case QWebEngineUrlRequestInfo::ResourceTypePluginResource:
- return testFlag(PluginResource);
- case QWebEngineUrlRequestInfo::ResourceTypeUnknown:
- break;
- }
-
- return m_shouldBlock;
-
-}
-
-bool FilterNode::isValid()
-{
- return m_valid;
-}
-
-bool FilterNode::testFlag(ResourceType flag)
-{
- if(m_rules.allowed.testFlag(flag)) {
- return false;
- } else if(m_rules.blocked.testFlag(flag)) {
- return true;
- } else {
- return m_shouldBlock;
- }
-}
diff --git a/src/blocker/filternode.h b/src/blocker/filternode.h
deleted file mode 100644
index e580383..0000000
--- a/src/blocker/filternode.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#ifndef FILTERNODE_H
-#define FILTERNODE_H
-
-#include <QList>
-#include <QVariant>
-#include <QUrl>
-#include "regexp.h"
-#include <QWebEngineUrlRequestInfo>
-
-class FilterNode
-{
-public:
-
- enum ResourceType {
- NoType = 0,
- MainFrame = 1,
- SubFrame = 2,
- Stylesheet = 4,
- Script = 8,
- Image = 16,
- FontResource = 32,
- SubResource = 64,
- Object = 128,
- Media = 256,
- Worker = 512,
- SharedWorker = 1024,
- Prefetch = 2048,
- Favicon = 4096,
- Xhr = 8192,
- Ping = 16384,
- ServiceWorker = 32768,
- CspReport = 65536,
- PluginResource = 131072,
- Unknown = 262144
- };
- Q_DECLARE_FLAGS(Resources, ResourceType)
-
- struct ResourceRules {
- Resources allowed;
- Resources blocked;
- };
-
- explicit FilterNode(const QString &domain, const QString &request, ResourceRules rules, bool shouldBlock, FilterNode *parentItem = 0);
- ~FilterNode();
-
- void enable();
-
- FilterNode *parentItem();
-
- // children
- void appendChild(FilterNode *child);
- FilterNode *child(int row);
- int childCount() const;
-
- // data
- QString domain() const;
- QString request() const;
- bool isBlocking();
-
- int row() const;
-
- // filtering
- bool hasMatch(const QWebEngineUrlRequestInfo &info);
- bool shouldBlock(const QWebEngineUrlRequestInfo &info);
-
- bool isValid();
-
-private:
- bool testFlag(ResourceType flag);
-
- FilterNode *m_parentItem;
- QList<FilterNode*> m_children;
-
- RegExp m_domainUrl;
- RegExp m_requestUrl;
-
- ResourceRules m_rules;
-
- bool m_valid = false;
- bool m_shouldBlock;
-};
-
-#endif // FILTERNODE_H
diff --git a/src/blocker/filtertree.cpp b/src/blocker/filtertree.cpp
deleted file mode 100644
index e264015..0000000
--- a/src/blocker/filtertree.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#include "filtertree.h"
-
-FilterTree::FilterTree(QObject *parent) :
- QAbstractItemModel(parent)
-{
- rootItem = new FilterNode("", "", FilterNode::ResourceRules(), false);
-}
-
-FilterTree::~FilterTree()
-{
- delete rootItem;
-}
-
-QModelIndex FilterTree::index(int row, int column, const QModelIndex &parent) const
-{
- if(!hasIndex(row, column, parent)) {
- return QModelIndex();
- }
-
- FilterNode *parentItem;
- if(!parent.isValid()) {
- parentItem = rootItem;
- } else {
- parentItem = static_cast<FilterNode*>(parent.internalPointer());
- }
-
- FilterNode *childItem = parentItem->child(row);
- if(childItem) {
- return createIndex(row, column, childItem);
- } else {
- return QModelIndex();
- }
-}
-
-QModelIndex FilterTree::parent(const QModelIndex &index) const
-{
- if(!index.isValid()) {
- return QModelIndex();
- }
-
- FilterNode *childItem = static_cast<FilterNode*>(index.internalPointer());
- FilterNode *parentItem = childItem->parentItem();
-
- if(parentItem == rootItem) {
- return QModelIndex();
- }
-
- return createIndex(parentItem->row(), 0, parentItem);
-}
-
-int FilterTree::rowCount(const QModelIndex &parent) const
-{
- FilterNode *parentItem;
- if(parent.column() > 0) {
- return 0;
- }
-
- if(!parent.isValid()) {
- parentItem = rootItem;
- } else {
- parentItem = static_cast<FilterNode*>(parent.internalPointer());
- }
-
- return parentItem->childCount();
-}
-
-int FilterTree::columnCount(const QModelIndex &parent) const
-{
- return 5;
-}
-
-QVariant FilterTree::data(const QModelIndex &index, int role) const
-{
- if(!index.isValid()) {
- return QVariant();
- }
-
- if(role != Qt::DisplayRole) {
- return QVariant();
- }
-
- FilterNode *n = static_cast<FilterNode*>(index.internalPointer());
- switch (index.column()) {
- case 0: // domain
- return QVariant(n->domain());
- case 1: // request
- return QVariant(n->request());
- case 2: // should block
- return QVariant(n->isBlocking() ? "true" : "false");
- case 3: // allowed types
- return QVariant("---");
- case 4: // blocked types
- return QVariant("---");
- default:
- return QVariant();
- }
-}
-
-QVariant FilterTree::headerData(int section, Qt::Orientation orientation, int role) const
-{
- if(orientation != Qt::Horizontal) {
- return QVariant();
- }
-
- if(role != Qt::DisplayRole) {
- return QVariant();
- }
-
- switch (section) {
- case 0:
- return QVariant(tr("Domain"));
- case 1:
- return QVariant(tr("Request"));
- case 2:
- return QVariant(tr("Should Block"));
- case 3:
- return QVariant(tr("Allowed Types"));
- case 4:
- return QVariant(tr("Blocked Types"));
- default:
- return QVariant();
- }
-}
-
-FilterNode *FilterTree::addFilter(const QString &domain, const QString &request, FilterNode::ResourceRules rules, bool shouldBlock)
-{
- FilterNode *node = new FilterNode(domain, request, rules, shouldBlock, rootItem);
- node->enable();
- rootItem->appendChild(node);
- return node;
-}
-
-QVector<FilterNode*> FilterTree::filters(const QString &domain)
-{
- QVector<FilterNode*> nodes;
- for(int i = 0; i < rootItem->childCount(); ++i) {
- nodes.append(rootItem->child(i));
- }
- return nodes;
-}
diff --git a/src/blocker/filtertree.h b/src/blocker/filtertree.h
deleted file mode 100644
index 0bae0e0..0000000
--- a/src/blocker/filtertree.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#ifndef FILTERTREE_H
-#define FILTERTREE_H
-
-#include <QAbstractItemModel>
-#include <QModelIndex>
-#include <QVariant>
-#include "filternode.h"
-
-class FilterTree : public QAbstractItemModel
-{
- Q_OBJECT
-
-public:
- explicit FilterTree(QObject *parent = 0);
- ~FilterTree();
-
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
- QModelIndex parent(const QModelIndex &index) const override;
- int rowCount(const QModelIndex &parent = QModelIndex()) const override;
- int columnCount(const QModelIndex &parent = QModelIndex()) const override;
- QVariant data(const QModelIndex &index, int role) const override;
- QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
-
- FilterNode *addFilter(const QString &domain, const QString &request, FilterNode::ResourceRules rules, bool shouldBlock);
- QVector<FilterNode*> filters(const QString &domain = "");
-
-private:
- FilterNode *rootItem;
-};
-
-#endif // FILTERTREE_H
diff --git a/src/blocker/regexp.cpp b/src/blocker/regexp.cpp
deleted file mode 100644
index 1f3c449..0000000
--- a/src/blocker/regexp.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#include "regexp.h"
-
-RegExp::RegExp(const QString &pattern, PatternOptions options) :
- QRegularExpression()
-{
- setPattern(pattern);
- setPatternOptions(options);
-}
-
-bool RegExp::hasMatch(const QString &subject, int offset, MatchType matchType, MatchOptions matchOptions) const
-{
- // Empty matches all
- if(pattern().isEmpty()) {
- return true;
- }
-
- return QRegularExpression::match(subject, offset, matchType, matchOptions).hasMatch();
-}
-
-void RegExp::setWildcardPattern(const QString &pattern)
-{
- QString parsed;
-
- for(int i=0; i<pattern.length(); i++) {
- const QChar c = pattern.at(i);
- switch (c.toLatin1()) {
- case '*':
- // remove * at the start and end
- if(i != 0 && i != pattern.length()-1) {
- parsed.append(".*");
- }
- break;
- case '^':
- parsed.append("(?:[^\\w\\d\\_\\-\\.\\%]|$)");
- break;
- case '|':
- if(i == 0) {
- // beginning of string
- parsed.append('^');
- } else {
- // end of string
- parsed.append('$');
- }
- break;
- default:
- parsed.append(c);
- break;
- }
- }
-
- setPattern(parsed);
-}
diff --git a/src/blocker/regexp.h b/src/blocker/regexp.h
deleted file mode 100644
index 86cedfd..0000000
--- a/src/blocker/regexp.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- **
- ** smolbote: yet another qute browser
- ** Copyright (C) 2017 Xian Nox
- **
- ** 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 3 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. If not, see <http://www.gnu.org/licenses/>.
- **
- ******************************************************************************/
-
-#ifndef REGEXP_H
-#define REGEXP_H
-
-#include <QRegularExpression>
-
-/*!
- * Regular Expression class for AdBlockPlus filters
- */
-class RegExp : public QRegularExpression
-{
-public:
- explicit RegExp(const QString &pattern = "", PatternOptions options = NoPatternOption);
-
- bool hasMatch(const QString &subject, int offset=0, MatchType matchType=NormalMatch, MatchOptions matchOptions=NoMatchOption) const;
- void setWildcardPattern(const QString &pattern);
-};
-
-#endif // REGEXP_H
diff --git a/src/blocker/subscriptiondialog.ui b/src/blocker/subscriptiondialog.ui
deleted file mode 100644
index 7a63cc9..0000000
--- a/src/blocker/subscriptiondialog.ui
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>UrlInterceptorDialog</class>
- <widget class="QDialog" name="UrlInterceptorDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>640</width>
- <height>480</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Blocker</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QTabWidget" name="tabWidget"/>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Close</set>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>UrlInterceptorDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel">
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>UrlInterceptorDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel">
- <x>316</x>
- <y>260</y>
- </hint>
- <hint type="destinationlabel">
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/src/blocker/subscriptionform.ui b/src/blocker/subscriptionform.ui
deleted file mode 100644
index 0a20582..0000000
--- a/src/blocker/subscriptionform.ui
+++ /dev/null
@@ -1,125 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>SubscriptionForm</class>
- <widget class="QWidget" name="SubscriptionForm">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>640</width>
- <height>480</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Form</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>Subscription</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <layout class="QFormLayout" name="leftFormLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="title_label">
- <property name="text">
- <string>Title</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLabel" name="title">
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="homepage_label">
- <property name="text">
- <string>Homepage</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLabel" name="homepage">
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="license_label">
- <property name="text">
- <string>License</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QLabel" name="license">
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QFormLayout" name="rightFormLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="version_label">
- <property name="text">
- <string>Version</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLabel" name="version">
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="lastModified_label">
- <property name="text">
- <string>Last Modified</string>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLabel" name="lastModified">
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="expires_label">
- <property name="text">
- <string>Expires</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QLabel" name="expires">
- <property name="text">
- <string>TextLabel</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QTreeView" name="treeView"/>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>