-
-
Notifications
You must be signed in to change notification settings - Fork 131
Settings system
Librum's settings system is straightforward. All settings are saved in local files that are managed by Qt's QSettings class. Librum simply provides a wrapper around this with it's SettingsService class, abstracting it to three operations: read, write and reset.
To access any data from the SettingsService, you must provide a key, which is an enum value equivalent to the setting's name.
Instead of utilizing raw strings to access settings, as was originally intended, Librum uses enums to represent all settings (listed here). These enums exist solely for the purpose of avoiding having to deal with raw strings. Under the hood, each enum key is dynamically converted to a string and stored as such. This is done by utilizing Qt's QMetaEnum class.
In Librum, settings are classified into groups (e.g. Appearance, General, Shortcuts, ...). These groups are also enum values, which have the same advantages as keys (The groups enum is here).
When you read or write a setting, you must specify the group it belongs to. This is done to improve the structure of the settings system, as well as due to performance reasons.
When the user logs into the application, the SettingsService is notified and loads in values from several default settings files.
These default settings files are simple json files, containing numerous default settings, in the format: "settingName": "settingValue"
. There is a default settings file for each settings group, e.g. "default_appearance_settings.json".
When the application starts up and Librum loads these json files into memory, it iterates through their key-value pairs, and checks if a setting with this key already exists in the user's unique settings file. If a setting with the given key already exists, nothing happens; if there isn't, Librum adds the key and its value to the user's settings file.
Because none of the default keys exist in the user's settings file at that time, the user gets the default settings on the first login.
Simultaneously, the system remains very flexible and is able to automatically add new default settings which are introduced by, say, a new version of Librum to the user's already existing settings.