Extract list of valid themes

Signed-off-by: weeman <weeman@frankfurt.ccc.de>
This commit is contained in:
weeman 2025-08-17 13:01:26 +02:00
parent f59f77a21e
commit 398cef5f8f
No known key found for this signature in database
GPG key ID: 77942618835C6903

View file

@ -25,6 +25,12 @@
#include "config/nheko.h" #include "config/nheko.h"
QStringList themes{
QStringLiteral("light"),
QStringLiteral("dark"),
QStringLiteral("system"),
};
QSharedPointer<UserSettings> UserSettings::instance_; QSharedPointer<UserSettings> UserSettings::instance_;
UserSettings::UserSettings() UserSettings::UserSettings()
@ -640,7 +646,7 @@ UserSettings::setShowImage(ShowImage state)
void void
UserSettings::setTheme(QString theme) UserSettings::setTheme(QString theme)
{ {
if (theme == theme_) if (theme == theme_ || !themes.contains(theme))
return; return;
theme_ = theme; theme_ = theme;
save(); save();
@ -1182,12 +1188,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const
} else if (role == Value) { } else if (role == Value) {
switch (index.row()) { switch (index.row()) {
case Theme: case Theme:
return QStringList{ return themes.indexOf(i->theme());
QStringLiteral("light"),
QStringLiteral("dark"),
QStringLiteral("system"),
}
.indexOf(i->theme());
case ScaleFactor: case ScaleFactor:
return utils::scaleFactor(); return utils::scaleFactor();
case MessageHoverHighlight: case MessageHoverHighlight:
@ -1741,14 +1742,10 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int
if (role == Value) { if (role == Value) {
switch (index.row()) { switch (index.row()) {
case Theme: { case Theme: {
if (value == 0) { auto idx = value.toInt();
i->setTheme("light");
return true; if (idx >= 0 && idx < themes.size()) {
} else if (value == 1) { i->setTheme(themes[idx]);
i->setTheme("dark");
return true;
} else if (value == 2) {
i->setTheme("system");
return true; return true;
} else } else
return false; return false;