From 790e717c82cb6a8c99b8f02671b0163d2922ebeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Wed, 11 Dec 2019 11:14:02 +0100 Subject: [PATCH] [KCM/Desktop] Port from KQuickAddons::ConfigModule to ManagedConfigModule Test Plan: kcmshell5 kcm_kwin_virtualdesktops kcm works as before Reviewers: #kwin, ervin, crossi, zzag Reviewed By: #kwin, ervin, zzag Subscribers: zzag, bport, crossi, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D25881 --- kcmkwin/kwindesktop/animationsmodel.cpp | 7 + kcmkwin/kwindesktop/animationsmodel.h | 1 + kcmkwin/kwindesktop/desktopsmodel.cpp | 39 +++++ kcmkwin/kwindesktop/desktopsmodel.h | 5 + .../kwindesktop/package/contents/ui/main.qml | 40 ++--- kcmkwin/kwindesktop/virtualdesktops.cpp | 146 +++--------------- kcmkwin/kwindesktop/virtualdesktops.h | 37 +---- .../kwindesktop/virtualdesktopssettings.kcfg | 6 +- 8 files changed, 101 insertions(+), 180 deletions(-) diff --git a/kcmkwin/kwindesktop/animationsmodel.cpp b/kcmkwin/kwindesktop/animationsmodel.cpp index 64c2a3e3ef..f80a64c537 100644 --- a/kcmkwin/kwindesktop/animationsmodel.cpp +++ b/kcmkwin/kwindesktop/animationsmodel.cpp @@ -135,6 +135,13 @@ void AnimationsModel::defaults() setCurrentIndex(modelCurrentIndex()); } +bool AnimationsModel::isDefaults() const +{ + // effect at m_currentIndex index may not be the current saved selected effect + const bool enabledByDefault = index(m_currentIndex, 0).data(EnabledByDefaultRole).toBool(); + return enabledByDefault; +} + bool AnimationsModel::needsSave() const { KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); diff --git a/kcmkwin/kwindesktop/animationsmodel.h b/kcmkwin/kwindesktop/animationsmodel.h index fd740e8523..f05d9feec0 100644 --- a/kcmkwin/kwindesktop/animationsmodel.h +++ b/kcmkwin/kwindesktop/animationsmodel.h @@ -46,6 +46,7 @@ public: void load(); void save(); void defaults(); + bool isDefaults() const; bool needsSave() const; Q_SIGNALS: diff --git a/kcmkwin/kwindesktop/desktopsmodel.cpp b/kcmkwin/kwindesktop/desktopsmodel.cpp index e3ad60c67e..b060ab6412 100644 --- a/kcmkwin/kwindesktop/desktopsmodel.cpp +++ b/kcmkwin/kwindesktop/desktopsmodel.cpp @@ -376,6 +376,45 @@ void DesktopsModel::reset() SLOT(handleCallError())); } +bool DesktopsModel::needsSave() const +{ + return m_userModified; +} + +bool DesktopsModel::isDefaults() const +{ + return m_rows == 2 && m_desktops.count() == 1; +} + +void DesktopsModel::defaults() +{ + beginResetModel(); + // default is 1 desktop with 2 rows + // see kwin/virtualdesktops.cpp VirtualDesktopGrid::VirtualDesktopGrid + while (m_desktops.count() > 1) { + const auto desktop = m_desktops.takeLast(); + m_names.remove(desktop); + } + m_rows = 2; + + endResetModel(); + + m_userModified = true; + updateModifiedState(); +} + +void DesktopsModel::load() +{ + beginResetModel(); + m_desktops = m_serverSideDesktops; + m_names = m_serverSideNames; + m_rows = m_serverSideRows; + endResetModel(); + + m_userModified = true; + updateModifiedState(); +} + void DesktopsModel::getAllAndConnect(const QDBusMessage &msg) { const QVariantMap &data = qdbus_cast(msg.arguments().at(0).value()); diff --git a/kcmkwin/kwindesktop/desktopsmodel.h b/kcmkwin/kwindesktop/desktopsmodel.h index e2626fe611..9d9f8ad7d1 100644 --- a/kcmkwin/kwindesktop/desktopsmodel.h +++ b/kcmkwin/kwindesktop/desktopsmodel.h @@ -93,6 +93,11 @@ public: Q_INVOKABLE void syncWithServer(); + bool needsSave() const; + void load(); + void defaults(); + bool isDefaults() const; + Q_SIGNALS: void readyChanged() const; void errorChanged() const; diff --git a/kcmkwin/kwindesktop/package/contents/ui/main.qml b/kcmkwin/kwindesktop/package/contents/ui/main.qml index dea0bd69f1..5e0f39b267 100644 --- a/kcmkwin/kwindesktop/package/contents/ui/main.qml +++ b/kcmkwin/kwindesktop/package/contents/ui/main.qml @@ -165,15 +165,6 @@ ScrollViewKCM { } Kirigami.FormLayout { - Connections { - target: kcm - - onNavWrapsChanged: navWraps.checked = kcm.navWraps - - onOsdEnabledChanged: osdEnabled.checked = kcm.osdEnabled - onOsdDurationChanged: osdDuration.value = kcm.osdDuration - onOsdTextOnlyChanged: osdTextOnly.checked = !kcm.osdTextOnly - } QQC2.CheckBox { id: navWraps @@ -181,10 +172,9 @@ ScrollViewKCM { Kirigami.FormData.label: i18n("Options:") text: i18n("Navigation wraps around") - - checked: kcm.navWraps - - onCheckedChanged: kcm.navWraps = checked + enabled: !kcm.virtualDesktopsSettings.isImmutable("rollOverDesktops") + checked: kcm.virtualDesktopsSettings.rollOverDesktops + onToggled: kcm.virtualDesktopsSettings.rollOverDesktops = checked } RowLayout { @@ -200,7 +190,7 @@ ScrollViewKCM { checked: kcm.animationsModel.enabled - onCheckedChanged: kcm.animationsModel.enabled = checked + onToggled: kcm.animationsModel.enabled = checked } QQC2.ComboBox { @@ -241,15 +231,17 @@ ScrollViewKCM { text: i18n("Show on-screen display when switching:") - checked: kcm.osdEnabled + enabled: !kcm.virtualDesktopsSettings.isImmutable("desktopChangeOsdEnabled") - onToggled: kcm.osdEnabled = checked + checked: kcm.virtualDesktopsSettings.desktopChangeOsdEnabled + + onToggled: kcm.virtualDesktopsSettings.desktopChangeOsdEnabled = checked } QQC2.SpinBox { id: osdDuration - enabled: osdEnabled.checked + enabled: osdEnabled.checked && !kcm.virtualDesktopsSettings.isImmutable("popupHideDelay") from: 0 to: 10000 @@ -257,9 +249,9 @@ ScrollViewKCM { textFromValue: function(value, locale) { return i18n("%1 ms", value)} - value: kcm.osdDuration + value: kcm.virtualDesktopsSettings.popupHideDelay - onValueChanged: kcm.osdDuration = value + onValueModified: kcm.virtualDesktopsSettings.popupHideDelay = value } } @@ -272,14 +264,10 @@ ScrollViewKCM { QQC2.CheckBox { id: osdTextOnly - - enabled: osdEnabled.checked - + enabled: osdEnabled.checked && !kcm.virtualDesktopsSettings.isImmutable("textOnly") text: i18n("Show desktop layout indicators") - - checked: !kcm.osdTextOnly - - onToggled: kcm.osdTextOnly = !checked + checked: !kcm.virtualDesktopsSettings.textOnly + onToggled: kcm.virtualDesktopsSettings.textOnly = !checked } } } diff --git a/kcmkwin/kwindesktop/virtualdesktops.cpp b/kcmkwin/kwindesktop/virtualdesktops.cpp index f450557fa8..5a433f4e32 100644 --- a/kcmkwin/kwindesktop/virtualdesktops.cpp +++ b/kcmkwin/kwindesktop/virtualdesktops.cpp @@ -32,13 +32,9 @@ namespace KWin { VirtualDesktops::VirtualDesktops(QObject *parent, const QVariantList &args) - : KQuickAddons::ConfigModule(parent, args) + : KQuickAddons::ManagedConfigModule(parent, args) , m_settings(new VirtualDesktopsSettings(this)) , m_desktopsModel(new KWin::DesktopsModel(this)) - , m_navWraps(true) - , m_osdEnabled(false) - , m_osdDuration(1000) - , m_osdTextOnly(false) , m_animationsModel(new AnimationsModel(this)) { KAboutData *about = new KAboutData(QStringLiteral("kcm_kwin_virtualdesktops"), @@ -46,14 +42,16 @@ VirtualDesktops::VirtualDesktops(QObject *parent, const QVariantList &args) QStringLiteral("2.0"), QString(), KAboutLicense::GPL); setAboutData(about); + qmlRegisterType(); + setButtons(Apply | Default); QObject::connect(m_desktopsModel, &KWin::DesktopsModel::userModifiedChanged, - this, &VirtualDesktops::updateNeedsSave); + this, &VirtualDesktops::settingsChanged); connect(m_animationsModel, &AnimationsModel::enabledChanged, - this, &VirtualDesktops::updateNeedsSave); + this, &VirtualDesktops::settingsChanged); connect(m_animationsModel, &AnimationsModel::currentIndexChanged, - this, &VirtualDesktops::updateNeedsSave); + this, &VirtualDesktops::settingsChanged); } VirtualDesktops::~VirtualDesktops() @@ -65,115 +63,47 @@ QAbstractItemModel *VirtualDesktops::desktopsModel() const return m_desktopsModel; } -bool VirtualDesktops::navWraps() const -{ - return m_navWraps; -} - -void VirtualDesktops::setNavWraps(bool wraps) -{ - if (m_navWraps != wraps) { - m_navWraps = wraps; - - emit navWrapsChanged(); - - updateNeedsSave(); - } -} - -bool VirtualDesktops::osdEnabled() const -{ - return m_osdEnabled; -} - -void VirtualDesktops::setOsdEnabled(bool enabled) -{ - if (m_osdEnabled != enabled) { - m_osdEnabled = enabled; - - emit osdEnabledChanged(); - - updateNeedsSave(); - } -} - -int VirtualDesktops::osdDuration() const -{ - return m_osdDuration; -} - -void VirtualDesktops::setOsdDuration(int duration) -{ - if (m_osdDuration != duration) { - m_osdDuration = duration; - - emit osdDurationChanged(); - - updateNeedsSave(); - } -} - -int VirtualDesktops::osdTextOnly() const -{ - return m_osdTextOnly; -} - -void VirtualDesktops::setOsdTextOnly(bool textOnly) -{ - if (m_osdTextOnly != textOnly) { - m_osdTextOnly = textOnly; - - emit osdTextOnlyChanged(); - - updateNeedsSave(); - } -} - QAbstractItemModel *VirtualDesktops::animationsModel() const { return m_animationsModel; } +VirtualDesktopsSettings *VirtualDesktops::virtualDesktopsSettings() const +{ + return m_settings; +} + void VirtualDesktops::load() { - setNavWraps(m_settings->rollOverDesktop()); - - setOsdEnabled(m_settings->desktopChangeOsdEnabled()); - - setOsdDuration(m_settings->popupHideDelay()); - setOsdTextOnly(m_settings->textOnly()); + ManagedConfigModule::load(); + m_desktopsModel->load(); m_animationsModel->load(); } void VirtualDesktops::save() { + ManagedConfigModule::save(); + m_desktopsModel->syncWithServer(); m_animationsModel->save(); - m_settings->setRollOverDesktop(m_navWraps); - m_settings->setDesktopChangeOsdEnabled(m_osdEnabled); - m_settings->setPopupHideDelay(m_osdDuration); - m_settings->setTextOnly(m_osdTextOnly); - - m_settings->save(); - QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); QDBusConnection::sessionBus().send(message); - - setNeedsSave(false); } void VirtualDesktops::defaults() { - m_desktopsModel->setRows(1); - m_animationsModel->defaults(); + ManagedConfigModule::defaults(); - setNavWraps(true); - setOsdEnabled(false); - setOsdDuration(1000); - setOsdTextOnly(false); + m_desktopsModel->defaults(); + m_animationsModel->defaults(); +} + +bool VirtualDesktops::isDefaults() const +{ + return m_animationsModel->isDefaults() && m_desktopsModel->isDefaults(); } void VirtualDesktops::configureAnimation() @@ -235,35 +165,9 @@ void VirtualDesktops::showAboutAnimation() delete aboutPlugin; } -void VirtualDesktops::updateNeedsSave() +bool VirtualDesktops::isSaveNeeded() const { - bool needsSave = false; - - if (m_desktopsModel->userModified()) { - needsSave = true; - } - - if (m_animationsModel->needsSave()) { - needsSave = true; - } - - if (m_navWraps != m_settings->rollOverDesktop()) { - needsSave = true; - } - - if (m_osdEnabled != m_settings->desktopChangeOsdEnabled()) { - needsSave = true; - } - - if (m_osdDuration != m_settings->popupHideDelay()) { - needsSave = true; - } - - if (m_osdTextOnly != m_settings->textOnly()) { - needsSave = true; - } - - setNeedsSave(needsSave); + return m_animationsModel->needsSave() || m_desktopsModel->needsSave(); } } diff --git a/kcmkwin/kwindesktop/virtualdesktops.h b/kcmkwin/kwindesktop/virtualdesktops.h index 285c4fe27c..9b486da9c9 100644 --- a/kcmkwin/kwindesktop/virtualdesktops.h +++ b/kcmkwin/kwindesktop/virtualdesktops.h @@ -19,7 +19,7 @@ #ifndef VIRTUALDESKTOPS_H #define VIRTUALDESKTOPS_H -#include +#include #include class VirtualDesktopsSettings; @@ -30,16 +30,13 @@ namespace KWin class AnimationsModel; class DesktopsModel; -class VirtualDesktops : public KQuickAddons::ConfigModule +class VirtualDesktops : public KQuickAddons::ManagedConfigModule { Q_OBJECT Q_PROPERTY(QAbstractItemModel* desktopsModel READ desktopsModel CONSTANT) - Q_PROPERTY(bool navWraps READ navWraps WRITE setNavWraps NOTIFY navWrapsChanged) - Q_PROPERTY(bool osdEnabled READ osdEnabled WRITE setOsdEnabled NOTIFY osdEnabledChanged) - Q_PROPERTY(int osdDuration READ osdDuration WRITE setOsdDuration NOTIFY osdDurationChanged) - Q_PROPERTY(bool osdTextOnly READ osdTextOnly WRITE setOsdTextOnly NOTIFY osdTextOnlyChanged) Q_PROPERTY(QAbstractItemModel *animationsModel READ animationsModel CONSTANT) + Q_PROPERTY(VirtualDesktopsSettings *virtualDesktopsSettings READ virtualDesktopsSettings CONSTANT) public: explicit VirtualDesktops(QObject *parent = nullptr, const QVariantList &list = QVariantList()); @@ -47,25 +44,12 @@ public: QAbstractItemModel *desktopsModel() const; - bool navWraps() const; - void setNavWraps(bool wraps); - - bool osdEnabled() const; - void setOsdEnabled(bool enabled); - - int osdDuration() const; - void setOsdDuration(int duration); - - int osdTextOnly() const; - void setOsdTextOnly(bool textOnly); - QAbstractItemModel *animationsModel() const; -Q_SIGNALS: - void navWrapsChanged() const; - void osdEnabledChanged() const; - void osdDurationChanged() const; - void osdTextOnlyChanged() const; + VirtualDesktopsSettings *virtualDesktopsSettings() const; + + bool isDefaults() const override; + bool isSaveNeeded() const override; public Q_SLOTS: void load() override; @@ -75,16 +59,9 @@ public Q_SLOTS: void configureAnimation(); void showAboutAnimation(); -private Q_SLOTS: - void updateNeedsSave(); - private: VirtualDesktopsSettings *m_settings; DesktopsModel *m_desktopsModel; - bool m_navWraps; - bool m_osdEnabled; - int m_osdDuration; - bool m_osdTextOnly; AnimationsModel *m_animationsModel; }; diff --git a/kcmkwin/kwindesktop/virtualdesktopssettings.kcfg b/kcmkwin/kwindesktop/virtualdesktopssettings.kcfg index df154d801d..7db898aef5 100644 --- a/kcmkwin/kwindesktop/virtualdesktopssettings.kcfg +++ b/kcmkwin/kwindesktop/virtualdesktopssettings.kcfg @@ -5,7 +5,7 @@ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > - + true @@ -17,11 +17,11 @@ - + 1000 - + false