Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwindesktop/virtualdesktops.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Eike Hein <hein@kde.org> | 2 | * Copyright (C) 2018 Eike Hein <hein@kde.org> | ||
3 | * Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 5 | * 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 | * 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 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | 8 | * (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. | ||
13 | * | 14 | * | ||
14 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 17 | */ | ||
17 | 18 | | |||
18 | #include "virtualdesktops.h" | 19 | #include "virtualdesktops.h" | ||
20 | #include "animationsmodel.h" | ||||
19 | #include "desktopsmodel.h" | 21 | #include "desktopsmodel.h" | ||
20 | 22 | | |||
23 | #include <KAboutApplicationDialog> | ||||
21 | #include <KAboutData> | 24 | #include <KAboutData> | ||
25 | #include <KCModule> | ||||
22 | #include <KConfigGroup> | 26 | #include <KConfigGroup> | ||
23 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
24 | #include <KPluginFactory> | 28 | #include <KPluginFactory> | ||
29 | #include <KPluginTrader> | ||||
30 | | ||||
31 | #include <QDialog> | ||||
32 | #include <QDialogButtonBox> | ||||
33 | #include <QPushButton> | ||||
34 | #include <QVBoxLayout> | ||||
25 | 35 | | |||
26 | K_PLUGIN_FACTORY_WITH_JSON(VirtualDesktopsFactory, "kcm_kwin_virtualdesktops.json", registerPlugin<KWin::VirtualDesktops>();) | 36 | K_PLUGIN_FACTORY_WITH_JSON(VirtualDesktopsFactory, "kcm_kwin_virtualdesktops.json", registerPlugin<KWin::VirtualDesktops>();) | ||
27 | 37 | | |||
28 | namespace KWin | 38 | namespace KWin | ||
29 | { | 39 | { | ||
30 | 40 | | |||
31 | VirtualDesktops::VirtualDesktops(QObject *parent, const QVariantList &args) | 41 | VirtualDesktops::VirtualDesktops(QObject *parent, const QVariantList &args) | ||
32 | : KQuickAddons::ConfigModule(parent, args) | 42 | : KQuickAddons::ConfigModule(parent, args) | ||
33 | , m_kwinConfig(KSharedConfig::openConfig("kwinrc")) | 43 | , m_kwinConfig(KSharedConfig::openConfig("kwinrc")) | ||
34 | , m_desktopsModel(new KWin::DesktopsModel(this)) | 44 | , m_desktopsModel(new KWin::DesktopsModel(this)) | ||
35 | , m_navWraps(true) | 45 | , m_navWraps(true) | ||
36 | , m_osdEnabled(false) | 46 | , m_osdEnabled(false) | ||
37 | , m_osdDuration(1000) | 47 | , m_osdDuration(1000) | ||
38 | , m_osdTextOnly(false) | 48 | , m_osdTextOnly(false) | ||
49 | , m_animationsModel(new AnimationsModel(this)) | ||||
39 | { | 50 | { | ||
40 | KAboutData *about = new KAboutData(QStringLiteral("kcm_kwin_virtualdesktops"), | 51 | KAboutData *about = new KAboutData(QStringLiteral("kcm_kwin_virtualdesktops"), | ||
41 | i18n("Configure Virtual Desktops"), | 52 | i18n("Configure Virtual Desktops"), | ||
42 | QStringLiteral("2.0"), QString(), KAboutLicense::GPL); | 53 | QStringLiteral("2.0"), QString(), KAboutLicense::GPL); | ||
43 | setAboutData(about); | 54 | setAboutData(about); | ||
44 | 55 | | |||
45 | setButtons(Apply | Default); | 56 | setButtons(Apply | Default); | ||
46 | 57 | | |||
47 | QObject::connect(m_desktopsModel, &KWin::DesktopsModel::userModifiedChanged, | 58 | QObject::connect(m_desktopsModel, &KWin::DesktopsModel::userModifiedChanged, | ||
48 | this, &VirtualDesktops::updateNeedsSave); | 59 | this, &VirtualDesktops::updateNeedsSave); | ||
60 | connect(m_animationsModel, &AnimationsModel::enabledChanged, | ||||
61 | this, &VirtualDesktops::updateNeedsSave); | ||||
62 | connect(m_animationsModel, &AnimationsModel::currentIndexChanged, | ||||
63 | this, &VirtualDesktops::updateNeedsSave); | ||||
49 | } | 64 | } | ||
50 | 65 | | |||
51 | VirtualDesktops::~VirtualDesktops() | 66 | VirtualDesktops::~VirtualDesktops() | ||
52 | { | 67 | { | ||
53 | } | 68 | } | ||
54 | 69 | | |||
55 | QAbstractItemModel *VirtualDesktops::desktopsModel() const | 70 | QAbstractItemModel *VirtualDesktops::desktopsModel() const | ||
56 | { | 71 | { | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 130 | if (m_osdTextOnly != textOnly) { | |||
116 | m_osdTextOnly = textOnly; | 131 | m_osdTextOnly = textOnly; | ||
117 | 132 | | |||
118 | emit osdTextOnlyChanged(); | 133 | emit osdTextOnlyChanged(); | ||
119 | 134 | | |||
120 | updateNeedsSave(); | 135 | updateNeedsSave(); | ||
121 | } | 136 | } | ||
122 | } | 137 | } | ||
123 | 138 | | |||
139 | QAbstractItemModel *VirtualDesktops::animationsModel() const | ||||
140 | { | ||||
141 | return m_animationsModel; | ||||
142 | } | ||||
143 | | ||||
124 | void VirtualDesktops::load() | 144 | void VirtualDesktops::load() | ||
125 | { | 145 | { | ||
126 | KConfigGroup navConfig(m_kwinConfig, "Windows"); | 146 | KConfigGroup navConfig(m_kwinConfig, "Windows"); | ||
127 | setNavWraps(navConfig.readEntry<bool>("RollOverDesktops", true)); | 147 | setNavWraps(navConfig.readEntry<bool>("RollOverDesktops", true)); | ||
128 | 148 | | |||
129 | KConfigGroup osdConfig(m_kwinConfig, "Plugins"); | 149 | KConfigGroup osdConfig(m_kwinConfig, "Plugins"); | ||
130 | setOsdEnabled(osdConfig.readEntry("desktopchangeosdEnabled", false)); | 150 | setOsdEnabled(osdConfig.readEntry("desktopchangeosdEnabled", false)); | ||
131 | 151 | | |||
132 | KConfigGroup osdSettings(m_kwinConfig, "Script-desktopchangeosd"); | 152 | KConfigGroup osdSettings(m_kwinConfig, "Script-desktopchangeosd"); | ||
133 | setOsdDuration(osdSettings.readEntry("PopupHideDelay", 1000)); | 153 | setOsdDuration(osdSettings.readEntry("PopupHideDelay", 1000)); | ||
134 | setOsdTextOnly(osdSettings.readEntry("TextOnly", false)); | 154 | setOsdTextOnly(osdSettings.readEntry("TextOnly", false)); | ||
155 | | ||||
156 | m_animationsModel->load(); | ||||
135 | } | 157 | } | ||
136 | 158 | | |||
137 | void VirtualDesktops::save() | 159 | void VirtualDesktops::save() | ||
138 | { | 160 | { | ||
139 | m_desktopsModel->syncWithServer(); | 161 | m_desktopsModel->syncWithServer(); | ||
162 | m_animationsModel->save(); | ||||
140 | 163 | | |||
141 | KConfigGroup navConfig(m_kwinConfig, "Windows"); | 164 | KConfigGroup navConfig(m_kwinConfig, "Windows"); | ||
142 | navConfig.writeEntry("RollOverDesktops", m_navWraps); | 165 | navConfig.writeEntry("RollOverDesktops", m_navWraps); | ||
143 | 166 | | |||
144 | KConfigGroup osdConfig(m_kwinConfig, "Plugins"); | 167 | KConfigGroup osdConfig(m_kwinConfig, "Plugins"); | ||
145 | osdConfig.writeEntry("desktopchangeosdEnabled", m_osdEnabled); | 168 | osdConfig.writeEntry("desktopchangeosdEnabled", m_osdEnabled); | ||
146 | 169 | | |||
147 | KConfigGroup osdSettings(m_kwinConfig, "Script-desktopchangeosd"); | 170 | KConfigGroup osdSettings(m_kwinConfig, "Script-desktopchangeosd"); | ||
148 | osdSettings.writeEntry("PopupHideDelay", m_osdDuration); | 171 | osdSettings.writeEntry("PopupHideDelay", m_osdDuration); | ||
149 | osdSettings.writeEntry("TextOnly", m_osdTextOnly); | 172 | osdSettings.writeEntry("TextOnly", m_osdTextOnly); | ||
150 | 173 | | |||
151 | m_kwinConfig->sync(); | 174 | m_kwinConfig->sync(); | ||
152 | 175 | | |||
153 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), | 176 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), | ||
154 | QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); | 177 | QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); | ||
155 | QDBusConnection::sessionBus().send(message); | 178 | QDBusConnection::sessionBus().send(message); | ||
156 | 179 | | |||
157 | setNeedsSave(false); | 180 | setNeedsSave(false); | ||
158 | } | 181 | } | ||
159 | 182 | | |||
160 | void VirtualDesktops::defaults() | 183 | void VirtualDesktops::defaults() | ||
161 | { | 184 | { | ||
162 | m_desktopsModel->setRows(1); | 185 | m_desktopsModel->setRows(1); | ||
186 | m_animationsModel->defaults(); | ||||
163 | 187 | | |||
164 | setNavWraps(true); | 188 | setNavWraps(true); | ||
165 | setOsdEnabled(false); | 189 | setOsdEnabled(false); | ||
166 | setOsdDuration(1000); | 190 | setOsdDuration(1000); | ||
167 | setOsdTextOnly(false); | 191 | setOsdTextOnly(false); | ||
168 | } | 192 | } | ||
169 | 193 | | |||
194 | void VirtualDesktops::configureAnimation() | ||||
195 | { | ||||
196 | const QModelIndex index = m_animationsModel->index(m_animationsModel->currentIndex(), 0); | ||||
197 | if (!index.isValid()) { | ||||
198 | return; | ||||
199 | } | ||||
200 | | ||||
201 | const QString name = index.data(AnimationsModel::NameRole).toString(); | ||||
202 | const QString serviceName = index.data(AnimationsModel::ServiceNameRole).toString(); | ||||
203 | | ||||
204 | QPointer<QDialog> configDialog = new QDialog(); | ||||
205 | | ||||
206 | KCModule *kcm = KPluginTrader::createInstanceFromQuery<KCModule>( | ||||
207 | QStringLiteral("kwin/effects/configs/"), | ||||
208 | QString(), | ||||
209 | QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(serviceName), | ||||
210 | configDialog | ||||
211 | ); | ||||
212 | | ||||
213 | if (!kcm) { | ||||
214 | delete configDialog; | ||||
215 | return; | ||||
216 | } | ||||
217 | | ||||
218 | configDialog->setWindowTitle(name); | ||||
219 | configDialog->setLayout(new QVBoxLayout); | ||||
220 | | ||||
221 | auto buttons = new QDialogButtonBox( | ||||
222 | QDialogButtonBox::Ok | | ||||
223 | QDialogButtonBox::Cancel | | ||||
224 | QDialogButtonBox::RestoreDefaults, | ||||
225 | configDialog | ||||
226 | ); | ||||
227 | QObject::connect(buttons, &QDialogButtonBox::accepted, configDialog, &QDialog::accept); | ||||
228 | QObject::connect(buttons, &QDialogButtonBox::rejected, configDialog, &QDialog::reject); | ||||
229 | QObject::connect(buttons->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, kcm, &KCModule::defaults); | ||||
230 | | ||||
231 | auto showWidget = new QWidget(configDialog); | ||||
232 | auto layout = new QVBoxLayout; | ||||
233 | showWidget->setLayout(layout); | ||||
234 | layout->addWidget(kcm); | ||||
235 | configDialog->layout()->addWidget(showWidget); | ||||
236 | configDialog->layout()->addWidget(buttons); | ||||
237 | | ||||
238 | if (configDialog->exec() == QDialog::Accepted) { | ||||
239 | kcm->save(); | ||||
240 | } else { | ||||
241 | kcm->load(); | ||||
davidedmundson: I assume you've seen https://blogs.kde.org/2009/03/26/how-crash-almost-every-qtkde-application… | |||||
242 | } | ||||
243 | | ||||
244 | delete configDialog; | ||||
245 | } | ||||
246 | | ||||
247 | void VirtualDesktops::showAboutAnimation() | ||||
248 | { | ||||
249 | const QModelIndex index = m_animationsModel->index(m_animationsModel->currentIndex(), 0); | ||||
250 | if (!index.isValid()) { | ||||
251 | return; | ||||
252 | } | ||||
253 | | ||||
254 | const QString name = index.data(AnimationsModel::NameRole).toString(); | ||||
255 | const QString comment = index.data(AnimationsModel::DescriptionRole).toString(); | ||||
256 | const QString author = index.data(AnimationsModel::AuthorNameRole).toString(); | ||||
257 | const QString email = index.data(AnimationsModel::AuthorEmailRole).toString(); | ||||
258 | const QString website = index.data(AnimationsModel::WebsiteRole).toString(); | ||||
259 | const QString version = index.data(AnimationsModel::VersionRole).toString(); | ||||
260 | const QString license = index.data(AnimationsModel::LicenseRole).toString(); | ||||
261 | const QString icon = index.data(AnimationsModel::IconNameRole).toString(); | ||||
262 | | ||||
263 | const KAboutLicense::LicenseKey licenseType = KAboutLicense::byKeyword(license).key(); | ||||
264 | | ||||
265 | KAboutData aboutData( | ||||
266 | name, // Plugin name | ||||
267 | name, // Display name | ||||
268 | version, // Version | ||||
269 | comment, // Short description | ||||
270 | licenseType, // License | ||||
271 | QString(), // Copyright statement | ||||
272 | QString(), // Other text | ||||
273 | website.toLatin1() // Home page | ||||
274 | ); | ||||
275 | aboutData.setProgramLogo(icon); | ||||
276 | | ||||
277 | const QStringList authors = author.split(','); | ||||
278 | const QStringList emails = email.split(','); | ||||
279 | | ||||
280 | if (authors.count() == emails.count()) { | ||||
281 | int i = 0; | ||||
282 | for (const QString &author : authors) { | ||||
283 | if (!author.isEmpty()) { | ||||
284 | aboutData.addAuthor(i18n(author.toUtf8()), QString(), emails[i]); | ||||
285 | } | ||||
286 | i++; | ||||
287 | } | ||||
288 | } | ||||
289 | | ||||
290 | QPointer<KAboutApplicationDialog> aboutPlugin = new KAboutApplicationDialog(aboutData); | ||||
291 | aboutPlugin->exec(); | ||||
292 | | ||||
293 | delete aboutPlugin; | ||||
294 | } | ||||
295 | | ||||
170 | void VirtualDesktops::updateNeedsSave() | 296 | void VirtualDesktops::updateNeedsSave() | ||
171 | { | 297 | { | ||
172 | bool needsSave = false; | 298 | bool needsSave = false; | ||
173 | 299 | | |||
174 | if (m_desktopsModel->userModified()) { | 300 | if (m_desktopsModel->userModified()) { | ||
175 | needsSave = true; | 301 | needsSave = true; | ||
176 | } | 302 | } | ||
177 | 303 | | |||
304 | if (m_animationsModel->needsSave()) { | ||||
305 | needsSave = true; | ||||
306 | } | ||||
307 | | ||||
178 | KConfigGroup navConfig(m_kwinConfig, "Windows"); | 308 | KConfigGroup navConfig(m_kwinConfig, "Windows"); | ||
179 | 309 | | |||
180 | if (m_navWraps != navConfig.readEntry<bool>("RollOverDesktops", true)) { | 310 | if (m_navWraps != navConfig.readEntry<bool>("RollOverDesktops", true)) { | ||
181 | needsSave = true; | 311 | needsSave = true; | ||
182 | } | 312 | } | ||
183 | 313 | | |||
184 | KConfigGroup osdConfig(m_kwinConfig, "Plugins"); | 314 | KConfigGroup osdConfig(m_kwinConfig, "Plugins"); | ||
185 | 315 | | |||
Show All 20 Lines |
I assume you've seen https://blogs.kde.org/2009/03/26/how-crash-almost-every-qtkde-application-and-how-fix-it-0
as you're using the QPointer on the exec'ing dialog, but you need to check here in the branch where dialog is rejected.