-
-
Notifications
You must be signed in to change notification settings - Fork 323
/
SettingsComponent.h
121 lines (96 loc) · 4.11 KB
/
SettingsComponent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef SETTINGSCOMPONENT_H
#define SETTINGSCOMPONENT_H
#include <QObject>
#include "utils/Utils.h"
#include "ComponentManager.h"
#include "SettingsValue.h"
#define SETTINGS_SECTION_AUDIO "audio"
#define SETTINGS_SECTION_VIDEO "video"
#define SETTINGS_SECTION_MAIN "main"
#define SETTINGS_SECTION_SYSTEM "system"
#define SETTINGS_SECTION_STATE "state"
#define SETTINGS_SECTION_PATH "path"
#define SETTINGS_SECTION_WEBCLIENT "webclient"
#define SETTINGS_SECTION_SUBTITLES "subtitles"
#define SETTINGS_SECTION_OVERRIDES "overrides"
#define SETTINGS_SECTION_CEC "cec"
#define SETTINGS_SECTION_APPLEREMOTE "appleremote"
#define SETTINGS_SECTION_OTHER "other"
#define AUDIO_DEVICE_TYPE_BASIC "basic"
#define AUDIO_DEVICE_TYPE_SPDIF "spdif"
#define AUDIO_DEVICE_TYPE_HDMI "hdmi"
class SettingsSection;
///////////////////////////////////////////////////////////////////////////////////////////////////
class SettingsComponent : public ComponentBase
{
Q_OBJECT
DEFINE_SINGLETON(SettingsComponent);
public:
bool componentInitialize() override;
void componentPostInitialize() override;
const char* componentName() override { return "settings"; }
bool componentExport() override { return true; }
SettingsSection* getSection(const QString& sectionID)
{
return m_sections.value(sectionID, nullptr);
}
void setCommandLineValues(const QStringList& values);
// JS interface
Q_INVOKABLE void setValue(const QString& sectionID, const QString& key, const QVariant& value);
Q_INVOKABLE void setValues(const QVariantMap& options);
Q_INVOKABLE QVariant value(const QString& sectionID, const QString& key);
Q_INVOKABLE QVariant orderedSections();
Q_INVOKABLE QVariant allValues(const QString& section = "");
// Note: the naming "remove" is a lie - it will remove the affected keys only if they are not
// declared in settings_descriptions.json. Also, sections are never removed, even if they
// remain empty.
Q_INVOKABLE void removeValue(const QString& sectionOrKey);
Q_INVOKABLE void resetToDefaultAll();
Q_INVOKABLE void resetToDefault(const QString& sectionID);
Q_INVOKABLE QVariantList settingDescriptions();
Q_INVOKABLE QString getWebClientUrl(bool desktop);
Q_INVOKABLE QString getExtensionPath();
Q_INVOKABLE QString getClientName();
Q_INVOKABLE bool ignoreSSLErrors();
Q_INVOKABLE bool autodetectCertBundle();
// host commands
Q_SLOT Q_INVOKABLE void cycleSettingCommand(const QString& args);
Q_SLOT Q_INVOKABLE void setSettingCommand(const QString& args);
void updatePossibleValues(const QString& sectionID, const QString& key, const QVariantList& possibleValues);
void saveSettings();
void saveStorage();
void load();
// Fired when a section's description is updated.
Q_SIGNAL void groupUpdate(const QString& section, const QVariant& description);
// Fired when a subset of a section's values are updated. The values parameter will
// contain the names of the changed values as keys, and the new settings values as
// map values. Settings which are part of the section, but did not change, are not
// part of the map.
Q_SIGNAL void sectionValueUpdate(const QString& section, const QVariantMap& values);
// A hack to load a value from the config file at very early init time, before
// the SettingsComponent is created.
//
static QVariant readPreinitValue(const QString& sectionID, const QString& key);
// Moves the current settings file to plexmediaplayer.conf.old to make way for new
// configuration.
//
static bool resetAndSaveOldConfiguration();
QString oldestPreviousVersion() const
{
return m_oldestPreviousVersion;
}
private:
explicit SettingsComponent(QObject *parent = nullptr);
bool loadDescription();
void parseSection(const QJsonObject& sectionObject);
int platformMaskFromObject(const QJsonObject& object);
Platform platformFromString(const QString& platformString);
void saveSection(SettingsSection* section);
void setupVersion();
QMap<QString, SettingsSection*> m_sections;
int m_settingsVersion;
int m_sectionIndex;
QString m_oldestPreviousVersion;
void loadConf(const QString& path, bool storage);
};
#endif // SETTINGSCOMPONENT_H