Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwindesktop/animationsmodel.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
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 | #include "animationsmodel.h" | ||||
22 | | ||||
23 | namespace KWin | ||||
24 | { | ||||
25 | | ||||
26 | AnimationsModel::AnimationsModel(QObject *parent) | ||||
27 | : EffectModel(parent) | ||||
28 | { | ||||
29 | connect(this, &AnimationsModel::currentIndexChanged, this, | ||||
30 | [this] { | ||||
31 | const QModelIndex index_ = index(m_currentIndex, 0); | ||||
32 | if (!index_.isValid()) { | ||||
33 | return; | ||||
34 | } | ||||
35 | const bool configurable = index_.data(ConfigurableRole).toBool(); | ||||
36 | if (configurable != m_currentConfigurable) { | ||||
37 | m_currentConfigurable = configurable; | ||||
38 | emit currentConfigurableChanged(); | ||||
39 | } | ||||
40 | } | ||||
41 | ); | ||||
42 | } | ||||
43 | | ||||
44 | bool AnimationsModel::enabled() const | ||||
45 | { | ||||
46 | return m_enabled; | ||||
47 | } | ||||
48 | | ||||
49 | void AnimationsModel::setEnabled(bool enabled) | ||||
50 | { | ||||
51 | if (m_enabled != enabled) { | ||||
52 | m_enabled = enabled; | ||||
53 | emit enabledChanged(); | ||||
54 | } | ||||
55 | } | ||||
56 | | ||||
57 | int AnimationsModel::currentIndex() const | ||||
58 | { | ||||
59 | return m_currentIndex; | ||||
60 | } | ||||
61 | | ||||
62 | void AnimationsModel::setCurrentIndex(int index) | ||||
63 | { | ||||
64 | if (m_currentIndex != index) { | ||||
65 | m_currentIndex = index; | ||||
66 | emit currentIndexChanged(); | ||||
67 | } | ||||
68 | } | ||||
69 | | ||||
70 | bool AnimationsModel::currentConfigurable() const | ||||
71 | { | ||||
72 | return m_currentConfigurable; | ||||
73 | } | ||||
74 | | ||||
75 | bool AnimationsModel::shouldStore(const EffectData &data) const | ||||
76 | { | ||||
77 | return data.untranslatedCategory.contains( | ||||
78 | QStringLiteral("Virtual Desktop Switching Animation"), Qt::CaseInsensitive); | ||||
79 | } | ||||
80 | | ||||
81 | EffectModel::Status AnimationsModel::status(int row) const | ||||
82 | { | ||||
83 | return Status(data(index(row, 0), static_cast<int>(EffectStatusRole)).toInt()); | ||||
84 | } | ||||
85 | | ||||
86 | bool AnimationsModel::modelCurrentEnabled() const | ||||
87 | { | ||||
88 | for (int i = 0; i < rowCount(); ++i) { | ||||
89 | if (status(i) != Status::Disabled) { | ||||
90 | return true; | ||||
91 | } | ||||
92 | } | ||||
93 | | ||||
94 | return false; | ||||
95 | } | ||||
96 | | ||||
97 | int AnimationsModel::modelCurrentIndex() const | ||||
98 | { | ||||
99 | for (int i = 0; i < rowCount(); ++i) { | ||||
100 | if (status(i) != Status::Disabled) { | ||||
101 | return i; | ||||
102 | } | ||||
103 | } | ||||
104 | | ||||
105 | return 0; | ||||
106 | } | ||||
107 | | ||||
108 | void AnimationsModel::load() | ||||
109 | { | ||||
110 | EffectModel::load(); | ||||
111 | setEnabled(modelCurrentEnabled()); | ||||
112 | setCurrentIndex(modelCurrentIndex()); | ||||
113 | } | ||||
114 | | ||||
115 | void AnimationsModel::save() | ||||
116 | { | ||||
117 | for (int i = 0; i < rowCount(); ++i) { | ||||
118 | const auto status = (m_enabled && i == m_currentIndex) | ||||
119 | ? EffectModel::Status::Enabled | ||||
120 | : EffectModel::Status::Disabled; | ||||
121 | updateEffectStatus(index(i, 0), status); | ||||
122 | } | ||||
123 | | ||||
124 | EffectModel::save(); | ||||
125 | } | ||||
126 | | ||||
127 | void AnimationsModel::defaults() | ||||
128 | { | ||||
129 | EffectModel::defaults(); | ||||
130 | setEnabled(modelCurrentEnabled()); | ||||
131 | setCurrentIndex(modelCurrentIndex()); | ||||
132 | } | ||||
133 | | ||||
134 | bool AnimationsModel::needsSave() const | ||||
135 | { | ||||
136 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | ||||
137 | | ||||
138 | for (int i = 0; i < rowCount(); ++i) { | ||||
139 | const QModelIndex index_ = index(i, 0); | ||||
140 | const bool enabledConfig = kwinConfig.readEntry( | ||||
141 | index_.data(ServiceNameRole).toString() + QLatin1String("Enabled"), | ||||
142 | index_.data(EnabledByDefaultRole).toBool() | ||||
143 | ); | ||||
144 | const bool enabled = (m_enabled && i == m_currentIndex); | ||||
145 | | ||||
146 | if (enabled != enabledConfig) { | ||||
147 | return true; | ||||
148 | } | ||||
149 | } | ||||
150 | | ||||
151 | return false; | ||||
152 | } | ||||
153 | | ||||
154 | } |