File indexing completed on 2024-04-21 05:45:02
0001 /*************************************************************************** 0002 * Copyright (C) 2010-2011 by Daniel Nicoletti * 0003 * dantti12@gmail.com * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; see the file COPYING. If not, write to * 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0018 * Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 #ifndef CATEGORY_MODEL_H 0022 #define CATEGORY_MODEL_H 0023 0024 #include <QObject> 0025 #include <QStandardItemModel> 0026 #include <QXmlStreamReader> 0027 0028 #include <Transaction> 0029 0030 #include <CategoryMatcher.h> 0031 0032 class CategoryModel : public QStandardItemModel 0033 { 0034 Q_OBJECT 0035 Q_ENUMS(Roles) 0036 public: 0037 typedef enum { 0038 SearchRole = Qt::UserRole, 0039 GroupRole, 0040 CategoryRole 0041 } Roles; 0042 explicit CategoryModel(QObject *parent = nullptr); 0043 ~CategoryModel() override; 0044 0045 void setRoles(PackageKit::Transaction::Roles roles); 0046 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 0047 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0048 void setRootIndex(const QModelIndex &index); 0049 bool setParentIndex(); 0050 bool hasParent() const; 0051 0052 Q_SIGNALS: 0053 void finished(); 0054 0055 private Q_SLOTS: 0056 void category(const QString &parentId, 0057 const QString &categoryId, 0058 const QString &name, 0059 const QString &summary, 0060 const QString &icon); 0061 0062 private: 0063 void fillWithStandardGroups(); 0064 void fillWithServiceGroups(); 0065 QStandardItem* findCategory(const QString &categoryId, const QModelIndex &parent = QModelIndex()) const; 0066 void parseMenu(QXmlStreamReader &xml, const QString &parentIcon, QStandardItem *parent = nullptr); 0067 QList<CategoryMatcher> parseCategories(QXmlStreamReader &xml); 0068 0069 PackageKit::Transaction::Roles m_roles; 0070 PackageKit::Transaction::Groups m_groups; 0071 QModelIndex m_rootIndex; 0072 }; 0073 0074 #endif