Commit 790e717c authored by Méven Car's avatar Méven Car
Browse files

[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
parent a823474e
......@@ -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");
......
......@@ -46,6 +46,7 @@ public:
void load();
void save();
void defaults();
bool isDefaults() const;
bool needsSave() const;
Q_SIGNALS:
......
......@@ -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<QVariantMap>(msg.arguments().at(0).value<QDBusArgument>());
......
......@@ -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;
......
......@@ -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
}
}
}
......
......@@ -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<VirtualDesktopsSettings>();
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)
QAbstractItemModel *VirtualDesktops::animationsModel() const
{
if (m_osdTextOnly != textOnly) {
m_osdTextOnly = textOnly;
emit osdTextOnlyChanged();
updateNeedsSave();
}
return m_animationsModel;
}
QAbstractItemModel *VirtualDesktops::animationsModel() const
VirtualDesktopsSettings *VirtualDesktops::virtualDesktopsSettings() const
{
return m_animationsModel;
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);
ManagedConfigModule::defaults();
m_desktopsModel->defaults();
m_animationsModel->defaults();
}
setNavWraps(true);
setOsdEnabled(false);
setOsdDuration(1000);
setOsdTextOnly(false);
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();
}
}
......
......@@ -19,7 +19,7 @@
#ifndef VIRTUALDESKTOPS_H
#define VIRTUALDESKTOPS_H
#include <KQuickAddons/ConfigModule>
#include <KQuickAddons/ManagedConfigModule>
#include <KSharedConfig>
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;
};
......
......@@ -5,7 +5,7 @@
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kwinrc"/>
<group name="Windows">
<entry name="rollOverDesktop" key="RollOverDesktops" type="bool">
<entry name="rollOverDesktops" key="RollOverDesktops" type="bool">
<label>Whether or not, we circle through the virtual desktop when moving from one to the next</label>
<default>true</default>
</entry>
......@@ -17,11 +17,11 @@
</entry>
</group>
<group name="Script-desktopchangeosd">
<entry name="PopupHideDelay" key="PopupHideDelay" type="int">
<entry name="popupHideDelay" key="PopupHideDelay" type="int">
<label>Duraton of the OSD</label>
<default>1000</default>
</entry>
<entry name="TextOnly" key="TextOnly" type="bool">
<entry name="textOnly" key="TextOnly" type="bool">
<label>Whether or not to display desktop layout in the OSD</label>
<default>false</default>
</entry>
......
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