2016-02-16 19:17:04 +01:00
|
|
|
#ifndef CSM_PREFS_STATE_H
|
2015-12-06 11:18:31 +01:00
|
|
|
#define CSM_PREFS_STATE_H
|
|
|
|
|
2015-12-06 12:06:28 +01:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2015-12-15 12:19:48 +01:00
|
|
|
#include <QMutex>
|
2015-12-06 11:18:31 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
#ifndef Q_MOC_RUN
|
|
|
|
#include <components/files/configurationmanager.hpp>
|
|
|
|
#endif
|
|
|
|
|
2015-12-06 12:06:28 +01:00
|
|
|
#include "category.hpp"
|
2015-12-10 17:33:14 +01:00
|
|
|
#include "enumsetting.hpp"
|
2016-07-07 23:45:02 -04:00
|
|
|
#include "shortcutmanager.hpp"
|
2015-12-06 12:06:28 +01:00
|
|
|
|
2015-12-11 11:15:14 +01:00
|
|
|
class QColor;
|
|
|
|
|
2023-11-11 00:53:27 +01:00
|
|
|
namespace Settings
|
|
|
|
{
|
|
|
|
class Index;
|
|
|
|
}
|
|
|
|
|
2015-12-06 11:18:31 +01:00
|
|
|
namespace CSMPrefs
|
|
|
|
{
|
2015-12-08 17:21:58 +01:00
|
|
|
class IntSetting;
|
2015-12-10 10:58:38 +01:00
|
|
|
class DoubleSetting;
|
2015-12-10 13:28:48 +01:00
|
|
|
class BoolSetting;
|
2015-12-11 11:15:14 +01:00
|
|
|
class ColourSetting;
|
2016-07-07 23:45:02 -04:00
|
|
|
class ShortcutSetting;
|
2016-07-27 13:53:33 -04:00
|
|
|
class ModifierSetting;
|
2022-10-09 10:39:43 +00:00
|
|
|
class Setting;
|
|
|
|
class StringSetting;
|
2024-01-03 22:55:00 +01:00
|
|
|
class EnumSettingValue;
|
2023-11-11 00:53:27 +01:00
|
|
|
struct Values;
|
2015-12-08 17:21:58 +01:00
|
|
|
|
2015-12-15 12:19:48 +01:00
|
|
|
/// \brief User settings state
|
|
|
|
///
|
|
|
|
/// \note Access to the user settings is thread-safe once all declarations and loading has
|
|
|
|
/// been completed.
|
2015-12-06 11:18:31 +01:00
|
|
|
class State : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2015-12-08 09:56:42 +01:00
|
|
|
|
2015-12-06 11:18:31 +01:00
|
|
|
static State* sThis;
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2015-12-06 11:18:31 +01:00
|
|
|
typedef std::map<std::string, Category> Collection;
|
|
|
|
typedef Collection::iterator Iterator;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string mConfigFile;
|
2021-06-26 20:00:25 +01:00
|
|
|
const std::string mDefaultConfigFile;
|
2015-12-06 11:18:31 +01:00
|
|
|
const Files::ConfigurationManager& mConfigurationManager;
|
2016-07-07 23:45:02 -04:00
|
|
|
ShortcutManager mShortcutManager;
|
2015-12-08 09:56:42 +01:00
|
|
|
Collection mCategories;
|
|
|
|
Iterator mCurrentCategory;
|
2015-12-15 12:19:48 +01:00
|
|
|
QMutex mMutex;
|
2023-11-11 00:53:27 +01:00
|
|
|
std::unique_ptr<Settings::Index> mIndex;
|
|
|
|
std::unique_ptr<Values> mValues;
|
2015-12-06 11:18:31 +01:00
|
|
|
|
2015-12-08 09:56:42 +01:00
|
|
|
void declare();
|
2015-12-06 12:06:28 +01:00
|
|
|
|
2015-12-10 10:58:38 +01:00
|
|
|
void declareCategory(const std::string& key);
|
2015-12-08 17:21:58 +01:00
|
|
|
|
2023-11-15 08:08:06 +01:00
|
|
|
IntSetting& declareInt(Settings::SettingValue<int>& value, const QString& label);
|
|
|
|
|
2023-11-15 23:45:56 +01:00
|
|
|
DoubleSetting& declareDouble(Settings::SettingValue<double>& value, const QString& label);
|
2015-12-10 13:28:48 +01:00
|
|
|
|
2023-11-15 09:26:59 +01:00
|
|
|
BoolSetting& declareBool(Settings::SettingValue<bool>& value, const QString& label);
|
2015-12-10 17:33:14 +01:00
|
|
|
|
2024-01-03 22:55:00 +01:00
|
|
|
EnumSetting& declareEnum(EnumSettingValue& value, const QString& label);
|
2015-12-11 11:15:14 +01:00
|
|
|
|
2024-01-05 12:51:48 +01:00
|
|
|
ColourSetting& declareColour(Settings::SettingValue<std::string>& value, const QString& label);
|
2016-07-07 23:45:02 -04:00
|
|
|
|
2024-01-05 12:57:04 +01:00
|
|
|
ShortcutSetting& declareShortcut(Settings::SettingValue<std::string>& value, const QString& label);
|
2021-04-15 00:37:00 +03:00
|
|
|
|
2023-11-15 09:32:18 +01:00
|
|
|
StringSetting& declareString(Settings::SettingValue<std::string>& value, const QString& label);
|
2016-07-27 13:53:33 -04:00
|
|
|
|
2023-11-15 08:23:06 +01:00
|
|
|
ModifierSetting& declareModifier(Settings::SettingValue<std::string>& value, const QString& label);
|
2015-12-11 11:32:55 +01:00
|
|
|
|
2023-11-10 13:09:37 +01:00
|
|
|
void declareSubcategory(const QString& label);
|
2015-12-08 17:21:58 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2015-12-06 11:18:31 +01:00
|
|
|
State(const Files::ConfigurationManager& configurationManager);
|
|
|
|
|
2023-11-12 00:42:58 +01:00
|
|
|
State(const State&) = delete;
|
|
|
|
|
2015-12-06 11:18:31 +01:00
|
|
|
~State();
|
|
|
|
|
2023-11-12 00:42:58 +01:00
|
|
|
State& operator=(const State&) = delete;
|
|
|
|
|
2015-12-06 11:18:31 +01:00
|
|
|
void save();
|
|
|
|
|
2015-12-08 09:56:42 +01:00
|
|
|
Iterator begin();
|
|
|
|
|
|
|
|
Iterator end();
|
2015-12-06 12:06:28 +01:00
|
|
|
|
2016-07-07 23:45:02 -04:00
|
|
|
ShortcutManager& getShortcutManager();
|
|
|
|
|
2015-12-11 11:50:06 +01:00
|
|
|
Category& operator[](const std::string& key);
|
2015-12-08 12:04:45 +01:00
|
|
|
|
2015-12-08 17:21:58 +01:00
|
|
|
void update(const Setting& setting);
|
|
|
|
|
2015-12-06 11:18:31 +01:00
|
|
|
static State& get();
|
2015-12-08 17:21:58 +01:00
|
|
|
|
2017-05-09 19:50:16 +12:00
|
|
|
void resetCategory(const std::string& category);
|
|
|
|
|
|
|
|
void resetAll();
|
|
|
|
|
2015-12-08 17:21:58 +01:00
|
|
|
signals:
|
|
|
|
|
2015-12-12 12:05:56 +01:00
|
|
|
void settingChanged(const CSMPrefs::Setting* setting);
|
2015-12-06 11:18:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// convenience function
|
|
|
|
State& get();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|