Changeset View
Changeset View
Standalone View
Standalone View
kcm/kcm.cpp
Show All 16 Lines | |||||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "kcm.h" | 20 | #include "kcm.h" | ||
21 | #include "kscreensaversettings.h" | 21 | #include "kscreensaversettings.h" | ||
22 | #include "ui_kcm.h" | 22 | #include "ui_kcm.h" | ||
23 | #include "screenlocker_interface.h" | 23 | #include "screenlocker_interface.h" | ||
24 | #include "../greeter/wallpaper_integration.h" | 24 | #include "../greeter/wallpaper_integration.h" | ||
25 | #include "../greeter/lnf_integration.h" | ||||
26 | | ||||
25 | #include <config-kscreenlocker.h> | 27 | #include <config-kscreenlocker.h> | ||
26 | #include <KActionCollection> | 28 | #include <KActionCollection> | ||
27 | #include <KGlobalAccel> | 29 | #include <KGlobalAccel> | ||
28 | #include <KCModule> | 30 | #include <KCModule> | ||
29 | #include <KPluginFactory> | 31 | #include <KPluginFactory> | ||
30 | #include <KConfigDialogManager> | 32 | #include <KConfigDialogManager> | ||
31 | #include <QVBoxLayout> | 33 | #include <QVBoxLayout> | ||
32 | #include <QMessageBox> | 34 | #include <QMessageBox> | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 68 | { | |||
79 | 81 | | |||
80 | loadWallpapers(); | 82 | loadWallpapers(); | ||
81 | auto wallpaperChangedSignal = static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged); | 83 | auto wallpaperChangedSignal = static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged); | ||
82 | connect(m_ui->wallpaperCombo, wallpaperChangedSignal, this, static_cast<void (KCModule::*)()>(&ScreenLockerKcm::changed)); | 84 | connect(m_ui->wallpaperCombo, wallpaperChangedSignal, this, static_cast<void (KCModule::*)()>(&ScreenLockerKcm::changed)); | ||
83 | connect(m_ui->wallpaperCombo, wallpaperChangedSignal, this, &ScreenLockerKcm::loadWallpaperConfig); | 85 | connect(m_ui->wallpaperCombo, wallpaperChangedSignal, this, &ScreenLockerKcm::loadWallpaperConfig); | ||
84 | 86 | | |||
85 | m_ui->wallpaperCombo->installEventFilter(this); | 87 | m_ui->wallpaperCombo->installEventFilter(this); | ||
86 | 88 | | |||
87 | m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | | |||
88 | auto proxy = new ScreenLockerProxy(this); | 89 | auto proxy = new ScreenLockerProxy(this); | ||
90 | m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | ||||
89 | m_ui->wallpaperConfigWidget->rootContext()->setContextProperty("configDialog", proxy); | 91 | m_ui->wallpaperConfigWidget->rootContext()->setContextProperty("configDialog", proxy); | ||
90 | 92 | | |||
93 | m_ui->lnfConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | ||||
94 | m_ui->lnfConfigWidget->rootContext()->setContextProperty("configDialog", proxy); | ||||
95 | | ||||
96 | | ||||
97 | | ||||
91 | connect(this, &ScreenLockerKcm::wallpaperConfigurationChanged, proxy, &ScreenLockerProxy::wallpaperConfigurationChanged); | 98 | connect(this, &ScreenLockerKcm::wallpaperConfigurationChanged, proxy, &ScreenLockerProxy::wallpaperConfigurationChanged); | ||
92 | connect(this, &ScreenLockerKcm::currentWallpaperChanged, proxy, &ScreenLockerProxy::currentWallpaperChanged); | 99 | connect(this, &ScreenLockerKcm::currentWallpaperChanged, proxy, &ScreenLockerProxy::currentWallpaperChanged); | ||
93 | 100 | | |||
94 | m_ui->wallpaperConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/config.qml"))); | 101 | m_ui->wallpaperConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/wallpaperconfig.qml"))); | ||
95 | connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(changed())); | 102 | connect(m_ui->wallpaperConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(changed())); | ||
96 | 103 | | |||
104 | m_ui->lnfConfigWidget->setSource(QUrl(QStringLiteral("qrc:/kscreenlocker-kcm-resources/lnfconfig.qml"))); | ||||
105 | connect(m_ui->lnfConfigWidget->rootObject(), SIGNAL(configurationChanged()), this, SLOT(changed())); | ||||
106 | | ||||
97 | m_ui->installEventFilter(this); | 107 | m_ui->installEventFilter(this); | ||
98 | } | 108 | } | ||
99 | 109 | | |||
100 | void ScreenLockerKcm::shortcutChanged(const QKeySequence &key) | 110 | void ScreenLockerKcm::shortcutChanged(const QKeySequence &key) | ||
101 | { | 111 | { | ||
102 | if (QAction *a = m_actionCollection->action(s_lockActionName)) { | 112 | if (QAction *a = m_actionCollection->action(s_lockActionName)) { | ||
103 | auto shortcuts = KGlobalAccel::self()->shortcut(a); | 113 | auto shortcuts = KGlobalAccel::self()->shortcut(a); | ||
104 | m_ui->lockscreenShortcut->setProperty("changed", !shortcuts.contains(key)); | 114 | m_ui->lockscreenShortcut->setProperty("changed", !shortcuts.contains(key)); | ||
Show All 13 Lines | 120 | { | |||
118 | } | 128 | } | ||
119 | 129 | | |||
120 | if (QAction *a = m_actionCollection->action(s_lockActionName)) { | 130 | if (QAction *a = m_actionCollection->action(s_lockActionName)) { | ||
121 | auto shortcuts = KGlobalAccel::self()->shortcut(a); | 131 | auto shortcuts = KGlobalAccel::self()->shortcut(a); | ||
122 | if (!shortcuts.isEmpty()) { | 132 | if (!shortcuts.isEmpty()) { | ||
123 | m_ui->lockscreenShortcut->setKeySequence(shortcuts.first()); | 133 | m_ui->lockscreenShortcut->setKeySequence(shortcuts.first()); | ||
124 | } | 134 | } | ||
125 | } | 135 | } | ||
136 | m_lnfIntegration = new ScreenLocker::LnFIntegration(this); | ||||
137 | m_lnfIntegration->setPackage(m_package); | ||||
138 | m_lnfIntegration->setConfig(KScreenSaverSettings::self()->sharedConfig()); | ||||
139 | m_lnfIntegration->init(); | ||||
140 | | ||||
126 | 141 | | |||
127 | selectWallpaper(KScreenSaverSettings::self()->wallpaperPlugin()); | 142 | selectWallpaper(KScreenSaverSettings::self()->wallpaperPlugin()); | ||
128 | loadWallpaperConfig(); | 143 | loadWallpaperConfig(); | ||
144 | loadLnfConfig(); | ||||
129 | } | 145 | } | ||
130 | 146 | | |||
131 | void ScreenLockerKcm::test(const QString &plugin) | 147 | void ScreenLockerKcm::test(const QString &plugin) | ||
132 | { | 148 | { | ||
133 | if (plugin.isEmpty() || plugin == QLatin1String("none")) { | 149 | if (plugin.isEmpty() || plugin == QLatin1String("none")) { | ||
134 | return; | 150 | return; | ||
135 | } | 151 | } | ||
136 | 152 | | |||
137 | QProcess proc; | 153 | QProcess proc; | ||
138 | QStringList arguments; | 154 | QStringList arguments; | ||
139 | arguments << plugin << QStringLiteral("--testing"); | 155 | arguments << plugin << QStringLiteral("--testing"); | ||
140 | if (proc.execute(KSCREENLOCKER_GREET_BIN, arguments)) { | 156 | if (proc.execute(KSCREENLOCKER_GREET_BIN, arguments)) { | ||
141 | QMessageBox::critical(this, i18n("Error"), i18n("Failed to successfully test the screen locker.")); | 157 | QMessageBox::critical(this, i18n("Error"), i18n("Failed to successfully test the screen locker.")); | ||
142 | } | 158 | } | ||
143 | } | 159 | } | ||
144 | 160 | | |||
145 | void ScreenLockerKcm::save() | 161 | void ScreenLockerKcm::save() | ||
146 | { | 162 | { | ||
147 | if (!shouldSaveShortcut()) { | 163 | if (!shouldSaveShortcut()) { | ||
148 | QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection); | 164 | QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection); | ||
149 | return; | 165 | return; | ||
150 | } | 166 | } | ||
151 | KCModule::save(); | 167 | KCModule::save(); | ||
152 | QMetaObject::invokeMethod(m_ui->wallpaperConfigWidget->rootObject(), "saveConfig"); | 168 | QMetaObject::invokeMethod(m_ui->wallpaperConfigWidget->rootObject(), "saveConfig"); | ||
169 | QMetaObject::invokeMethod(m_ui->lnfConfigWidget->rootObject(), "saveConfig"); | ||||
153 | 170 | | |||
154 | // set the wallpaper config | 171 | // set the wallpaper config | ||
155 | KScreenSaverSettings::self()->setWallpaperPlugin(m_ui->wallpaperCombo->currentData().toString()); | 172 | KScreenSaverSettings::self()->setWallpaperPlugin(m_ui->wallpaperCombo->currentData().toString()); | ||
156 | 173 | | |||
157 | KScreenSaverSettings::self()->save(); | 174 | KScreenSaverSettings::self()->save(); | ||
158 | if (m_ui->lockscreenShortcut->property("changed").toBool()) { | 175 | if (m_ui->lockscreenShortcut->property("changed").toBool()) { | ||
159 | if (QAction *a = m_actionCollection->action(s_lockActionName)) { | 176 | if (QAction *a = m_actionCollection->action(s_lockActionName)) { | ||
160 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>{m_ui->lockscreenShortcut->keySequence()}, KGlobalAccel::NoAutoloading); | 177 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>{m_ui->lockscreenShortcut->keySequence()}, KGlobalAccel::NoAutoloading); | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 236 | { | |||
230 | m_wallpaperIntegration->setConfig(KScreenSaverSettings::self()->sharedConfig()); | 247 | m_wallpaperIntegration->setConfig(KScreenSaverSettings::self()->sharedConfig()); | ||
231 | m_wallpaperIntegration->setPluginName(m_ui->wallpaperCombo->currentData().toString()); | 248 | m_wallpaperIntegration->setPluginName(m_ui->wallpaperCombo->currentData().toString()); | ||
232 | m_wallpaperIntegration->init(); | 249 | m_wallpaperIntegration->init(); | ||
233 | m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("wallpaper"), m_wallpaperIntegration); | 250 | m_ui->wallpaperConfigWidget->rootContext()->setContextProperty(QStringLiteral("wallpaper"), m_wallpaperIntegration); | ||
234 | emit wallpaperConfigurationChanged(); | 251 | emit wallpaperConfigurationChanged(); | ||
235 | m_ui->wallpaperConfigWidget->rootObject()->setProperty("sourceFile", m_wallpaperIntegration->package().filePath(QByteArrayLiteral("ui"), QStringLiteral("config.qml"))); | 252 | m_ui->wallpaperConfigWidget->rootObject()->setProperty("sourceFile", m_wallpaperIntegration->package().filePath(QByteArrayLiteral("ui"), QStringLiteral("config.qml"))); | ||
236 | } | 253 | } | ||
237 | 254 | | |||
255 | void ScreenLockerKcm::loadLnfConfig() | ||||
256 | { | ||||
257 | auto sourceFile = m_package.fileUrl(QByteArrayLiteral("lockscreen"), QStringLiteral("config.qml")); | ||||
258 | if (sourceFile.isEmpty()) { | ||||
259 | m_ui->lnfConfigWidget->hide(); | ||||
260 | return; | ||||
261 | } | ||||
262 | m_ui->lnfConfigWidget->rootObject()->setProperty("sourceFile", sourceFile); | ||||
263 | } | ||||
264 | | ||||
238 | KDeclarative::ConfigPropertyMap * ScreenLockerKcm::wallpaperConfiguration() const | 265 | KDeclarative::ConfigPropertyMap * ScreenLockerKcm::wallpaperConfiguration() const | ||
239 | { | 266 | { | ||
240 | if (!m_wallpaperIntegration) { | 267 | if (!m_wallpaperIntegration) { | ||
241 | return nullptr; | 268 | return nullptr; | ||
242 | } | 269 | } | ||
243 | return m_wallpaperIntegration->configuration(); | 270 | return m_wallpaperIntegration->configuration(); | ||
244 | } | 271 | } | ||
245 | 272 | | |||
273 | KDeclarative::ConfigPropertyMap * ScreenLockerKcm::lnfConfiguration() const | ||||
274 | { | ||||
275 | if (!m_lnfIntegration) { | ||||
276 | return nullptr; | ||||
277 | } | ||||
278 | return m_lnfIntegration->configuration(); | ||||
279 | } | ||||
280 | | ||||
281 | | ||||
246 | QString ScreenLockerKcm::currentWallpaper() const | 282 | QString ScreenLockerKcm::currentWallpaper() const | ||
247 | { | 283 | { | ||
248 | return m_ui->wallpaperCombo->currentData().toString(); | 284 | return m_ui->wallpaperCombo->currentData().toString(); | ||
249 | } | 285 | } | ||
250 | 286 | | |||
251 | bool ScreenLockerKcm::eventFilter(QObject *watched, QEvent *event) | 287 | bool ScreenLockerKcm::eventFilter(QObject *watched, QEvent *event) | ||
252 | { | 288 | { | ||
253 | if (watched == m_ui) { | 289 | if (watched == m_ui) { | ||
254 | if (event->type() == QEvent::PaletteChange) { | 290 | if (event->type() == QEvent::PaletteChange) { | ||
255 | m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | 291 | m_ui->wallpaperConfigWidget->setClearColor(m_ui->palette().color(QPalette::Active, QPalette::Window)); | ||
256 | } | 292 | } | ||
257 | return false; | 293 | return false; | ||
258 | } | 294 | } | ||
259 | if (watched != m_ui->wallpaperCombo) { | 295 | if (watched != m_ui->wallpaperCombo) { | ||
260 | return false; | 296 | return false; | ||
261 | } | 297 | } | ||
262 | if (event->type() == QEvent::Move) { | 298 | if (event->type() == QEvent::Move) { | ||
263 | if (auto object = m_ui->wallpaperConfigWidget->rootObject()) { | 299 | if (auto object = m_ui->wallpaperConfigWidget->rootObject()) { | ||
264 | // QtQuick Layouts have a hardcoded 5 px spacing by default | 300 | // QtQuick Layouts have a hardcoded 5 px spacing by default | ||
265 | object->setProperty("formAlignment", m_ui->wallpaperCombo->x() + 5); | 301 | object->setProperty("formAlignment", m_ui->wallpaperCombo->x() + 5); | ||
266 | } | 302 | } | ||
303 | if (auto object = m_ui->lnfConfigWidget->rootObject()) { | ||||
304 | // QtQuick Layouts have a hardcoded 5 px spacing by default | ||||
305 | object->setProperty("formAlignment", m_ui->wallpaperCombo->x() + 5); | ||||
306 | } | ||||
307 | | ||||
267 | } | 308 | } | ||
268 | return false; | 309 | return false; | ||
269 | } | 310 | } | ||
270 | 311 | | |||
271 | K_PLUGIN_FACTORY_WITH_JSON(ScreenLockerKcmFactory, | 312 | K_PLUGIN_FACTORY_WITH_JSON(ScreenLockerKcmFactory, | ||
272 | "screenlocker.json", | 313 | "screenlocker.json", | ||
273 | registerPlugin<ScreenLockerKcm>();) | 314 | registerPlugin<ScreenLockerKcm>();) | ||
274 | 315 | | |||
275 | #include "kcm.moc" | 316 | #include "kcm.moc" |