SettingsComponent.h 4.1 KB

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