File indexing completed on 2024-05-19 16:39:55
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef THEMEMODEL_H 0008 #define THEMEMODEL_H 0009 0010 #include <QAbstractListModel> 0011 #include <QJsonArray> 0012 #include <QJsonDocument> 0013 #include <QJsonObject> 0014 #include <kpackage/package.h> 0015 0016 namespace Plasma 0017 { 0018 class Theme; 0019 } 0020 0021 class ThemeListModel; 0022 class ColorEditor; 0023 0024 class ThemeModel : public QAbstractListModel 0025 { 0026 Q_OBJECT 0027 0028 Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) 0029 Q_PROPERTY(ThemeListModel *themeList READ themeList CONSTANT) 0030 Q_PROPERTY(ColorEditor *colorEditor READ colorEditor CONSTANT) 0031 0032 Q_PROPERTY(QString author READ author NOTIFY themeChanged) 0033 Q_PROPERTY(QString email READ email NOTIFY themeChanged) 0034 Q_PROPERTY(QString license READ license NOTIFY themeChanged) 0035 Q_PROPERTY(QString website READ website NOTIFY themeChanged) 0036 0037 Q_PROPERTY(QString themeFolder READ themeFolder NOTIFY themeChanged) 0038 public: 0039 enum Roles { 0040 ImagePath, 0041 Description, 0042 Delegate, 0043 UsesFallback, 0044 SvgAbsolutePath, 0045 IsWritable, 0046 IconElements, 0047 FrameSvgPrefixes, 0048 }; 0049 0050 explicit ThemeModel(const KPackage::Package &package, QObject *parent = nullptr); 0051 ~ThemeModel() override; 0052 0053 ThemeListModel *themeList(); 0054 ColorEditor *colorEditor(); 0055 0056 QHash<int, QByteArray> roleNames() const override; 0057 int rowCount(const QModelIndex &parent) const override; 0058 QVariant data(const QModelIndex &index, int role) const override; 0059 0060 void setTheme(const QString &theme); 0061 QString theme() const; 0062 0063 QString author() const; 0064 QString email() const; 0065 QString license() const; 0066 QString website() const; 0067 0068 void load(); 0069 0070 Q_INVOKABLE void editElement(const QString &imagePath); 0071 Q_INVOKABLE void editThemeMetaData(const QString &name, const QString &author, const QString &email, const QString &license, const QString &website); 0072 Q_INVOKABLE void createNewTheme(const QString &name, const QString &author, const QString &email, const QString &license, const QString &website); 0073 0074 QString themeFolder(); 0075 0076 Q_SIGNALS: 0077 void themeChanged(); 0078 0079 private Q_SLOTS: 0080 void processFinished(); 0081 0082 private: 0083 QHash<int, QByteArray> m_roleNames; 0084 0085 Plasma::Theme *m_theme; 0086 QString m_themeName; 0087 KPackage::Package m_package; 0088 QJsonDocument m_jsonDoc; 0089 ThemeListModel *m_themeListModel; 0090 ColorEditor *m_colorEditor; 0091 }; 0092 0093 #endif // THEMEMODEL_H