Changeset View
Changeset View
Standalone View
Standalone View
kcms/desktoptheme/kcm.cpp
Show All 18 Lines | 1 | /* This file is part of the KDE Project | |||
---|---|---|---|---|---|
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
20 | Boston, MA 02110-1301, USA. | 20 | Boston, MA 02110-1301, USA. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "kcm.h" | 23 | #include "kcm.h" | ||
24 | 24 | | |||
25 | #include <KPluginFactory> | 25 | #include <KPluginFactory> | ||
26 | #include <KAboutData> | 26 | #include <KAboutData> | ||
27 | #include <KSharedConfig> | | |||
28 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
29 | #include <KDesktopFile> | 28 | #include <KDesktopFile> | ||
30 | 29 | | |||
31 | #include <KIO/FileCopyJob> | 30 | #include <KIO/FileCopyJob> | ||
32 | #include <KIO/JobUiDelegate> | 31 | #include <KIO/JobUiDelegate> | ||
33 | 32 | | |||
34 | #include <Plasma/Theme> | 33 | #include <Plasma/Theme> | ||
35 | #include <Plasma/Svg> | 34 | #include <Plasma/Svg> | ||
36 | 35 | | |||
37 | #include <QDebug> | 36 | #include <QDebug> | ||
38 | #include <QProcess> | 37 | #include <QProcess> | ||
39 | #include <QQuickItem> | 38 | #include <QQuickItem> | ||
40 | #include <QQuickWindow> | 39 | #include <QQuickWindow> | ||
41 | #include <QStandardPaths> | 40 | #include <QStandardPaths> | ||
42 | #include <QStandardItemModel> | 41 | #include <QStandardItemModel> | ||
43 | #include <QTemporaryFile> | 42 | #include <QTemporaryFile> | ||
44 | 43 | | |||
45 | #include <KNewStuff3/KNS3/DownloadDialog> | 44 | #include <KNewStuff3/KNS3/DownloadDialog> | ||
46 | 45 | | |||
46 | #include "desktopthemesettings.h" | ||||
47 | | ||||
47 | Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme") | 48 | Q_LOGGING_CATEGORY(KCM_DESKTOP_THEME, "kcm_desktoptheme") | ||
48 | 49 | | |||
49 | K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();) | 50 | K_PLUGIN_FACTORY_WITH_JSON(KCMDesktopThemeFactory, "kcm_desktoptheme.json", registerPlugin<KCMDesktopTheme>();) | ||
50 | 51 | | |||
51 | KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args) | 52 | KCMDesktopTheme::KCMDesktopTheme(QObject *parent, const QVariantList &args) | ||
52 | : KQuickAddons::ConfigModule(parent, args) | 53 | : KQuickAddons::ConfigModule(parent, args) | ||
54 | , m_settings(new DesktopThemeSettings) | ||||
53 | , m_haveThemeExplorerInstalled(false) | 55 | , m_haveThemeExplorerInstalled(false) | ||
54 | { | 56 | { | ||
57 | // Unfortunately doesn't generate a ctor taking the parent as parameter | ||||
58 | m_settings->setParent(this); | ||||
55 | qmlRegisterType<QStandardItemModel>(); | 59 | qmlRegisterType<QStandardItemModel>(); | ||
56 | 60 | | |||
57 | KAboutData* about = new KAboutData(QStringLiteral("kcm_desktoptheme"), i18n("Plasma Style"), | 61 | KAboutData* about = new KAboutData(QStringLiteral("kcm_desktoptheme"), i18n("Plasma Style"), | ||
58 | QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); | 62 | QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); | ||
59 | about->addAuthor(i18n("David Rosca"), QString(), QStringLiteral("nowrep@gmail.com")); | 63 | about->addAuthor(i18n("David Rosca"), QString(), QStringLiteral("nowrep@gmail.com")); | ||
60 | setAboutData(about); | 64 | setAboutData(about); | ||
61 | setButtons(Apply | Default | Help); | 65 | setButtons(Apply | Default | Help); | ||
62 | 66 | | |||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Line(s) | 272 | if (m_model->findItems(packageName).isEmpty()) { | |||
275 | item->setData(false, PendingDeletionRole); | 279 | item->setData(false, PendingDeletionRole); | ||
276 | m_model->appendRow(item); | 280 | m_model->appendRow(item); | ||
277 | } | 281 | } | ||
278 | } | 282 | } | ||
279 | 283 | | |||
280 | m_model->setSortRole(ThemeNameRole); // FIXME the model should really be just using Qt::DisplayRole | 284 | m_model->setSortRole(ThemeNameRole); // FIXME the model should really be just using Qt::DisplayRole | ||
281 | m_model->sort(0 /*column*/); | 285 | m_model->sort(0 /*column*/); | ||
282 | 286 | | |||
283 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); | 287 | setSelectedPlugin(m_settings->name()); | ||
284 | setSelectedPlugin(cg.readEntry("name", QStringLiteral("default"))); | | |||
285 | 288 | | |||
286 | emit selectedPluginIndexChanged(); | 289 | emit selectedPluginIndexChanged(); | ||
287 | 290 | | |||
288 | updateNeedsSave(); | 291 | updateNeedsSave(); | ||
289 | } | 292 | } | ||
290 | 293 | | |||
291 | void KCMDesktopTheme::save() | 294 | void KCMDesktopTheme::save() | ||
292 | { | 295 | { | ||
293 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); | 296 | if (m_settings->name() != m_selectedPlugin) { | ||
294 | const auto currentTheme = cg.readEntry("name", QStringLiteral("default")); | 297 | m_settings->setName(m_selectedPlugin); | ||
295 | if (currentTheme != m_selectedPlugin) { | 298 | m_settings->save(); | ||
296 | cg.writeEntry("name", m_selectedPlugin); | 299 | Plasma::Theme().setThemeName(m_settings->name()); | ||
297 | cg.sync(); | | |||
298 | Plasma::Theme().setThemeName(m_selectedPlugin); | | |||
299 | } | 300 | } | ||
300 | 301 | | |||
301 | processPendingDeletions(); | 302 | processPendingDeletions(); | ||
302 | updateNeedsSave(); | 303 | updateNeedsSave(); | ||
303 | } | 304 | } | ||
304 | 305 | | |||
305 | void KCMDesktopTheme::defaults() | 306 | void KCMDesktopTheme::defaults() | ||
306 | { | 307 | { | ||
307 | setSelectedPlugin(QStringLiteral("default")); | 308 | setSelectedPlugin(m_settings->defaultNameValue()); | ||
308 | 309 | | |||
309 | // can this be done more elegantly? | 310 | // can this be done more elegantly? | ||
310 | const auto pendingDeletions = m_model->match(m_model->index(0, 0), PendingDeletionRole, true); | 311 | const auto pendingDeletions = m_model->match(m_model->index(0, 0), PendingDeletionRole, true); | ||
311 | for (const QModelIndex &idx : pendingDeletions) { | 312 | for (const QModelIndex &idx : pendingDeletions) { | ||
312 | m_model->setData(idx, false, PendingDeletionRole); | 313 | m_model->setData(idx, false, PendingDeletionRole); | ||
313 | } | 314 | } | ||
314 | } | 315 | } | ||
315 | 316 | | |||
316 | bool KCMDesktopTheme::canEditThemes() const | 317 | bool KCMDesktopTheme::canEditThemes() const | ||
317 | { | 318 | { | ||
318 | return m_haveThemeExplorerInstalled; | 319 | return m_haveThemeExplorerInstalled; | ||
319 | } | 320 | } | ||
320 | 321 | | |||
321 | void KCMDesktopTheme::editTheme(const QString &theme) | 322 | void KCMDesktopTheme::editTheme(const QString &theme) | ||
322 | { | 323 | { | ||
323 | QProcess::startDetached(QStringLiteral("plasmathemeexplorer -t ") % theme); | 324 | QProcess::startDetached(QStringLiteral("plasmathemeexplorer -t ") % theme); | ||
324 | } | 325 | } | ||
325 | 326 | | |||
326 | void KCMDesktopTheme::updateNeedsSave() | 327 | void KCMDesktopTheme::updateNeedsSave() | ||
327 | { | 328 | { | ||
328 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("plasmarc")), "Theme"); | | |||
329 | const auto currentTheme = cg.readEntry("name", QStringLiteral("default")); | | |||
330 | setNeedsSave(!m_model->match(m_model->index(0, 0), PendingDeletionRole, true).isEmpty() | 329 | setNeedsSave(!m_model->match(m_model->index(0, 0), PendingDeletionRole, true).isEmpty() | ||
331 | || m_selectedPlugin != currentTheme); | 330 | || m_selectedPlugin != m_settings->name()); | ||
332 | } | 331 | } | ||
333 | 332 | | |||
334 | void KCMDesktopTheme::processPendingDeletions() | 333 | void KCMDesktopTheme::processPendingDeletions() | ||
335 | { | 334 | { | ||
336 | const QString program = QStringLiteral("plasmapkg2"); | 335 | const QString program = QStringLiteral("plasmapkg2"); | ||
337 | 336 | | |||
338 | const auto pendingDeletions = m_model->match(m_model->index(0, 0), PendingDeletionRole, true, -1 /*all*/); | 337 | const auto pendingDeletions = m_model->match(m_model->index(0, 0), PendingDeletionRole, true, -1 /*all*/); | ||
339 | QVector<QPersistentModelIndex> persistentPendingDeletions; | 338 | QVector<QPersistentModelIndex> persistentPendingDeletions; | ||
Show All 34 Lines |