Changeset View
Changeset View
Standalone View
Standalone View
kcms/cursortheme/kcmcursortheme.cpp
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright © 2003-2007 Fredrik Höglund <fredrik@kde.org> | 2 | * Copyright © 2003-2007 Fredrik Höglund <fredrik@kde.org> | ||
3 | * Copyright © 2019 Benjamin Port <benjamin.port@enioka.com> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | 8 | * (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 10 | * This program 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 | ||
Show All 13 Lines | |||||
24 | #include "xcursor/sortproxymodel.h" | 25 | #include "xcursor/sortproxymodel.h" | ||
25 | #include "xcursor/cursortheme.h" | 26 | #include "xcursor/cursortheme.h" | ||
26 | #include "xcursor/previewwidget.h" | 27 | #include "xcursor/previewwidget.h" | ||
27 | #include "../krdb/krdb.h" | 28 | #include "../krdb/krdb.h" | ||
28 | 29 | | |||
29 | #include <KAboutData> | 30 | #include <KAboutData> | ||
30 | #include <KPluginFactory> | 31 | #include <KPluginFactory> | ||
31 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
32 | #include <KConfig> | | |||
33 | #include <KConfigGroup> | | |||
34 | #include <KMessageBox> | 33 | #include <KMessageBox> | ||
35 | #include <KUrlRequesterDialog> | 34 | #include <KUrlRequesterDialog> | ||
36 | #include <KIO/CopyJob> | 35 | #include <KIO/CopyJob> | ||
37 | #include <KIO/DeleteJob> | 36 | #include <KIO/DeleteJob> | ||
38 | #include <KIO/Job> | 37 | #include <KIO/Job> | ||
39 | #include <KIO/JobUiDelegate> | 38 | #include <KIO/JobUiDelegate> | ||
40 | #include <KTar> | 39 | #include <KTar> | ||
41 | #include <KGlobalSettings> | 40 | #include <KGlobalSettings> | ||
42 | 41 | | |||
43 | #include <KNewStuff3/KNS3/DownloadDialog> | 42 | #include <KNewStuff3/KNS3/DownloadDialog> | ||
44 | 43 | | |||
45 | #include <QX11Info> | 44 | #include <QX11Info> | ||
46 | #include <QStandardItemModel> | 45 | #include <QStandardItemModel> | ||
47 | 46 | | |||
48 | #include <X11/Xlib.h> | 47 | #include <X11/Xlib.h> | ||
49 | #include <X11/Xcursor/Xcursor.h> | 48 | #include <X11/Xcursor/Xcursor.h> | ||
50 | 49 | | |||
50 | #include "cursorthemesettings.h" | ||||
51 | #include <klauncher_iface.h> | 51 | #include <klauncher_iface.h> | ||
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::ConfigModule(parent, args), | ||
61 | m_settings(new CursorThemeSettings), | ||||
61 | m_appliedSize(0), | 62 | m_appliedSize(0), | ||
62 | m_preferredSize(0), | 63 | m_preferredSize(0), | ||
63 | m_selectedThemeRow(-1), | 64 | m_selectedThemeRow(-1), | ||
64 | m_selectedSizeRow(-1), | 65 | m_selectedSizeRow(-1), | ||
65 | m_originalSelectedThemeRow(-1), | 66 | m_originalSelectedThemeRow(-1), | ||
66 | m_canInstall(true), | 67 | m_canInstall(true), | ||
67 | m_canResize(true), | 68 | m_canResize(true), | ||
68 | m_canConfigure(true) | 69 | m_canConfigure(true) | ||
69 | { | 70 | { | ||
71 | // Unfortunately doesn't generate a ctor taking the parent as parameter | ||||
72 | m_settings->setParent(this); | ||||
davidedmundson: I assume Kevin's patch set fixes this? | |||||
Yes but kevin patch is not yet merged. bport: Yes but kevin patch is not yet merged.
However we will need to go throught this code a second… | |||||
Yes, giving a bit more time to people to review the latest revisions of my KConfig patches. They changed quite a bit and I didn't get further comment yet. ervin: Yes, giving a bit more time to people to review the latest revisions of my KConfig patches. | |||||
70 | qmlRegisterType<PreviewWidget>("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget"); | 73 | qmlRegisterType<PreviewWidget>("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget"); | ||
71 | qmlRegisterType<SortProxyModel>(); | 74 | qmlRegisterType<SortProxyModel>(); | ||
72 | 75 | | |||
73 | KAboutData* aboutData = new KAboutData(QStringLiteral("kcm_cursortheme"), i18n("Cursors"), | 76 | KAboutData* aboutData = new KAboutData(QStringLiteral("kcm_cursortheme"), i18n("Cursors"), | ||
74 | QStringLiteral("1.0"), QString(), KAboutLicense::GPL, i18n("(c) 2003-2007 Fredrik Höglund")); | 77 | QStringLiteral("1.0"), QString(), KAboutLicense::GPL, i18n("(c) 2003-2007 Fredrik Höglund")); | ||
75 | aboutData->addAuthor(i18n("Fredrik Höglund")); | 78 | aboutData->addAuthor(i18n("Fredrik Höglund")); | ||
76 | aboutData->addAuthor(i18n("Marco Martin")); | 79 | aboutData->addAuthor(i18n("Marco Martin")); | ||
77 | setAboutData(aboutData); | 80 | setAboutData(aboutData); | ||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Line(s) | 227 | if (sizes.size() > 1) { | |||
279 | if (selectItem < 0) { | 282 | if (selectItem < 0) { | ||
280 | selectItem = 0; | 283 | selectItem = 0; | ||
281 | } | 284 | } | ||
282 | setSelectedSizeRow(selectItem); | 285 | setSelectedSizeRow(selectItem); | ||
283 | } | 286 | } | ||
284 | } | 287 | } | ||
285 | 288 | | |||
286 | // enable or disable the combobox | 289 | // enable or disable the combobox | ||
287 | KConfig c("kcminputrc"); | 290 | if (m_settings->isImmutable("cursorSize")) { | ||
288 | KConfigGroup cg(&c, "Mouse"); | | |||
289 | if (cg.isEntryImmutable("cursorSize")) { | | |||
290 | setCanResize(false); | 291 | setCanResize(false); | ||
291 | } else { | 292 | } else { | ||
292 | setCanResize(m_sizesModel->rowCount() > 0); | 293 | setCanResize(m_sizesModel->rowCount() > 0); | ||
293 | } | 294 | } | ||
294 | 295 | | |||
295 | } | 296 | } | ||
296 | 297 | | |||
297 | bool CursorThemeConfig::applyTheme(const CursorTheme *theme, const int size) | 298 | bool CursorThemeConfig::applyTheme(const CursorTheme *theme, const int size) | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
353 | #endif | 354 | #endif | ||
354 | } | 355 | } | ||
355 | 356 | | |||
356 | 357 | | |||
357 | void CursorThemeConfig::save() | 358 | void CursorThemeConfig::save() | ||
358 | { | 359 | { | ||
359 | const CursorTheme *theme = selectedIndex().isValid() ? m_proxyModel->theme(selectedIndex()) : nullptr; | 360 | const CursorTheme *theme = selectedIndex().isValid() ? m_proxyModel->theme(selectedIndex()) : nullptr; | ||
360 | 361 | | |||
361 | KConfig config("kcminputrc"); | | |||
362 | KConfigGroup c(&config, "Mouse"); | | |||
363 | if (theme) { | 362 | if (theme) { | ||
364 | c.writeEntry("cursorTheme", theme->name()); | 363 | m_settings->setCursorTheme(theme->name()); | ||
365 | } | 364 | } | ||
366 | c.writeEntry("cursorSize", m_preferredSize); | 365 | m_settings->setCursorSize(m_preferredSize); | ||
367 | c.sync(); | 366 | | ||
367 | m_settings->save(); | ||||
368 | 368 | | |||
369 | if (!applyTheme(theme, m_preferredSize)) { | 369 | if (!applyTheme(theme, m_preferredSize)) { | ||
370 | emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect.")); | 370 | emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect.")); | ||
371 | } | 371 | } | ||
372 | 372 | | |||
373 | m_appliedIndex = selectedIndex(); | 373 | m_appliedIndex = selectedIndex(); | ||
374 | m_appliedSize = m_preferredSize; | 374 | m_appliedSize = m_preferredSize; | ||
375 | m_originalSelectedThemeRow = m_selectedThemeRow; | 375 | m_originalSelectedThemeRow = m_selectedThemeRow; | ||
376 | m_originalPreferredSize = m_preferredSize; | 376 | m_originalPreferredSize = m_preferredSize; | ||
377 | setNeedsSave(false); | 377 | setNeedsSave(false); | ||
378 | } | 378 | } | ||
379 | 379 | | |||
380 | 380 | | |||
381 | void CursorThemeConfig::load() | 381 | void CursorThemeConfig::load() | ||
382 | { | 382 | { | ||
383 | | ||||
384 | // Get the name of the theme libXcursor currently uses | | |||
385 | QString currentTheme; | | |||
386 | if (QX11Info::isPlatformX11()) { | | |||
387 | currentTheme = XcursorGetTheme(QX11Info::display()); | | |||
388 | } | | |||
389 | | ||||
390 | // Get the name of the theme KDE is configured to use | 383 | // Get the name of the theme KDE is configured to use | ||
391 | KConfig c("kcminputrc"); | 384 | QString currentTheme = m_settings->cursorTheme(); | ||
392 | KConfigGroup cg(&c, "Mouse"); | | |||
393 | currentTheme = cg.readEntry("cursorTheme", currentTheme); | | |||
394 | 385 | | |||
395 | // Find the theme in the listview | 386 | // Find the theme in the listview | ||
396 | if (!currentTheme.isEmpty()) { | 387 | if (!currentTheme.isEmpty()) { | ||
397 | m_appliedIndex = m_proxyModel->findIndex(currentTheme); | 388 | m_appliedIndex = m_proxyModel->findIndex(currentTheme); | ||
398 | } else { | 389 | } else { | ||
399 | m_appliedIndex = m_proxyModel->defaultIndex(); | 390 | m_appliedIndex = m_proxyModel->defaultIndex(); | ||
400 | } | 391 | } | ||
401 | 392 | | |||
402 | // Disable the listview and the buttons if we're in kiosk mode | 393 | // Disable the listview and the buttons if we're in kiosk mode | ||
403 | if (cg.isEntryImmutable("cursorTheme")) { | 394 | if (m_settings->isImmutable( QStringLiteral( "cursorTheme" ))) { | ||
404 | setCanConfigure(false); | 395 | setCanConfigure(false); | ||
405 | setCanInstall(false); | 396 | setCanInstall(false); | ||
406 | } | 397 | } | ||
407 | 398 | | |||
408 | setSelectedThemeRow(m_appliedIndex.row()); | 399 | setSelectedThemeRow(m_appliedIndex.row()); | ||
409 | m_originalSelectedThemeRow = m_selectedThemeRow; | 400 | m_originalSelectedThemeRow = m_selectedThemeRow; | ||
410 | 401 | | |||
411 | // Load cursor size | 402 | // Load cursor size | ||
412 | int size = cg.readEntry("cursorSize", 0); | 403 | int size = m_settings->cursorSize(); | ||
413 | if (size <= 0) { | 404 | if (size <= 0) { | ||
414 | m_preferredSize = 0; | 405 | m_preferredSize = 0; | ||
415 | } else { | 406 | } else { | ||
416 | m_preferredSize = size; | 407 | m_preferredSize = size; | ||
417 | } | 408 | } | ||
418 | m_originalPreferredSize = m_preferredSize; | 409 | m_originalPreferredSize = m_preferredSize; | ||
419 | updateSizeComboBox(); // This handles also the kiosk mode | 410 | updateSizeComboBox(); // This handles also the kiosk mode | ||
420 | 411 | | |||
421 | m_appliedSize = size; | 412 | m_appliedSize = size; | ||
422 | 413 | | |||
423 | 414 | | |||
424 | setNeedsSave(false); | 415 | setNeedsSave(false); | ||
425 | } | 416 | } | ||
426 | 417 | | |||
427 | 418 | | |||
428 | void CursorThemeConfig::defaults() | 419 | void CursorThemeConfig::defaults() | ||
429 | { | 420 | { | ||
430 | QModelIndex defaultIndex = m_proxyModel->findIndex("breeze_cursors"); | 421 | QModelIndex defaultIndex = m_proxyModel->findIndex(m_settings->defaultCursorThemeValue()); | ||
431 | setSelectedThemeRow(defaultIndex.row()); | 422 | setSelectedThemeRow(defaultIndex.row()); | ||
432 | m_preferredSize = 0; | 423 | m_preferredSize = m_settings->defaultCursorSizeValue(); | ||
433 | updateSizeComboBox(); | 424 | updateSizeComboBox(); | ||
434 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | 425 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | ||
435 | } | 426 | } | ||
436 | 427 | | |||
437 | QModelIndex CursorThemeConfig::selectedIndex() const | 428 | QModelIndex CursorThemeConfig::selectedIndex() const | ||
438 | { | 429 | { | ||
439 | return m_proxyModel->index(m_selectedThemeRow, 0); | 430 | return m_proxyModel->index(m_selectedThemeRow, 0); | ||
440 | } | 431 | } | ||
▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines |
I assume Kevin's patch set fixes this?