File indexing completed on 2024-05-19 05:38:25

0001 /*
0002     SPDX-FileCopyrightText: 2020 Mikhail Zolotukhin <zomial@protonmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QAbstractListModel>
0010 #include <QMap>
0011 #include <QStringList>
0012 
0013 class QString;
0014 
0015 class GtkThemesModel : public QAbstractListModel
0016 {
0017     Q_OBJECT
0018 
0019     Q_PROPERTY(QString selectedTheme READ selectedTheme WRITE setSelectedTheme NOTIFY selectedThemeChanged)
0020 
0021 public:
0022     GtkThemesModel(QObject *parent = nullptr);
0023 
0024     enum Roles {
0025         ThemeNameRole = Qt::UserRole + 1,
0026         ThemePathRole,
0027     };
0028 
0029     void load();
0030 
0031     void setThemesList(const QMap<QString, QString> &themes);
0032     QMap<QString, QString> themesList();
0033 
0034     void setSelectedTheme(const QString &themeName);
0035     QString selectedTheme();
0036     Q_SIGNAL void selectedThemeChanged(const QString &themeName);
0037 
0038     Q_INVOKABLE bool selectedThemeRemovable();
0039     Q_INVOKABLE void removeSelectedTheme();
0040     Q_INVOKABLE int findThemeIndex(const QString &themeName);
0041     Q_INVOKABLE void setSelectedThemeDirty();
0042 
0043     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0044     QVariant data(const QModelIndex &index, int role = Roles::ThemeNameRole) const override;
0045     QHash<int, QByteArray> roleNames() const override;
0046 
0047     void requestThemesListUpdate();
0048 
0049 Q_SIGNALS:
0050     void themeRemoved();
0051 
0052 private:
0053     QStringList possiblePathsToThemes();
0054     QString themePath(const QString &themeName);
0055 
0056     QString m_selectedTheme;
0057     // mapping from theme name to theme path, ordered by name
0058     QMap<QString, QString> m_themes;
0059 };