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) 2013 - Raw Material Software 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. #ifndef __JUCE_APPLICATIONPROPERTIES_JUCEHEADER__
  18. #define __JUCE_APPLICATIONPROPERTIES_JUCEHEADER__
  19. #include "juce_PropertiesFile.h"
  20. //==============================================================================
  21. /**
  22. Manages a collection of properties.
  23. This is a slightly higher-level wrapper for managing PropertiesFile objects.
  24. It holds two different PropertiesFile objects internally, one for user-specific
  25. settings (stored in your user directory), and one for settings that are common to
  26. all users (stored in a folder accessible to all users).
  27. The class manages the creation of these files on-demand, allowing access via the
  28. getUserSettings() and getCommonSettings() methods.
  29. After creating an instance of an ApplicationProperties object, you should first
  30. of all call setStorageParameters() to tell it the parameters to use to create
  31. its files.
  32. @see PropertiesFile
  33. */
  34. class JUCE_API ApplicationProperties
  35. {
  36. public:
  37. //==============================================================================
  38. /**
  39. Creates an ApplicationProperties object.
  40. Before using it, you must call setStorageParameters() to give it the info
  41. it needs to create the property files.
  42. */
  43. ApplicationProperties();
  44. /** Destructor. */
  45. ~ApplicationProperties();
  46. //==============================================================================
  47. /** Gives the object the information it needs to create the appropriate properties files.
  48. See the PropertiesFile::Options class for details about what options you need to set.
  49. */
  50. void setStorageParameters (const PropertiesFile::Options& options);
  51. //==============================================================================
  52. /** Returns the user settings file.
  53. The first time this is called, it will create and load the properties file.
  54. Note that when you search the user PropertiesFile for a value that it doesn't contain,
  55. the common settings are used as a second-chance place to look. This is done via the
  56. PropertySet::setFallbackPropertySet() method - by default the common settings are set
  57. to the fallback for the user settings.
  58. @see getCommonSettings
  59. */
  60. PropertiesFile* getUserSettings();
  61. /** Returns the common settings file.
  62. The first time this is called, it will create and load the properties file.
  63. @param returnUserPropsIfReadOnly if this is true, and the common properties file is
  64. read-only (e.g. because the user doesn't have permission to write
  65. to shared files), then this will return the user settings instead,
  66. (like getUserSettings() would do). This is handy if you'd like to
  67. write a value to the common settings, but if that's no possible,
  68. then you'd rather write to the user settings than none at all.
  69. If returnUserPropsIfReadOnly is false, this method will always return
  70. the common settings, even if any changes to them can't be saved.
  71. @see getUserSettings
  72. */
  73. PropertiesFile* getCommonSettings (bool returnUserPropsIfReadOnly);
  74. //==============================================================================
  75. /** Saves both files if they need to be saved.
  76. @see PropertiesFile::saveIfNeeded
  77. */
  78. bool saveIfNeeded();
  79. /** Flushes and closes both files if they are open.
  80. This flushes any pending changes to disk with PropertiesFile::saveIfNeeded()
  81. and closes both files. They will then be re-opened the next time getUserSettings()
  82. or getCommonSettings() is called.
  83. */
  84. void closeFiles();
  85. private:
  86. //==============================================================================
  87. PropertiesFile::Options options;
  88. ScopedPointer <PropertiesFile> userProps, commonProps;
  89. int commonSettingsAreReadOnly;
  90. void openFiles();
  91. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationProperties)
  92. };
  93. #endif // __JUCE_APPLICATIONPROPERTIES_JUCEHEADER__