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

Load/save store for scrolling templates. More...

#include <PhosphorZones/ScrollingTemplateStore.h>

Inheritance diagram for PhosphorZones::ScrollingTemplateStore:
[legend]

Signals

void templatesChanged ()
 The loaded template set changed (load, save, remove, duplicate).

Public Member Functions

 ScrollingTemplateStore (QString templateSubdirectory, QObject *parent=nullptr)
 templateSubdirectory is where the app keeps its templates, relative to every QStandardPaths::GenericDataLocation directory, no leading slash, the way LayoutRegistry takes its layout subdirectory.
QString templateSubdirectory () const
 The data-location subdirectory templates live in, relative to GenericDataLocation, as the constructor received it.
QString userTemplateDirectory () const
 Absolute path of the USER template directory (GenericDataLocation + templateSubdirectory()).
void loadTemplates ()
 Rescan every data location (system first, user last).
QList< ScrollingTemplate > templates () const
 All templates, name-sorted (case-insensitive) for stable UI order.
ScrollingTemplate templateById (const QUuid &id) const
 The template with id, or an invalid template.
bool contains (const QUuid &id) const
int count () const
QUuid saveTemplate (ScrollingTemplate templ)
 Persist templ (create or update).
bool removeTemplate (const QUuid &id)
 Delete the USER files for id.
QUuid duplicateTemplate (const QUuid &id, const QString &newName=QString())
 Store a copy of id under a fresh UUID with newName (or a "name (Copy)" derivative when empty).

Detailed Description

Load/save store for scrolling templates.

The persistence peer of LayoutRegistry's layout loading, for the ScrollingTemplate object: JSON files in the app's template subdirectory (PlasmaZones uses "plasmazones/scrolling-templates") under every GenericDataLocation. System directories load first and the user directory last, so a user file sharing a bundled template's id SHADOWS it (edit-a-bundled-template writes a user copy; deleting that copy resurfaces the original). Templates get their own directory rather than sharing the layouts directory, so the layout loader's sidecar skip-list stays untouched.

Mutations write the USER directory only and re-announce via templatesChanged. The store is process-local: the daemon owns the authoritative instance behind the D-Bus CRUD verbs, and the settings/KCM processes instantiate their own read view exactly as they do for the local LayoutRegistry.

Constructor & Destructor Documentation

◆ ScrollingTemplateStore()

PhosphorZones::ScrollingTemplateStore::ScrollingTemplateStore ( QString templateSubdirectory,
QObject * parent = nullptr )
explicit

templateSubdirectory is where the app keeps its templates, relative to every QStandardPaths::GenericDataLocation directory, no leading slash, the way LayoutRegistry takes its layout subdirectory.

Empty disables the store: it loads nothing and refuses every save.

Member Function Documentation

◆ contains()

bool PhosphorZones::ScrollingTemplateStore::contains ( const QUuid & id) const
inline

◆ count()

int PhosphorZones::ScrollingTemplateStore::count ( ) const
inline

◆ duplicateTemplate()

QUuid PhosphorZones::ScrollingTemplateStore::duplicateTemplate ( const QUuid & id,
const QString & newName = QString() )

Store a copy of id under a fresh UUID with newName (or a "name (Copy)" derivative when empty).

Returns the new id, null on failure.

◆ loadTemplates()

void PhosphorZones::ScrollingTemplateStore::loadTemplates ( )

Rescan every data location (system first, user last).

Emits templatesChanged when the loaded set differs.

◆ removeTemplate()

bool PhosphorZones::ScrollingTemplateStore::removeTemplate ( const QUuid & id)

Delete the USER files for id.

Both candidates are removed: the entry's own sourcePath when that path lies inside the user directory (a hand-placed user file need not be named after its id) and the id-derived path, since those can be two different files carrying the same id. A bundled (system) template shadowed by a user file resurfaces on the rescan this triggers; a template whose loaded entry came from a system location is refused (returns false) — the UI disables delete for those. Returns true when no user file for id remains afterwards, which includes the case where the files were already gone: the requested state holds either way. Returns false when a file survives (a remove that failed, which is logged) and when there was no user file to target at all, since nothing was deleted and the entry is still visible.

◆ saveTemplate()

QUuid PhosphorZones::ScrollingTemplateStore::saveTemplate ( ScrollingTemplate templ)

Persist templ (create or update).

A null id is assigned a fresh UUID. Normalizes first; refuses (returns null id) when the template is invalid after normalization or the write fails. A save that would store a byte-identical entry writes nothing and emits nothing, and still returns the stored id. Writes to <id>.json in the user directory and retires every other user file declaring the same id, so a hand-placed duplicate cannot win the next rescan and revert the save. Returns the stored id.

◆ templateById()

ScrollingTemplate PhosphorZones::ScrollingTemplateStore::templateById ( const QUuid & id) const

The template with id, or an invalid template.

◆ templates()

QList< ScrollingTemplate > PhosphorZones::ScrollingTemplateStore::templates ( ) const

All templates, name-sorted (case-insensitive) for stable UI order.

◆ templatesChanged

void PhosphorZones::ScrollingTemplateStore::templatesChanged ( )
signal

The loaded template set changed (load, save, remove, duplicate).

◆ templateSubdirectory()

QString PhosphorZones::ScrollingTemplateStore::templateSubdirectory ( ) const
inline

The data-location subdirectory templates live in, relative to GenericDataLocation, as the constructor received it.

UI code that opens the folder must use this rather than inlining the path.

◆ userTemplateDirectory()

QString PhosphorZones::ScrollingTemplateStore::userTemplateDirectory ( ) const

Absolute path of the USER template directory (GenericDataLocation + templateSubdirectory()).

UI code that has to open or create the folder must use this rather than re-joining the two parts itself. Empty when the store has no subdirectory.


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