Changeset View
Changeset View
Standalone View
Standalone View
kcms/notifications/sourcesmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include <QAbstractItemModel> | ||||
24 | #include <QHash> | ||||
25 | #include <QString> | ||||
26 | #include <QVector> | ||||
27 | | ||||
28 | struct EventData | ||||
29 | { | ||||
30 | QString name; | ||||
31 | QString comment; | ||||
32 | QString iconName; | ||||
33 | QString eventId; | ||||
34 | QStringList actions; | ||||
35 | }; | ||||
36 | | ||||
37 | // FIXME add constructors for KService and KConfigGroup | ||||
38 | struct SourceData | ||||
39 | { | ||||
40 | QString name; | ||||
41 | QString comment; | ||||
42 | QString iconName; | ||||
43 | | ||||
44 | QString notifyRcName; | ||||
45 | QString desktopEntry; | ||||
46 | | ||||
47 | QVector<EventData> events; | ||||
48 | | ||||
49 | QString display() const | ||||
50 | { | ||||
51 | return !name.isEmpty() ? name : comment; | ||||
52 | } | ||||
53 | }; | ||||
54 | | ||||
55 | class SourcesModel : public QAbstractItemModel | ||||
56 | { | ||||
57 | Q_OBJECT | ||||
58 | | ||||
59 | public: | ||||
60 | SourcesModel(QObject *parent = nullptr); | ||||
61 | ~SourcesModel() override; | ||||
62 | | ||||
63 | enum Roles { | ||||
64 | SourceTypeRole = Qt::UserRole + 1, | ||||
65 | NotifyRcNameRole, | ||||
66 | DesktopEntryRole, | ||||
67 | | ||||
68 | EventIdRole, | ||||
69 | ActionsRole | ||||
70 | }; | ||||
71 | Q_ENUM(Roles) | ||||
72 | | ||||
73 | enum Type { | ||||
74 | ApplicationType, | ||||
75 | ServiceType | ||||
76 | }; | ||||
77 | Q_ENUM(Type) | ||||
78 | | ||||
79 | Q_INVOKABLE QPersistentModelIndex makePersistentModelIndex(const QModelIndex &idx) const; | ||||
80 | | ||||
81 | Q_INVOKABLE QPersistentModelIndex persistentIndexForDesktopEntry(const QString &desktopEntry) const; | ||||
82 | Q_INVOKABLE QPersistentModelIndex persistentIndexForNotifyRcName(const QString ¬ifyRcName) const; | ||||
83 | | ||||
84 | int columnCount(const QModelIndex &parent) const override; | ||||
85 | int rowCount(const QModelIndex &parent) const override; | ||||
86 | | ||||
87 | QVariant data(const QModelIndex &index, int role) const override; | ||||
88 | bool setData(const QModelIndex &index, const QVariant &value, int role) override; | ||||
89 | | ||||
90 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; | ||||
91 | QModelIndex parent(const QModelIndex &child) const override; | ||||
92 | | ||||
93 | QHash<int, QByteArray> roleNames() const override; | ||||
94 | | ||||
95 | Q_INVOKABLE void load(); | ||||
96 | | ||||
97 | private: | ||||
98 | QVector<SourceData> m_data; | ||||
99 | | ||||
100 | }; |