File indexing completed on 2025-02-16 05:07:45
0001 /* 0002 SPDX-FileCopyrightText: 2014-2015 Sebastian Kügler <sebas@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef CUTTLEFISHICONMODEL_H 0008 #define CUTTLEFISHICONMODEL_H 0009 0010 #include <QAbstractListModel> 0011 #include <QFileInfo> 0012 #include <QJsonArray> 0013 #include <QJsonObject> 0014 #include <QVariantList> 0015 #include <QVariantMap> 0016 0017 namespace CuttleFish 0018 { 0019 class IconModel : public QAbstractListModel 0020 { 0021 Q_OBJECT 0022 0023 Q_PROPERTY(QStringList categories READ categories NOTIFY categoriesChanged) 0024 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0025 0026 public: 0027 enum Roles { 0028 FileName = Qt::UserRole + 1, 0029 IconName, 0030 Icon, 0031 FullPath, 0032 Category, 0033 Scalable, 0034 Sizes, 0035 Type, 0036 Theme, 0037 }; 0038 0039 explicit IconModel(QObject *parent = nullptr); 0040 0041 Q_INVOKABLE QVariantList inOtherThemes(const QString &iconName, int size); 0042 0043 QHash<int, QByteArray> roleNames() const override; 0044 int rowCount(const QModelIndex &parent) const override; 0045 QVariant data(const QModelIndex &index, int role) const override; 0046 0047 QString key(int role) const; 0048 0049 void add(const QFileInfo &info, const QString &cat); 0050 void remove(const QString &iconFile); 0051 0052 QStringList categories() const; 0053 0054 bool loading(); 0055 0056 void load(); 0057 0058 Q_INVOKABLE void output(const QString &text); 0059 0060 Q_INVOKABLE void openContainingFolder(const QString &filename); 0061 0062 Q_SIGNALS: 0063 void categoriesChanged(); 0064 void loadingChanged(); 0065 0066 private: 0067 QHash<int, QByteArray> m_roleNames; 0068 0069 QStringList m_icons; 0070 QStringList m_categories; 0071 QHash<QString, QVariantMap> m_data; 0072 QHash<QString, QString> m_categoryTranslations; 0073 0074 bool m_loading; 0075 QString categoryFromPath(const QString &path); 0076 }; 0077 0078 } // namespace 0079 0080 #endif // CUTTLEFISHICONMODEL_H