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

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