Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
RetintController.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3#pragma once
4
5#include <QObject>
6#include <QPointer>
7#include <QString>
8#include <QVariantMap>
9#include <QtQmlIntegration/qqmlintegration.h>
10
11QT_BEGIN_NAMESPACE
12class QTimer;
13QT_END_NAMESPACE
14
15namespace PhosphorShellPicker {
16
49class RetintController : public QObject
50{
51 Q_OBJECT
52 QML_ELEMENT
53
54 Q_PROPERTY(QObject* runner READ runner WRITE setRunner NOTIFY runnerChanged)
55 Q_PROPERTY(QObject* store READ store WRITE setStore NOTIFY storeChanged)
56 Q_PROPERTY(int debounceMs READ debounceMs WRITE setDebounceMs NOTIFY debounceMsChanged)
60 Q_PROPERTY(QString persistPath READ persistPath WRITE setPersistPath NOTIFY persistPathChanged)
63 Q_PROPERTY(QString defaultPersistPath READ defaultPersistPath CONSTANT)
66 Q_PROPERTY(QString previewPath READ previewPath NOTIFY previewPathChanged)
68 Q_PROPERTY(bool previewing READ isPreviewing NOTIFY previewingChanged)
70 Q_PROPERTY(bool busy READ isBusy NOTIFY busyChanged)
71 Q_PROPERTY(QString lastError READ lastError NOTIFY lastErrorChanged)
72
73public:
74 explicit RetintController(QObject* parent = nullptr);
76
77 [[nodiscard]] QObject* runner() const;
78 void setRunner(QObject* runner);
79
80 [[nodiscard]] QObject* store() const;
81 void setStore(QObject* store);
82
83 [[nodiscard]] int debounceMs() const;
84 void setDebounceMs(int ms);
85
86 [[nodiscard]] QString persistPath() const;
87 void setPersistPath(const QString& path);
88
89 [[nodiscard]] QString previewPath() const;
90 [[nodiscard]] bool isPreviewing() const;
91 [[nodiscard]] bool isBusy() const;
92 [[nodiscard]] QString lastError() const;
93
95 Q_INVOKABLE void preview(const QString& wallpaperPath);
97 Q_INVOKABLE void previewTokens(const QVariantMap& tokens, const QString& label);
99 Q_INVOKABLE void clearPreview();
102 Q_INVOKABLE void commit();
103
107 [[nodiscard]] static QString defaultPersistPath();
108
110 [[nodiscard]] static QVariantMap withoutBrandStops(const QVariantMap& tokens);
111
113 [[nodiscard]] static bool writePalette(const QString& path, const QVariantMap& tokens);
114
115Q_SIGNALS:
125 void previewApplied(const QString& path);
127 void previewFailed(const QString& path, const QString& reason);
128
129private Q_SLOTS:
130 void onPaletteReady(const QVariantMap& tokens, const QString& wallpaperPath);
131 void onRunnerFailed(const QString& wallpaperPath, const QString& reason);
132
133private:
134 void startRun();
135 void ensureSnapshot();
136 // Returns false when nothing reached the store, so a caller does not
137 // latch a preview path the user cannot see.
138 [[nodiscard]] bool applyToStore(const QVariantMap& tokens);
139 void setPreviewPath(const QString& path);
140 void setBusy(bool busy);
141 void setLastError(const QString& error);
142 [[nodiscard]] QVariantMap storePalette() const;
143
144 QPointer<QObject> m_runner;
145 QPointer<QObject> m_store;
146 QTimer* m_debounce = nullptr;
147 QString m_persistPath;
148 QString m_pendingPath;
149 QString m_previewPath;
150 QString m_lastError;
151 QVariantMap m_snapshot;
152 bool m_hasSnapshot = false;
153 bool m_busy = false;
154};
155
156} // namespace PhosphorShellPicker
void previewFailed(const QString &path, const QString &reason)
The runner could not produce a palette for path.
void commit()
Apply: keep what is live (and what a still-pending run lands), forget the snapshot,...
void preview(const QString &wallpaperPath)
Hover a wallpaper candidate: debounced, cancels the previous run.
void previewTokens(const QVariantMap &tokens, const QString &label)
Hover a theme tile: its tokens are applied at once under label.
void setPersistPath(const QString &path)
RetintController(QObject *parent=nullptr)
Where commit() writes the committed palette, in the { "tokens": { ... } } shape PaletteStore reads.
static bool writePalette(const QString &path, const QVariantMap &tokens)
Write tokens to path atomically in the wrapped shape.
void previewApplied(const QString &path)
The store now shows path's palette.
static QVariantMap withoutBrandStops(const QVariantMap &tokens)
tokens without the four brand stops. Pure, for the tests.
void clearPreview()
The pointer left without Apply: put the snapshot back.
static QString defaultPersistPath()
The palette file the shell reads at startup and commit() writes: <AppLocalDataLocation>/palettes/curr...
Definition AppearanceLibrary.h:13