Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorRules::RuleStore Class Reference

Persistent store for the unified Rule set. More...

#include <PhosphorRules/RuleStore.h>

Inheritance diagram for PhosphorRules::RuleStore:
[legend]

Signals

void rulesChanged (bool persisted)
 Emitted whenever the in-memory rule set changes (load or any mutator).

Public Member Functions

 RuleStore (const QString &filePath, QObject *parent=nullptr)
 ~RuleStore () override=default
QString filePath () const
 The backing file path.
const RuleSet & ruleSet () const
 Read-only access to the live rule set.
int count () const
 Number of rules in the store.
bool contains (const QUuid &id) const
 True if a rule with id is present.
void load ()
 (Re)load from disk.
bool save ()
 Persist the in-memory set to disk (atomic temp-write + rename).
bool setAllRules (const QList< Rule > &rules)
 Replace the entire rule list.
bool addRule (const Rule &rule)
 Append a rule.
bool updateRule (const Rule &rule)
 Replace the rule with the same id.
bool removeRule (const QUuid &id)
 Remove the rule with id.
bool setRuleEnabled (const QUuid &id, bool enabled)
 Set the enabled flag of the rule with id.
bool setRulePriority (const QUuid &id, int priority)
 Set the priority of the rule with id.

Detailed Description

Persistent store for the unified Rule set.

Owns an in-memory RuleSet and persists it to a caller-supplied file path (the daemon points it at ~/.config/plasmazones/rules.json, schema v4). The daemon is the primary writer — settings / KCM normally mutate the store over D-Bus — but the file is also rewritten out of process (settings reset, config import, hand edits), which an owner picks up through RuleStoreWatcher or an explicit load().

The store is the runtime counterpart of the config migration: migrateV3ToV4 writes the initial store as windowrules.json, then the v4→v5 conversion renames it to rules.json. The store reads that file on daemon start and owns every subsequent mutation.

Loader robustness follows the RuleSet contract: a missing file yields an empty set (a fresh install or a config that never had any rules), malformed individual rules are dropped with a logged diagnostic, and every save canonicalizes (temp-file + atomic rename).

This class lives in the LGPL phosphor-rules library so that both the LGPL phosphor-zones registry and the GPL daemon can own/borrow it without a GPL→LGPL dependency inversion. It is a plain QObject (Qt6::Core only) — it never derives a config location itself; the caller passes the path.

Separate-process consumers that own their own store and have no D-Bus path to the daemon (standalone plasmazones-settings, plasmazones-editor) can opt into cross-process auto-reload via RuleStoreWatcher, which watches the file and drives load() on external writes. The store's idempotent load() (it emits only on a real content change) makes that watcher's self-write events harmless without any extra bookkeeping here.

Constructor & Destructor Documentation

◆ RuleStore()

PhosphorRules::RuleStore::RuleStore ( const QString & filePath,
QObject * parent = nullptr )
explicit
Parameters
filePathAbsolute path to rules.json. Required — the library never derives config locations; an empty path is a developer error and is asserted against.
parentQt parent.

◆ ~RuleStore()

PhosphorRules::RuleStore::~RuleStore ( )
overridedefault

Member Function Documentation

◆ addRule()

bool PhosphorRules::RuleStore::addRule ( const Rule & rule)

Append a rule.

Returns false if the rule is invalid, its id collides with an existing rule (no persist, no emit), or the persist failed.

◆ contains()

bool PhosphorRules::RuleStore::contains ( const QUuid & id) const
inline

True if a rule with id is present.

◆ count()

int PhosphorRules::RuleStore::count ( ) const
inline

Number of rules in the store.

◆ filePath()

QString PhosphorRules::RuleStore::filePath ( ) const
inline

The backing file path.

◆ load()

void PhosphorRules::RuleStore::load ( )

(Re)load from disk.

A missing file is not an error — the store ends up empty. Replaces the in-memory set and emits rulesChanged only when the loaded content actually differs from the in-memory set; an idempotent re-load of an unchanged file does not emit (downstream cache flushes would otherwise fire for nothing).

◆ removeRule()

bool PhosphorRules::RuleStore::removeRule ( const QUuid & id)

Remove the rule with id.

Returns false if no such rule exists or the persist failed.

◆ rulesChanged

void PhosphorRules::RuleStore::rulesChanged ( bool persisted)
signal

Emitted whenever the in-memory rule set changes (load or any mutator).

persisted reports whether the change was written to disk successfully. true is the normal case (and is always true for a load — the disk is the source). false signals "in-memory state changed but the persist failed" — consumers that need to differentiate "user saved" from "user edited but the rule store is now divergent from disk" can branch on this flag.

◆ ruleSet()

const RuleSet & PhosphorRules::RuleStore::ruleSet ( ) const
inline

Read-only access to the live rule set.

◆ save()

bool PhosphorRules::RuleStore::save ( )

Persist the in-memory set to disk (atomic temp-write + rename).

Returns false on an I/O failure. Does not emit rulesChanged (the in-memory state did not change).

◆ setAllRules()

bool PhosphorRules::RuleStore::setAllRules ( const QList< Rule > & rules)

Replace the entire rule list.

Invalid rules are dropped. A no-op replacement (the incoming list equals the current set) skips the persist and the emit and returns true. Returns false only on an I/O failure while persisting an actual change.

◆ setRuleEnabled()

bool PhosphorRules::RuleStore::setRuleEnabled ( const QUuid & id,
bool enabled )

Set the enabled flag of the rule with id.

Returns false if no such rule exists or the persist failed. A no-op change (already at enabled) returns true without persisting or emitting.

◆ setRulePriority()

bool PhosphorRules::RuleStore::setRulePriority ( const QUuid & id,
int priority )

Set the priority of the rule with id.

Returns false if no such rule exists or the persist failed. A no-op change returns true without persisting/emitting.

◆ updateRule()

bool PhosphorRules::RuleStore::updateRule ( const Rule & rule)

Replace the rule with the same id.

Returns false if no such rule exists, the replacement is invalid, or the persist failed.


The documentation for this class was generated from the following file: