Commit f53d7844 authored by Benjamin Port's avatar Benjamin Port
Browse files

Port kcm cursor to KConfigXT

Summary: - Allow code reuse

Reviewers: #plasma, mart, ervin, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24517
parent 29f83460
......@@ -21,6 +21,7 @@ qt5_add_dbus_interface(libnoinst_SRCS ${klauncher_xml} klauncher_iface)
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})
......@@ -55,6 +56,7 @@ kcoreaddons_desktop_to_json(kcm_cursortheme "kcm_cursortheme.desktop")
########### install files ###############
install(FILES cursorthemesettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install( FILES kcm_cursortheme.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )
install( FILES xcursor/xcursor.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR} )
......
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kcminputrc" />
<group name="Mouse">
<entry name="cursorTheme" type="String">
<label>Name of the current cursor theme</label>
<default>breeze_cursors</default>
</entry>
<entry name="cursorSize" type="Int">
<label>Current cursor size</label>
<default>0</default>
</entry>
</group>
</kcfg>
File=cursorthemesettings.kcfg
ClassName=CursorThemeSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
/*
* Copyright © 2003-2007 Fredrik Höglund <fredrik@kde.org>
* Copyright © 2019 Benjamin Port <benjamin.port@enioka.com>
*
* 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 <KAboutData>
#include <KPluginFactory>
#include <KLocalizedString>
#include <KConfig>
#include <KConfigGroup>
#include <KMessageBox>
#include <KUrlRequesterDialog>
#include <KIO/CopyJob>
......@@ -48,6 +47,7 @@
#include <X11/Xlib.h>
#include <X11/Xcursor/Xcursor.h>
#include "cursorthemesettings.h"
#include <klauncher_iface.h>
#ifdef HAVE_XFIXES
......@@ -58,6 +58,7 @@ K_PLUGIN_FACTORY_WITH_JSON(CursorThemeConfigFactory, "kcm_cursortheme.json", reg
CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args),
m_settings(new CursorThemeSettings),
m_appliedSize(0),
m_preferredSize(0),
m_selectedThemeRow(-1),
......@@ -67,6 +68,8 @@ CursorThemeConfig::CursorThemeConfig(QObject *parent, const QVariantList &args)
m_canResize(true),
m_canConfigure(true)
{
// Unfortunately doesn't generate a ctor taking the parent as parameter
m_settings->setParent(this);
qmlRegisterType<PreviewWidget>("org.kde.private.kcm_cursortheme", 1, 0, "PreviewWidget");
qmlRegisterType<SortProxyModel>();
......@@ -284,9 +287,7 @@ void CursorThemeConfig::updateSizeComboBox()
}
// 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);
......@@ -358,13 +359,12 @@ void CursorThemeConfig::save()
{
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."));
......@@ -380,17 +380,8 @@ void CursorThemeConfig::save()
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()) {
......@@ -400,7 +391,7 @@ void CursorThemeConfig::load()
}
// 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);
}
......@@ -409,7 +400,7 @@ void CursorThemeConfig::load()
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 {
......@@ -427,9 +418,9 @@ void CursorThemeConfig::load()
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);
}
......
/*
* Copyright © 2003-2007 Fredrik Höglund <fredrik@kde.org>
* Copyright © 2019 Benjamin Port <benjamin.port@enioka.com>
*
* 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 QTemporaryFile;
class CursorThemeModel;
class SortProxyModel;
class CursorTheme;
class CursorThemeSettings;
namespace KIO
{
......@@ -120,6 +122,7 @@ private:
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment