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.

130 lines
5.3KB

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