SettingsComponent.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 QString getClientName();
  52. // host commands
  53. Q_SLOT Q_INVOKABLE void cycleSettingCommand(const QString& args);
  54. Q_SLOT Q_INVOKABLE void setSettingCommand(const QString& args);
  55. void updatePossibleValues(const QString& sectionID, const QString& key, const QVariantList& possibleValues);
  56. void saveSettings();
  57. void saveStorage();
  58. void load();
  59. // Fired when a section's description is updated.
  60. Q_SIGNAL void groupUpdate(const QString& section, const QVariant& description);
  61. // Fired when a subset of a section's values are updated. The values parameter will
  62. // contain the names of the changed values as keys, and the new settings values as
  63. // map values. Settings which are part of the section, but did not change, are not
  64. // part of the map.
  65. Q_SIGNAL void sectionValueUpdate(const QString& section, const QVariantMap& values);
  66. // A hack to load a value from the config file at very early init time, before
  67. // the SettingsComponent is created.
  68. //
  69. static QVariant readPreinitValue(const QString& sectionID, const QString& key);
  70. // Moves the current settings file to plexmediaplayer.conf.old to make way for new
  71. // configuration.
  72. //
  73. static bool resetAndSaveOldConfiguration();
  74. QString oldestPreviousVersion() const
  75. {
  76. return m_oldestPreviousVersion;
  77. }
  78. private:
  79. explicit SettingsComponent(QObject *parent = nullptr);
  80. bool loadDescription();
  81. void parseSection(const QJsonObject& sectionObject);
  82. int platformMaskFromObject(const QJsonObject& object);
  83. Platform platformFromString(const QString& platformString);
  84. void saveSection(SettingsSection* section);
  85. void setupVersion();
  86. QMap<QString, SettingsSection*> m_sections;
  87. int m_settingsVersion;
  88. int m_sectionIndex;
  89. QString m_oldestPreviousVersion;
  90. void loadConf(const QString& path, bool storage);
  91. };
  92. #endif // SETTINGSCOMPONENT_H