Commit a3b97eaa authored by Cyril Rossi's avatar Cyril Rossi
Browse files

KCM WorkspaceOptions port to KConfigXT. Take into account immutable properties

Reviewers: #plasma, ervin, bport, mart, davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25586
parent 2b2383cc
......@@ -6,6 +6,9 @@ set(kcm_workspace_SRCS
workspaceoptions.cpp
)
kconfig_add_kcfg_files(kcm_workspace_SRCS workspaceoptions_kdeglobalssettings.kcfgc GENERATE_MOC)
kconfig_add_kcfg_files(kcm_workspace_SRCS workspaceoptions_plasmasettings.kcfgc GENERATE_MOC)
add_library(kcm_workspace MODULE ${kcm_workspace_SRCS})
target_link_libraries(kcm_workspace
......@@ -21,6 +24,8 @@ target_link_libraries(kcm_workspace
kcoreaddons_desktop_to_json(kcm_workspace "kcm_workspace.desktop" SERVICE_TYPES kcmodule.desktop)
########### install files ###############
install(FILES workspaceoptions_kdeglobalssettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES workspaceoptions_plasmasettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install( FILES kcm_workspace.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
install(TARGETS kcm_workspace DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
......
......@@ -26,8 +26,6 @@ import org.kde.plasma.core 2.0 as PlasmaCore
KCM.SimpleKCM {
id: root
KCM.ConfigModule.buttons: KCM.ConfigModule.Help | KCM.ConfigModule.Defaults | KCM.ConfigModule.Apply
implicitWidth: Kirigami.Units.gridUnit * 40
Kirigami.FormLayout {
......@@ -38,15 +36,23 @@ KCM.SimpleKCM {
id: showToolTips
Kirigami.FormData.label: i18n("Visual behavior:")
text: i18n("Display informational tooltips on mouse hover")
checked: kcm.toolTip
onCheckedChanged: kcm.toolTip = checked
enabled: !kcm.plasmaSettings.isImmutable("delay")
checked: kcm.plasmaSettings.delay > 0
onCheckedChanged: {
if (checked) {
kcm.plasmaSettings.delay = 0.7
} else {
kcm.plasmaSettings.delay = -1
}
}
}
QQC2.CheckBox {
id: showVisualFeedback
text: i18n("Display visual feedback for status changes")
checked: kcm.visualFeedback
onCheckedChanged: kcm.visualFeedback = checked
enabled: !kcm.plasmaSettings.isImmutable("osdEnabled")
checked: kcm.plasmaSettings.osdEnabled
onCheckedChanged: kcm.plasmaSettings.osdEnabled = checked
}
Item {
......@@ -57,6 +63,7 @@ KCM.SimpleKCM {
// move from 4x, 3x, 2x, 1x, 0.5x, 0.25x, 0.125x
// 0 is a special case
ColumnLayout {
enabled: !kcm.globalsSettings.isImmutable("animationDurationFactor")
Kirigami.FormData.label: i18n("Animation speed:")
Kirigami.FormData.buddyFor: slider
......@@ -69,15 +76,15 @@ KCM.SimpleKCM {
snapMode: QQC2.Slider.SnapAlways
onMoved: {
if(value === to) {
kcm.animationDurationFactor = 0;
kcm.globalsSettings.animationDurationFactor = 0;
} else {
kcm.animationDurationFactor = 1.0 / Math.pow(2, value);
kcm.globalsSettings.animationDurationFactor = 1.0 / Math.pow(2, value);
}
}
value: if (kcm.animationDurationFactor === 0) {
value: if (kcm.globalsSettings.animationDurationFactor === 0) {
return slider.to;
} else {
return -(Math.log(kcm.animationDurationFactor) / Math.log(2));
return -(Math.log(kcm.globalsSettings.animationDurationFactor) / Math.log(2));
}
}
RowLayout {
......@@ -93,12 +100,6 @@ KCM.SimpleKCM {
}
}
Connections {
target: kcm
onToolTipChanged: showToolTips.checked = kcm.toolTip
onVisualFeedbackChanged: showVisualFeedback.checked = kcm.visualFeedback
}
Item {
Kirigami.FormData.isSection: false
}
......@@ -109,21 +110,18 @@ KCM.SimpleKCM {
id: singleClick
Kirigami.FormData.label: i18n("Click behavior:")
text: i18n("Single-click to open files and folders")
checked: kcm.singleClick
onCheckedChanged: kcm.singleClick = checked
enabled: !kcm.globalsSettings.isImmutable("singleClick")
checked: kcm.globalsSettings.singleClick
onToggled: kcm.globalsSettings.singleClick = true
}
QQC2.RadioButton {
id: doubleClick
text: i18n("Double-click to open files and folders (single click to select)")
enabled: !kcm.globalsSettings.isImmutable("singleClick")
checked: !kcm.globalsSettings.singleClick
onToggled: kcm.globalsSettings.singleClick = false
}
Connections {
target: kcm
onSingleClickChanged: {
singleClick.checked = kcm.singleClick
doubleClick.checked = !singleClick.checked
}
}
}
}
/*
* Copyright (C) 2018 <furkantokac34@gmail.com>
* Copyright (c) 2019 Cyril Rossi <cyril.rossi@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
......@@ -15,28 +16,31 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "workspaceoptions.h"
#include <KPluginFactory>
#include <KAboutData>
#include <KLocalizedString>
#include <KConfigGroup>
#include <KSharedConfig>
#include <KGlobalSettings>
#include <../migrationlib/kdelibs4config.h>
#include <QDBusMessage>
#include <QDBusConnection>
#include "workspaceoptions_kdeglobalssettings.h"
#include "workspaceoptions_plasmasettings.h"
K_PLUGIN_FACTORY_WITH_JSON(KCMWorkspaceOptionsFactory, "kcm_workspace.json", registerPlugin<KCMWorkspaceOptions>();)
KCMWorkspaceOptions::KCMWorkspaceOptions(QObject *parent, const QVariantList& args)
: KQuickAddons::ConfigModule(parent, args),
m_toolTipCurrentState(true),
m_visualFeedbackCurrentState(true),
m_singleClickCurrentState(true)
KCMWorkspaceOptions::KCMWorkspaceOptions(QObject *parent, const QVariantList &args)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_globalsSettings(new WorkspaceOptionsGlobalsSettings(this))
, m_plasmaSettings(new WorkspaceOptionsPlasmaSettings(this))
{
KAboutData* about = new KAboutData(QStringLiteral("kcm_workspace"),
qmlRegisterType<WorkspaceOptionsGlobalsSettings>();
qmlRegisterType<WorkspaceOptionsPlasmaSettings>();
KAboutData *about = new KAboutData(QStringLiteral("kcm_workspace"),
i18n("General Behavior"),
QStringLiteral("1.1"),
i18n("System Settings module for configuring general workspace behavior."),
......@@ -45,186 +49,22 @@ KCMWorkspaceOptions::KCMWorkspaceOptions(QObject *parent, const QVariantList& ar
about->addAuthor(i18n("Furkan Tokac"), QString(), QStringLiteral("furkantokac34@gmail.com"));
setAboutData(about);
setButtons(Default | Apply);
}
void KCMWorkspaceOptions::load()
{
loadPlasmarc();
loadKdeglobals();
setNeedsSave(false);
}
void KCMWorkspaceOptions::save()
{
savePlasmarc();
saveKdeglobals();
setNeedsSave(false);
setButtons(Apply | Default | Help);
}
void KCMWorkspaceOptions::defaults()
WorkspaceOptionsGlobalsSettings *KCMWorkspaceOptions::globalsSettings() const
{
setToolTip(true);
setVisualFeedback(true);
setSingleClick(true);
setAnimationDurationFactor(1.0);
handleNeedsSave();
return m_globalsSettings;
}
bool KCMWorkspaceOptions::getToolTip() const
WorkspaceOptionsPlasmaSettings *KCMWorkspaceOptions::plasmaSettings() const
{
return m_toolTipCurrentState;
}
void KCMWorkspaceOptions::setToolTip(bool state)
{
// Prevent from binding loop
if (m_toolTipCurrentState == state) {
return;
}
m_toolTipCurrentState = state;
emit toolTipChanged();
handleNeedsSave();
return m_plasmaSettings;
}
bool KCMWorkspaceOptions::getVisualFeedback() const
{
return m_visualFeedbackCurrentState;
}
void KCMWorkspaceOptions::setVisualFeedback(bool state)
{
// Prevent from binding loop
if (m_visualFeedbackCurrentState == state) {
return;
}
m_visualFeedbackCurrentState = state;
emit visualFeedbackChanged();
handleNeedsSave();
}
bool KCMWorkspaceOptions::getSingleClick() const
{
return m_singleClickCurrentState;
}
void KCMWorkspaceOptions::setSingleClick(bool state)
{
// Prevent from binding loop
if (m_singleClickCurrentState == state) {
return;
}
m_singleClickCurrentState = state;
emit singleClickChanged();
handleNeedsSave();
}
qreal KCMWorkspaceOptions::getAnimationDurationFactor() const
{
return m_animationDurationFactor;
}
void KCMWorkspaceOptions::setAnimationDurationFactor(qreal factor)
{
if (m_animationDurationFactor == factor) {
return;
}
m_animationDurationFactor = factor;
emit animationDurationFactorChanged();
handleNeedsSave();
}
void KCMWorkspaceOptions::loadPlasmarc()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("plasmarc"));
bool state;
// Load toolTip
{
const KConfigGroup cg(config, QStringLiteral("PlasmaToolTips"));
state = cg.readEntry("Delay", 0.7) > 0;
setToolTip(state);
m_toolTipOriginalState = state;
}
// Load visualFeedback
{
const KConfigGroup cg(config, QStringLiteral("OSD"));
state = cg.readEntry(QStringLiteral("Enabled"), true);
setVisualFeedback(state);
m_visualFeedbackOriginalState = state;
}
}
void KCMWorkspaceOptions::loadKdeglobals()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("kdeglobals"));
const KConfigGroup cg(config, QStringLiteral("KDE"));
bool state = cg.readEntry(QStringLiteral("SingleClick"), true);
setSingleClick(state);
m_singleClickOriginalState = state;
setAnimationDurationFactor(cg.readEntry("AnimationDurationFactor", 1.0));
m_animationOriginalDurationFactor = m_animationDurationFactor;
}
void KCMWorkspaceOptions::savePlasmarc()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("plasmarc"));
bool state;
// Save toolTip
{
KConfigGroup cg(config, QStringLiteral("PlasmaToolTips"));
state = getToolTip();
cg.writeEntry("Delay", state ? 0.7 : -1);
m_toolTipOriginalState = state;
}
// Save visualFeedback
{
KConfigGroup cg(config, QStringLiteral("OSD"));
state = getVisualFeedback();
cg.writeEntry("Enabled", state);
m_visualFeedbackOriginalState = state;
}
config->sync();
}
void KCMWorkspaceOptions::saveKdeglobals()
void KCMWorkspaceOptions::save()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig(QStringLiteral("kdeglobals"));
bool state;
{
KConfigGroup cg(config, QStringLiteral("KDE"));
state = getSingleClick();
cg.writeEntry("SingleClick", state);
m_singleClickOriginalState = state;
cg.writeEntry("AnimationDurationFactor", m_animationDurationFactor, KConfig::Notify);
m_animationOriginalDurationFactor = m_animationDurationFactor;
}
config->sync();
Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("KDE"), "kdeglobals");
ManagedConfigModule::save();
QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange");
QList<QVariant> args;
......@@ -234,13 +74,4 @@ void KCMWorkspaceOptions::saveKdeglobals()
QDBusConnection::sessionBus().send(message);
}
// Checks if the current states are different than the first states. If yes, setNeedsSave(true).
void KCMWorkspaceOptions::handleNeedsSave()
{
setNeedsSave(m_toolTipOriginalState != getToolTip() ||
m_visualFeedbackOriginalState != getVisualFeedback() ||
m_singleClickOriginalState != getSingleClick() ||
!qFuzzyCompare(m_animationOriginalDurationFactor, getAnimationDurationFactor()));
}
#include "workspaceoptions.moc"
/*
* Copyright (C) 2018 <furkantokac34@gmail.com>
* Copyright (c) 2019 Cyril Rossi <cyril.rossi@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
......@@ -15,68 +16,34 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _KCM_WORKSPACEOPTIONS_H
#define _KCM_WORKSPACEOPTIONS_H
#include <KQuickAddons/ConfigModule>
#include <KQuickAddons/ManagedConfigModule>
class WorkspaceOptionsGlobalsSettings;
class WorkspaceOptionsPlasmaSettings;
class KCMWorkspaceOptions : public KQuickAddons::ConfigModule
class KCMWorkspaceOptions : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(bool toolTip READ getToolTip WRITE setToolTip NOTIFY toolTipChanged)
Q_PROPERTY(bool visualFeedback READ getVisualFeedback WRITE setVisualFeedback NOTIFY visualFeedbackChanged)
Q_PROPERTY(bool singleClick READ getSingleClick WRITE setSingleClick NOTIFY singleClickChanged)
Q_PROPERTY(qreal animationDurationFactor READ getAnimationDurationFactor WRITE setAnimationDurationFactor NOTIFY animationDurationFactorChanged)
Q_PROPERTY(WorkspaceOptionsGlobalsSettings *globalsSettings READ globalsSettings CONSTANT)
Q_PROPERTY(WorkspaceOptionsPlasmaSettings *plasmaSettings READ plasmaSettings CONSTANT)
public:
KCMWorkspaceOptions(QObject* parent, const QVariantList& args);
KCMWorkspaceOptions(QObject *parent, const QVariantList &args);
~KCMWorkspaceOptions() override {}
// QML Properties
bool getToolTip() const;
void setToolTip(bool state);
bool getVisualFeedback() const;
void setVisualFeedback(bool state);
bool getSingleClick() const;
void setSingleClick(bool state);
qreal getAnimationDurationFactor() const;
void setAnimationDurationFactor(qreal speed);
WorkspaceOptionsGlobalsSettings *globalsSettings() const;
WorkspaceOptionsPlasmaSettings *plasmaSettings() const;
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
Q_SIGNALS:
void toolTipChanged();
void visualFeedbackChanged();
void singleClickChanged();
void animationDurationFactorChanged();
private:
void loadPlasmarc();
void loadKdeglobals();
void savePlasmarc();
void saveKdeglobals();
void handleNeedsSave();
// QML variables
bool m_toolTipOriginalState;
bool m_toolTipCurrentState;
bool m_visualFeedbackOriginalState;
bool m_visualFeedbackCurrentState;
bool m_singleClickOriginalState;
bool m_singleClickCurrentState;
qreal m_animationDurationFactor = 1.0;
qreal m_animationOriginalDurationFactor = 1.0;
WorkspaceOptionsGlobalsSettings *m_globalsSettings;
WorkspaceOptionsPlasmaSettings *m_plasmaSettings;
};
#endif // _KCM_WORKSPACEOPTIONS_H
<?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="kdeglobals" />
<group name="KDE">
<entry name="singleClick" key="SingleClick" type="Bool">
<label>Signle click to open files</label>
<default>true</default>
</entry>
<entry name="animationDurationFactor" key="AnimationDurationFactor" type="Double">
<label>Animation speed</label>
<default>1.0</default>
</entry>
</group>
</kcfg>
File=workspaceoptions_kdeglobalssettings.kcfg
ClassName=WorkspaceOptionsGlobalsSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
<?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="plasmarc" />
<group name="PlasmaToolTips">
<entry name="delay" key="Delay" type="Double">
<label>Display informational tooltips on mouse hover</label>
<default>0.7</default>
</entry>
</group>
<group name="OSD">
<entry name="osdEnabled" key="Enabled" type="Bool">
<label>Display visual feedback for status changes</label>
<default>true</default>
</entry>
</group>
</kcfg>
File=workspaceoptions_plasmasettings.kcfgc
ClassName=WorkspaceOptionsPlasmaSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
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