Changeset View
Changeset View
Standalone View
Standalone View
kcms/cursortheme/kcmcursortheme.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | |||||
52 | 52 | | |||
53 | #ifdef HAVE_XFIXES | 53 | #ifdef HAVE_XFIXES | ||
54 | # include <X11/extensions/Xfixes.h> | 54 | # include <X11/extensions/Xfixes.h> | ||
55 | #endif | 55 | #endif | ||
56 | 56 | | |||
57 | K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin<CursorThemeConfig>();) | 57 | K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin<CursorThemeConfig>();) | ||
58 | 58 | | |||
59 | CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) | 59 | CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) | ||
60 | : KQuickAddons::ConfigModule(parent, args), | 60 | : KQuickAddons::ManagedConfigModule(parent, args), | ||
61 | m_settings(new CursorThemeSettings), | 61 | m_settings(new CursorThemeSettings(this)), | ||
62 | m_canInstall(true), | 62 | m_canInstall(true), | ||
63 | m_canResize(true), | 63 | m_canResize(true), | ||
64 | m_canConfigure(true) | 64 | m_canConfigure(true) | ||
65 | { | 65 | { | ||
66 | // Unfortunately doesn't generate a ctor taking the parent as parameter | 66 | m_preferredSize = m_settings->cursorSize(); | ||
67 | m_settings->setParent(this); | | |||
68 | m_currentSize = m_settings->cursorSize(); | | |||
69 | m_currentTheme = m_settings->cursorTheme(); | | |||
70 | m_preferredSize = m_currentSize; | | |||
71 | connect(m_settings, &CursorThemeSettings::configChanged, this, &CursorThemeConfig::updateNeedsSave); | | |||
72 | connect(m_settings, &CursorThemeSettings::cursorSizeChanged, this, &CursorThemeConfig::updateNeedsSave); | | |||
73 | connect(m_settings, &CursorThemeSettings::cursorThemeChanged, this, &CursorThemeConfig::updateNeedsSave); | | |||
74 | connect(m_settings, &CursorThemeSettings::cursorThemeChanged, this, &CursorThemeConfig::updateSizeComboBox); | 67 | connect(m_settings, &CursorThemeSettings::cursorThemeChanged, this, &CursorThemeConfig::updateSizeComboBox); | ||
75 | qmlRegisterType<PreviewWidget>("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget"); | 68 | qmlRegisterType<PreviewWidget>("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget"); | ||
76 | qmlRegisterType<SortProxyModel>(); | 69 | qmlRegisterType<SortProxyModel>(); | ||
77 | qmlRegisterType<CursorThemeSettings>(); | 70 | qmlRegisterType<CursorThemeSettings>(); | ||
78 | KAboutData* aboutData = new KAboutData(QStringLiteral("kcm_cursortheme"), i18n("Cursors"), | 71 | KAboutData* aboutData = new KAboutData(QStringLiteral("kcm_cursortheme"), i18n("Cursors"), | ||
79 | QStringLiteral("1.0"), QString(), KAboutLicense::GPL, i18n("(c) 2003-2007 Fredrik Höglund")); | 72 | QStringLiteral("1.0"), QString(), KAboutLicense::GPL, i18n("(c) 2003-2007 Fredrik Höglund")); | ||
80 | aboutData->addAuthor(i18n("Fredrik Höglund")); | 73 | aboutData->addAuthor(i18n("Fredrik Höglund")); | ||
81 | aboutData->addAuthor(i18n("Marco Martin")); | 74 | aboutData->addAuthor(i18n("Marco Martin")); | ||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Line(s) | 251 | for (int i = 2; i < comboBoxList.size(); ++i) { | |||
260 | distance = qAbs(m_preferredSize - j); | 253 | distance = qAbs(m_preferredSize - j); | ||
261 | if (distance < smallestDistance || (distance == smallestDistance && j > m_preferredSize)) { | 254 | if (distance < smallestDistance || (distance == smallestDistance && j > m_preferredSize)) { | ||
262 | smallestDistance = distance; | 255 | smallestDistance = distance; | ||
263 | selectItem = i; | 256 | selectItem = i; | ||
264 | size = j; | 257 | size = j; | ||
265 | } | 258 | } | ||
266 | } | 259 | } | ||
267 | } | 260 | } | ||
268 | if (selectItem < 0) { | | |||
269 | selectItem = 0; | | |||
270 | } | | |||
271 | m_settings->setCursorSize(size); | 261 | m_settings->setCursorSize(size); | ||
272 | } | 262 | } | ||
273 | } | 263 | } | ||
274 | 264 | | |||
275 | // enable or disable the combobox | 265 | // enable or disable the combobox | ||
276 | if (m_settings->isImmutable("cursorSize")) { | 266 | if (m_settings->isImmutable("cursorSize")) { | ||
277 | setCanResize(false); | 267 | setCanResize(false); | ||
278 | } else { | 268 | } else { | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | |||||
368 | 358 | | |||
369 | QString CursorThemeConfig::cursorThemeFromIndex(int index) const | 359 | QString CursorThemeConfig::cursorThemeFromIndex(int index) const | ||
370 | { | 360 | { | ||
371 | QModelIndex idx = m_themeProxyModel->index(index, 0); | 361 | QModelIndex idx = m_themeProxyModel->index(index, 0); | ||
372 | return m_themeProxyModel->theme(idx)->name(); | 362 | return m_themeProxyModel->theme(idx)->name(); | ||
373 | } | 363 | } | ||
374 | 364 | | |||
375 | void CursorThemeConfig::save() | 365 | void CursorThemeConfig::save() | ||
376 | { | 366 | { | ||
377 | m_settings->save(); | 367 | ManagedConfigModule::save(); | ||
crossi: Now you should simply call ManagedConfigModule::save(); instead | |||||
378 | m_currentTheme = m_settings->cursorTheme(); | 368 | setPreferredSize(m_settings->cursorSize()); | ||
379 | m_currentSize = m_settings->cursorSize(); | | |||
380 | setPreferredSize(m_currentSize); | | |||
381 | 369 | | |||
382 | int row = cursorThemeIndex(m_settings->cursorTheme()); | 370 | int row = cursorThemeIndex(m_settings->cursorTheme()); | ||
383 | QModelIndex selected = m_themeProxyModel->index(row, 0); | 371 | QModelIndex selected = m_themeProxyModel->index(row, 0); | ||
384 | const CursorTheme *theme = selected.isValid() ? m_themeProxyModel->theme(selected) : nullptr; | 372 | const CursorTheme *theme = selected.isValid() ? m_themeProxyModel->theme(selected) : nullptr; | ||
385 | 373 | | |||
386 | if (!applyTheme(theme, m_currentSize)) { | 374 | if (!applyTheme(theme, m_settings->cursorSize())) { | ||
387 | emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect.")); | 375 | emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect.")); | ||
388 | } | 376 | } | ||
389 | 377 | | |||
390 | KGlobalSettings::self()->emitChange(KGlobalSettings::CursorChanged); | 378 | KGlobalSettings::self()->emitChange(KGlobalSettings::CursorChanged); | ||
391 | setNeedsSave(false); | | |||
392 | } | 379 | } | ||
393 | 380 | | |||
394 | 381 | | |||
395 | void CursorThemeConfig::load() | 382 | void CursorThemeConfig::load() | ||
396 | { | 383 | { | ||
397 | m_settings->load(); | 384 | ManagedConfigModule::load(); | ||
crossi: ManagedConfigModule::load(); | |||||
398 | m_currentSize = m_settings->cursorSize(); | 385 | setPreferredSize(m_settings->cursorSize()); | ||
399 | m_currentTheme = m_settings->cursorTheme(); | | |||
400 | setPreferredSize(m_currentSize); | | |||
401 | // Get the name of the theme KDE is configured to use | 386 | // Get the name of the theme KDE is configured to use | ||
402 | QString currentTheme = m_settings->cursorTheme(); | 387 | QString currentTheme = m_settings->cursorTheme(); | ||
403 | 388 | | |||
404 | // Disable the listview and the buttons if we're in kiosk mode | 389 | // Disable the listview and the buttons if we're in kiosk mode | ||
405 | if (m_settings->isImmutable( QStringLiteral( "cursorTheme" ))) { | 390 | if (m_settings->isImmutable( QStringLiteral( "cursorTheme" ))) { | ||
406 | setCanConfigure(false); | 391 | setCanConfigure(false); | ||
407 | setCanInstall(false); | 392 | setCanInstall(false); | ||
408 | } | 393 | } | ||
409 | 394 | | |||
410 | updateSizeComboBox(); // This handles also the kiosk mode | 395 | updateSizeComboBox(); // This handles also the kiosk mode | ||
411 | 396 | | |||
412 | setNeedsSave(false); | 397 | setNeedsSave(false); | ||
413 | } | 398 | } | ||
414 | 399 | | |||
415 | 400 | | |||
416 | void CursorThemeConfig::defaults() | 401 | void CursorThemeConfig::defaults() | ||
417 | { | 402 | { | ||
418 | m_settings->setDefaults(); | 403 | ManagedConfigModule::defaults(); | ||
crossi: ManagedConfigModule::defaults(); | |||||
419 | m_preferredSize = m_settings->cursorSize(); | 404 | m_preferredSize = m_settings->cursorSize(); | ||
420 | } | 405 | } | ||
421 | 406 | | |||
422 | void CursorThemeConfig::updateNeedsSave() | | |||
423 | { | | |||
424 | setNeedsSave(m_settings->cursorTheme() != m_currentTheme || m_settings->cursorSize() != m_currentSize); | | |||
425 | } | | |||
426 | | ||||
427 | void CursorThemeConfig::getNewClicked() | 407 | void CursorThemeConfig::getNewClicked() | ||
428 | { | 408 | { | ||
429 | KNS3::DownloadDialog dialog("xcursor.knsrc", nullptr); | 409 | KNS3::DownloadDialog dialog("xcursor.knsrc", nullptr); | ||
430 | if (dialog.exec()) { | 410 | if (dialog.exec()) { | ||
431 | KNS3::Entry::List list = dialog.changedEntries(); | 411 | KNS3::Entry::List list = dialog.changedEntries(); | ||
432 | if (!list.isEmpty()) { | 412 | if (!list.isEmpty()) { | ||
433 | for (const KNS3::Entry& entry : list) { | 413 | for (const KNS3::Entry& entry : list) { | ||
434 | if (entry.status() == KNS3::Entry::Deleted) { | 414 | if (entry.status() == KNS3::Entry::Deleted) { | ||
▲ Show 20 Lines • Show All 139 Lines • ▼ Show 20 Line(s) | 553 | { | |||
574 | QModelIndex idx = m_themeProxyModel->index(row, 0); | 554 | QModelIndex idx = m_themeProxyModel->index(row, 0); | ||
575 | if (!idx.isValid()) { | 555 | if (!idx.isValid()) { | ||
576 | return; | 556 | return; | ||
577 | } | 557 | } | ||
578 | 558 | | |||
579 | const CursorTheme *theme = m_themeProxyModel->theme(idx); | 559 | const CursorTheme *theme = m_themeProxyModel->theme(idx); | ||
580 | 560 | | |||
581 | // Don't let the user delete the currently configured theme | 561 | // Don't let the user delete the currently configured theme | ||
582 | if (theme->name() == m_currentTheme) { | 562 | if (theme->name() == m_settings->cursorTheme()) { | ||
583 | KMessageBox::sorry(nullptr, i18n("<qt>You cannot delete the theme you are currently " | 563 | KMessageBox::sorry(nullptr, i18n("<qt>You cannot delete the theme you are currently " | ||
584 | "using.<br />You have to switch to another theme first.</qt>")); | 564 | "using.<br />You have to switch to another theme first.</qt>")); | ||
585 | return; | 565 | return; | ||
586 | } | 566 | } | ||
587 | 567 | | |||
588 | // Get confirmation from the user | 568 | // Get confirmation from the user | ||
589 | QString question = i18n("<qt>Are you sure you want to remove the " | 569 | QString question = i18n("<qt>Are you sure you want to remove the " | ||
590 | "<i>%1</i> cursor theme?<br />" | 570 | "<i>%1</i> cursor theme?<br />" | ||
Show All 26 Lines |
Now you should simply call ManagedConfigModule::save(); instead