Changeset View
Changeset View
Standalone View
Standalone View
kcms/lookandfeel/kcm.cpp
1 | /* This file is part of the KDE Project | 1 | /* This file is part of the KDE Project | ||
---|---|---|---|---|---|
2 | Copyright (c) 2014 Marco Martin <mart@kde.org> | 2 | Copyright (c) 2014 Marco Martin <mart@kde.org> | ||
3 | Copyright (c) 2014 Vishesh Handa <me@vhanda.in> | 3 | Copyright (c) 2014 Vishesh Handa <me@vhanda.in> | ||
4 | Copyright (c) 2019 Cyril Rossi <cyril.rossi@enioka.com> | ||||
4 | 5 | | |||
5 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public | ||
7 | License version 2 as published by the Free Software Foundation. | 8 | License version 2 as published by the Free Software Foundation. | ||
8 | 9 | | |||
9 | This library is distributed in the hope that it will be useful, | 10 | This library 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 GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Show All 29 Lines | |||||
41 | #include <QX11Info> | 42 | #include <QX11Info> | ||
42 | 43 | | |||
43 | #include <KLocalizedString> | 44 | #include <KLocalizedString> | ||
44 | #include <KPackage/PackageLoader> | 45 | #include <KPackage/PackageLoader> | ||
45 | 46 | | |||
46 | #include <X11/Xlib.h> | 47 | #include <X11/Xlib.h> | ||
47 | #include <X11/Xcursor/Xcursor.h> | 48 | #include <X11/Xcursor/Xcursor.h> | ||
48 | 49 | | |||
50 | #include "lookandfeelsettings.h" | ||||
51 | | ||||
49 | #ifdef HAVE_XFIXES | 52 | #ifdef HAVE_XFIXES | ||
50 | # include <X11/extensions/Xfixes.h> | 53 | # include <X11/extensions/Xfixes.h> | ||
51 | #endif | 54 | #endif | ||
52 | 55 | | |||
53 | KCMLookandFeel::KCMLookandFeel(QObject* parent, const QVariantList& args) | 56 | KCMLookandFeel::KCMLookandFeel(QObject *parent, const QVariantList &args) | ||
54 | : KQuickAddons::ConfigModule(parent, args) | 57 | : KQuickAddons::ManagedConfigModule(parent, args) | ||
58 | , m_settings(new LookAndFeelSettings(this)) | ||||
55 | , m_config(QStringLiteral("kdeglobals")) | 59 | , m_config(QStringLiteral("kdeglobals")) | ||
56 | , m_configGroup(m_config.group("KDE")) | 60 | , m_configGroup(m_config.group("KDE")) | ||
57 | , m_applyColors(true) | 61 | , m_applyColors(true) | ||
58 | , m_applyWidgetStyle(true) | 62 | , m_applyWidgetStyle(true) | ||
59 | , m_applyIcons(true) | 63 | , m_applyIcons(true) | ||
60 | , m_applyPlasmaTheme(true) | 64 | , m_applyPlasmaTheme(true) | ||
61 | , m_applyCursors(true) | 65 | , m_applyCursors(true) | ||
62 | , m_applyWindowSwitcher(true) | 66 | , m_applyWindowSwitcher(true) | ||
63 | , m_applyDesktopSwitcher(true) | 67 | , m_applyDesktopSwitcher(true) | ||
64 | , m_resetDefaultLayout(false) | 68 | , m_resetDefaultLayout(false) | ||
65 | , m_applyWindowDecoration(true) | 69 | , m_applyWindowDecoration(true) | ||
66 | { | 70 | { | ||
71 | qmlRegisterType<LookAndFeelSettings>(); | ||||
67 | qmlRegisterType<QStandardItemModel>(); | 72 | qmlRegisterType<QStandardItemModel>(); | ||
68 | qmlRegisterType<KCMLookandFeel>(); | 73 | qmlRegisterType<KCMLookandFeel>(); | ||
74 | | ||||
69 | KAboutData* about = new KAboutData(QStringLiteral("kcm_lookandfeel"), i18n("Global Theme"), | 75 | KAboutData *about = new KAboutData(QStringLiteral("kcm_lookandfeel"), i18n("Global Theme"), | ||
70 | QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); | 76 | QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); | ||
71 | about->addAuthor(i18n("Marco Martin"), QString(), QStringLiteral("mart@kde.org")); | 77 | about->addAuthor(i18n("Marco Martin"), QString(), QStringLiteral("mart@kde.org")); | ||
72 | setAboutData(about); | 78 | setAboutData(about); | ||
73 | setButtons(Apply | Default); | 79 | setButtons(Apply | Default); | ||
74 | 80 | | |||
75 | m_model = new QStandardItemModel(this); | 81 | m_model = new QStandardItemModel(this); | ||
76 | QHash<int, QByteArray> roles = m_model->roleNames(); | 82 | QHash<int, QByteArray> roles = m_model->roleNames(); | ||
77 | roles[PluginNameRole] = "pluginName"; | 83 | roles[PluginNameRole] = "pluginName"; | ||
Show All 25 Lines | 108 | { | |||
103 | loadModel(); | 109 | loadModel(); | ||
104 | } | 110 | } | ||
105 | 111 | | |||
106 | QStandardItemModel *KCMLookandFeel::lookAndFeelModel() const | 112 | QStandardItemModel *KCMLookandFeel::lookAndFeelModel() const | ||
107 | { | 113 | { | ||
108 | return m_model; | 114 | return m_model; | ||
109 | } | 115 | } | ||
110 | 116 | | |||
111 | QString KCMLookandFeel::selectedPlugin() const | 117 | int KCMLookandFeel::pluginIndex(const QString &pluginName) const | ||
112 | { | | |||
113 | return m_selectedPlugin; | | |||
114 | } | | |||
115 | | ||||
116 | void KCMLookandFeel::setSelectedPlugin(const QString &plugin) | | |||
117 | { | 118 | { | ||
118 | if (m_selectedPlugin == plugin) { | 119 | const auto results = m_model->match(m_model->index(0, 0), PluginNameRole, pluginName); | ||
119 | return; | 120 | if (results.count() == 1) { | ||
120 | } | 121 | return results.first().row(); | ||
121 | | ||||
122 | const bool firstTime = m_selectedPlugin.isNull(); | | |||
123 | m_selectedPlugin = plugin; | | |||
124 | emit selectedPluginChanged(); | | |||
125 | emit selectedPluginIndexChanged(); | | |||
126 | | ||||
127 | if (!firstTime) { | | |||
128 | setNeedsSave(true); | | |||
129 | } | | |||
130 | } | 122 | } | ||
131 | 123 | | |||
132 | int KCMLookandFeel::selectedPluginIndex() const | | |||
133 | { | | |||
134 | for (int i = 0; i < m_model->rowCount(); ++i) { | | |||
135 | if (m_model->data(m_model->index(i, 0), PluginNameRole).toString() == m_selectedPlugin) { | | |||
136 | return i; | | |||
137 | } | | |||
138 | } | | |||
139 | return -1; | 124 | return -1; | ||
140 | } | 125 | } | ||
141 | 126 | | |||
142 | QList<KPackage::Package> KCMLookandFeel::availablePackages(const QStringList &components) | 127 | QList<KPackage::Package> KCMLookandFeel::availablePackages(const QStringList &components) | ||
143 | { | 128 | { | ||
144 | QList<KPackage::Package> packages; | 129 | QList<KPackage::Package> packages; | ||
145 | QStringList paths; | 130 | QStringList paths; | ||
146 | const QStringList dataPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); | 131 | const QStringList dataPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); | ||
Show All 18 Lines | 146 | for (const auto &component : components) { | |||
165 | } | 150 | } | ||
166 | } | 151 | } | ||
167 | } | 152 | } | ||
168 | } | 153 | } | ||
169 | 154 | | |||
170 | return packages; | 155 | return packages; | ||
171 | } | 156 | } | ||
172 | 157 | | |||
158 | LookAndFeelSettings *KCMLookandFeel::lookAndFeelSettings() const | ||||
159 | { | ||||
160 | return m_settings; | ||||
161 | } | ||||
162 | | ||||
173 | void KCMLookandFeel::loadModel() | 163 | void KCMLookandFeel::loadModel() | ||
174 | { | 164 | { | ||
175 | m_model->clear(); | 165 | m_model->clear(); | ||
176 | 166 | | |||
177 | const QList<KPackage::Package> pkgs = availablePackages({"defaults", "layouts"}); | 167 | const QList<KPackage::Package> pkgs = availablePackages({"defaults", "layouts"}); | ||
178 | for (const KPackage::Package &pkg : pkgs) { | 168 | for (const KPackage::Package &pkg : pkgs) { | ||
179 | if (!pkg.metadata().isValid()) { | 169 | if (!pkg.metadata().isValid()) { | ||
180 | continue; | 170 | continue; | ||
181 | } | 171 | } | ||
182 | QStandardItem* row = new QStandardItem(pkg.metadata().name()); | 172 | QStandardItem *row = new QStandardItem(pkg.metadata().name()); | ||
183 | row->setData(pkg.metadata().pluginId(), PluginNameRole); | 173 | row->setData(pkg.metadata().pluginId(), PluginNameRole); | ||
184 | row->setData(pkg.metadata().description(), DescriptionRole); | 174 | row->setData(pkg.metadata().description(), DescriptionRole); | ||
185 | row->setData(pkg.filePath("preview"), ScreenshotRole); | 175 | row->setData(pkg.filePath("preview"), ScreenshotRole); | ||
186 | row->setData(pkg.filePath("fullscreenpreview"), FullScreenPreviewRole); | 176 | row->setData(pkg.filePath("fullscreenpreview"), FullScreenPreviewRole); | ||
187 | 177 | | |||
188 | //What the package provides | 178 | //What the package provides | ||
189 | row->setData(!pkg.filePath("splashmainscript").isEmpty(), HasSplashRole); | 179 | row->setData(!pkg.filePath("splashmainscript").isEmpty(), HasSplashRole); | ||
190 | row->setData(!pkg.filePath("lockscreenmainscript").isEmpty(), HasLockScreenRole); | 180 | row->setData(!pkg.filePath("lockscreenmainscript").isEmpty(), HasLockScreenRole); | ||
Show All 30 Lines | 184 | if (!pkg.filePath("defaults").isEmpty()) { | |||
221 | cg = KConfigGroup(conf, "kwinrc"); | 211 | cg = KConfigGroup(conf, "kwinrc"); | ||
222 | cg = KConfigGroup(&cg, "DesktopSwitcher"); | 212 | cg = KConfigGroup(&cg, "DesktopSwitcher"); | ||
223 | row->setData(!cg.readEntry("LayoutName", QString()).isEmpty(), HasDesktopSwitcherRole); | 213 | row->setData(!cg.readEntry("LayoutName", QString()).isEmpty(), HasDesktopSwitcherRole); | ||
224 | } | 214 | } | ||
225 | 215 | | |||
226 | m_model->appendRow(row); | 216 | m_model->appendRow(row); | ||
227 | } | 217 | } | ||
228 | m_model->sort(0 /*column*/); | 218 | m_model->sort(0 /*column*/); | ||
229 | emit selectedPluginIndexChanged(); | 219 | | ||
220 | //Model has been cleared so pretend the selected look and fell changed to force view update | ||||
ervin: s/fell/feel/ :-) | |||||
221 | emit m_settings->lookAndFeelPackageChanged(); | ||||
230 | } | 222 | } | ||
231 | 223 | | |||
232 | void KCMLookandFeel::load() | 224 | void KCMLookandFeel::load() | ||
233 | { | 225 | { | ||
234 | m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); | 226 | ManagedConfigModule::load(); | ||
235 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); | | |||
236 | const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); | | |||
237 | if (!packageName.isEmpty()) { | | |||
238 | m_package.setPath(packageName); | | |||
239 | } | | |||
240 | | ||||
241 | if (!m_package.metadata().isValid()) { | | |||
242 | return; | | |||
243 | } | | |||
244 | | ||||
245 | setSelectedPlugin(m_package.metadata().pluginId()); | | |||
246 | 227 | | |||
247 | setNeedsSave(false); | 228 | m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); | ||
229 | m_package.setPath(m_settings->lookAndFeelPackage()); | ||||
248 | } | 230 | } | ||
249 | 231 | | |||
250 | | ||||
251 | void KCMLookandFeel::save() | 232 | void KCMLookandFeel::save() | ||
252 | { | 233 | { | ||
253 | KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); | 234 | KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); | ||
254 | package.setPath(m_selectedPlugin); | 235 | package.setPath(m_settings->lookAndFeelPackage()); | ||
255 | 236 | | |||
256 | if (!package.isValid()) { | 237 | if (!package.isValid()) { | ||
257 | return; | 238 | return; | ||
258 | } | 239 | } | ||
259 | 240 | | |||
260 | m_configGroup.writeEntry("LookAndFeelPackage", m_selectedPlugin); | 241 | ManagedConfigModule::save(); | ||
261 | 242 | | |||
262 | if (m_resetDefaultLayout) { | 243 | if (m_resetDefaultLayout) { | ||
263 | QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), QStringLiteral("/PlasmaShell"), | 244 | QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"), QStringLiteral("/PlasmaShell"), | ||
264 | QStringLiteral("org.kde.PlasmaShell"), QStringLiteral("loadLookAndFeelDefaultLayout")); | 245 | QStringLiteral("org.kde.PlasmaShell"), QStringLiteral("loadLookAndFeelDefaultLayout")); | ||
265 | 246 | | |||
266 | QList<QVariant> args; | 247 | QList<QVariant> args; | ||
267 | args << m_selectedPlugin; | 248 | args << m_settings->lookAndFeelPackage(); | ||
268 | message.setArguments(args); | 249 | message.setArguments(args); | ||
269 | 250 | | |||
270 | QDBusConnection::sessionBus().call(message, QDBus::NoBlock); | 251 | QDBusConnection::sessionBus().call(message, QDBus::NoBlock); | ||
271 | } | 252 | } | ||
272 | 253 | | |||
273 | if (!package.filePath("defaults").isEmpty()) { | 254 | if (!package.filePath("defaults").isEmpty()) { | ||
274 | KSharedConfigPtr conf = KSharedConfig::openConfig(package.filePath("defaults")); | 255 | KSharedConfigPtr conf = KSharedConfig::openConfig(package.filePath("defaults")); | ||
275 | KConfigGroup cg(conf, "kdeglobals"); | 256 | KConfigGroup cg(conf, "kdeglobals"); | ||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Line(s) | 382 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) { | |||
402 | KRun::runApplication(service, {}, nullptr); | 383 | KRun::runApplication(service, {}, nullptr); | ||
403 | } | 384 | } | ||
404 | } | 385 | } | ||
405 | } | 386 | } | ||
406 | } | 387 | } | ||
407 | } | 388 | } | ||
408 | 389 | | |||
409 | //TODO: option to enable/disable apply? they don't seem required by UI design | 390 | //TODO: option to enable/disable apply? they don't seem required by UI design | ||
410 | setSplashScreen(m_selectedPlugin); | 391 | setSplashScreen(m_settings->lookAndFeelPackage()); | ||
411 | setLockScreen(m_selectedPlugin); | 392 | setLockScreen(m_settings->lookAndFeelPackage()); | ||
412 | 393 | | |||
413 | m_configGroup.sync(); | 394 | m_configGroup.sync(); | ||
414 | m_package.setPath(m_selectedPlugin); | 395 | m_package.setPath(m_settings->lookAndFeelPackage()); | ||
415 | runRdb(KRdbExportQtColors | KRdbExportGtkTheme | KRdbExportColors | KRdbExportQtSettings | KRdbExportXftSettings); | 396 | runRdb(KRdbExportQtColors | KRdbExportGtkTheme | KRdbExportColors | KRdbExportQtSettings | KRdbExportXftSettings); | ||
416 | } | 397 | } | ||
417 | 398 | | |||
418 | void KCMLookandFeel::defaults() | | |||
419 | { | | |||
420 | if (!m_package.metadata().isValid()) { | | |||
421 | return; | | |||
422 | } | | |||
423 | | ||||
424 | setSelectedPlugin(m_package.metadata().pluginId()); | | |||
425 | } | | |||
426 | | ||||
427 | void KCMLookandFeel::setWidgetStyle(const QString &style) | 399 | void KCMLookandFeel::setWidgetStyle(const QString &style) | ||
428 | { | 400 | { | ||
429 | if (style.isEmpty()) { | 401 | if (style.isEmpty()) { | ||
430 | return; | 402 | return; | ||
431 | } | 403 | } | ||
432 | 404 | | |||
433 | m_configGroup.writeEntry("widgetStyle", style); | 405 | m_configGroup.writeEntry("widgetStyle", style); | ||
434 | m_configGroup.sync(); | 406 | m_configGroup.sync(); | ||
▲ Show 20 Lines • Show All 293 Lines • Show Last 20 Lines |
s/fell/feel/ :-)