Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/common/effectmodel.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2013 Antonis Tsiapaliokas <kok3rs@gmail.com> | ||||
6 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
7 | | ||||
8 | This program is free software; you can redistribute it and/or modify | ||||
9 | it under the terms of the GNU General Public License as published by | ||||
10 | the Free Software Foundation; either version 2 of the License, or | ||||
11 | (at your option) any later version. | ||||
12 | | ||||
13 | This program is distributed in the hope that it will be useful, | ||||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
16 | GNU General Public License for more details. | ||||
17 | | ||||
18 | You should have received a copy of the GNU General Public License | ||||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | *********************************************************************/ | ||||
21 | | ||||
22 | #pragma once | ||||
23 | | ||||
24 | #include <kwin_export.h> | ||||
25 | | ||||
26 | #include <QAbstractItemModel> | ||||
27 | #include <QString> | ||||
28 | #include <QUrl> | ||||
29 | | ||||
30 | #include <KPluginInfo> | ||||
31 | #include <KSharedConfig> | ||||
32 | | ||||
33 | namespace KWin | ||||
34 | { | ||||
35 | | ||||
36 | class KWIN_EXPORT EffectModel : public QAbstractItemModel | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | | ||||
40 | public: | ||||
41 | /** | ||||
42 | * This enum type is used to specify data roles. | ||||
43 | * | ||||
44 | * @value NameRole The user-friendly name of the effect. | ||||
45 | * | ||||
46 | * @value DescriptionRole The description of the effect. | ||||
47 | * | ||||
48 | * @value AuthorNameRole The name of the effect's author. If there are | ||||
49 | * several authors, they will be comma separated. | ||||
50 | * | ||||
51 | * @value AuthorEmailRole The email of the effect's author. If there are | ||||
52 | * several authors, the emails will be comma separated. | ||||
53 | * | ||||
54 | * @value LicenseRole The license of the effect. | ||||
55 | * | ||||
56 | * @value VersionRole The version of the effect. | ||||
57 | * | ||||
58 | * @value CategoryRole The category of the effect. | ||||
59 | * | ||||
60 | * @value ServiceNameRole The service name(plugin name) of the effect. | ||||
61 | * | ||||
62 | * @value IconNameRole The icon name of the effect. | ||||
63 | * | ||||
64 | * @value EffectStatusRole Whether the effect is enabled or disabled. | ||||
65 | * | ||||
66 | * @value VideoRole The link to a video demonstration of the effect. | ||||
67 | * | ||||
68 | * @value WebsiteRole The link to the home page of the effect. | ||||
69 | * | ||||
70 | * @value SupportedRole Whether the effect is supported. | ||||
71 | * | ||||
72 | * @value ExclusiveRole The exclusive group of the effect. | ||||
73 | * | ||||
74 | * @value InternalRole Whether the effect is internal. | ||||
75 | * | ||||
76 | * @value ConfigurableRole Whether effect has a KCM. | ||||
77 | * | ||||
78 | * @value ScriptedRole Whether the effect is scripted. | ||||
79 | * | ||||
80 | * @value EnabledByDefaultRole Whether the effect is enabled by default. | ||||
81 | **/ | ||||
82 | enum EffectRoles { | ||||
83 | NameRole = Qt::UserRole + 1, | ||||
84 | DescriptionRole, | ||||
85 | AuthorNameRole, | ||||
86 | AuthorEmailRole, | ||||
87 | LicenseRole, | ||||
88 | VersionRole, | ||||
89 | CategoryRole, | ||||
90 | ServiceNameRole, | ||||
91 | IconNameRole, | ||||
92 | EffectStatusRole, | ||||
93 | VideoRole, | ||||
94 | WebsiteRole, | ||||
95 | SupportedRole, | ||||
96 | ExclusiveRole, | ||||
97 | InternalRole, | ||||
98 | ConfigurableRole, | ||||
99 | ScriptedRole, | ||||
100 | EnabledByDefaultRole | ||||
101 | }; | ||||
102 | | ||||
103 | /** | ||||
104 | * This enum type is used to specify the status of a given effect. | ||||
105 | * | ||||
106 | * @value Disabled An effect is disabled. | ||||
107 | * | ||||
108 | * @value EnabledUndeterminded An enable function is used to determine | ||||
109 | * whether the effect is enabled. For example, such function can be | ||||
110 | * useful to disable the blur effect when running in a virtual machine. | ||||
111 | * | ||||
112 | * @value Enabled An effect is enabled. | ||||
113 | **/ | ||||
114 | enum class EffectStatus { | ||||
115 | Disabled = Qt::Unchecked, | ||||
116 | EnabledUndeterminded = Qt::PartiallyChecked, | ||||
117 | Enabled = Qt::Checked | ||||
118 | }; | ||||
119 | | ||||
120 | explicit EffectModel(QObject *parent = nullptr); | ||||
121 | | ||||
122 | // Overrides from QAbstractItemModel. | ||||
123 | QHash<int, QByteArray> roleNames() const override; | ||||
124 | QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; | ||||
125 | QModelIndex parent(const QModelIndex &child) const override; | ||||
126 | int rowCount(const QModelIndex &parent = {}) const override; | ||||
127 | int columnCount(const QModelIndex &parent = {}) const override; | ||||
128 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||||
129 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; | ||||
130 | | ||||
131 | /** | ||||
132 | * Changes the status of a given effect. | ||||
133 | * | ||||
134 | * @param rowIndex An effect represented by the given index. | ||||
135 | * @param effectState The new state. | ||||
136 | * @note In order to actually apply the change, you have to call @p save. | ||||
137 | **/ | ||||
138 | void updateEffectStatus(const QModelIndex &rowIndex, EffectStatus effectState); | ||||
139 | | ||||
140 | /** | ||||
141 | * Loads effects. | ||||
142 | * | ||||
143 | * You have to call this method in order to populate the model. | ||||
144 | **/ | ||||
145 | void load(); | ||||
146 | | ||||
147 | /** | ||||
148 | * Saves status of each modified effect. | ||||
149 | **/ | ||||
150 | void save(); | ||||
151 | | ||||
152 | /** | ||||
153 | * Resets the status of each effect to the default state. | ||||
154 | * | ||||
155 | * @note In order to actually apply the change, you have to call @p save. | ||||
156 | **/ | ||||
157 | void defaults(); | ||||
158 | | ||||
159 | protected: | ||||
160 | struct EffectData { | ||||
161 | QString name; | ||||
162 | QString description; | ||||
163 | QString authorName; | ||||
164 | QString authorEmail; | ||||
165 | QString license; | ||||
166 | QString version; | ||||
167 | QString untranslatedCategory; | ||||
168 | QString category; | ||||
169 | QString serviceName; | ||||
170 | QString iconName; | ||||
171 | EffectStatus effectStatus; | ||||
172 | bool enabledByDefault; | ||||
173 | bool enabledByDefaultFunction; | ||||
174 | QUrl video; | ||||
175 | QUrl website; | ||||
176 | bool supported; | ||||
177 | QString exclusiveGroup; | ||||
178 | bool internal; | ||||
179 | bool configurable; | ||||
180 | bool scripted; | ||||
181 | bool changed = false; | ||||
182 | }; | ||||
183 | | ||||
184 | /** | ||||
185 | * Returns whether the given effect should be stored in the model. | ||||
186 | * | ||||
187 | * @param data The effect. | ||||
188 | * @returns @c true if the effect should be stored, otherwise @c false. | ||||
189 | **/ | ||||
190 | virtual bool shouldStore(const EffectData &data) const; | ||||
191 | | ||||
192 | private: | ||||
193 | void loadBuiltInEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs); | ||||
194 | void loadJavascriptEffects(const KConfigGroup &kwinConfig); | ||||
195 | void loadPluginEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs); | ||||
196 | int findRowByServiceName(const QString &serviceName); | ||||
197 | void syncEffectsToKWin(); | ||||
198 | | ||||
199 | QVector<EffectData> m_effectsList; | ||||
200 | QVector<EffectData> m_effectsChanged; | ||||
201 | | ||||
202 | Q_DISABLE_COPY(EffectModel) | ||||
203 | }; | ||||
204 | | ||||
205 | } |