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 | | |||
51 | //#include "cursorthemesettings.h" | 50 | #include "cursorthemesettings.h" | ||
52 | #include <klauncher_iface.h> | 51 | #include <klauncher_iface.h> | ||
53 | 52 | | |||
54 | #ifdef HAVE_XFIXES | 53 | #ifdef HAVE_XFIXES | ||
55 | # include <X11/extensions/Xfixes.h> | 54 | # include <X11/extensions/Xfixes.h> | ||
56 | #endif | 55 | #endif | ||
57 | 56 | | |||
58 | K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin<CursorThemeConfig>();) | 57 | K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", registerPlugin<CursorThemeConfig>();) | ||
59 | 58 | | |||
60 | CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) | 59 | CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) | ||
61 | : KQuickAddons::ConfigModule(parent, args), | 60 | : KQuickAddons::ConfigModule(parent, args), | ||
61 | m_settings(new CursorThemeSettings), | ||||
62 | m_appliedSize(0), | 62 | m_appliedSize(0), | ||
63 | m_preferredSize(0), | 63 | m_preferredSize(0), | ||
64 | m_selectedThemeRow(-1), | 64 | m_selectedThemeRow(-1), | ||
65 | m_selectedSizeRow(-1), | 65 | m_selectedSizeRow(-1), | ||
66 | m_originalSelectedThemeRow(-1), | 66 | m_originalSelectedThemeRow(-1), | ||
67 | m_canInstall(true), | 67 | m_canInstall(true), | ||
68 | m_canResize(true), | 68 | m_canResize(true), | ||
69 | m_canConfigure(true) | 69 | m_canConfigure(true) | ||
70 | { | 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. | |||||
71 | qmlRegisterType<PreviewWidget>("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget"); | 73 | qmlRegisterType<PreviewWidget>("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget"); | ||
72 | qmlRegisterType<SortProxyModel>(); | 74 | qmlRegisterType<SortProxyModel>(); | ||
73 | 75 | | |||
74 | KAboutData* aboutData = new KAboutData(QStringLiteral("kcm_cursortheme"), i18n("Cursors"), | 76 | KAboutData* aboutData = new KAboutData(QStringLiteral("kcm_cursortheme"), i18n("Cursors"), | ||
75 | 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")); | ||
76 | aboutData->addAuthor(i18n("Fredrik Höglund")); | 78 | aboutData->addAuthor(i18n("Fredrik Höglund")); | ||
77 | aboutData->addAuthor(i18n("Marco Martin")); | 79 | aboutData->addAuthor(i18n("Marco Martin")); | ||
78 | setAboutData(aboutData); | 80 | setAboutData(aboutData); | ||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Line(s) | 227 | if (sizes.size() > 1) { | |||
280 | if (selectItem < 0) { | 282 | if (selectItem < 0) { | ||
281 | selectItem = 0; | 283 | selectItem = 0; | ||
282 | } | 284 | } | ||
283 | setSelectedSizeRow(selectItem); | 285 | setSelectedSizeRow(selectItem); | ||
284 | } | 286 | } | ||
285 | } | 287 | } | ||
286 | 288 | | |||
287 | // enable or disable the combobox | 289 | // enable or disable the combobox | ||
288 | KConfig c("kcminputrc"); | 290 | if (m_settings->isImmutable("cursorSize")) { | ||
289 | KConfigGroup cg(&c, "Mouse"); | | |||
290 | if (cg.isEntryImmutable("cursorSize")) { | | |||
291 | setCanResize(false); | 291 | setCanResize(false); | ||
292 | } else { | 292 | } else { | ||
293 | setCanResize(m_sizesModel->rowCount() > 0); | 293 | setCanResize(m_sizesModel->rowCount() > 0); | ||
294 | } | 294 | } | ||
295 | 295 | | |||
296 | } | 296 | } | ||
297 | 297 | | |||
298 | 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) | |||||
354 | #endif | 354 | #endif | ||
355 | } | 355 | } | ||
356 | 356 | | |||
357 | 357 | | |||
358 | void CursorThemeConfig::save() | 358 | void CursorThemeConfig::save() | ||
359 | { | 359 | { | ||
360 | const CursorTheme *theme = selectedIndex().isValid() ? m_proxyModel->theme(selectedIndex()) : nullptr; | 360 | const CursorTheme *theme = selectedIndex().isValid() ? m_proxyModel->theme(selectedIndex()) : nullptr; | ||
361 | 361 | | |||
362 | KConfig config("kcminputrc"); | | |||
363 | KConfigGroup c(&config, "Mouse"); | | |||
364 | if (theme) { | 362 | if (theme) { | ||
365 | c.writeEntry("cursorTheme", theme->name()); | 363 | m_settings->setCursorTheme(theme->name()); | ||
366 | } | 364 | } | ||
367 | c.writeEntry("cursorSize", m_preferredSize); | 365 | m_settings->setCursorSize(m_preferredSize); | ||
368 | c.sync(); | 366 | | ||
367 | m_settings->save(); | ||||
369 | 368 | | |||
370 | if (!applyTheme(theme, m_preferredSize)) { | 369 | if (!applyTheme(theme, m_preferredSize)) { | ||
371 | 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.")); | ||
372 | } | 371 | } | ||
373 | 372 | | |||
374 | m_appliedIndex = selectedIndex(); | 373 | m_appliedIndex = selectedIndex(); | ||
375 | m_appliedSize = m_preferredSize; | 374 | m_appliedSize = m_preferredSize; | ||
376 | m_originalSelectedThemeRow = m_selectedThemeRow; | 375 | m_originalSelectedThemeRow = m_selectedThemeRow; | ||
377 | m_originalPreferredSize = m_preferredSize; | 376 | m_originalPreferredSize = m_preferredSize; | ||
378 | setNeedsSave(false); | 377 | setNeedsSave(false); | ||
379 | } | 378 | } | ||
380 | 379 | | |||
381 | 380 | | |||
382 | void CursorThemeConfig::load() | 381 | void CursorThemeConfig::load() | ||
383 | { | 382 | { | ||
384 | | ||||
385 | // Get the name of the theme libXcursor currently uses | | |||
386 | QString currentTheme; | | |||
387 | if (QX11Info::isPlatformX11()) { | | |||
388 | currentTheme = XcursorGetTheme(QX11Info::display()); | | |||
389 | } | | |||
390 | | ||||
391 | // Get the name of the theme KDE is configured to use | 383 | // Get the name of the theme KDE is configured to use | ||
392 | KConfig c("kcminputrc"); | 384 | QString currentTheme = m_settings->cursorTheme(); | ||
393 | KConfigGroup cg(&c, "Mouse"); | | |||
394 | currentTheme = cg.readEntry("cursorTheme", currentTheme); | | |||
395 | 385 | | |||
396 | // Find the theme in the listview | 386 | // Find the theme in the listview | ||
397 | if (!currentTheme.isEmpty()) { | 387 | if (!currentTheme.isEmpty()) { | ||
398 | m_appliedIndex = m_proxyModel->findIndex(currentTheme); | 388 | m_appliedIndex = m_proxyModel->findIndex(currentTheme); | ||
399 | } else { | 389 | } else { | ||
400 | m_appliedIndex = m_proxyModel->defaultIndex(); | 390 | m_appliedIndex = m_proxyModel->defaultIndex(); | ||
401 | } | 391 | } | ||
402 | 392 | | |||
403 | // 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 | ||
404 | if (cg.isEntryImmutable("cursorTheme")) { | 394 | if (m_settings->isImmutable( QStringLiteral( "cursorTheme" ))) { | ||
405 | setCanConfigure(false); | 395 | setCanConfigure(false); | ||
406 | setCanInstall(false); | 396 | setCanInstall(false); | ||
407 | } | 397 | } | ||
408 | 398 | | |||
409 | setSelectedThemeRow(m_appliedIndex.row()); | 399 | setSelectedThemeRow(m_appliedIndex.row()); | ||
410 | m_originalSelectedThemeRow = m_selectedThemeRow; | 400 | m_originalSelectedThemeRow = m_selectedThemeRow; | ||
411 | 401 | | |||
412 | // Load cursor size | 402 | // Load cursor size | ||
413 | int size = cg.readEntry("cursorSize", 0); | 403 | int size = m_settings->cursorSize(); | ||
414 | if (size <= 0) { | 404 | if (size <= 0) { | ||
415 | m_preferredSize = 0; | 405 | m_preferredSize = 0; | ||
416 | } else { | 406 | } else { | ||
417 | m_preferredSize = size; | 407 | m_preferredSize = size; | ||
418 | } | 408 | } | ||
419 | m_originalPreferredSize = m_preferredSize; | 409 | m_originalPreferredSize = m_preferredSize; | ||
420 | updateSizeComboBox(); // This handles also the kiosk mode | 410 | updateSizeComboBox(); // This handles also the kiosk mode | ||
421 | 411 | | |||
422 | m_appliedSize = size; | 412 | m_appliedSize = size; | ||
423 | 413 | | |||
424 | 414 | | |||
425 | setNeedsSave(false); | 415 | setNeedsSave(false); | ||
426 | } | 416 | } | ||
427 | 417 | | |||
428 | 418 | | |||
429 | void CursorThemeConfig::defaults() | 419 | void CursorThemeConfig::defaults() | ||
430 | { | 420 | { | ||
431 | QModelIndex defaultIndex = m_proxyModel->findIndex("breeze_cursors"); | 421 | QModelIndex defaultIndex = m_proxyModel->findIndex(m_settings->defaultCursorThemeValue()); | ||
432 | setSelectedThemeRow(defaultIndex.row()); | 422 | setSelectedThemeRow(defaultIndex.row()); | ||
433 | m_preferredSize = 0; | 423 | m_preferredSize = m_settings->defaultCursorSizeValue(); | ||
434 | updateSizeComboBox(); | 424 | updateSizeComboBox(); | ||
435 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | 425 | setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); | ||
436 | } | 426 | } | ||
437 | 427 | | |||
438 | QModelIndex CursorThemeConfig::selectedIndex() const | 428 | QModelIndex CursorThemeConfig::selectedIndex() const | ||
439 | { | 429 | { | ||
440 | return m_proxyModel->index(m_selectedThemeRow, 0); | 430 | return m_proxyModel->index(m_selectedThemeRow, 0); | ||
441 | } | 431 | } | ||
▲ Show 20 Lines • Show All 191 Lines • Show Last 20 Lines |
I assume Kevin's patch set fixes this?