summaryrefslogtreecommitdiff
path: root/rockwork/notificationsourcemodel.h
blob: 89fa26f0eee40cef951f0bd9d13ff8ee9e51fec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef NOTIFICATIONSOURCEMODEL_H
#define NOTIFICATIONSOURCEMODEL_H

#include <QAbstractListModel>

class NotificationSourceItem
{
public:
    QString m_id;
    QString m_displayName;
    QString m_icon;
    bool m_enabled = false;

    bool operator ==(const NotificationSourceItem &other) {
        return m_id == other.m_id;
    }
};

class NotificationSourceModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
    enum Roles {
        RoleName,
        RoleEnabled,
        RoleIcon
    };

    explicit NotificationSourceModel(QObject *parent = 0);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    QHash<int, QByteArray> roleNames() const override;

    void insert(const QString &sourceId, bool enabled);

signals:
    void countChanged();

private:
    NotificationSourceItem fromDesktopFile(const QString &sourceId);

private:
    QList<NotificationSourceItem> m_sources;
};

#endif // NOTIFICATIONSOURCEMODEL_H