File indexing completed on 2024-05-12 17:08:27

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: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0008  * SPDX-FileCopyrightText: 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
0009  * SPDX-FileCopyrightText: 2008 Petri Damsten <damu@iki.fi>
0010  * SPDX-FileCopyrightText: 2000 TrollTech AS.
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-only
0013  */
0014 
0015 #ifndef THEMELISTMODEL_H
0016 #define THEMELISTMODEL_H
0017 
0018 #include <QAbstractItemView>
0019 
0020 namespace Plasma
0021 {
0022 }
0023 
0024 // Theme selector code by Andre Duffeck (modified to add package description)
0025 class ThemeInfo
0026 {
0027 public:
0028     QString package;
0029     QString description;
0030     QString author;
0031     QString version;
0032     QString themeRoot;
0033 };
0034 
0035 class ThemeListModel : public QAbstractListModel
0036 {
0037     Q_OBJECT
0038     Q_PROPERTY(int count READ count NOTIFY countChanged)
0039 public:
0040     enum {
0041         PackageNameRole = Qt::UserRole,
0042         PackageDescriptionRole = Qt::UserRole + 1,
0043         PackageAuthorRole = Qt::UserRole + 2,
0044         PackageVersionRole = Qt::UserRole + 3,
0045     };
0046 
0047     explicit ThemeListModel(QObject *parent = nullptr);
0048     ~ThemeListModel() override;
0049 
0050     QHash<int, QByteArray> roleNames() const override;
0051 
0052     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0053     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0054     QModelIndex indexOf(const QString &path) const;
0055     void reload();
0056     void clearThemeList();
0057     int count() const
0058     {
0059         return rowCount();
0060     }
0061 
0062     Q_INVOKABLE QVariantMap get(int index) const;
0063 
0064 Q_SIGNALS:
0065     void countChanged();
0066 
0067 private:
0068     QHash<int, QByteArray> m_roleNames;
0069 
0070     QMap<QString, ThemeInfo> m_themes;
0071 };
0072 
0073 #endif