/*
SPDX-FileCopyrightText: 2004 Lubos Lunak Window-specific Settings
Here you can customize window settings specifically only"
" for some windows.
Please note that this configuration will not take effect if you do not use" " KWin as your window manager. If you do use a different window manager, please refer to its documentation" " for how to customize window behavior.
")); connect(m_rulesModel, &RulesModel::descriptionChanged, this, [this]{ if (m_editIndex.isValid()) { m_ruleBookModel->setDescriptionAt(m_editIndex.row(), m_rulesModel->description()); } } ); connect(m_rulesModel, &RulesModel::dataChanged, this, &KCMKWinRules::updateNeedsSave); connect(m_ruleBookModel, &RulesModel::dataChanged, this, &KCMKWinRules::updateNeedsSave); } void KCMKWinRules::load() { m_ruleBookModel->load(); m_editIndex = QModelIndex(); emit editIndexChanged(); setNeedsSave(false); } void KCMKWinRules::save() { saveCurrentRule(); m_ruleBookModel->save(); // Notify kwin to reload configuration QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); QDBusConnection::sessionBus().send(message); } void KCMKWinRules::updateNeedsSave() { setNeedsSave(true); emit needsSaveChanged(); } void KCMKWinRules::saveCurrentRule() { if (m_editIndex.isValid() && needsSave()) { m_ruleBookModel->setRuleAt(m_editIndex.row(), m_rulesModel->exportToRules()); } } int KCMKWinRules::editIndex() const { if (!m_editIndex.isValid()) { return -1; } return m_editIndex.row(); } void KCMKWinRules::setRuleDescription(int index, const QString &description) { if (index < 0 || index >= m_ruleBookModel->rowCount()) { return; } if (m_editIndex.row() == index) { m_rulesModel->setDescription(description); return; } m_ruleBookModel->setDescriptionAt(index, description); updateNeedsSave(); } void KCMKWinRules::editRule(int index) { if (index < 0 || index >= m_ruleBookModel->rowCount()) { return; } saveCurrentRule(); m_editIndex = m_ruleBookModel->index(index); emit editIndexChanged(); m_rulesModel->importFromRules(m_ruleBookModel->ruleAt(m_editIndex.row())); // Set the active page to rules editor (0:RulesList, 1:RulesEditor) setCurrentIndex(1); } void KCMKWinRules::createRule() { const int newIndex = m_ruleBookModel->rowCount(); m_ruleBookModel->insertRow(newIndex); updateNeedsSave(); editRule(newIndex); } void KCMKWinRules::removeRule(int index) { if (index < 0 || index >= m_ruleBookModel->rowCount()) { return; } m_ruleBookModel->removeRow(index); emit editIndexChanged(); updateNeedsSave(); } void KCMKWinRules::moveRule(int sourceIndex, int destIndex) { const int lastIndex = m_ruleBookModel->rowCount() - 1; if (sourceIndex == destIndex || (sourceIndex < 0 || sourceIndex > lastIndex) || (destIndex < 0 || destIndex > lastIndex)) { return; } m_ruleBookModel->moveRow(QModelIndex(), sourceIndex, QModelIndex(), destIndex); emit editIndexChanged(); updateNeedsSave(); } void KCMKWinRules::exportToFile(const QUrl &path, const QList