From f7ed63179fa4f99322d6c7716e17466ec4e3e4ce Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 23 Dec 2017 16:45:31 +0100 Subject: Request filter now properly takes hostlists - hostslist directory is set in browser.filterPath --- src/filter/filtertree.cpp | 151 ---------------------------------------------- 1 file changed, 151 deletions(-) delete mode 100644 src/filter/filtertree.cpp (limited to 'src/filter/filtertree.cpp') diff --git a/src/filter/filtertree.cpp b/src/filter/filtertree.cpp deleted file mode 100644 index 73cc261..0000000 --- a/src/filter/filtertree.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: git://neueland.iserlohn-fortress.net/smolbote.git - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "filtertree.h" - -FilterTree::FilterTree(QObject *parent) : - QAbstractItemModel(parent) -{ - rootItem = new Filter("", "", Filter::ResourceRules(), false); -} - -FilterTree::~FilterTree() -{ - delete rootItem; -} - -QModelIndex FilterTree::index(int row, int column, const QModelIndex &parent) const -{ - if(!hasIndex(row, column, parent)) { - return QModelIndex(); - } - - Filter *parentItem; - if(!parent.isValid()) { - parentItem = rootItem; - } else { - parentItem = static_cast(parent.internalPointer()); - } - - Filter *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(); - } - - Filter *childItem = static_cast(index.internalPointer()); - Filter *parentItem = childItem->parentItem(); - - if(parentItem == rootItem) { - return QModelIndex(); - } - - return createIndex(parentItem->row(), 0, parentItem); -} - -int FilterTree::rowCount(const QModelIndex &parent) const -{ - Filter *parentItem; - if(parent.column() > 0) { - return 0; - } - - if(!parent.isValid()) { - parentItem = rootItem; - } else { - parentItem = static_cast(parent.internalPointer()); - } - - return parentItem->childCount(); -} - -int FilterTree::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent) - return 5; -} - -QVariant FilterTree::data(const QModelIndex &index, int role) const -{ - if(!index.isValid()) { - return QVariant(); - } - - if(role != Qt::DisplayRole) { - return QVariant(); - } - - Filter *n = static_cast(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(n->allowedTypes()); - case 4: // blocked types - return QVariant(n->blockedTypes()); - 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(); - } -} - -Filter *FilterTree::addFilter(const QString &domain, const QString &request, Filter::ResourceRules rules, bool shouldBlock) -{ - Filter *node = new Filter(domain, request, rules, shouldBlock, rootItem); - node->enable(); - rootItem->appendChild(node); - return node; -} - -QVector FilterTree::filters(const QString &domain) -{ - QVector nodes; - for(int i = 0; i < rootItem->childCount(); ++i) { - if(rootItem->child(i)->hasDomainMatch(domain)) { - nodes.append(rootItem->child(i)); - } - } - return nodes; -} -- cgit v1.2.1