Changeset View
Changeset View
Standalone View
Standalone View
kcm/kcm.cpp
Show All 33 Lines | |||||
34 | #include <QMessageBox> | 34 | #include <QMessageBox> | ||
35 | 35 | | |||
36 | #include <KPackage/Package> | 36 | #include <KPackage/Package> | ||
37 | #include <KPackage/PackageLoader> | 37 | #include <KPackage/PackageLoader> | ||
38 | 38 | | |||
39 | #include <QQmlContext> | 39 | #include <QQmlContext> | ||
40 | #include <QQuickItem> | 40 | #include <QQuickItem> | ||
41 | 41 | | |||
42 | static const QString s_defaultWallpaperPackage = QStringLiteral("org.kde.image"); | | |||
43 | | ||||
44 | class ScreenLockerKcmForm : public QWidget, public Ui::ScreenLockerKcmForm | 42 | class ScreenLockerKcmForm : public QWidget, public Ui::ScreenLockerKcmForm | ||
45 | { | 43 | { | ||
46 | Q_OBJECT | 44 | Q_OBJECT | ||
47 | public: | 45 | public: | ||
48 | explicit ScreenLockerKcmForm(QWidget *parent); | 46 | explicit ScreenLockerKcmForm(QWidget *parent); | ||
49 | }; | 47 | }; | ||
50 | 48 | | |||
51 | ScreenLockerKcmForm::ScreenLockerKcmForm(QWidget *parent) | 49 | ScreenLockerKcmForm::ScreenLockerKcmForm(QWidget *parent) | ||
Show All 10 Lines | |||||
62 | 60 | | |||
63 | ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args) | 61 | ScreenLockerKcm::ScreenLockerKcm(QWidget *parent, const QVariantList &args) | ||
64 | : KCModule(parent, args) | 62 | : KCModule(parent, args) | ||
65 | , m_settings(new KScreenSaverSettings(this)) | 63 | , m_settings(new KScreenSaverSettings(this)) | ||
66 | , m_ui(new ScreenLockerKcmForm(this)) | 64 | , m_ui(new ScreenLockerKcmForm(this)) | ||
67 | { | 65 | { | ||
68 | QVBoxLayout* layout = new QVBoxLayout(this); | 66 | QVBoxLayout* layout = new QVBoxLayout(this); | ||
69 | layout->addWidget(m_ui); | 67 | layout->addWidget(m_ui); | ||
70 | 68 | for (const auto &pluginInfo : m_settings->availableWallpaperPlugins()) { | |||
71 | addConfig(m_settings, m_ui); | 69 | m_ui->kcfg_wallpaperPluginIndex->addItem(pluginInfo.name, pluginInfo.id); | ||
72 | 70 | } | |||
73 | loadWallpapers(); | 71 | connect(m_ui->kcfg_wallpaperPluginIndex, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), | ||
74 | connect(m_ui->wallpaperCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), | | |||
75 | this, &ScreenLockerKcm::loadWallpaperConfig); | 72 | this, &ScreenLockerKcm::loadWallpaperConfig); | ||
76 | 73 | m_ui->kcfg_wallpaperPluginIndex->installEventFilter(this); | |||
77 | m_ui->wallpaperCombo->installEventFilter(this); | 74 | m_ui->installEventFilter(this); | ||
78 | 75 | | |||
79 | auto proxy = new ScreenLockerProxy(this); | 76 | auto proxy = new ScreenLockerProxy(this); | ||
77 | | ||||
80 | m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | 78 | m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | ||
81 | m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("configDialog"), proxy); | 79 | m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("configDialog"), proxy); | ||
82 | | ||||
83 | m_ui->lnfConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | | |||
84 | m_ui->lnfConfigWidget->rootContext()->setContextProperty(QStringLiteral("configDialog"), proxy); | | |||
85 | | ||||
86 | | ||||
87 | | ||||
88 | connect(this, &ScreenLockerKcm::wallpaperConfigurationChanged, proxy, &ScreenLockerProxy::wallpaperConfigurationChanged); | | |||
89 | connect(this, &ScreenLockerKcm::currentWallpaperChanged, proxy, &ScreenLockerProxy::currentWallpaperChanged); | | |||
90 | | ||||
91 | m_ui->wallpaperConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/wallpaperconfig.qml"))); | 80 | m_ui->wallpaperConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/wallpaperconfig.qml"))); | ||
92 | connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState())); | 81 | connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState())); | ||
93 | 82 | | |||
83 | m_ui->lnfConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | ||||
84 | m_ui->lnfConfigWidget->rootContext()->setContextProperty(QStringLiteral("configDialog"), proxy); | ||||
94 | m_ui->lnfConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/lnfconfig.qml"))); | 85 | m_ui->lnfConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/lnfconfig.qml"))); | ||
95 | connect(m_ui->lnfConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState())); | 86 | connect(m_ui->lnfConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(updateState())); | ||
96 | 87 | | |||
97 | m_ui->installEventFilter(this); | 88 | addConfig(m_settings, m_ui); | ||
98 | } | 89 | } | ||
99 | 90 | | |||
100 | void ScreenLockerKcm::load() | 91 | void ScreenLockerKcm::load() | ||
101 | { | 92 | { | ||
102 | KCModule::load(); | 93 | KCModule::load(); | ||
103 | // Because the wallpaper plugin is currently handled wrongly | | |||
104 | m_settings->load(); | | |||
105 | | ||||
106 | m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); | | |||
107 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); | | |||
108 | const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); | | |||
109 | if (!packageName.isEmpty()) { | | |||
110 | m_package.setPath(packageName); | | |||
111 | } | | |||
112 | | ||||
113 | m_lnfIntegration = new ScreenLocker::LnFIntegration(this); | | |||
114 | m_lnfIntegration->setPackage(m_package); | | |||
115 | m_lnfIntegration->setConfig(m_settings->sharedConfig()); | | |||
116 | m_lnfIntegration->init(); | | |||
117 | m_lnfSettings = m_lnfIntegration->configScheme(); | | |||
118 | 94 | | |||
119 | selectWallpaper(m_settings->wallpaperPlugin()); | | |||
120 | loadWallpaperConfig(); | 95 | loadWallpaperConfig(); | ||
121 | loadLnfConfig(); | 96 | loadLnfConfig(); | ||
122 | 97 | | |||
123 | updateState(); | 98 | updateState(); | ||
124 | } | 99 | } | ||
125 | 100 | | |||
126 | void ScreenLockerKcm::save() | 101 | void ScreenLockerKcm::save() | ||
127 | { | 102 | { | ||
Show All 15 Lines | |||||
143 | } | 118 | } | ||
144 | 119 | | |||
145 | updateState(); | 120 | updateState(); | ||
146 | } | 121 | } | ||
147 | 122 | | |||
148 | void ScreenLockerKcm::defaults() | 123 | void ScreenLockerKcm::defaults() | ||
149 | { | 124 | { | ||
150 | KCModule::defaults(); | 125 | KCModule::defaults(); | ||
151 | selectWallpaper(s_defaultWallpaperPackage); | | |||
152 | 126 | | |||
153 | if (m_lnfSettings) { | 127 | if (m_lnfSettings) { | ||
154 | m_lnfSettings->setDefaults(); | 128 | m_lnfSettings->setDefaults(); | ||
155 | } | 129 | } | ||
156 | 130 | | |||
157 | if (m_wallpaperSettings) { | 131 | if (m_wallpaperSettings) { | ||
158 | m_wallpaperSettings->setDefaults(); | 132 | m_wallpaperSettings->setDefaults(); | ||
159 | } | 133 | } | ||
Show All 15 Lines | 148 | if (m_wallpaperSettings) { | |||
175 | isDefaults &= m_wallpaperSettings->isDefaults(); | 149 | isDefaults &= m_wallpaperSettings->isDefaults(); | ||
176 | isSaveNeeded |= m_wallpaperSettings->isSaveNeeded(); | 150 | isSaveNeeded |= m_wallpaperSettings->isSaveNeeded(); | ||
177 | } | 151 | } | ||
178 | 152 | | |||
179 | emit changed(isSaveNeeded); | 153 | emit changed(isSaveNeeded); | ||
180 | emit defaulted(isDefaults); | 154 | emit defaulted(isDefaults); | ||
181 | } | 155 | } | ||
182 | 156 | | |||
183 | void ScreenLockerKcm::loadWallpapers() | | |||
184 | { | | |||
185 | const auto wallpaperPackages = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/Wallpaper")); | | |||
186 | for (auto &package : wallpaperPackages) { | | |||
187 | m_ui->wallpaperCombo->addItem(package.name(), package.pluginId()); | | |||
188 | } | | |||
189 | } | | |||
190 | | ||||
191 | void ScreenLockerKcm::selectWallpaper(const QString &pluginId) | | |||
192 | { | | |||
193 | const auto index = m_ui->wallpaperCombo->findData(pluginId); | | |||
194 | if (index != -1) { | | |||
195 | m_ui->wallpaperCombo->setCurrentIndex(index); | | |||
196 | } else if (pluginId != s_defaultWallpaperPackage) { | | |||
197 | // fall back to default plugin | | |||
198 | selectWallpaper(s_defaultWallpaperPackage); | | |||
199 | } | | |||
200 | } | | |||
201 | | ||||
202 | void ScreenLockerKcm::loadWallpaperConfig() | 157 | void ScreenLockerKcm::loadWallpaperConfig() | ||
203 | { | 158 | { | ||
204 | // set the wallpaper config | | |||
205 | m_settings->setWallpaperPlugin(m_ui->wallpaperCombo->currentData().toString()); | | |||
206 | updateState(); | | |||
207 | | ||||
208 | if (m_wallpaperIntegration) { | 159 | if (m_wallpaperIntegration) { | ||
209 | if (m_wallpaperIntegration->pluginName() == m_ui->wallpaperCombo->currentData().toString()) { | 160 | if (m_wallpaperIntegration->pluginName() == m_ui->kcfg_wallpaperPluginIndex->currentData().toString()) { | ||
210 | // nothing changed | 161 | // nothing changed | ||
211 | return; | 162 | return; | ||
212 | } | 163 | } | ||
213 | delete m_wallpaperIntegration; | 164 | delete m_wallpaperIntegration; | ||
214 | } | 165 | } | ||
215 | emit currentWallpaperChanged(); | 166 | emit currentWallpaperChanged(); | ||
216 | 167 | | |||
217 | m_wallpaperIntegration = new ScreenLocker::WallpaperIntegration(this); | 168 | m_wallpaperIntegration = new ScreenLocker::WallpaperIntegration(this); | ||
218 | m_wallpaperIntegration->setConfig(m_settings->sharedConfig()); | 169 | m_wallpaperIntegration->setConfig(m_settings->sharedConfig()); | ||
219 | m_wallpaperIntegration->setPluginName(m_ui->wallpaperCombo->currentData().toString()); | 170 | m_wallpaperIntegration->setPluginName(m_ui->kcfg_wallpaperPluginIndex->currentData().toString()); | ||
220 | m_wallpaperIntegration->init(); | 171 | m_wallpaperIntegration->init(); | ||
221 | m_wallpaperSettings = m_wallpaperIntegration->configScheme(); | 172 | m_wallpaperSettings = m_wallpaperIntegration->configScheme(); | ||
222 | m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("wallpaper"), m_wallpaperIntegration); | 173 | m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("wallpaper"), m_wallpaperIntegration); | ||
223 | emit wallpaperConfigurationChanged(); | 174 | emit wallpaperConfigurationChanged(); | ||
224 | m_ui->wallpaperConfigWidget->rootObject()->setProperty("sourceFile", m_wallpaperIntegration->package().filePath(QByteArrayLiteral("ui"), QStringLiteral("config.qml"))); | 175 | m_ui->wallpaperConfigWidget->rootObject()->setProperty("sourceFile", m_wallpaperIntegration->package().filePath(QByteArrayLiteral("ui"), QStringLiteral("config.qml"))); | ||
225 | } | 176 | } | ||
226 | 177 | | |||
227 | void ScreenLockerKcm::loadLnfConfig() | 178 | void ScreenLockerKcm::loadLnfConfig() | ||
228 | { | 179 | { | ||
180 | Q_ASSERT(!m_package.isValid() && !m_lnfIntegration); | ||||
181 | | ||||
182 | m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); | ||||
183 | KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); | ||||
184 | const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); | ||||
185 | if (!packageName.isEmpty()) { | ||||
186 | m_package.setPath(packageName); | ||||
187 | } | ||||
188 | | ||||
189 | m_lnfIntegration = new ScreenLocker::LnFIntegration(this); | ||||
190 | m_lnfIntegration->setPackage(m_package); | ||||
191 | m_lnfIntegration->setConfig(m_settings->sharedConfig()); | ||||
192 | m_lnfIntegration->init(); | ||||
193 | m_lnfSettings = m_lnfIntegration->configScheme(); | ||||
194 | | ||||
229 | auto sourceFile = m_package.fileUrl(QByteArrayLiteral("lockscreen"), QStringLiteral("config.qml")); | 195 | auto sourceFile = m_package.fileUrl(QByteArrayLiteral("lockscreen"), QStringLiteral("config.qml")); | ||
230 | if (sourceFile.isEmpty()) { | 196 | if (sourceFile.isEmpty()) { | ||
231 | m_ui->lnfConfigWidget->hide(); | 197 | m_ui->lnfConfigWidget->hide(); | ||
232 | return; | 198 | return; | ||
233 | } | 199 | } | ||
234 | m_ui->lnfConfigWidget->rootObject()->setProperty("sourceFile", sourceFile); | 200 | m_ui->lnfConfigWidget->rootObject()->setProperty("sourceFile", sourceFile); | ||
235 | } | 201 | } | ||
236 | 202 | | |||
Show All 11 Lines | 213 | if (!m_lnfIntegration) { | |||
248 | return nullptr; | 214 | return nullptr; | ||
249 | } | 215 | } | ||
250 | return m_lnfIntegration->configuration(); | 216 | return m_lnfIntegration->configuration(); | ||
251 | } | 217 | } | ||
252 | 218 | | |||
253 | 219 | | |||
254 | QString ScreenLockerKcm::currentWallpaper() const | 220 | QString ScreenLockerKcm::currentWallpaper() const | ||
255 | { | 221 | { | ||
256 | return m_ui->wallpaperCombo->currentData().toString(); | 222 | return m_ui->kcfg_wallpaperPluginIndex->currentData().toString(); | ||
257 | } | 223 | } | ||
258 | 224 | | |||
259 | bool ScreenLockerKcm::eventFilter(QObject *watched, QEvent *event) | 225 | bool ScreenLockerKcm::eventFilter(QObject *watched, QEvent *event) | ||
260 | { | 226 | { | ||
261 | if (watched == m_ui) { | 227 | if (watched == m_ui) { | ||
262 | if (event->type() == QEvent::PaletteChange) { | 228 | if (event->type() == QEvent::PaletteChange) { | ||
263 | m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | 229 | m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | ||
264 | } | 230 | } | ||
265 | return false; | 231 | return false; | ||
266 | } | 232 | } | ||
267 | if (watched != m_ui->wallpaperCombo) { | 233 | if (watched != m_ui->kcfg_wallpaperPluginIndex) { | ||
268 | return false; | 234 | return false; | ||
269 | } | 235 | } | ||
270 | if (event->type() == QEvent::Move) { | 236 | if (event->type() == QEvent::Move) { | ||
271 | if (auto object = m_ui->wallpaperConfigWidget->rootObject()) { | 237 | if (auto object = m_ui->wallpaperConfigWidget->rootObject()) { | ||
272 | // QtQuick Layouts have a hardcoded 5 px spacing by default | 238 | // QtQuick Layouts have a hardcoded 5 px spacing by default | ||
273 | object->setProperty("formAlignment", m_ui->wallpaperCombo->x() + 5); | 239 | object->setProperty("formAlignment", m_ui->kcfg_wallpaperPluginIndex->x() + 5); | ||
274 | } | 240 | } | ||
275 | if (auto object = m_ui->lnfConfigWidget->rootObject()) { | 241 | if (auto object = m_ui->lnfConfigWidget->rootObject()) { | ||
276 | // QtQuick Layouts have a hardcoded 5 px spacing by default | 242 | // QtQuick Layouts have a hardcoded 5 px spacing by default | ||
277 | object->setProperty("formAlignment", m_ui->wallpaperCombo->x() + 5); | 243 | object->setProperty("formAlignment", m_ui->kcfg_wallpaperPluginIndex->x() + 5); | ||
278 | } | 244 | } | ||
279 | 245 | | |||
280 | } | 246 | } | ||
281 | return false; | 247 | return false; | ||
282 | } | 248 | } | ||
283 | 249 | | |||
284 | K_PLUGIN_FACTORY_WITH_JSON(ScreenLockerKcmFactory, | 250 | K_PLUGIN_FACTORY_WITH_JSON(ScreenLockerKcmFactory, | ||
285 | "screenlocker.json", | 251 | "screenlocker.json", | ||
286 | registerPlugin<ScreenLockerKcm>();) | 252 | registerPlugin<ScreenLockerKcm>();) | ||
287 | 253 | | |||
288 | #include "kcm.moc" | 254 | #include "kcm.moc" |