From 398cef5f8fc452fb390445fae601f31d916d6777 Mon Sep 17 00:00:00 2001 From: weeman Date: Sun, 17 Aug 2025 13:01:26 +0200 Subject: [PATCH] Extract list of valid themes Signed-off-by: weeman --- src/UserSettingsPage.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 705a605b..3f348d61 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -25,6 +25,12 @@ #include "config/nheko.h" +QStringList themes{ + QStringLiteral("light"), + QStringLiteral("dark"), + QStringLiteral("system"), +}; + QSharedPointer UserSettings::instance_; UserSettings::UserSettings() @@ -640,7 +646,7 @@ UserSettings::setShowImage(ShowImage state) void UserSettings::setTheme(QString theme) { - if (theme == theme_) + if (theme == theme_ || !themes.contains(theme)) return; theme_ = theme; save(); @@ -1182,12 +1188,7 @@ UserSettingsModel::data(const QModelIndex &index, int role) const } else if (role == Value) { switch (index.row()) { case Theme: - return QStringList{ - QStringLiteral("light"), - QStringLiteral("dark"), - QStringLiteral("system"), - } - .indexOf(i->theme()); + return themes.indexOf(i->theme()); case ScaleFactor: return utils::scaleFactor(); case MessageHoverHighlight: @@ -1741,14 +1742,10 @@ UserSettingsModel::setData(const QModelIndex &index, const QVariant &value, int if (role == Value) { switch (index.row()) { case Theme: { - if (value == 0) { - i->setTheme("light"); - return true; - } else if (value == 1) { - i->setTheme("dark"); - return true; - } else if (value == 2) { - i->setTheme("system"); + auto idx = value.toInt(); + + if (idx >= 0 && idx < themes.size()) { + i->setTheme(themes[idx]); return true; } else return false;