File indexing completed on 2024-03-24 17:01:59
0001 /* 0002 SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #pragma once 0007 0008 #include <QAbstractListModel> 0009 #include <qnamespace.h> 0010 0011 class KDirWatch; 0012 0013 struct ProfileData { 0014 QString name; 0015 QString profileIdentifier; 0016 QString iconName; 0017 }; 0018 0019 class ProfilesModel : public QAbstractListModel 0020 { 0021 Q_OBJECT 0022 Q_PROPERTY(QString appName READ appName WRITE setAppName NOTIFY appNameChanged) 0023 0024 public: 0025 explicit ProfilesModel(QObject *parent = nullptr); 0026 0027 enum Roles { 0028 NameRole = Qt::DisplayRole, 0029 ProfileIdentifierRole = Qt::UserRole, 0030 IconNameRole = Qt::DecorationRole, 0031 }; 0032 0033 QHash<int, QByteArray> roleNames() const override; 0034 QVariant data(const QModelIndex &index, int role) const override; 0035 Q_INVOKABLE void openProfile(const QString profileIdentifier); 0036 0037 int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const override 0038 { 0039 return m_data.size(); 0040 } 0041 0042 QString appName() const 0043 { 0044 return m_appName; 0045 } 0046 0047 void setAppName(const QString &name) 0048 { 0049 if (m_appName != name) { 0050 m_appName = name; 0051 init(); 0052 Q_EMIT appNameChanged(); 0053 } 0054 } 0055 0056 Q_SIGNALS: 0057 void appNameChanged(); 0058 0059 private: 0060 void init(); 0061 void loadProfiles(); 0062 0063 QString m_appName; 0064 KDirWatch *m_dirWatch = nullptr; 0065 QList<ProfileData> m_data; 0066 };