diff --git a/kcms/workspaceoptions/CMakeLists.txt b/kcms/workspaceoptions/CMakeLists.txt index 58789f3db..ec49882c5 100644 --- a/kcms/workspaceoptions/CMakeLists.txt +++ b/kcms/workspaceoptions/CMakeLists.txt @@ -1,27 +1,32 @@ # KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"kcm_workspace\") ########### next target ############### 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 KF5::QuickAddons KF5::I18n KF5::ConfigWidgets KF5::Declarative KF5::KDELibs4Support # kglobalsettings Qt5::DBus ) 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) kpackage_install_package(package kcm_workspace kcms) diff --git a/kcms/workspaceoptions/package/contents/ui/main.qml b/kcms/workspaceoptions/package/contents/ui/main.qml index 18b3bea65..61757b04f 100644 --- a/kcms/workspaceoptions/package/contents/ui/main.qml +++ b/kcms/workspaceoptions/package/contents/ui/main.qml @@ -1,129 +1,127 @@ /* * Copyright 2018 Furkan Tokac * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.7 import QtQuick.Controls 2.5 as QQC2 import QtQuick.Layouts 1.3 import org.kde.kirigami 2.5 as Kirigami import org.kde.kcm 1.2 as KCM 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 { id: formLayout // Visual behavior settings QQC2.CheckBox { 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 { Kirigami.FormData.isSection: false } // We want to show the slider in a logarithmic way. ie // 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 QQC2.Slider { id: slider Layout.fillWidth: true from: -4 to: 4 stepSize: 1 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 { QQC2.Label { text: i18nc("Animation speed", "Slow") } Item { Layout.fillWidth: true } QQC2.Label { text: i18nc("Animation speed", "Instant") } } } - Connections { - target: kcm - onToolTipChanged: showToolTips.checked = kcm.toolTip - onVisualFeedbackChanged: showVisualFeedback.checked = kcm.visualFeedback - } - Item { Kirigami.FormData.isSection: false } // Click behavior settings QQC2.RadioButton { 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 - } - } } } diff --git a/kcms/workspaceoptions/workspaceoptions.cpp b/kcms/workspaceoptions/workspaceoptions.cpp index d6443e219..31fb5f000 100644 --- a/kcms/workspaceoptions/workspaceoptions.cpp +++ b/kcms/workspaceoptions/workspaceoptions.cpp @@ -1,246 +1,77 @@ /* * Copyright (C) 2018 + * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * 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 #include #include -#include -#include #include -#include <../migrationlib/kdelibs4config.h> #include #include +#include "workspaceoptions_kdeglobalssettings.h" +#include "workspaceoptions_plasmasettings.h" + K_PLUGIN_FACTORY_WITH_JSON(KCMWorkspaceOptionsFactory, "kcm_workspace.json", registerPlugin();) -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(); + qmlRegisterType(); + + KAboutData *about = new KAboutData(QStringLiteral("kcm_workspace"), i18n("General Behavior"), QStringLiteral("1.1"), i18n("System Settings module for configuring general workspace behavior."), KAboutLicense::GPL); 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 args; args.append(KGlobalSettings::SettingsChanged); args.append(KGlobalSettings::SETTINGS_MOUSE); message.setArguments(args); 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" diff --git a/kcms/workspaceoptions/workspaceoptions.h b/kcms/workspaceoptions/workspaceoptions.h index a8c34006d..74aa4bbf9 100644 --- a/kcms/workspaceoptions/workspaceoptions.h +++ b/kcms/workspaceoptions/workspaceoptions.h @@ -1,82 +1,49 @@ /* * Copyright (C) 2018 + * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * 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 +#include + +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 diff --git a/kcms/workspaceoptions/workspaceoptions_kdeglobalssettings.kcfg b/kcms/workspaceoptions/workspaceoptions_kdeglobalssettings.kcfg new file mode 100644 index 000000000..20eca2c83 --- /dev/null +++ b/kcms/workspaceoptions/workspaceoptions_kdeglobalssettings.kcfg @@ -0,0 +1,17 @@ + + + + + + + true + + + + 1.0 + + + diff --git a/kcms/workspaceoptions/workspaceoptions_kdeglobalssettings.kcfgc b/kcms/workspaceoptions/workspaceoptions_kdeglobalssettings.kcfgc new file mode 100644 index 000000000..d01e18d5d --- /dev/null +++ b/kcms/workspaceoptions/workspaceoptions_kdeglobalssettings.kcfgc @@ -0,0 +1,6 @@ +File=workspaceoptions_kdeglobalssettings.kcfg +ClassName=WorkspaceOptionsGlobalsSettings +Mutators=true +DefaultValueGetters=true +GenerateProperties=true +ParentInConstructor=true diff --git a/kcms/workspaceoptions/workspaceoptions_plasmasettings.kcfg b/kcms/workspaceoptions/workspaceoptions_plasmasettings.kcfg new file mode 100644 index 000000000..fad916027 --- /dev/null +++ b/kcms/workspaceoptions/workspaceoptions_plasmasettings.kcfg @@ -0,0 +1,19 @@ + + + + + + + 0.7 + + + + + + true + + + diff --git a/kcms/workspaceoptions/workspaceoptions_plasmasettings.kcfgc b/kcms/workspaceoptions/workspaceoptions_plasmasettings.kcfgc new file mode 100644 index 000000000..aecaa0d95 --- /dev/null +++ b/kcms/workspaceoptions/workspaceoptions_plasmasettings.kcfgc @@ -0,0 +1,6 @@ +File=workspaceoptions_plasmasettings.kcfgc +ClassName=WorkspaceOptionsPlasmaSettings +Mutators=true +DefaultValueGetters=true +GenerateProperties=true +ParentInConstructor=true