61c2055da7
Previously, the only way to access the rules list was via the `rules()` and `setRules()` methods, so the actual settings objects were not accesible. This commit adds methods to retrieve, insert, remove or reorder the rules within the list. Since every individual rule is stored as a KConfig group, and they are not designed to be dynamically renamed, using consecutive numbered groups and store only the total count is problematic. So we also add a new stringlist setting to store the rules group names and their order. Now any group name is valid. To avoid collisions use random QUuids as group names for newly created rules.
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
/*
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
SPDX-FileCopyrightText: 2020 Henri Chain <henri.chain@enioka.com>
|
|
SPDX-FileCopyrightText: 2021 Ismael Asensio <isma.af@gmail.com>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#ifndef RULEBOOKSETTINGS_H
|
|
#define RULEBOOKSETTINGS_H
|
|
|
|
#include "rulebooksettingsbase.h"
|
|
#include <KSharedConfig>
|
|
|
|
namespace KWin
|
|
{
|
|
class Rules;
|
|
class RuleSettings;
|
|
|
|
class RuleBookSettings : public RuleBookSettingsBase
|
|
{
|
|
public:
|
|
RuleBookSettings(KSharedConfig::Ptr config, QObject *parent = nullptr);
|
|
RuleBookSettings(const QString &configname, KConfig::OpenFlags, QObject *parent = nullptr);
|
|
RuleBookSettings(KConfig::OpenFlags, QObject *parent = nullptr);
|
|
RuleBookSettings(QObject *parent = nullptr);
|
|
~RuleBookSettings();
|
|
|
|
void setRules(const QVector<Rules *> &);
|
|
QVector<Rules *> rules();
|
|
|
|
bool usrSave() override;
|
|
void usrRead() override;
|
|
bool usrIsSaveNeeded() const;
|
|
|
|
int ruleCount() const;
|
|
RuleSettings *ruleSettingsAt(int row) const;
|
|
RuleSettings *insertRuleSettingsAt(int row);
|
|
void removeRuleSettingsAt(int row);
|
|
void moveRuleSettings(int srcRow, int destRow);
|
|
|
|
private:
|
|
static QString generateGroupName();
|
|
|
|
private:
|
|
QVector<RuleSettings *> m_list;
|
|
QStringList m_storedGroups;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // RULEBOOKSETTINGS_H
|