Changeset View
Changeset View
Standalone View
Standalone View
applets/systemtray/systemtraymodel.h
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Konrad Materka <materka@gmail.com> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program; if not, write to the * | ||||
16 | * Free Software Foundation, Inc., * | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||||
18 | ***************************************************************************/ | ||||
19 | | ||||
20 | #ifndef SYSTEMTRAYMODEL_H | ||||
21 | #define SYSTEMTRAYMODEL_H | ||||
22 | | ||||
23 | #include <QStandardItemModel> | ||||
24 | | ||||
25 | #include <KItemModels/KConcatenateRowsProxyModel> | ||||
26 | #include <Plasma/DataEngineConsumer> | ||||
27 | #include <Plasma/DataEngine> | ||||
28 | | ||||
29 | namespace Plasma { | ||||
30 | class Applet; | ||||
31 | } | ||||
32 | | ||||
33 | enum class BaseRole { | ||||
34 | ItemType = Qt::UserRole + 1, | ||||
35 | ItemId, | ||||
36 | CanRender, | ||||
37 | LastBaseRole | ||||
38 | }; | ||||
39 | | ||||
40 | class PlasmoidModel: public QStandardItemModel | ||||
41 | { | ||||
42 | Q_OBJECT | ||||
43 | public: | ||||
44 | enum class Role { | ||||
45 | Applet = static_cast<int>(BaseRole::LastBaseRole) + 1, | ||||
46 | HasApplet | ||||
47 | }; | ||||
48 | | ||||
49 | explicit PlasmoidModel(QObject *parent = nullptr); | ||||
50 | | ||||
51 | QHash<int, QByteArray> roleNames() const override; | ||||
52 | | ||||
53 | public slots: | ||||
54 | void addApplet(Plasma::Applet *applet); | ||||
55 | void removeApplet(Plasma::Applet *applet); | ||||
56 | }; | ||||
57 | | ||||
58 | class StatusNotifierModel : public QStandardItemModel, public Plasma::DataEngineConsumer { | ||||
59 | Q_OBJECT | ||||
60 | public: | ||||
61 | enum class Role { | ||||
62 | DataEngineSource = static_cast<int>(BaseRole::LastBaseRole) + 100, | ||||
63 | AttentionIcon, | ||||
64 | AttentionIconName, | ||||
65 | AttentionMovieName, | ||||
66 | Category, | ||||
67 | Icon, | ||||
68 | IconName, | ||||
69 | IconThemePath, | ||||
70 | IconsChanged, | ||||
71 | Id, | ||||
72 | ItemIsMenu, | ||||
73 | OverlayIconName, | ||||
74 | Status, | ||||
75 | StatusChanged, | ||||
76 | Title, | ||||
77 | TitleChanged, | ||||
78 | ToolTipChanged, | ||||
79 | ToolTipIcon, | ||||
80 | ToolTipSubTitle, | ||||
81 | ToolTipTitle, | ||||
82 | WindowId | ||||
83 | }; | ||||
84 | | ||||
85 | StatusNotifierModel(QObject* parent); | ||||
86 | | ||||
87 | QHash<int, QByteArray> roleNames() const override; | ||||
88 | | ||||
89 | Plasma::Service *serviceForSource(const QString &source); | ||||
90 | | ||||
91 | public slots: | ||||
92 | void addSource(const QString &source); | ||||
93 | void removeSource(const QString &source); | ||||
94 | void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data); | ||||
95 | | ||||
96 | private: | ||||
97 | void updateItemData(QStandardItem *dataItem, const Plasma::DataEngine::Data &data, const Role role); | ||||
98 | | ||||
99 | Plasma::DataEngine *m_dataEngine = nullptr; | ||||
100 | QStringList m_sources; | ||||
101 | QHash<QString, Plasma::Service *> m_services; | ||||
102 | }; | ||||
103 | | ||||
104 | class SystemTrayModel : public KConcatenateRowsProxyModel | ||||
105 | { | ||||
106 | Q_OBJECT | ||||
107 | public: | ||||
108 | explicit SystemTrayModel(QObject *parent = nullptr); | ||||
109 | | ||||
110 | QHash<int, QByteArray> roleNames() const override; | ||||
111 | | ||||
112 | void addSourceModel(QAbstractItemModel *sourceModel); | ||||
113 | | ||||
114 | private: | ||||
115 | QHash<int, QByteArray> m_roleNames; | ||||
116 | }; | ||||
117 | | ||||
118 | #endif // SYSTEMTRAYMODEL_H |