diff --git a/libdiscover/Category/CategoryModel.cpp b/libdiscover/Category/CategoryModel.cpp index 2e6835b5..ead0900c 100644 --- a/libdiscover/Category/CategoryModel.cpp +++ b/libdiscover/Category/CategoryModel.cpp @@ -1,103 +1,106 @@ /*************************************************************************** * Copyright © 2012 Aleix Pol Gonzalez * * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 . * ***************************************************************************/ // Own includes #include "CategoryModel.h" #include "Category.h" #include "CategoriesReader.h" #include #include #include #include CategoryModel::CategoryModel(QObject* parent) : QObject(parent) { connect(ResourcesModel::global(), &ResourcesModel::backendsChanged, this, &CategoryModel::populateCategories); } CategoryModel * CategoryModel::global() { static CategoryModel *instance = nullptr; if (!instance) { instance = new CategoryModel; } return instance; } void CategoryModel::populateCategories() { const auto backends = ResourcesModel::global()->backends(); QVector ret; CategoriesReader cr; Q_FOREACH (const auto backend, backends) { + if (!backend->isValid()) + continue; + const QVector cats = cr.loadCategoriesFile(backend); if(ret.isEmpty()) { ret = cats; } else { Q_FOREACH (Category* c, cats) Category::addSubcategory(ret, c); } } if (m_rootCategories != ret) { m_rootCategories = ret; Q_EMIT rootCategoriesChanged(); } } QVariantList CategoryModel::rootCategoriesVL() const { return kTransform(m_rootCategories, [](Category* cat) {return qVariantFromValue(cat); }); } void CategoryModel::blacklistPlugin(const QString &name) { const bool ret = Category::blacklistPluginsInVector({name}, m_rootCategories); if (ret) { Q_EMIT rootCategoriesChanged(); } } static Category* recFindCategory(Category* root, const QString& name) { if(root->name()==name) return root; else { const auto subs = root->subCategories(); Q_FOREACH (Category* c, subs) { Category* ret = recFindCategory(c, name); if(ret) return ret; } } return nullptr; } Category* CategoryModel::findCategoryByName(const QString& name) const { for (Category* cat: m_rootCategories) { Category* ret = recFindCategory(cat, name); if(ret) return ret; } return nullptr; }