SettingsComponent.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_STATE "state"
  11. #define SETTINGS_SECTION_PATH "path"
  12. #define SETTINGS_SECTION_WEBCLIENT "webclient"
  13. #define SETTINGS_SECTION_SUBTITLES "subtitles"
  14. #define SETTINGS_SECTION_OVERRIDES "overrides"
  15. #define SETTINGS_SECTION_CEC "cec"
  16. #define SETTINGS_SECTION_OPENELEC "openelec"
  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. // JS interface
  37. Q_INVOKABLE void setValue(const QString& sectionID, const QString& key, const QVariant& value);
  38. Q_INVOKABLE void setValues(const QVariantMap& options);
  39. Q_INVOKABLE QVariant value(const QString& sectionID, const QString& key);
  40. Q_INVOKABLE QVariant allValues(const QString& section = "");
  41. Q_INVOKABLE void removeValue(const QString& sectionOrKey);
  42. Q_INVOKABLE void resetToDefault();
  43. Q_INVOKABLE QVariantList settingDescriptions();
  44. // host commands
  45. Q_SLOT void cycleSetting(const QString& args);
  46. void updatePossibleValues(const QString& sectionID, const QString& key, const QVariantList& possibleValues);
  47. void saveSettings();
  48. void saveStorage();
  49. void load();
  50. Q_SIGNAL void groupUpdate(const QString& section, const QVariant& description);
  51. void setUserRoleList(const QStringList& userRoles);
  52. // A hack to load a value from the config file at very early init time, before
  53. // the SettingsComponent is created.
  54. //
  55. static QVariant readPreinitValue(const QString& sectionID, const QString& key);
  56. // Moves the current settings file to plexmediaplayer.conf.old to make way for new
  57. // configuration.
  58. //
  59. static bool resetAndSaveOldConfiguration();
  60. private:
  61. explicit SettingsComponent(QObject *parent = nullptr);
  62. bool loadDescription();
  63. void parseSection(const QJsonObject& sectionObject);
  64. int platformMaskFromObject(const QJsonObject& object);
  65. Platform platformFromString(const QString& platformString);
  66. void saveSection(SettingsSection* section);
  67. QMap<QString, SettingsSection*> m_sections;
  68. int m_settingsVersion;
  69. int m_sectionIndex;
  70. void loadConf(const QString& path, bool storage);
  71. };
  72. #endif // SETTINGSCOMPONENT_H