Changeset View
Changeset View
Standalone View
Standalone View
kcms/desktoptheme/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) 2016 David Rosca <nowrep@gmail.com> | 4 | Copyright (c) 2016 David Rosca <nowrep@gmail.com> | ||
5 | Copyright (c) 2018 Kai Uwe Broulik <kde@privat.broulik.de> | 5 | Copyright (c) 2018 Kai Uwe Broulik <kde@privat.broulik.de> | ||
6 | Copyright (c) 2019 Kevin Ottens <kevin.ottens@enioka.com> | ||||
6 | 7 | | |||
7 | This library is free software; you can redistribute it and/or | 8 | This library is free software; you can redistribute it and/or | ||
8 | modify it under the terms of the GNU Library General Public | 9 | modify it under the terms of the GNU Library General Public | ||
9 | License version 2 as published by the Free Software Foundation. | 10 | License version 2 as published by the Free Software Foundation. | ||
10 | 11 | | |||
11 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Show All 30 Lines | |||||
44 | #include <KNewStuff3/KNS3/DownloadDialog> | 45 | #include <KNewStuff3/KNS3/DownloadDialog> | ||
45 | 46 | | |||
46 | Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme") | 47 | Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme") | ||
47 | 48 | | |||
48 | K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();) | 49 | K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();) | ||
49 | 50 | | |||
50 | KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args) | 51 | KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args) | ||
51 | : KQuickAddons::ConfigModule(parent, args) | 52 | : KQuickAddons::ConfigModule(parent, args) | ||
52 | , m_defaultTheme(new Plasma::Theme(this)) | | |||
53 | , m_haveThemeExplorerInstalled(false) | 53 | , m_haveThemeExplorerInstalled(false) | ||
54 | { | 54 | { | ||
55 | qmlRegisterType<QStandardItemModel>(); | 55 | qmlRegisterType<QStandardItemModel>(); | ||
56 | 56 | | |||
57 | KAboutData* about = new KAboutData(QStringLiteral("kcm_desktoptheme"), i18n("Plasma Style"), | 57 | KAboutData* about = new KAboutData(QStringLiteral("kcm_desktoptheme"), i18n("Plasma Style"), | ||
58 | QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); | 58 | QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); | ||
59 | about->addAuthor(i18n("David Rosca"), QString(), QStringLiteral("nowrep@gmail.com")); | 59 | about->addAuthor(i18n("David Rosca"), QString(), QStringLiteral("nowrep@gmail.com")); | ||
60 | setAboutData(about); | 60 | setAboutData(about); | ||
61 | setButtons(Apply | Default | Help); | 61 | setButtons(Apply | Default | Help); | ||
62 | 62 | | |||
63 | m_model = new QStandardItemModel(this); | 63 | m_model = new QStandardItemModel(this); | ||
64 | QHash<int, QByteArray> roles = m_model->roleNames(); | 64 | QHash<int, QByteArray> roles = m_model->roleNames(); | ||
65 | roles[PluginNameRole] = QByteArrayLiteral("pluginName"); | 65 | roles[PluginNameRole] = QByteArrayLiteral("pluginName"); | ||
66 | roles[ThemeNameRole] = QByteArrayLiteral("themeName"); | 66 | roles[ThemeNameRole] = QByteArrayLiteral("themeName"); | ||
67 | roles[DescriptionRole] = QByteArrayLiteral("description"); | 67 | roles[DescriptionRole] = QByteArrayLiteral("description"); | ||
68 | roles[IsLocalRole] = QByteArrayLiteral("isLocal"); | 68 | roles[IsLocalRole] = QByteArrayLiteral("isLocal"); | ||
69 | roles[PendingDeletionRole] = QByteArrayLiteral("pendingDeletion"); | 69 | roles[PendingDeletionRole] = QByteArrayLiteral("pendingDeletion"); | ||
70 | m_model->setItemRoleNames(roles); | 70 | m_model->setItemRoleNames(roles); | ||
71 | 71 | | |||
72 | m_haveThemeExplorerInstalled = !QStandardPaths::findExecutable(QStringLiteral("plasmathemeexplorer")).isEmpty(); | 72 | m_haveThemeExplorerInstalled = !QStandardPaths::findExecutable(QStringLiteral("plasmathemeexplorer")).isEmpty(); | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | KCMDesktopTheme::~KCMDesktopTheme() | 75 | KCMDesktopTheme::~KCMDesktopTheme() | ||
76 | { | 76 | { | ||
77 | delete m_defaultTheme; | | |||
78 | } | 77 | } | ||
79 | 78 | | |||
80 | QStandardItemModel *KCMDesktopTheme::desktopThemeModel() const | 79 | QStandardItemModel *KCMDesktopTheme::desktopThemeModel() const | ||
81 | { | 80 | { | ||
82 | return m_model; | 81 | return m_model; | ||
83 | } | 82 | } | ||
84 | 83 | | |||
85 | QString KCMDesktopTheme::selectedPlugin() const | 84 | QString KCMDesktopTheme::selectedPlugin() const | ||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Line(s) | 268 | if (m_model->findItems(packageName).isEmpty()) { | |||
277 | m_model->appendRow(item); | 276 | m_model->appendRow(item); | ||
278 | } | 277 | } | ||
279 | } | 278 | } | ||
280 | 279 | | |||
281 | m_model->setSortRole(ThemeNameRole); // FIXME the model should really be just using Qt::DisplayRole | 280 | m_model->setSortRole(ThemeNameRole); // FIXME the model should really be just using Qt::DisplayRole | ||
282 | m_model->sort(0 /*column*/); | 281 | m_model->sort(0 /*column*/); | ||
283 | 282 | | |||
284 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); | 283 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); | ||
285 | setSelectedPlugin(cg.readEntry("name", m_defaultTheme->themeName())); | 284 | setSelectedPlugin(cg.readEntry("name", QStringLiteral("default"))); | ||
286 | 285 | | |||
287 | emit selectedPluginIndexChanged(); | 286 | emit selectedPluginIndexChanged(); | ||
288 | 287 | | |||
289 | updateNeedsSave(); | 288 | updateNeedsSave(); | ||
290 | } | 289 | } | ||
291 | 290 | | |||
292 | void KCMDesktopTheme::save() | 291 | void KCMDesktopTheme::save() | ||
293 | { | 292 | { | ||
294 | if (m_defaultTheme->themeName() != m_selectedPlugin) { | 293 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); | ||
295 | m_defaultTheme->setThemeName(m_selectedPlugin); | 294 | const auto currentTheme = cg.readEntry("name", QStringLiteral("default")); | ||
295 | if (currentTheme != m_selectedPlugin) { | ||||
296 | cg.writeEntry("name", m_selectedPlugin); | ||||
297 | cg.sync(); | ||||
298 | Plasma::Theme().setThemeName(m_selectedPlugin); | ||||
296 | } | 299 | } | ||
297 | 300 | | |||
298 | processPendingDeletions(); | 301 | processPendingDeletions(); | ||
299 | updateNeedsSave(); | 302 | updateNeedsSave(); | ||
300 | } | 303 | } | ||
301 | 304 | | |||
302 | void KCMDesktopTheme::defaults() | 305 | void KCMDesktopTheme::defaults() | ||
303 | { | 306 | { | ||
Show All 13 Lines | |||||
317 | 320 | | |||
318 | void KCMDesktopTheme::editTheme(const QString &theme) | 321 | void KCMDesktopTheme::editTheme(const QString &theme) | ||
319 | { | 322 | { | ||
320 | QProcess::startDetached(QStringLiteral("plasmathemeexplorer -t ") % theme); | 323 | QProcess::startDetached(QStringLiteral("plasmathemeexplorer -t ") % theme); | ||
321 | } | 324 | } | ||
322 | 325 | | |||
323 | void KCMDesktopTheme::updateNeedsSave() | 326 | void KCMDesktopTheme::updateNeedsSave() | ||
324 | { | 327 | { | ||
328 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); | ||||
329 | const auto currentTheme = cg.readEntry("name", QStringLiteral("default")); | ||||
325 | setNeedsSave(!m_model->match(m_model->index(0, 0), PendingDeletionRole, true).isEmpty() | 330 | setNeedsSave(!m_model->match(m_model->index(0, 0), PendingDeletionRole, true).isEmpty() | ||
326 | || m_selectedPlugin != m_defaultTheme->themeName()); | 331 | || m_selectedPlugin != currentTheme); | ||
327 | } | 332 | } | ||
328 | 333 | | |||
329 | void KCMDesktopTheme::processPendingDeletions() | 334 | void KCMDesktopTheme::processPendingDeletions() | ||
330 | { | 335 | { | ||
331 | const QString program = QStringLiteral("plasmapkg2"); | 336 | const QString program = QStringLiteral("plasmapkg2"); | ||
332 | 337 | | |||
333 | const auto pendingDeletions = m_model->match(m_model->index(0, 0), PendingDeletionRole, true, -1 /*all*/); | 338 | const auto pendingDeletions = m_model->match(m_model->index(0, 0), PendingDeletionRole, true, -1 /*all*/); | ||
334 | QVector<QPersistentModelIndex> persistentPendingDeletions; | 339 | QVector<QPersistentModelIndex> persistentPendingDeletions; | ||
Show All 34 Lines |