File indexing completed on 2024-05-12 17:06:43

0001 /*
0002  * ThemeListModel
0003  * SPDX-FileCopyrightText: 2002 Karol Szwed <gallium@kde.org>
0004  * SPDX-FileCopyrightText: 2002 Daniel Molkentin <molkentin@kde.org>
0005  * SPDX-FileCopyrightText: 2007 Urs Wolfer <uwolfer @ kde.org>
0006  * SPDX-FileCopyrightText: 2009 Davide Bettio <davide.bettio@kdemail.net>
0007  * SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0008 
0009  * Portions SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0010  * Portions SPDX-FileCopyrightText: 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
0011  * Portions SPDX-FileCopyrightText: 2008 Petri Damsten <damu@iki.fi>
0012  * Portions SPDX-FileCopyrightText: 2000 TrollTech AS.
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-only
0015  */
0016 
0017 #ifndef THEMELISTMODEL_H
0018 #define THEMELISTMODEL_H
0019 
0020 #include <QAbstractListModel>
0021 
0022 namespace Plasma
0023 {
0024 class FrameSvg;
0025 }
0026 
0027 class ThemeInfo;
0028 
0029 class ThemeListModel : public QAbstractListModel
0030 {
0031     Q_OBJECT
0032 public:
0033     enum { PackageNameRole = Qt::UserRole, PluginNameRole = Qt::UserRole + 1, PackageDescriptionRole = Qt::UserRole + 2, PackageAuthorRole = Qt::UserRole + 3, PackageVersionRole = Qt::UserRole + 4, ColorTypeRole =  Qt::UserRole + 5 };
0034 
0035     enum ColorType {
0036         LightTheme,
0037         DarkTheme,
0038         FollowsColorTheme,
0039     };
0040 
0041     ThemeListModel(QObject *parent = nullptr);
0042     ~ThemeListModel() override;
0043 
0044     QHash<int, QByteArray> roleNames() const override;
0045 
0046     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0047     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0048     QModelIndex indexOf(const QString &path) const;
0049     void reload();
0050     void clearThemeList();
0051 
0052     Q_INVOKABLE QVariantMap get(int index) const;
0053 
0054 private:
0055     QHash<int, QByteArray> m_roleNames;
0056 
0057     QMap<QString, ThemeInfo> m_themes;
0058 };
0059 
0060 // Theme selector code by Andre Duffeck (modified to add package description)
0061 class ThemeInfo
0062 {
0063 public:
0064     QString package;
0065     QString pluginName;
0066     QString description;
0067     QString author;
0068     QString version;
0069     QString themeRoot;
0070     ThemeListModel::ColorType type;
0071 };
0072 
0073 #endif