The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. Manages a collection of properties.
  21. This is a slightly higher-level wrapper for managing PropertiesFile objects.
  22. It holds two different PropertiesFile objects internally, one for user-specific
  23. settings (stored in your user directory), and one for settings that are common to
  24. all users (stored in a folder accessible to all users).
  25. The class manages the creation of these files on-demand, allowing access via the
  26. getUserSettings() and getCommonSettings() methods.
  27. After creating an instance of an ApplicationProperties object, you should first
  28. of all call setStorageParameters() to tell it the parameters to use to create
  29. its files.
  30. @see PropertiesFile
  31. */
  32. class JUCE_API ApplicationProperties
  33. {
  34. public:
  35. //==============================================================================
  36. /**
  37. Creates an ApplicationProperties object.
  38. Before using it, you must call setStorageParameters() to give it the info
  39. it needs to create the property files.
  40. */
  41. ApplicationProperties();
  42. /** Destructor. */
  43. ~ApplicationProperties();
  44. //==============================================================================
  45. /** Gives the object the information it needs to create the appropriate properties files.
  46. See the PropertiesFile::Options class for details about what options you need to set.
  47. */
  48. void setStorageParameters (const PropertiesFile::Options& options);
  49. /** Returns the current storage parameters.
  50. @see setStorageParameters
  51. */
  52. const PropertiesFile::Options& getStorageParameters() const noexcept { return options; }
  53. //==============================================================================
  54. /** Returns the user settings file.
  55. The first time this is called, it will create and load the properties file.
  56. Note that when you search the user PropertiesFile for a value that it doesn't contain,
  57. the common settings are used as a second-chance place to look. This is done via the
  58. PropertySet::setFallbackPropertySet() method - by default the common settings are set
  59. to the fallback for the user settings.
  60. @see getCommonSettings
  61. */
  62. PropertiesFile* getUserSettings();
  63. /** Returns the common settings file.
  64. The first time this is called, it will create and load the properties file.
  65. @param returnUserPropsIfReadOnly if this is true, and the common properties file is
  66. read-only (e.g. because the user doesn't have permission to write
  67. to shared files), then this will return the user settings instead,
  68. (like getUserSettings() would do). This is handy if you'd like to
  69. write a value to the common settings, but if that's no possible,
  70. then you'd rather write to the user settings than none at all.
  71. If returnUserPropsIfReadOnly is false, this method will always return
  72. the common settings, even if any changes to them can't be saved.
  73. @see getUserSettings
  74. */
  75. PropertiesFile* getCommonSettings (bool returnUserPropsIfReadOnly);
  76. //==============================================================================
  77. /** Saves both files if they need to be saved.
  78. @see PropertiesFile::saveIfNeeded
  79. */
  80. bool saveIfNeeded();
  81. /** Flushes and closes both files if they are open.
  82. This flushes any pending changes to disk with PropertiesFile::saveIfNeeded()
  83. and closes both files. They will then be re-opened the next time getUserSettings()
  84. or getCommonSettings() is called.
  85. */
  86. void closeFiles();
  87. private:
  88. //==============================================================================
  89. PropertiesFile::Options options;
  90. ScopedPointer<PropertiesFile> userProps, commonProps;
  91. int commonSettingsAreReadOnly;
  92. void openFiles();
  93. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationProperties)
  94. };