settings: use enums for ChatTheme/FontSize, translate choices (#2667)

Also change SuggestionMode to work the same way.

Signed-off-by: Adam Treat <treat.adam@gmail.com>
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
Co-authored-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
AT
2024-07-16 16:12:44 -04:00
committed by GitHub
parent f0c754bece
commit 88a206ab93
9 changed files with 372 additions and 258 deletions

View File

@@ -16,12 +16,29 @@
namespace MySettingsEnums {
Q_NAMESPACE
/* NOTE: values of these enums are used as indices for the corresponding combo boxes in
* ApplicationSettings.qml, as well as the corresponding name lists in mysettings.cpp */
enum class SuggestionMode {
LocalDocsOnly = 0,
On = 1,
Off = 2,
On = 1,
Off = 2,
};
Q_ENUM_NS(SuggestionMode)
enum class ChatTheme {
Light = 0,
Dark = 1,
LegacyDark = 2,
};
Q_ENUM_NS(ChatTheme)
enum class FontSize {
Small = 0,
Medium = 1,
Large = 2,
};
Q_ENUM_NS(FontSize)
}
using namespace MySettingsEnums;
@@ -33,10 +50,8 @@ class MySettings : public QObject
Q_PROPERTY(bool serverChat READ serverChat WRITE setServerChat NOTIFY serverChatChanged)
Q_PROPERTY(QString modelPath READ modelPath WRITE setModelPath NOTIFY modelPathChanged)
Q_PROPERTY(QString userDefaultModel READ userDefaultModel WRITE setUserDefaultModel NOTIFY userDefaultModelChanged)
// FIXME: This should be changed to an enum to allow translations to work
Q_PROPERTY(QString chatTheme READ chatTheme WRITE setChatTheme NOTIFY chatThemeChanged)
// FIXME: This should be changed to an enum to allow translations to work
Q_PROPERTY(QString fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(ChatTheme chatTheme READ chatTheme WRITE setChatTheme NOTIFY chatThemeChanged)
Q_PROPERTY(FontSize fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(QString languageAndLocale READ languageAndLocale WRITE setLanguageAndLocale NOTIFY languageAndLocaleChanged)
Q_PROPERTY(bool forceMetal READ forceMetal WRITE setForceMetal NOTIFY forceMetalChanged)
Q_PROPERTY(QString lastVersionStarted READ lastVersionStarted WRITE setLastVersionStarted NOTIFY lastVersionStartedChanged)
@@ -131,10 +146,10 @@ public:
void setModelPath(const QString &value);
QString userDefaultModel() const;
void setUserDefaultModel(const QString &value);
QString chatTheme() const;
void setChatTheme(const QString &value);
QString fontSize() const;
void setFontSize(const QString &value);
ChatTheme chatTheme() const;
void setChatTheme(ChatTheme value);
FontSize fontSize() const;
void setFontSize(FontSize value);
bool forceMetal() const;
void setForceMetal(bool value);
QString device();
@@ -144,7 +159,7 @@ public:
int32_t gpuLayers() const;
void setGpuLayers(int32_t value);
SuggestionMode suggestionMode() const;
void setSuggestionMode(SuggestionMode mode);
void setSuggestionMode(SuggestionMode value);
QString languageAndLocale() const;
void setLanguageAndLocale(const QString &bcp47Name = QString()); // called on startup with QString()
@@ -239,6 +254,7 @@ private:
QVariant getBasicSetting(const QString &name) const;
void setBasicSetting(const QString &name, const QVariant &value, std::optional<QString> signal = std::nullopt);
int getEnumSetting(const QString &setting, const QStringList &valueNames) const;
QVariant getModelSetting(const QString &name, const ModelInfo &info) const;
void setModelSetting(const QString &name, const ModelInfo &info, const QVariant &value, bool force,
bool signal = false);