Warning, file /plasma/plasma-workspace/kcms/notifications/sourcesmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@privat.broulik.de>
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 <QAbstractItemModel>
0010 #include <QHash>
0011 #include <QString>
0012 #include <QVector>
0013 
0014 struct EventData {
0015     QString name;
0016     QString comment;
0017     QString iconName;
0018     QString eventId;
0019     QStringList actions;
0020 };
0021 
0022 // FIXME add constructors for KService and KConfigGroup
0023 struct SourceData {
0024     QString name;
0025     QString comment;
0026     QString iconName;
0027     bool isDefault;
0028 
0029     QString notifyRcName;
0030     QString desktopEntry;
0031 
0032     QVector<EventData> events;
0033 
0034     QString display() const
0035     {
0036         return !name.isEmpty() ? name : comment;
0037     }
0038 };
0039 
0040 class SourcesModel : public QAbstractItemModel
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     SourcesModel(QObject *parent = nullptr);
0046     ~SourcesModel() override;
0047 
0048     enum Roles {
0049         SourceTypeRole = Qt::UserRole + 1,
0050         NotifyRcNameRole,
0051         DesktopEntryRole,
0052         IsDefaultRole,
0053 
0054         EventIdRole,
0055         ActionsRole,
0056     };
0057     Q_ENUM(Roles)
0058 
0059     enum Type {
0060         ApplicationType,
0061         ServiceType,
0062     };
0063     Q_ENUM(Type)
0064 
0065     Q_INVOKABLE QPersistentModelIndex makePersistentModelIndex(const QModelIndex &idx) const;
0066 
0067     Q_INVOKABLE QPersistentModelIndex persistentIndexForDesktopEntry(const QString &desktopEntry) const;
0068     Q_INVOKABLE QPersistentModelIndex persistentIndexForNotifyRcName(const QString &notifyRcName) const;
0069 
0070     int columnCount(const QModelIndex &parent) const override;
0071     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0072 
0073     QVariant data(const QModelIndex &index, int role) const override;
0074     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0075 
0076     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0077     QModelIndex parent(const QModelIndex &child) const override;
0078 
0079     QHash<int, QByteArray> roleNames() const override;
0080 
0081     Q_INVOKABLE void load();
0082 
0083 private:
0084     QVector<SourceData> m_data;
0085 };