mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Use json file based themes instead of code to create them (theme editor + theme mode settings)
This commit is contained in:
57
common/themes/theme_repository.h
Normal file
57
common/themes/theme_repository.h
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef THEME_REPOSITORY_H
|
||||
#define THEME_REPOSITORY_H
|
||||
|
||||
#include "theme_meta.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
struct ThemeListEntry {
|
||||
QString id;
|
||||
QString displayName;
|
||||
ThemeVariant variant;
|
||||
bool isBuiltin;
|
||||
};
|
||||
|
||||
class ThemeRepository
|
||||
{
|
||||
public:
|
||||
explicit ThemeRepository(const QString &qrcPrefix, const QString &userThemesDir);
|
||||
|
||||
QList<ThemeListEntry> availableThemes() const;
|
||||
bool contains(const QString &themeId) const;
|
||||
QJsonObject loadThemeJson(const QString &themeId) const;
|
||||
|
||||
QString saveUserTheme(QJsonObject themeJson);
|
||||
bool deleteUserTheme(const QString &themeId);
|
||||
QString importThemeFromFile(const QString &filePath);
|
||||
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
QString qrcPrefix;
|
||||
QString userThemesDir;
|
||||
|
||||
struct BuiltinEntry {
|
||||
QString id;
|
||||
QString resourcePath;
|
||||
ThemeMeta meta;
|
||||
};
|
||||
QList<BuiltinEntry> builtins;
|
||||
|
||||
struct UserEntry {
|
||||
QString id;
|
||||
QString filePath;
|
||||
ThemeMeta meta;
|
||||
};
|
||||
QList<UserEntry> userThemes;
|
||||
|
||||
void scanBuiltins();
|
||||
void scanUserThemes();
|
||||
static ThemeMeta extractMeta(const QJsonObject &json);
|
||||
static QJsonObject readJsonFile(const QString &path);
|
||||
QString filePathForUserTheme(const QString &uuid) const;
|
||||
};
|
||||
|
||||
#endif // THEME_REPOSITORY_H
|
||||
Reference in New Issue
Block a user