aboutsummaryrefslogtreecommitdiff
path: root/src/blocker/filtertree.cpp
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/filtertree.cpp
parentMerged FilterRule into FilterNode (diff)
downloadsmolbote-1143429887f61d8b3c74a4c3a1fafca632eb4b87.tar.xz
Filter code refactoring
Diffstat (limited to 'src/blocker/filtertree.cpp')
-rw-r--r--src/blocker/filtertree.cpp160
1 files changed, 0 insertions, 160 deletions
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;
-}