Changeset View
Changeset View
Standalone View
Standalone View
kcms/ksplash/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 | ||
12 | Library General Public License for more details. | 13 | Library General Public License for more details. | ||
13 | 14 | | |||
14 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. | ||
18 | */ | 19 | */ | ||
19 | 20 | | |||
20 | #include "kcm.h" | 21 | #include "kcm.h" | ||
21 | 22 | | |||
22 | #include <KPluginFactory> | 23 | #include <KPluginFactory> | ||
23 | #include <KPluginLoader> | 24 | #include <KPluginLoader> | ||
24 | #include <KAboutData> | 25 | #include <KAboutData> | ||
25 | #include <KSharedConfig> | 26 | #include <KLocalizedString> | ||
27 | | ||||
26 | #include <QStandardPaths> | 28 | #include <QStandardPaths> | ||
27 | #include <QProcess> | 29 | #include <QProcess> | ||
28 | #include <QQuickView> | | |||
29 | | ||||
30 | #include <QVBoxLayout> | | |||
31 | #include <QPushButton> | | |||
32 | #include <QStandardItemModel> | 30 | #include <QStandardItemModel> | ||
33 | #include <QQmlContext> | | |||
34 | #include <QDir> | 31 | #include <QDir> | ||
35 | 32 | | |||
36 | #include <KLocalizedString> | | |||
37 | #include <Plasma/PluginLoader> | 33 | #include <Plasma/PluginLoader> | ||
38 | 34 | | |||
39 | #include <KNewStuff3/KNS3/DownloadDialog> | 35 | #include <KNewStuff3/KNS3/DownloadDialog> | ||
40 | 36 | | |||
37 | #include "splashscreensettings.h" | ||||
38 | | ||||
41 | K_PLUGIN_FACTORY_WITH_JSON(KCMSplashScreenFactory, "kcm_splashscreen.json", registerPlugin<KCMSplashScreen>();) | 39 | K_PLUGIN_FACTORY_WITH_JSON(KCMSplashScreenFactory, "kcm_splashscreen.json", registerPlugin<KCMSplashScreen>();) | ||
42 | 40 | | |||
43 | KCMSplashScreen::KCMSplashScreen(QObject* parent, const QVariantList& args) | 41 | KCMSplashScreen::KCMSplashScreen(QObject* parent, const QVariantList& args) | ||
44 | : KQuickAddons::ConfigModule(parent, args) | 42 | : KQuickAddons::ConfigModule(parent, args) | ||
45 | , m_config(QStringLiteral("ksplashrc")) | 43 | , m_settings(new SplashScreenSettings(this)) | ||
46 | , m_configGroup(m_config.group("KSplash")) | 44 | , m_model(new QStandardItemModel(this)) | ||
47 | { | 45 | { | ||
46 | connect(m_settings, &SplashScreenSettings::engineChanged, this, [this]{ setNeedsSave(true); }); | ||||
47 | connect(m_settings, &SplashScreenSettings::themeChanged, this, [this]{ setNeedsSave(true); }); | ||||
48 | | ||||
49 | qmlRegisterType<SplashScreenSettings>(); | ||||
48 | qmlRegisterType<QStandardItemModel>(); | 50 | qmlRegisterType<QStandardItemModel>(); | ||
51 | | ||||
49 | KAboutData* about = new KAboutData(QStringLiteral("kcm_splashscreen"), i18n("Splash Screen"), | 52 | KAboutData* about = new KAboutData(QStringLiteral("kcm_splashscreen"), i18n("Splash Screen"), | ||
50 | QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); | 53 | QStringLiteral("0.1"), QString(), KAboutLicense::LGPL); | ||
51 | about->addAuthor(i18n("Marco Martin"), QString(), QStringLiteral("mart@kde.org")); | 54 | about->addAuthor(i18n("Marco Martin"), QString(), QStringLiteral("mart@kde.org")); | ||
52 | setAboutData(about); | 55 | setAboutData(about); | ||
53 | setButtons(Help | Apply | Default); | 56 | setButtons(Help | Apply | Default); | ||
54 | 57 | | |||
55 | m_model = new QStandardItemModel(this); | | |||
56 | QHash<int, QByteArray> roles = m_model->roleNames(); | 58 | QHash<int, QByteArray> roles = m_model->roleNames(); | ||
57 | roles[PluginNameRole] = "pluginName"; | 59 | roles[PluginNameRole] = "pluginName"; | ||
58 | roles[ScreenshotRole] = "screenshot"; | 60 | roles[ScreenshotRole] = "screenshot"; | ||
59 | roles[DescriptionRole] = "description"; | 61 | roles[DescriptionRole] = "description"; | ||
60 | m_model->setItemRoleNames(roles); | 62 | m_model->setItemRoleNames(roles); | ||
61 | loadModel(); | 63 | loadModel(); | ||
62 | } | 64 | } | ||
63 | 65 | | |||
Show All 15 Lines | 77 | for (const QString &path : paths) { | |||
79 | if (component.isEmpty() || !pkg.filePath(component.toUtf8()).isEmpty()) { | 81 | if (component.isEmpty() || !pkg.filePath(component.toUtf8()).isEmpty()) { | ||
80 | packages << pkg; | 82 | packages << pkg; | ||
81 | } | 83 | } | ||
82 | } | 84 | } | ||
83 | 85 | | |||
84 | return packages; | 86 | return packages; | ||
85 | } | 87 | } | ||
86 | 88 | | |||
87 | QStandardItemModel *KCMSplashScreen::splashModel() const | 89 | SplashScreenSettings *KCMSplashScreen::splashScreenSettings() const | ||
88 | { | 90 | { | ||
89 | return m_model; | 91 | return m_settings; | ||
90 | } | 92 | } | ||
91 | 93 | | |||
92 | QString KCMSplashScreen::selectedPlugin() const | 94 | QStandardItemModel *KCMSplashScreen::splashModel() const | ||
93 | { | | |||
94 | return m_selectedPlugin; | | |||
95 | } | | |||
96 | | ||||
97 | void KCMSplashScreen::setSelectedPlugin(const QString &plugin) | | |||
98 | { | 95 | { | ||
99 | if (m_selectedPlugin == plugin) { | 96 | return m_model; | ||
100 | return; | | |||
101 | } | | |||
102 | | ||||
103 | if (!m_selectedPlugin.isEmpty()) { | | |||
104 | setNeedsSave(true); | | |||
105 | } | | |||
106 | m_selectedPlugin = plugin; | | |||
107 | emit selectedPluginChanged(); | | |||
108 | emit selectedPluginIndexChanged(); | | |||
109 | } | 97 | } | ||
110 | 98 | | |||
111 | void KCMSplashScreen::getNewClicked() | 99 | void KCMSplashScreen::getNewClicked() | ||
112 | { | 100 | { | ||
113 | KNS3::DownloadDialog dialog("ksplash.knsrc", nullptr); | 101 | KNS3::DownloadDialog dialog("ksplash.knsrc", nullptr); | ||
114 | if (dialog.exec()) { | 102 | if (dialog.exec()) { | ||
115 | KNS3::Entry::List list = dialog.changedEntries(); | 103 | KNS3::Entry::List list = dialog.changedEntries(); | ||
116 | if (!list.isEmpty()) { | 104 | if (!list.isEmpty()) { | ||
Show All 16 Lines | 111 | { | |||
133 | } | 121 | } | ||
134 | m_model->sort(0 /*column*/); | 122 | m_model->sort(0 /*column*/); | ||
135 | 123 | | |||
136 | QStandardItem* row = new QStandardItem(i18n("None")); | 124 | QStandardItem* row = new QStandardItem(i18n("None")); | ||
137 | row->setData("None", PluginNameRole); | 125 | row->setData("None", PluginNameRole); | ||
138 | row->setData(i18n("No splash screen will be shown"), DescriptionRole); | 126 | row->setData(i18n("No splash screen will be shown"), DescriptionRole); | ||
139 | m_model->insertRow(0, row); | 127 | m_model->insertRow(0, row); | ||
140 | 128 | | |||
141 | emit selectedPluginIndexChanged(); | 129 | if (-1 == pluginIndex(m_settings->theme())) { | ||
142 | } | 130 | defaults(); | ||
143 | | ||||
144 | void KCMSplashScreen::load() | | |||
145 | { | | |||
146 | m_package = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); | | |||
147 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); | | |||
148 | const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); | | |||
149 | if (!packageName.isEmpty()) { | | |||
150 | m_package.setPath(packageName); | | |||
151 | } | 131 | } | ||
152 | 132 | | |||
153 | QString currentPlugin = m_configGroup.readEntry("Theme", QString()); | 133 | emit m_settings->themeChanged(); | ||
154 | if (currentPlugin.isEmpty()) { | | |||
155 | currentPlugin = m_package.metadata().pluginName(); | | |||
156 | } | 134 | } | ||
157 | setSelectedPlugin(currentPlugin); | | |||
158 | 135 | | |||
136 | void KCMSplashScreen::load() | ||||
137 | { | ||||
138 | m_settings->load(); | ||||
ervin: I'd expect this to be unnecessary since load() will emit ThemeChanged or EngineChanged if said… | |||||
crossi: Yes, this one is not necessary. | |||||
159 | setNeedsSave(false); | 139 | setNeedsSave(false); | ||
160 | } | 140 | } | ||
161 | 141 | | |||
162 | | ||||
163 | void KCMSplashScreen::save() | 142 | void KCMSplashScreen::save() | ||
164 | { | 143 | { | ||
165 | if (m_selectedPlugin.isEmpty()) { | 144 | m_settings->setEngine(m_settings->theme() == QStringLiteral("None") ? QStringLiteral("none") : QStringLiteral("KSplashQML")); | ||
166 | return; | 145 | m_settings->save(); | ||
I'd expect either setNeedsSave(false) here, or configChanged() to be connected from the ctor. Are we sure that state is reset properly on apply being clicked? ervin: I'd expect either setNeedsSave(false) here, or configChanged() to be connected from the ctor. | |||||
crossi: When clicking on "apply", the button is disabled. | |||||
167 | } else if (m_selectedPlugin == QLatin1String("None")) { | | |||
168 | m_configGroup.writeEntry("Theme", m_selectedPlugin); | | |||
169 | m_configGroup.writeEntry("Engine", "none"); | | |||
170 | } else { | | |||
171 | m_configGroup.writeEntry("Theme", m_selectedPlugin); | | |||
172 | m_configGroup.writeEntry("Engine", "KSplashQML"); | | |||
173 | } | | |||
174 | | ||||
175 | m_configGroup.sync(); | | |||
176 | setNeedsSave(false); | | |||
177 | } | 146 | } | ||
178 | 147 | | |||
179 | void KCMSplashScreen::defaults() | 148 | void KCMSplashScreen::defaults() | ||
180 | { | 149 | { | ||
181 | if (!m_package.metadata().isValid()) { | 150 | m_settings->setDefaults(); | ||
182 | return; | 151 | setNeedsSave(m_settings->isSaveNeeded()); | ||
183 | } | | |||
184 | setSelectedPlugin(m_package.metadata().pluginName()); | | |||
185 | } | 152 | } | ||
186 | 153 | | |||
187 | int KCMSplashScreen::selectedPluginIndex() const | 154 | int KCMSplashScreen::pluginIndex(const QString &pluginName) const | ||
188 | { | 155 | { | ||
189 | for (int i = 0; i < m_model->rowCount(); ++i) { | 156 | const auto results = m_model->match(m_model->index(0, 0), PluginNameRole, pluginName); | ||
190 | if (m_model->data(m_model->index(i, 0), PluginNameRole).toString() == m_selectedPlugin) { | 157 | if (results.count() == 1) { | ||
191 | return i; | 158 | return results.first().row(); | ||
192 | } | | |||
193 | } | 159 | } | ||
160 | | ||||
194 | return -1; | 161 | return -1; | ||
195 | } | 162 | } | ||
196 | 163 | | |||
197 | bool KCMSplashScreen::testing() const | 164 | bool KCMSplashScreen::testing() const | ||
198 | { | 165 | { | ||
199 | return m_testProcess; | 166 | return m_testProcess; | ||
200 | } | 167 | } | ||
201 | 168 | | |||
Show All 26 Lines |
I'd expect this to be unnecessary since load() will emit ThemeChanged or EngineChanged if said config keys really changed.