diff --git a/kcms/cursortheme/CMakeLists.txt b/kcms/cursortheme/CMakeLists.txt --- a/kcms/cursortheme/CMakeLists.txt +++ b/kcms/cursortheme/CMakeLists.txt @@ -3,7 +3,6 @@ include_directories( ${LIBUSB_INCLUDE_DIR} ) - set( libnoinst_SRCS xcursor/thememodel.cpp xcursor/cursortheme.cpp @@ -20,7 +19,7 @@ ########### next target ############### set(kcm_cursortheme_PART_SRCS kcmcursortheme.cpp ${libnoinst_SRCS}) - +kconfig_add_kcfg_files(kcm_cursortheme_PART_SRCS cursorthemesettings.kcfgc GENERATE_MOC) add_library(kcm_cursortheme MODULE ${kcm_cursortheme_PART_SRCS}) diff --git a/kcms/cursortheme/cursorthemesettings.kcfg b/kcms/cursortheme/cursorthemesettings.kcfg new file mode 100644 --- /dev/null +++ b/kcms/cursortheme/cursorthemesettings.kcfg @@ -0,0 +1,20 @@ + + + + QString + QX11Info + X11/Xcursor/Xcursor.h + + + + breeze_cursors + + + + 0 + + + diff --git a/kcms/cursortheme/cursorthemesettings.kcfgc b/kcms/cursortheme/cursorthemesettings.kcfgc new file mode 100644 --- /dev/null +++ b/kcms/cursortheme/cursorthemesettings.kcfgc @@ -0,0 +1,5 @@ +File=cursorthemesettings.kcfg +ClassName=CursorThemeSettings +Mutators=true +DefaultValueGetters=true +GenerateProperties=true diff --git a/kcms/cursortheme/kcmcursortheme.h b/kcms/cursortheme/kcmcursortheme.h --- a/kcms/cursortheme/kcmcursortheme.h +++ b/kcms/cursortheme/kcmcursortheme.h @@ -1,5 +1,6 @@ /* * Copyright © 2003-2007 Fredrik Höglund + * Copyright © 2019 Benjamin Port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +29,7 @@ class CursorThemeModel; class SortProxyModel; class CursorTheme; +class CursorThemeSettings; namespace KIO { @@ -120,11 +122,11 @@ CursorThemeModel *m_model; SortProxyModel *m_proxyModel; QStandardItemModel *m_sizesModel; + CursorThemeSettings *m_settings; int m_appliedSize; // This index refers to the CursorThemeModel, not the proxy or the view QPersistentModelIndex m_appliedIndex; - /** Holds the last size that was chosen by the user. Example: The user chooses theme1 which provides the sizes 24 and 36. He chooses 36. preferredSize gets set to 36. Now, he switches to theme2 which provides the sizes 30 and 40. diff --git a/kcms/cursortheme/kcmcursortheme.cpp b/kcms/cursortheme/kcmcursortheme.cpp --- a/kcms/cursortheme/kcmcursortheme.cpp +++ b/kcms/cursortheme/kcmcursortheme.cpp @@ -1,5 +1,6 @@ /* * Copyright © 2003-2007 Fredrik Höglund + * Copyright © 2019 Benjamin Port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,8 +30,6 @@ #include #include #include -#include -#include #include #include #include @@ -48,7 +47,7 @@ #include #include -//#include "cursorthemesettings.h" +#include "cursorthemesettings.h" #include #ifdef HAVE_XFIXES @@ -59,6 +58,7 @@ CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args) : KQuickAddons::ConfigModule(parent, args), + m_settings(new CursorThemeSettings), m_appliedSize(0), m_preferredSize(0), m_selectedThemeRow(-1), @@ -68,6 +68,8 @@ m_canResize(true), m_canConfigure(true) { + // Unfortunately doesn't generate a ctor taking the parent as parameter + m_settings->setParent(this); qmlRegisterType("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget"); qmlRegisterType(); @@ -285,9 +287,7 @@ } // enable or disable the combobox - KConfig c("kcminputrc"); - KConfigGroup cg(&c, "Mouse"); - if (cg.isEntryImmutable("cursorSize")) { + if (m_settings->isImmutable("cursorSize")) { setCanResize(false); } else { setCanResize(m_sizesModel->rowCount() > 0); @@ -359,13 +359,12 @@ { const CursorTheme *theme = selectedIndex().isValid() ? m_proxyModel->theme(selectedIndex()) : nullptr; - KConfig config("kcminputrc"); - KConfigGroup c(&config, "Mouse"); if (theme) { - c.writeEntry("cursorTheme", theme->name()); + m_settings->setCursorTheme(theme->name()); } - c.writeEntry("cursorSize", m_preferredSize); - c.sync(); + m_settings->setCursorSize(m_preferredSize); + + m_settings->save(); if (!applyTheme(theme, m_preferredSize)) { emit showInfoMessage(i18n("You have to restart the Plasma session for these changes to take effect.")); @@ -381,17 +380,8 @@ void CursorThemeConfig::load() { - - // Get the name of the theme libXcursor currently uses - QString currentTheme; - if (QX11Info::isPlatformX11()) { - currentTheme = XcursorGetTheme(QX11Info::display()); - } - // Get the name of the theme KDE is configured to use - KConfig c("kcminputrc"); - KConfigGroup cg(&c, "Mouse"); - currentTheme = cg.readEntry("cursorTheme", currentTheme); + QString currentTheme = m_settings->cursorTheme(); // Find the theme in the listview if (!currentTheme.isEmpty()) { @@ -401,16 +391,16 @@ } // Disable the listview and the buttons if we're in kiosk mode - if (cg.isEntryImmutable("cursorTheme")) { + if (m_settings->isImmutable( QStringLiteral( "cursorTheme" ))) { setCanConfigure(false); setCanInstall(false); } setSelectedThemeRow(m_appliedIndex.row()); m_originalSelectedThemeRow = m_selectedThemeRow; // Load cursor size - int size = cg.readEntry("cursorSize", 0); + int size = m_settings->cursorSize(); if (size <= 0) { m_preferredSize = 0; } else { @@ -428,9 +418,9 @@ void CursorThemeConfig::defaults() { - QModelIndex defaultIndex = m_proxyModel->findIndex("breeze_cursors"); + QModelIndex defaultIndex = m_proxyModel->findIndex(m_settings->defaultCursorThemeValue()); setSelectedThemeRow(defaultIndex.row()); - m_preferredSize = 0; + m_preferredSize = m_settings->defaultCursorSizeValue(); updateSizeComboBox(); setNeedsSave(m_originalSelectedThemeRow != m_selectedThemeRow || m_originalPreferredSize != m_preferredSize); }