Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
RuleStore.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <QObject>
7#include <QString>
8#include <QUuid>
9
10#include "RuleSet.h"
11#include "phosphorrules_export.h"
12
13namespace PhosphorRules {
14
47class PHOSPHORRULES_EXPORT RuleStore : public QObject
48{
49 Q_OBJECT
50
51public:
58 explicit RuleStore(const QString& filePath, QObject* parent = nullptr);
59 ~RuleStore() override = default;
60
62 QString filePath() const
63 {
64 return m_filePath;
65 }
66
68 const RuleSet& ruleSet() const
69 {
70 return m_ruleSet;
71 }
72
74 int count() const
75 {
76 return m_ruleSet.count();
77 }
78
80 bool contains(const QUuid& id) const
81 {
82 return m_ruleSet.ruleById(id).has_value();
83 }
84
85 // ─── Persistence ──────────────────────────────────────────────────────
86
92 void load();
93
97 bool save();
98
99 // ─── Mutation — every mutator persists then emits rulesChanged ────────
100 //
101 // Every mutator keeps the in-memory set and the on-disk file consistent:
102 // the in-memory set is updated first, then persisted. A failed `save()`
103 // makes the mutator return false — the in-memory set still reflects the
104 // requested change, but the caller knows the file is now stale.
105
110 bool setAllRules(const QList<Rule>& rules);
111
114 bool addRule(const Rule& rule);
115
118 bool updateRule(const Rule& rule);
119
122 bool removeRule(const QUuid& id);
123
127 bool setRuleEnabled(const QUuid& id, bool enabled);
128
132 bool setRulePriority(const QUuid& id, int priority);
133
134Q_SIGNALS:
143 void rulesChanged(bool persisted);
144
145private:
146 QString m_filePath;
147 RuleSet m_ruleSet;
148};
149
150} // namespace PhosphorRules
An ordered collection of Rules — the persistent rule store.
Definition RuleSet.h:33
QString filePath() const
The backing file path.
Definition RuleStore.h:62
void load()
(Re)load from disk.
void rulesChanged(bool persisted)
Emitted whenever the in-memory rule set changes (load or any mutator).
bool contains(const QUuid &id) const
True if a rule with id is present.
Definition RuleStore.h:80
bool setRuleEnabled(const QUuid &id, bool enabled)
Set the enabled flag of the rule with id.
int count() const
Number of rules in the store.
Definition RuleStore.h:74
bool updateRule(const Rule &rule)
Replace the rule with the same id.
const RuleSet & ruleSet() const
Read-only access to the live rule set.
Definition RuleStore.h:68
bool addRule(const Rule &rule)
Append a rule.
~RuleStore() override=default
bool setRulePriority(const QUuid &id, int priority)
Set the priority of the rule with id.
bool removeRule(const QUuid &id)
Remove the rule with id.
bool save()
Persist the in-memory set to disk (atomic temp-write + rename).
bool setAllRules(const QList< Rule > &rules)
Replace the entire rule list.
RuleStore(const QString &filePath, QObject *parent=nullptr)
Definition ActionParams.h:25
One rule — { id, name, enabled, priority, match, actions, managed }.
Definition Rule.h:106