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

KCM launchfeedback : port to KConfig XT

Summary: Simple KCM, all settings' states are automatically handled thanks to ManagedConfigModule.

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

Subscribers: broulik, ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D25290
parent 613d5e12
......@@ -8,6 +8,8 @@ set(kcm_launchfeedback_PART_SRCS launchfeedback.cpp)
set_source_files_properties(${KWIN_EFFECTS_INTERFACE} PROPERTIES INCLUDE "interface_util.h")
qt5_add_dbus_interface(kcm_launchfeedback_PART_SRCS ${KWIN_EFFECTS_INTERFACE} kwin_interface)
kconfig_add_kcfg_files(kcm_launchfeedback_PART_SRCS launchfeedbacksettings.kcfgc GENERATE_MOC)
add_library(kcm_launchfeedback MODULE ${kcm_launchfeedback_PART_SRCS})
target_link_libraries(kcm_launchfeedback
......@@ -21,7 +23,7 @@ kcoreaddons_desktop_to_json(kcm_launchfeedback "kcm_launchfeedback.desktop")
########### install files ###############
install(FILES launchfeedbacksettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(TARGETS kcm_launchfeedback DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
install(FILES kcm_launchfeedback.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
kpackage_install_package(package kcm_launchfeedback kcms)
/*
* Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
* Copyright (C) 2017 Eike Hein <hein@kde.org>
* 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
......@@ -19,23 +20,22 @@
#include "launchfeedback.h"
#include <KAboutData>
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KPluginFactory>
#include "kwin_interface.h"
#define STARTUP_DEFAULT_TIMEOUT 5
#include "launchfeedbacksettings.h"
K_PLUGIN_FACTORY_WITH_JSON(LaunchFactory, "kcm_launchfeedback.json", registerPlugin<LaunchFeedback>();)
LaunchFeedback::LaunchFeedback(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent, args)
, m_busyCursorCurrentIndex(3)
, m_taskManagerNotification(true)
, m_notificationTimeout(STARTUP_DEFAULT_TIMEOUT)
: KQuickAddons::ManagedConfigModule(parent, args)
, m_settings(new LaunchFeedbackSettings(this))
{
qmlRegisterUncreatableType<LaunchFeedback>("org.kde.private.kcms.launchfeedback", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM"));
qmlRegisterType<LaunchFeedbackSettings>();
KAboutData *about = new KAboutData(QStringLiteral("kcm_launchfeedback"),
i18n("Configure application launch feedback"),
QStringLiteral("0.2"), QString(), KAboutLicense::LGPL);
......@@ -48,100 +48,14 @@ LaunchFeedback::~LaunchFeedback()
{
}
int LaunchFeedback::busyCursorCurrentIndex() const
{
return m_busyCursorCurrentIndex;
}
void LaunchFeedback::setBusyCursorCurrentIndex(int index)
{
if (m_busyCursorCurrentIndex != index) {
m_busyCursorCurrentIndex = index;
emit busyCursorCurrentIndexChanged();
updateNeedsSave();
}
}
bool LaunchFeedback::taskManagerNotification() const
LaunchFeedbackSettings *LaunchFeedback::launchFeedbackSettings() const
{
return m_taskManagerNotification;
}
void LaunchFeedback::setTaskManagerNotification(bool enabled)
{
if (m_taskManagerNotification != enabled) {
m_taskManagerNotification = enabled;
emit taskManagerNotificationChanged();
updateNeedsSave();
}
}
int LaunchFeedback::notificationTimeout() const
{
return m_notificationTimeout;
}
void LaunchFeedback::setNotificationTimeout(int duration)
{
if (m_notificationTimeout != duration) {
m_notificationTimeout = duration;
emit notificationTimeoutChanged();
updateNeedsSave();
}
}
void LaunchFeedback::load()
{
KConfig conf(QStringLiteral("klaunchrc"), KConfig::NoGlobals);
KConfigGroup c = conf.group("FeedbackStyle");
const bool busyCursor = c.readEntry("BusyCursor", true);
setTaskManagerNotification(c.readEntry("TaskbarButton", true));
c = conf.group("BusyCursorSettings");
setNotificationTimeout(c.readEntry("Timeout", STARTUP_DEFAULT_TIMEOUT));
bool busyBlinking = c.readEntry("Blinking", false);
bool busyBouncing = c.readEntry("Bouncing", true);
if (!busyCursor) {
setBusyCursorCurrentIndex(0);
} else if (busyBlinking) {
setBusyCursorCurrentIndex(2);
} else if (busyBouncing) {
setBusyCursorCurrentIndex(3);
} else {
setBusyCursorCurrentIndex(1);
}
return m_settings;
}
void LaunchFeedback::save()
{
KConfig conf(QStringLiteral("klaunchrc"), KConfig::NoGlobals);
KConfigGroup c = conf.group("FeedbackStyle");
c.writeEntry("BusyCursor", m_busyCursorCurrentIndex != 0);
c.writeEntry("TaskbarButton", m_taskManagerNotification);
c = conf.group("BusyCursorSettings");
c.writeEntry("Timeout", m_notificationTimeout);
c.writeEntry("Blinking", m_busyCursorCurrentIndex == 2);
c.writeEntry("Bouncing", m_busyCursorCurrentIndex == 3);
c = conf.group("TaskbarButtonSettings");
c.writeEntry( "Timeout", m_notificationTimeout);
c.sync();
setNeedsSave(false);
ManagedConfigModule::save();
org::kde::kwin::Effects kwin(QStringLiteral("org.kde.KWin"),
QStringLiteral("/Effects"),
......@@ -149,54 +63,4 @@ void LaunchFeedback::save()
kwin.reconfigureEffect(QStringLiteral("startupfeedback"));
}
void LaunchFeedback::defaults()
{
setBusyCursorCurrentIndex(3); // Bouncing cursor.
setTaskManagerNotification(true);
setNotificationTimeout(STARTUP_DEFAULT_TIMEOUT);
}
void LaunchFeedback::updateNeedsSave()
{
bool needsSave = false;
KConfig conf(QStringLiteral("klaunchrc"), KConfig::NoGlobals);
KConfigGroup c = conf.group("FeedbackStyle");
const bool savedBusyCursor = c.readEntry("BusyCursor", true);
if (m_taskManagerNotification != c.readEntry("TaskbarButton", true)) {
needsSave = true;
}
c = conf.group("BusyCursorSettings");
if (m_notificationTimeout != c.readEntry("Timeout", STARTUP_DEFAULT_TIMEOUT)) {
needsSave = true;
}
int savedBusyCursorIndex = 3; // Bouncing cursor (default);
bool savedBusyBlinking = c.readEntry("Blinking", false);
bool savedBusyBouncing = c.readEntry("Bouncing", true);
if (!savedBusyCursor) {
savedBusyCursorIndex = 0;
} else if (savedBusyBlinking) {
savedBusyCursorIndex = 2;
} else if (savedBusyBouncing) {
savedBusyCursorIndex = 3;
} else {
savedBusyCursorIndex = 1;
}
if (m_busyCursorCurrentIndex != savedBusyCursorIndex) {
needsSave = true;
}
setNeedsSave(needsSave);
}
#include "launchfeedback.moc"
/*
* Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
* Copyright (C) 2017 Eike Hein <hein@kde.org>
* 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
......@@ -19,51 +20,35 @@
#ifndef LAUNCHFEEDBACK_H
#define LAUNCHFEEDBACK_H
#include <KQuickAddons/ConfigModule>
#include <KQuickAddons/ManagedConfigModule>
class LaunchFeedback : public KQuickAddons::ConfigModule
class LaunchFeedbackSettings;
class LaunchFeedback : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(int busyCursorCurrentIndex READ busyCursorCurrentIndex WRITE setBusyCursorCurrentIndex NOTIFY busyCursorCurrentIndexChanged)
Q_PROPERTY(bool taskManagerNotification READ taskManagerNotification WRITE setTaskManagerNotification NOTIFY taskManagerNotificationChanged)
Q_PROPERTY(int notificationTimeout READ notificationTimeout WRITE setNotificationTimeout NOTIFY notificationTimeoutChanged)
public:
explicit LaunchFeedback(QObject* parent = nullptr, const QVariantList &list = QVariantList());
~LaunchFeedback() override;
int busyCursorCurrentIndex() const;
void setBusyCursorCurrentIndex(int index);
bool taskManagerNotification() const;
void setTaskManagerNotification(bool enabled);
int notificationTimeout() const;
void setNotificationTimeout(int duration);
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
Q_SIGNALS:
void busyCursorCurrentIndexChanged() const;
void taskManagerNotificationChanged() const;
Q_PROPERTY(LaunchFeedbackSettings *launchFeedbackSettings READ launchFeedbackSettings CONSTANT)
void notificationTimeoutChanged() const;
public:
enum class CursorFeedbackType {
None,
Static,
Blinking,
Bouncing,
};
Q_ENUM(CursorFeedbackType)
private:
void updateNeedsSave();
explicit LaunchFeedback(QObject *parent = nullptr, const QVariantList &list = QVariantList());
~LaunchFeedback() override;
int m_busyCursorCurrentIndex;
LaunchFeedbackSettings *launchFeedbackSettings() const;
bool m_taskManagerNotification;
public Q_SLOTS:
void save() override;
int m_notificationTimeout;
private:
LaunchFeedbackSettings *m_settings;
};
#endif
<?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="klaunchrc"/>
<group name="BusyCursorSettings">
<entry name="blinking" key="Blinking" type="Bool">
<default>false</default>
</entry>
<entry name="bouncing" key="Bouncing" type="Bool">
<default>true</default>
</entry>
<entry name="cursorTimeout" key="Timeout" type="Int">
<label>Timeout in seconds</label>
<default>5</default>
</entry>
</group>
<group name="FeedbackStyle">
<entry name="busyCursor" key="BusyCursor" type="Bool">
<default>true</default>
</entry>
<entry name="taskbarButton" key="TaskbarButton" type="Bool">
<default>true</default>
</entry>
</group>
<group name="TaskbarButtonSettings">
<entry name="taskbarTimeout" key="Timeout" type="Int">
<label>Timeout in seconds</label>
<default>5</default>
</entry>
</group>
</kcfg>
File=launchfeedbacksettings.kcfg
ClassName=LaunchFeedbackSettings
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
......@@ -21,70 +21,53 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 2.2 as QtControls
import org.kde.kirigami 2.3 as Kirigami
import org.kde.kcm 1.1
import org.kde.private.kcms.launchfeedback 1.0 as Private
SimpleKCM {
id: root
ConfigModule.quickHelp: i18n("Launch Feedback")
ConfigModule.buttons: ConfigModule.Help | ConfigModule.Defaults | ConfigModule.Apply
function applyBusyCursorCurrentIndex() {
if (kcm.busyCursorCurrentIndex === 0) {
busyCursorDisabled.checked = true;
} else if (kcm.busyCursorCurrentIndex === 1) {
busyCursorStatic.checked = true;
} else if (kcm.busyCursorCurrentIndex === 2) {
busyCursorBlinking.checked = true;
} else if (kcm.busyCursorCurrentIndex === 3) {
busyCursorBouncing.checked = true;
}
}
Kirigami.FormLayout {
id: formLayout
Connections {
target: kcm
onBusyCursorCurrentIndexChanged: applyBusyCursorCurrentIndex()
onTaskManagerNotificationChanged: taskManagerNotification.checked = kcm.taskManagerNotification
onNotificationTimeoutChanged: notificationTimeout.value = kcm.notificationTimeout
function setCursorSettings(feedback) {
kcm.launchFeedbackSettings.busyCursor = feedback !== Private.KCM.None
kcm.launchFeedbackSettings.blinking = feedback === Private.KCM.Blinking
kcm.launchFeedbackSettings.bouncing = feedback === Private.KCM.Bouncing
}
QtControls.RadioButton {
id: busyCursorDisabled
Kirigami.FormData.label: i18n("Cursor:")
text: i18n("No Feedback")
onToggled: kcm.busyCursorCurrentIndex = 0;
checked: !kcm.launchFeedbackSettings.busyCursor && !kcm.launchFeedbackSettings.blinking && !kcm.launchFeedbackSettings.bouncing
onToggled: formLayout.setCursorSettings(Private.KCM.None)
}
QtControls.RadioButton {
id: busyCursorStatic
text: i18n("Static")
onToggled: kcm.busyCursorCurrentIndex = 1;
checked: kcm.launchFeedbackSettings.busyCursor && !kcm.launchFeedbackSettings.blinking && !kcm.launchFeedbackSettings.bouncing
onToggled: formLayout.setCursorSettings(Private.KCM.Static)
}
QtControls.RadioButton {
id: busyCursorBlinking
text: i18n("Blinking")
onToggled: kcm.busyCursorCurrentIndex = 2;
checked: kcm.launchFeedbackSettings.busyCursor && kcm.launchFeedbackSettings.blinking && !kcm.launchFeedbackSettings.bouncing
onToggled: formLayout.setCursorSettings(Private.KCM.Blinking)
}
QtControls.RadioButton {
id: busyCursorBouncing
id: busyCursorBouncing
text: i18n("Bouncing")
onToggled: kcm.busyCursorCurrentIndex = 3;
checked: kcm.launchFeedbackSettings.busyCursor && !kcm.launchFeedbackSettings.blinking && kcm.launchFeedbackSettings.bouncing
onToggled: formLayout.setCursorSettings(Private.KCM.Bouncing)
}
QtControls.CheckBox {
......@@ -94,8 +77,8 @@ SimpleKCM {
text: i18n("Enable animation")
checked: kcm.taskManagerNotification
onToggled: kcm.taskManagerNotification = checked
checked: kcm.launchFeedbackSettings.taskbarButton
onToggled: kcm.launchFeedbackSettings.taskbarButton = checked
}
QtControls.SpinBox {
......@@ -108,14 +91,14 @@ SimpleKCM {
enabled: taskManagerNotification.checked
value: kcm.notificationTimeout
onValueChanged: kcm.notificationTimeout = value
value: kcm.launchFeedbackSettings.cursorTimeout
onValueModified: {
kcm.launchFeedbackSettings.cursorTimeout = value
kcm.launchFeedbackSettings.taskbarTimeout = value
}
textFromValue: function(value, locale) { return i18np("%1 sec", "%1 secs", value)}
valueFromText: function(text, locale) { return parseInt(text) }
}
}
Component.onCompleted: applyBusyCursorCurrentIndex()
}
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