diff --git a/kcms/launch/CMakeLists.txt b/kcms/launch/CMakeLists.txt --- a/kcms/launch/CMakeLists.txt +++ b/kcms/launch/CMakeLists.txt @@ -8,6 +8,8 @@ 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 @@ ########### 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) - diff --git a/kcms/launch/launchfeedback.h b/kcms/launch/launchfeedback.h --- a/kcms/launch/launchfeedback.h +++ b/kcms/launch/launchfeedback.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2001 Rik Hemsley (rikkus) * Copyright (C) 2017 Eike Hein + * Copyright (c) 2019 Cyril Rossi * * 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 +#include -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 diff --git a/kcms/launch/launchfeedback.cpp b/kcms/launch/launchfeedback.cpp --- a/kcms/launch/launchfeedback.cpp +++ b/kcms/launch/launchfeedback.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2001 Rik Hemsley (rikkus) * Copyright (C) 2017 Eike Hein + * Copyright (c) 2019 Cyril Rossi * * 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 -#include -#include #include #include #include "kwin_interface.h" -#define STARTUP_DEFAULT_TIMEOUT 5 +#include "launchfeedbacksettings.h" K_PLUGIN_FACTORY_WITH_JSON(LaunchFactory, "kcm_launchfeedback.json", registerPlugin();) 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("org.kde.private.kcms.launchfeedback", 1, 0, "KCM", QStringLiteral("Cannot create instances of KCM")); + qmlRegisterType(); + KAboutData *about = new KAboutData(QStringLiteral("kcm_launchfeedback"), i18n("Configure application launch feedback"), QStringLiteral("0.2"), QString(), KAboutLicense::LGPL); @@ -48,155 +48,19 @@ { } -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"), QDBusConnection::sessionBus()); 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" diff --git a/kcms/launch/launchfeedbacksettings.kcfg b/kcms/launch/launchfeedbacksettings.kcfg new file mode 100644 --- /dev/null +++ b/kcms/launch/launchfeedbacksettings.kcfg @@ -0,0 +1,33 @@ + + + + + + false + + + true + + + + 5 + + + + + true + + + true + + + + + + 5 + + + diff --git a/kcms/launch/launchfeedbacksettings.kcfgc b/kcms/launch/launchfeedbacksettings.kcfgc new file mode 100644 --- /dev/null +++ b/kcms/launch/launchfeedbacksettings.kcfgc @@ -0,0 +1,6 @@ +File=launchfeedbacksettings.kcfg +ClassName=LaunchFeedbackSettings +Mutators=true +DefaultValueGetters=true +GenerateProperties=true +ParentInConstructor=true diff --git a/kcms/launch/package/contents/ui/main.qml b/kcms/launch/package/contents/ui/main.qml --- a/kcms/launch/package/contents/ui/main.qml +++ b/kcms/launch/package/contents/ui/main.qml @@ -21,70 +21,53 @@ 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 @@ 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 @@ 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() } -